Java Code Examples for java.awt.Component

The following code examples are extracted from open source projects. You can click to vote up the examples that are useful to you.

Example 1

From project addis, under directory /application/src/main/java/org/drugis/addis/gui/renderer/.

Source file: BRATForestCellRenderer.java

  18 
vote

@Override public Component getTableCellRendererComponent(JTable table,Object value,boolean isSelected,boolean hasFocus,int row,int column){
  Component superRenderer=super.getTableCellRendererComponent(table,value,isSelected,hasFocus,row,column);
  final Color bg=superRenderer.getBackground();
  final Color fg=superRenderer.getForeground();
  final BRATForest forest=(BRATForest)value;
  JPanel panel=new ForestPlotTableCell(forest,bg,fg);
  return panel;
}
 

Example 2

From project autopsy, under directory /HashDatabase/src/org/sleuthkit/autopsy/hashdatabase/.

Source file: HashDbManagementPanel.java

  18 
vote

@Override public Component prepareRenderer(TableCellRenderer renderer,int row,int column){
  Component c=super.prepareRenderer(renderer,row,column);
  JComponent jc=(JComponent)c;
  jc.setToolTipText((String)getValueAt(row,column));
  return c;
}
 

Example 3

From project beam-meris-icol, under directory /src/main/java/org/esa/beam/meris/icol/ui/.

Source file: IcolForm.java

  18 
vote

@Override public Component getListCellRendererComponent(JList list,Object value,int index,boolean isSelected,boolean cellHasFocus){
  final Component cellRendererComponent=super.getListCellRendererComponent(list,value,index,isSelected,cellHasFocus);
  if (cellRendererComponent instanceof JLabel && value instanceof AeArea) {
    final JLabel label=(JLabel)cellRendererComponent;
    final AeArea aeArea=(AeArea)value;
    label.setText(aeArea.getLabel());
  }
  return cellRendererComponent;
}
 

Example 4

From project beanmill_1, under directory /src/main/java/com/traxel/lumbermill/filter/.

Source file: TreeControl.java

  18 
vote

/** 
 * DOCUMENT ME!
 * @return  DOCUMENT ME!
 */
private List getLocations(){
  final List locations;
  Component parent;
  locations=new ArrayList();
  parent=TREE_VIEW;
  while (parent != null) {
    locations.add(parent.getLocation());
    parent=parent.getParent();
  }
  return locations;
}
 

Example 5

From project ceres, under directory /ceres-glayer/src/main/java/com/bc/ceres/glayer/swing/.

Source file: WakefulComponent.java

  18 
vote

@Override public void remove(int index){
  final Component comp=getComponent(index);
  comp.removeComponentListener(childResizeHandler);
  deinstallHitHandler(comp);
  super.remove(index);
}
 

Example 6

From project Clotho-Core, under directory /ClothoApps/PluginManager/src/org/clothocore/tool/pluginmanager/gui/.

Source file: StackLayout.java

  18 
vote

public void layoutContainer(Container parent){
synchronized (parent.getTreeLock()) {
    int width=parent.getWidth();
    int height=parent.getHeight();
    Rectangle bounds=new Rectangle(0,0,width,height);
    int componentsCount=components.size();
    for (int i=0; i < componentsCount; i++) {
      Component comp=components.get(i);
      comp.setBounds(bounds);
      parent.setComponentZOrder(comp,componentsCount - i - 1);
    }
  }
}
 

Example 7

From project codjo-data-process, under directory /codjo-data-process-gui/src/main/java/net/codjo/dataprocess/gui/launcher/.

Source file: ManagerStateModifier.java

  18 
vote

private void enableAction(boolean enable){
  for (int i=0; i < popupMenu.getComponentCount(); i++) {
    Component component=popupMenu.getComponent(i);
    if (component instanceof JMenuItem) {
      Action action=((JMenuItem)component).getAction();
      if (action instanceof DesactivableAction && ((DesactivableAction)action).isDesactivable()) {
        action.setEnabled(enable);
      }
    }
  }
}
 

Example 8

From project codjo-standalone-common, under directory /src/main/java/net/codjo/utils/sql/.

Source file: DataFormater.java

  18 
vote

protected Object getRenderedValue(JTable table,int row,int col){
  TableCellRenderer renderer=table.getCellRenderer(row,table.convertColumnIndexToView(col));
  Object value=table.getValueAt(row,col);
  if (renderer != null && renderer instanceof NumberFormatRenderer) {
    Component component=renderer.getTableCellRendererComponent(table,value,false,false,row,col);
    if (component instanceof JLabel) {
      return ((JLabel)component).getText();
    }
  }
  return value;
}
 

Example 9

From project contribution_eevolution_smart_browser, under directory /client/src/org/compiere/apps/.

Source file: WindowManager.java

  18 
vote

public void componentHidden(ComponentEvent e){
  Component c=e.getComponent();
  if (c instanceof CFrame) {
    c.removeComponentListener(this);
    ((CFrame)c).removeWindowListener(this);
    windowManager.remove((CFrame)c);
  }
}
 

Example 10

From project dawn-common, under directory /org.dawb.hdf5/src/ncsa/hdf/view/.

Source file: DefaultTreeView.java

  18 
vote

/** 
 * disable/enable GUI components 
 */
private static void setEnabled(List<JMenuItem> list,boolean b){
  Component item=null;
  Iterator<JMenuItem> it=list.iterator();
  while (it.hasNext()) {
    item=it.next();
    item.setEnabled(b);
  }
}
 

Example 11

From project dawn-isencia, under directory /com.isencia.passerelle.commons/src/main/java/com/isencia/util/swing/layout/.

Source file: AbsoluteLayout.java

  18 
vote

/** 
 * Lays out the container in the specified panel.
 * @param parent the component which needs to be laid out
 */
public void layoutContainer(Container parent){
  for (Enumeration<Component> e=constraints.keys(); e.hasMoreElements(); ) {
    Component comp=e.nextElement();
    AbsoluteConstraints ac=constraints.get(comp);
    Dimension size=comp.getPreferredSize();
    int width=ac.getWidth();
    if (width == -1)     width=size.width;
    int height=ac.getHeight();
    if (height == -1)     height=size.height;
    comp.setBounds(ac.x,ac.y,width,height);
  }
}
 

Example 12

From project BMach, under directory /src/jsyntaxpane/actions/gui/.

Source file: MembersListRenderer.java

  17 
vote

@Override public Component getListCellRendererComponent(final JList list,Object value,final int index,final boolean isSelected,boolean cellHasFocus){
  Color back=(index % 2 == 1) ? list.getBackground() : evensColor;
  if (value instanceof Method) {
    final Method method=(Method)value;
    return new MethodCell(list,isSelected,back,method,dlg.getTheClass());
  }
 else   if (value instanceof Field) {
    Field field=(Field)value;
    return new FieldCell(list,isSelected,back,field,dlg.getTheClass());
  }
 else   if (value instanceof Constructor) {
    Constructor cons=(Constructor)value;
    return new ConstructorCell(list,isSelected,back,cons,dlg.getTheClass());
  }
 else {
    Component comp=super.getListCellRendererComponent(list,value,index,isSelected,cellHasFocus);
    comp.setBackground(back);
    return comp;
  }
}
 

Example 13

From project coffeescript-netbeans, under directory /src/coffeescript/nb/project/sample/.

Source file: CoffeeScriptApplicationWizardIterator.java

  17 
vote

public void initialize(WizardDescriptor wiz){
  this.wiz=wiz;
  index=0;
  panels=createPanels();
  String[] steps=createSteps();
  for (int i=0; i < panels.length; i++) {
    Component c=panels[i].getComponent();
    if (steps[i] == null) {
      steps[i]=c.getName();
    }
    if (c instanceof JComponent) {
      JComponent jc=(JComponent)c;
      jc.putClientProperty("WizardPanel_contentSelectedIndex",new Integer(i));
      jc.putClientProperty("WizardPanel_contentData",steps);
    }
  }
}
 

Example 14

From project dolphin, under directory /texcel/svn/com/tan/util/.

Source file: TanUtil.java

  17 
vote

/** 
 * Chose the directory.
 * @param dir	default directory.
 * @param title	Dialog title.
 * @return
 */
public static File chooseDir(final String dir,final String title){
  Component parent=null;
  JFileChooser chooser=new JFileChooser(dir);
  chooser.setDialogTitle(title);
  javax.swing.filechooser.FileFilter dirFilter=new javax.swing.filechooser.FileFilter(){
    public boolean accept(    File f){
      return f.isDirectory();
    }
    public String getDescription(){
      return "";
    }
  }
;
  chooser.setFileFilter(dirFilter);
  chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
  if (chooser.showOpenDialog(parent) == JFileChooser.APPROVE_OPTION) {
    return chooser.getSelectedFile();
  }
  return null;
}
 

Example 15

From project Android-DB-Editor, under directory /src/com/troido/dbeditor/.

Source file: CellRenderer.java

  15 
vote

@Override public Component getTreeCellRendererComponent(JTree tree,Object value,boolean selected,boolean expanded,boolean leaf,int row,boolean hasFocus){
  JLabel label=new JLabel();
  TreeObject obj=(TreeObject)((DefaultMutableTreeNode)value).getUserObject();
  label.setIcon(new ImageIcon(getClass().getResource("/" + obj.getIconPath())));
  label.setText(obj.getName());
  return label;
}
 

Example 16

From project ardverk-dht, under directory /components/tools/src/main/java/org/ardverk/dht/ui/.

Source file: JuicePainter.java

  15 
vote

@Override protected void paint(Component c,Graphics2D g){
  double width=c.getWidth();
  double height=c.getHeight();
  double gap=50d;
  double radius=Math.max(Math.min(width / 2d,height / 2d) - gap,gap);
  double arc_x=width / 2d - radius;
  double arc_y=height / 2d - radius;
  double arc_width=2d * radius;
  double arc_height=2d * radius;
  g.setColor(Color.orange);
  g.setStroke(PainterUtils.TWO_PIXEL_STROKE);
  ellipse.setFrame(arc_x,arc_y,arc_width,arc_height);
  g.draw(ellipse);
  double fi=position(localhostId,2d * Math.PI) - Math.PI / 2d;
  double dx=width / 2d + radius * Math.cos(fi);
  double dy=height / 2d + radius * Math.sin(fi);
  localhost.setLocation(dx,dy);
  dot.setFrame(dx - PainterUtils.DOT_SIZE / 2d,dy - PainterUtils.DOT_SIZE / 2d,PainterUtils.DOT_SIZE,PainterUtils.DOT_SIZE);
synchronized (nodes) {
    for (Iterator<Node> it=nodes.iterator(); it.hasNext(); ) {
      if (it.next().paint(localhost,width,height,radius,g)) {
        it.remove();
      }
    }
  }
  g.setColor(Color.ORANGE);
  g.setStroke(PainterUtils.DEFAULT_STROKE);
  g.fill(dot);
}
 

Example 17

From project BoneJ, under directory /src/org/doube/util/.

Source file: DialogModifier.java

  15 
vote

/** 
 * Go through all values in a GenericDialog's Components and call the appropriate get method. Recursively enter Panel Components. Will throw an ArrayIndexOutOfBounds exception if gd.getNext... is called elsewhere in dialogItemChanged().
 * @param gd
 * @param comps
 */
public static void registerMacroValues(GenericDialog gd,Component[] comps){
  try {
    for (    Component c : comps) {
      if (c instanceof Checkbox)       gd.getNextBoolean();
 else       if (c instanceof Choice)       gd.getNextChoice();
 else       if (c instanceof TextField) {
        String text=((TextField)c).getText();
        try {
          Double.parseDouble(text);
          gd.getNextNumber();
        }
 catch (        NumberFormatException e) {
          gd.getNextString();
        }
      }
 else       if (c instanceof Panel)       registerMacroValues(gd,((Panel)c).getComponents());
 else       continue;
    }
  }
 catch (  Exception e) {
    IJ.log("This plugin causes an exception\n" + e.toString());
  }
  return;
}
 

Example 18

From project Briss, under directory /src/main/java/at/laborg/briss/.

Source file: BrissGUI.java

  15 
vote

@Override public void componentResized(ComponentEvent e){
  previewPanel.revalidate();
  for (  Component component : previewPanel.getComponents()) {
    component.repaint();
  }
}
 

Example 19

From project Calendar-Application, under directory /com/toedter/calendar/.

Source file: JDateChooserCellEditor.java

  15 
vote

public Component getTableCellEditorComponent(JTable table,Object value,boolean isSelected,int row,int column){
  Date date=null;
  if (value instanceof Date)   date=(Date)value;
  dateChooser.setDate(date);
  return dateChooser;
}
 

Example 20

From project Chess_1, under directory /src/chess/gui/.

Source file: AbstractDisplay.java

  15 
vote

/** 
 * Draw the given object. Scales and rotates the coordinate appropriately then invokes the simple draw method above that is only responsible for drawing a unit-length occupant facing North.
 * @param obj the occupant we want to draw
 * @param comp the component on which to draw
 * @param g2 the graphics context
 * @param rect rectangle in which to draw
 */
public void draw(Object obj,Component comp,Graphics2D g2,Rectangle rect){
  float scaleFactor=Math.min(rect.width,rect.height);
  g2=(Graphics2D)g2.create();
  g2.translate(rect.x + rect.width / 2.0,rect.y + rect.height / 2.0);
  if (obj != null) {
    Integer direction=(Integer)getProperty(obj,"direction");
    int rotationInDegrees=direction == null ? 0 : direction.intValue();
    g2.rotate(Math.toRadians(rotationInDegrees));
  }
  g2.scale(scaleFactor,scaleFactor);
  g2.setStroke(new BasicStroke(1.0f / scaleFactor));
  draw(obj,comp,g2);
}
 

Example 21

From project CloudReports, under directory /src/main/java/cloudreports/gui/.

Source file: CloudTree.java

  15 
vote

public Component getTreeCellRendererComponent(JTree tree,Object value,boolean sel,boolean expanded,boolean leaf,int row,boolean hasFocus){
  super.getTreeCellRendererComponent(tree,value,sel,expanded,leaf,row,hasFocus);
  if (leaf) {
    setIcon(icon3);
  }
 else   if (isCloud(value)) {
    setIcon(icon0);
  }
 else   if (isProvider(value)) {
    setIcon(icon1);
  }
 else {
    setIcon(icon2);
  }
  return this;
}
 

Example 22

From project codjo-broadcast, under directory /codjo-broadcast-gui/src/main/java/net/codjo/broadcast/gui/.

Source file: BroadcastSectionsDetailWindow.java

  15 
vote

@Override public Component getListCellRendererComponent(JList list,Object value,int idx,boolean selected,boolean focus){
  JLabel label=(JLabel)super.getListCellRendererComponent(list,value,idx,selected,focus);
  if (value != null) {
    GuiPreference guiPreference=guiPrefManager.getPreferenceFor((String)value);
    String rendererLabel=guiPreference.getFamilyLabel();
    label.setText(rendererLabel);
  }
  return label;
}
 

Example 23

From project codjo-control, under directory /codjo-control-gui/src/main/java/net/codjo/control/gui/plugin/.

Source file: DefaultQuarantineWindow.java

  15 
vote

private void reloadFilter(RequestComboBox comboBox) throws RequestException {
  comboBox.getDataSource().load();
  Result loadResult=comboBox.getDataSource().getLoadResult();
  List<Row> rows=loadResult.getRows();
  if (rows == null) {
    rows=new ArrayList<Row>();
  }
  Row newRow=new Row();
  newRow.addField("value",FilterConstants.ALL);
  rows.add(0,newRow);
  loadResult.setRows(rows);
  comboBox.getDataSource().setLoadResult(loadResult);
  ListCellRenderer actualRenderer=comboBox.getRenderer();
  if (actualRenderer == null) {
    comboBox.setRenderer(new DefaultListCellRenderer(){
      @Override public Component getListCellRendererComponent(      JList list,      Object value,      int index,      boolean isSelected,      boolean cellHasFocus){
        if (FilterConstants.ALL.equals(value)) {
          value=translate("DefaultQuarantineWindow.filterComboBox.all",guiContext);
        }
        return super.getListCellRendererComponent(list,value,index,isSelected,cellHasFocus);
      }
    }
);
  }
 else {
    comboBox.setRenderer(new TranslationRenderer(actualRenderer));
  }
}
 

Example 24

From project codjo-imports, under directory /codjo-imports-gui/src/main/java/net/codjo/imports/gui/.

Source file: FieldImportDetailWindow.java

  15 
vote

public Component getListCellRendererComponent(JList list,Object value,int index,boolean isSelected,boolean cellHasFocus){
  setText("");
  if (null != value) {
    char charValue=(Character)value;
switch (charValue) {
case FieldType.BOOLEAN_FIELD:
      setText(InternationalizationUtil.translate("FieldImportDetailWindow#FieldTypeRenderer.boolean",dataSource.getGuiContext()));
    break;
case FieldType.CLASS_FIELD:
  setText(InternationalizationUtil.translate("FieldImportDetailWindow#FieldTypeRenderer.class",dataSource.getGuiContext()));
break;
case FieldType.DATE_FIELD:
setText(InternationalizationUtil.translate("FieldImportDetailWindow#FieldTypeRenderer.date",dataSource.getGuiContext()));
break;
case FieldType.NUMERIC_FIELD:
setText(InternationalizationUtil.translate("FieldImportDetailWindow#FieldTypeRenderer.numeric",dataSource.getGuiContext()));
break;
case FieldType.STRING_FIELD:
setText(InternationalizationUtil.translate("FieldImportDetailWindow#FieldTypeRenderer.string",dataSource.getGuiContext()));
break;
default :
setText(InternationalizationUtil.translate("FieldImportDetailWindow#FieldTypeRenderer.unknown",dataSource.getGuiContext()));
}
}
return this;
}
 

Example 25

From project codjo-segmentation, under directory /codjo-segmentation-gui/src/main/java/net/codjo/segmentation/gui/settings/.

Source file: AxisTreeToolBar.java

  15 
vote

public static void doEffect(JToolBar tb){
  Component[] components=tb.getComponents();
  for (  Component component : components) {
    if (component instanceof JButton) {
      ((JButton)component).setMargin(new Insets(1,3,1,3));
    }
  }
}
 

Example 26

From project cytoscape-plugins, under directory /org.openbel.cytoscape.navigator/src/org/openbel/cytoscape/navigator/.

Source file: KamNavigatorPlugin.java

  15 
vote

private static JMenu getKamPluginMenu(){
  final JMenu pluginMenu=Cytoscape.getDesktop().getCyMenus().getOperationsMenu();
  JMenu kiMenu=null;
  for (  final Component menu : pluginMenu.getMenuComponents()) {
    if (menu == null) {
      continue;
    }
    if (menu instanceof JMenu && KAM_PLUGIN_SUBMENU.equals(((JMenu)menu).getText())) {
      kiMenu=(JMenu)menu;
      break;
    }
  }
  return kiMenu;
}
 

Example 27

From project des, under directory /daemon/lib/apache-log4j-1.2.16/contribs/CekiGulcu/.

Source file: AppenderTable.java

  15 
vote

public Component getTableCellRendererComponent(JTable table,Object value,boolean isSelected,boolean hasFocus,int row,int column){
  if (value instanceof LoggingEvent) {
    LoggingEvent event=(LoggingEvent)value;
    String str=layout.format(event);
    setText(str);
  }
 else {
    setText(value.toString());
  }
  return this;
}
 

Example 28

From project drugis-common, under directory /common-extra/src/main/java/org/drugis/common/gui/.

Source file: ImageExporter.java

  15 
vote

public static void writeImage(Component frame,final JComponent p,final int width,final int height){
  String[] extensions={"png"};
  String[] descriptions={"PNG files"};
  FileSaveDialog dialog=new FileSaveDialog(frame,extensions,descriptions){
    @Override public void doAction(    String path,    String extension){
      if (extension.equals("png"))       writePNG(path,p,width,height);
 else       throw new IllegalArgumentException("Unknown extension " + extension);
    }
  }
;
  dialog.saveActions();
}