public Component getTableCellRendererComponent(
     JTable aTable,
     Object aNumberValue,
     boolean aIsSelected,
     boolean aHasFocus,
     int aRow,
     int aColumn) {
   /*
    * Implementation Note :
    * It is important that no "new" be present in this
    * implementation (excluding exceptions):
    * if the table is large, then a large number of objects would be
    * created during rendering.
    */
   if (aNumberValue == null) return this;
   Component renderer =
       super.getTableCellRendererComponent(
           aTable, aNumberValue, aIsSelected, aHasFocus, aRow, aColumn);
   Number value = (Number) aNumberValue;
   if (value.doubleValue() < 0) {
     renderer.setForeground(Color.red);
   } else {
     renderer.setForeground(fDarkGreen);
   }
   return this;
 }
 /** Shades alternate rows in different colors. */
 @Override
 public Component prepareRenderer(TableCellRenderer renderer, int row, int column) {
   Component c = super.prepareRenderer(renderer, row, column);
   if (!isCellSelected(row, column)) {
     c.setBackground(colorForRow(row));
     c.setForeground(UIManager.getColor("Table.foreground"));
   } else {
     c.setBackground(UIManager.getColor("Table.selectionBackground"));
     c.setForeground(UIManager.getColor("Table.selectionForeground"));
   }
   return c;
 }
 @Override
 public Component prepareRenderer(TableCellRenderer tcr, int row, int column) {
   Component c = super.prepareRenderer(tcr, row, column);
   if (isRowSelected(row)) {
     c.setForeground(getSelectionForeground());
     c.setBackground(getSelectionBackground());
   } else {
     c.setForeground(getForeground());
     c.setBackground(row % 2 == 0 ? EVEN_COLOR : getBackground());
   }
   return c;
 }
Exemple #4
0
 public void applyHighlighters(@NotNull Component rendererComponent, int row, boolean selected) {
   boolean fgUpdated = false;
   for (VcsLogHighlighter highlighter : myHighlighters) {
     Color color =
         highlighter.getForeground(myDataPack.getGraphFacade().getCommitAtRow(row), selected);
     if (color != null) {
       rendererComponent.setForeground(color);
       fgUpdated = true;
     }
   }
   if (!fgUpdated) { // reset highlighting if no-one wants to change it
     rendererComponent.setForeground(UIUtil.getTableForeground(selected));
   }
 }
  private static Pair<Image, Point> createDragImage(
      final Tree tree, final Component c, Point dragOrigin, boolean adjustToPathUnderDragOrigin) {
    if (c instanceof JComponent) {
      ((JComponent) c).setOpaque(true);
    }

    c.setForeground(tree.getForeground());
    c.setBackground(tree.getBackground());
    c.setFont(tree.getFont());
    c.setSize(c.getPreferredSize());
    final BufferedImage image =
        new BufferedImage(c.getWidth(), c.getHeight(), BufferedImage.TYPE_INT_ARGB);
    Graphics2D g2 = (Graphics2D) image.getGraphics();
    g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.7f));
    c.paint(g2);
    g2.dispose();

    Point point = new Point(-image.getWidth(null) / 2, -image.getHeight(null) / 2);

    if (adjustToPathUnderDragOrigin) {
      TreePath path = tree.getPathForLocation(dragOrigin.x, dragOrigin.y);
      if (path != null) {
        Rectangle bounds = tree.getPathBounds(path);
        point = new Point(bounds.x - dragOrigin.x, bounds.y - dragOrigin.y);
      }
    }

    return new Pair<Image, Point>(image, point);
  }
 public Component getTableCellRendererComponent(
     JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
   final Color color = UIUtil.getTableFocusCellBackground();
   Component component;
   T t = (T) value;
   try {
     UIManager.put(UIUtil.TABLE_FOCUS_CELL_BACKGROUND_PROPERTY, table.getSelectionBackground());
     component =
         super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
     setText(t != null ? getItemText(t) : "");
     if (component instanceof JLabel) {
       ((JLabel) component).setBorder(noFocusBorder);
     }
   } finally {
     UIManager.put(UIUtil.TABLE_FOCUS_CELL_BACKGROUND_PROPERTY, color);
   }
   final MyTableModel model = (MyTableModel) table.getModel();
   component.setEnabled(
       ElementsChooser.this.isEnabled()
           && (myColorUnmarkedElements ? model.isElementMarked(row) : true));
   final ElementProperties properties = myElementToPropertiesMap.get(t);
   if (component instanceof JLabel) {
     final Icon icon =
         properties != null ? properties.getIcon() : t != null ? getItemIcon(t) : null;
     JLabel label = (JLabel) component;
     label.setIcon(icon);
     label.setDisabledIcon(icon);
   }
   component.setForeground(
       properties != null && properties.getColor() != null
           ? properties.getColor()
           : (isSelected ? table.getSelectionForeground() : table.getForeground()));
   return component;
 }
  public SimpleTextAttributes applyHighlighters(
      @NotNull Component rendererComponent,
      int row,
      int column,
      String text,
      boolean hasFocus,
      final boolean selected) {
    VcsLogHighlighter.VcsCommitStyle style = getStyle(row, column, text, hasFocus, selected);

    assert style.getBackground() != null
        && style.getForeground() != null
        && style.getTextStyle() != null;

    rendererComponent.setBackground(style.getBackground());
    rendererComponent.setForeground(style.getForeground());

    switch (style.getTextStyle()) {
      case BOLD:
        return SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES;
      case ITALIC:
        return SimpleTextAttributes.REGULAR_ITALIC_ATTRIBUTES;
      default:
    }
    return SimpleTextAttributes.REGULAR_ATTRIBUTES;
  }
 public Component getTableCellRendererComponent(
     JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
   final Color color = UIUtil.getTableFocusCellBackground();
   Component component;
   final Module module = value instanceof Module ? (Module) value : null;
   try {
     UIManager.put(UIUtil.TABLE_FOCUS_CELL_BACKGROUND_PROPERTY, table.getSelectionBackground());
     component =
         super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
     if (module != null) {
       setText(
           module.getName()
               + " ("
               + FileUtil.toSystemDependentName(module.getModuleFilePath())
               + ")");
     }
     if (component instanceof JLabel) {
       ((JLabel) component).setBorder(noFocusBorder);
     }
   } finally {
     UIManager.put(UIUtil.TABLE_FOCUS_CELL_BACKGROUND_PROPERTY, color);
   }
   component.setEnabled(ProcessedModulesTable.this.isEnabled());
   if (component instanceof JLabel) {
     final Icon icon = module != null ? ModuleType.get(module).getIcon() : null;
     JLabel label = (JLabel) component;
     label.setIcon(icon);
     label.setDisabledIcon(icon);
   }
   component.setForeground(isSelected ? table.getSelectionForeground() : table.getForeground());
   return component;
 }
 /**
  * Returns the default table cell renderer.
  *
  * @param table the <code>JTable</code>
  * @param value the value to assign to the cell at <code>[row, column]</code>
  * @param isSelected true if cell is selected
  * @param hasFocus true if cell has focus
  * @param row the row of the cell to render
  * @param column the column of the cell to render
  * @return the default table cell renderer
  */
 public Component getTableCellRendererComponent(
     JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
   ReadingList list = model.getLists()[row];
   Component comp =
       super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
   comp.setForeground(list.isMissing() ? Color.GRAY : table.getForeground());
   return comp;
 }
Exemple #10
0
 public static void makeEmphasized(Component widget) {
   // Set to bold amd add color
   Font font = widget.getFont();
   if (!UserPreferences.readLocalePref()
       .equals("ko")) // HACK!!!  refector with variable localeSupportsBold
   widget.setFont(new Font(font.getFamily(), Font.BOLD, font.getSize()));
   widget.setForeground(UIProperties.emphasisColor);
 }
 // Implementation of TableCellRenderer interface
 public Component getTableCellRendererComponent(
     JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
   TableCellRenderer rend = super.getCellRenderer(row, column);
   Component c =
       rend.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
   c.setBackground(getBack(isSelected, hasFocus, row, column));
   c.setForeground(getFore(isSelected, hasFocus, row, column));
   return c;
 }
 private static Component setLabelColors(
     final Component label, final JTable table, final boolean isSelected, final int row) {
   if (label instanceof JComponent) {
     ((JComponent) label).setOpaque(true);
   }
   label.setForeground(isSelected ? table.getSelectionForeground() : table.getForeground());
   label.setBackground(isSelected ? table.getSelectionBackground() : table.getBackground());
   return label;
 }
 public void paintCurrentValue(Graphics g, Rectangle bounds, boolean hasFocus) {
   ListCellRenderer renderer = comboBox.getRenderer();
   Component c;
   Dimension d;
   c =
       renderer.getListCellRendererComponent(
           listBox, comboBox.getSelectedItem(), -1, false, false);
   c.setFont(comboBox.getFont());
   if (comboBox.isEnabled()) {
     c.setForeground(comboBox.getForeground());
     c.setBackground(comboBox.getBackground());
   } else {
     c.setForeground(UIManager.getColor("ComboBox.disabledForeground"));
     c.setBackground(UIManager.getColor("ComboBox.disabledBackground"));
   }
   d = c.getPreferredSize();
   currentValuePane.paintComponent(g, c, comboBox, bounds.x, bounds.y, bounds.width, d.height);
 }
Exemple #14
0
 public Component getTableCellRendererComponent(
     JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
   Component comp =
       super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
   if (value != null && highlight(table, value, isSelected, hasFocus, row, column)) {
     if (isSelected) {
       comp.setBackground(new Color((HIGHLIGHT_COLOR.getRGB() ^ comp.getBackground().getRGB())));
       comp.setForeground(new Color(Color.BLACK.getRGB() ^ comp.getForeground().getRGB()));
     } else {
       comp.setBackground(HIGHLIGHT_COLOR);
       comp.setForeground(Color.BLACK);
     }
   } else {
     if (!isSelected) {
       comp.setBackground(Color.WHITE);
       comp.setForeground(Color.BLACK);
     }
   }
   return comp;
 }
Exemple #15
0
  private Component createNameLabel(DetailsDecoration detail) {

    if (detail instanceof JComponentDetailsDecoration) {
      Component c = createComponentNameLabel((JComponentDetailsDecoration) detail);
      if (c != null) {
        c.setForeground(detail.isVisible() ? Color.BLACK : Color.lightGray);
        return c;
      }
    }

    WebLabel label = new WebLabel(StringUtils.capitalize(detail.getName()), JLabel.TRAILING);

    label.setDrawShade(true);
    SwingUtils.changeFontSize(label, -1);

    if (detail.isSelected()) {
      SwingUtils.setBoldFont(label);
    }

    label.setCursor(new Cursor(Cursor.HAND_CURSOR));
    label.addMouseListener(new PropertyMouseListener(detail));

    if (StringUtils.isNotEmpty(detail.getDescription())) {
      String description =
          "<html><body width=\"300px\">" + detail.getDescription() + "</body></html>";
      TooltipManager.setTooltip(label, description, TooltipWay.down, 0);
    }

    if (!StringUtils.isEmpty(detail.getDescriptionLink())) {
      DetailsWebLinkLabel webLabel = new DetailsWebLinkLabel("", JLabel.TRAILING);
      webLabel.setIcon(IconNames.INFO_ICON);
      webLabel.setLink(detail.getDescriptionLink(), false);
      TooltipManager.setTooltip(webLabel, detail.getDescriptionLink(), TooltipWay.down, 0);
      return new GroupPanel(GroupingType.fillFirst, 5, webLabel, label);
    }

    label.setForeground(detail.isVisible() ? Color.BLACK : Color.lightGray);
    return label;
  }
  public void showFrame(Editor editor, ContributionType contributionType) {
    this.editor = editor;

    // Calculating index to switch to the required tab
    int index = getIndex(contributionType);
    if (dialog == null) {
      makeFrame(editor);
      // done before as downloadAndUpdateContributionListing()
      // requires the current selected tab
      tabbedPane.setSelectedIndex(index);
      downloadAndUpdateContributionListing(editor.getBase());
      if (index != 4) {
        Component selected = tabbedPane.getTabComponentAt(tabbedPane.getSelectedIndex());
        selected.setBackground(new Color(0xe0fffd));
        selected.setForeground(Color.BLACK);
      } else {
        updateTabPanel.setBackground(new Color(0xe0fffd));
        updateTabLabel.setForeground(Color.BLACK);
      }
    }
    tabbedPane.setSelectedIndex(index);
    dialog.setVisible(true);
  }
 private void adjustColors(Color bg, Color fg) {
   for (Component c : panel.toAdjust) {
     c.setForeground(fg);
     c.setBackground(bg);
   }
 }