@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;
 }
 /** 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;
 }
  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 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;
  }
Beispiel #5
0
 @Override
 public Component getTableCellRendererComponent(
     JTable table, Object o, boolean isSelected, boolean hasFocus, int row, int column) {
   if (selBackground == null) {
     return super.getTableCellRendererComponent(table, o, isSelected, hasFocus, row, column);
   } else {
     Component c =
         super.getTableCellRendererComponent(table, o, isSelected, hasFocus, row, column);
     if (isSelected) {
       c.setBackground(selBackground);
     } else {
       c.setBackground(background);
     }
     return c;
   }
 }
Beispiel #6
0
 /**
  * *****************************************************************************************************
  */
 public Component getTableCellRendererComponent(
     JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int col) {
   String columnName = new ConvertImpl().removeHtmlTags(table.getModel().getColumnName(col));
   String sub = "";
   String sub2 = "";
   try {
     sub = columnName.substring(0, 9);
     sub2 = columnName.substring(0, 4);
   } catch (Exception e) {
   }
   Component comp =
       super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, col);
   setHorizontalAlignment(SwingConstants.CENTER);
   if (sub.equals("Time (ms)")
       || columnName.equals("GTS")
       || columnName.equals("LQI")
       || columnName.equals("RSSI")
       || columnName.equals("CRC")
       || columnName.equals("Header Length")
       || columnName.equals("Channel")
       || columnName.equals("Code")
       || columnName.equals("Cheksum")
       || sub.equals("MAC Heade")
       || columnName.equals("Type")) comp.setBackground(new Color(194, 223, 255));
   else if (columnName.equals("DispatchID")
       || columnName.equals("Length")
       || sub.equals("Frame con")
       || sub2.equals("Sequ")
       || sub.equals("Destinati")
       || sub2.equals("Sour")
       || sub.equals("Super fra")
       || columnName.equals("FCS")
       || sub2.equals("Dest")
       || columnName.equals("Dest.PAN")
       || sub2.equals("Src.")) comp.setBackground(new Color(240, 239, 239));
   else if (columnName.equals("Dispatch")
       || columnName.equals("Encoding")
       || sub.equals("Next head")
       || columnName.equals("Hop limit")
       || sub2.equals("6LoW")
       || columnName.equals("Context")
       || sub.equals("Traffic c")) comp.setBackground(new Color(204, 251, 93));
   else if (columnName.equals("Payload") || columnName.equals("Frame"))
     comp.setBackground(new Color(255, 200, 0));
   else comp.setBackground(Color.WHITE);
   return comp;
 }
Beispiel #7
0
 public static void recursiveSetBackground(Component comp, Color color) {
   if (comp instanceof JToolBar || comp instanceof JButton) return;
   comp.setBackground(color);
   if (comp instanceof Container) {
     Container cc = (Container) comp;
     for (int i = 0; i < cc.getComponentCount(); i++)
       recursiveSetBackground(cc.getComponent(i), color);
   }
 }
 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;
 }
 // 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;
 }
    public AwtPopupWrapper(Popup popup) {
      myPopup = popup;

      if (SystemInfo.isMac && UIUtil.isUnderAquaLookAndFeel()) {
        final Component c =
            (Component) ReflectionUtil.getField(Popup.class, myPopup, Component.class, "component");
        c.setBackground(UIUtil.getPanelBackground());
      }
    }
 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);
 }
 public void run() {
   while (true) {
     synchronized (semaphore) {
       try {
         semaphore.wait();
       } catch (InterruptedException ex) {
       }
     }
     Color origColor = c.getBackground();
     for (int i = 0; i < flashCount; i++) {
       c.setBackground(flashColor);
       try {
         Thread.currentThread().sleep(100);
       } catch (Exception ex) {
       }
       c.setBackground(origColor);
     }
   }
 }
Beispiel #13
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;
 }
  @Override
  public Component prepareRenderer(TableCellRenderer renderer, int row, int column) {
    final Component result = super.prepareRenderer(renderer, row, column);
    final boolean selected =
        myExpandableItemsHandler.getExpandedItems().contains(new TableCell(row, column));

    // Fix GTK background
    if (UIUtil.isUnderGTKLookAndFeel()) {
      UIUtil.changeBackGround(this, UIUtil.getTreeTextBackground());
    }

    if (isTableDecorationSupported() && isStriped() && result instanceof JComponent) {
      final Color bg = row % 2 == 1 ? getBackground() : DECORATED_ROW_BG_COLOR;
      final JComponent c = (JComponent) result;
      final boolean cellSelected = isCellSelected(row, column);
      if (!cellSelected || (!hasFocus() && !getSelectionBackground().equals(c.getBackground()))) {
        c.setOpaque(true);
        c.setBackground(bg);
        for (Component child : c.getComponents()) {
          child.setBackground(bg);
        }
      }
    }

    if (!selected) return result;

    return new JComponent() {
      {
        add(result);
        setOpaque(false);
        setLayout(
            new AbstractLayoutManager() {
              @Override
              public Dimension preferredLayoutSize(Container parent) {
                return result.getPreferredSize();
              }

              @Override
              public void layoutContainer(Container parent) {
                Dimension size = parent.getSize();
                Insets i = parent.getInsets();
                Dimension pref = result.getPreferredSize();
                result.setBounds(
                    i.left,
                    i.top,
                    Math.max(pref.width, size.width - i.left - i.right),
                    size.height - i.top - i.bottom);
              }
            });
      }
    };
  }
    public Component getTableCellRendererComponent(
        JTable table,
        Object value,
        boolean selected,
        boolean hasFocus,
        int rowIndex,
        int columnIndex) {
      Component component =
          super.getTableCellRendererComponent(
              table, value, selected, hasFocus, rowIndex, columnIndex);

      if (!selected) component.setBackground(table.getTableHeader().getBackground());

      return component;
    }
Beispiel #16
0
    @Override
    public Component getTableCellRendererComponent(
        JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
      Component result =
          super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
      if (!isSelected) {
        MyTableModel tableModel = (MyTableModel) table.getModel();
        Color color = table.getBackground();

        switch (tableModel.getKind(row)) {
          case ERROR:
            color = new Color(255, 175, 175);
            break;
          case CONFLICT:
            color = new Color(255, 240, 240);
            break;
        }
        result.setBackground(color);
      }
      return result;
    }
  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);
  }
    @Override
    public Component getTableCellEditorComponent(
        JTable table, Object value, boolean isSelected, int row, int column) {
      final DefaultMutableTreeNode defaultNode =
          (DefaultMutableTreeNode)
              ((TreeTable) table).getTree().getPathForRow(row).getLastPathComponent();
      myCurrentEditor = null;
      myCurrentNode = null;
      if (defaultNode instanceof MyTreeNode) {
        MyTreeNode node = (MyTreeNode) defaultNode;
        myCurrentNode = node;
        if (node.getKey() instanceof BooleanOption) {
          myCurrentEditor = myBooleanEditor;
          myBooleanEditor.setSelected(node.getValue() == Boolean.TRUE);
          myBooleanEditor.setEnabled(node.isEnabled());
        } else if (node.getKey() instanceof IntOption) {
          IntOption intOption = (IntOption) node.getKey();
          myCurrentEditor = myIntOptionsEditor;
          myIntOptionsEditor.setText(
              intOption.isDefaultValue(node.getValue()) ? "" : node.getValue().toString());
          myIntOptionsEditor.setMinValue(intOption.getMinValue());
          myIntOptionsEditor.setMaxValue(intOption.getMaxValue());
          myIntOptionsEditor.setDefaultValue(intOption.getDefaultValue());
        } else {
          myCurrentEditor = myOptionsEditor;
          myOptionsEditor.setCell(table, row, column);
          myOptionsEditor.setText(String.valueOf(node.getValue()));
          myOptionsEditor.setOptions(((SelectionOption) node.getKey()).options);
          myOptionsEditor.setDefaultValue(node.getValue());
        }
      }

      if (myCurrentEditor != null) {
        myCurrentEditor.setBackground(table.getBackground());
      }
      return myCurrentEditor;
    }
Beispiel #19
0
    /**
     * This is the only method necessary to overload. All we have to do is print the String value of
     * the model along with its index in the ModelList data structure.
     *
     * @param list the JList
     * @param value the value
     * @param index the index of the value
     * @param isSelected if true the item is selected
     * @param cellHasFocus whether it has the focus
     * @return the rendering component
     */
    public Component getListCellRendererComponent(
        JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {

      Component modelComponent = null;

      if (value instanceof EnsembleLibraryModel) {

        EnsembleLibraryModel model = ((EnsembleLibraryModel) value);

        String modelString =
            index + ": " + model.getStringRepresentation().replaceAll("weka.classifiers.", "");

        modelComponent =
            super.getListCellRendererComponent(list, modelString, index, isSelected, cellHasFocus);

        if (!model.getOptionsWereValid()) {
          modelComponent.setBackground(Color.pink);
        }

        ((JComponent) modelComponent).setToolTipText(model.getDescriptionText());
      }

      return modelComponent;
    }
Beispiel #20
0
  /**
   * Renders a table cell in the main JTable. As a TableCellRenderer, we have to implement this
   * method, but we use it to colour different types of matches in different ways. Remember that
   * this is run every time a cell is displayed on the screen, so it needs to be as fast as can be.
   *
   * @param table The table which needs rendering.
   * @param value The object which needs rendering. For now, this can only be a Name object, but
   *     later on we might colour different types of cells in different ways.
   * @param isSelected Is this cell selected, i.e. is the row selected?
   * @param hasFocus Is this cell focused, i.e. is this individual cell selected?
   * @param row The row coordinate of this cell.
   * @param column The column coordinate of this cell.
   * @return A component representing this cell.
   */
  @Override
  public Component getTableCellRendererComponent(
      JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
    // TODO: Check if we can get a saving out of this by just rendering a JLabel/JTextField
    // directly.
    Component c =
        defTableCellRenderer.getTableCellRendererComponent(
            table, value, isSelected, hasFocus, row, column);

    // Set all backgrounds to white.
    c.setBackground(Color.WHITE);

    if (value == null) {
      // Null values look null-ish.
      c.setBackground(COLOR_NULL);
      return c;

    } else if (hasFocus) {
      // ANY cell with focus should look focussed.
      c.setBackground(COLOR_FOCUS);
      return c;

    } else if (Name.class.isAssignableFrom(value.getClass())) {
      // Aha, a Name! Color it special.
      Name name = (Name) value;
      int str_length = name.toString().length();

      if (currentMatch == null) {
        // No current match? Then just colour blank cells blank,
        // and unmatched name colours special so people know that
        // they have been recognized as names.

        if (str_length == 0) {
          c.setBackground(COLOR_BLANK_CELL);
        } else {
          c.setBackground(COLOR_NAME_UNMATCHED);
        }
      } else {
        // So which RowIndex is the match against?
        RowIndex against = currentMatch.getAgainst();

        // System.err.println("Checking against: " + against);

        if (str_length == 0) {
          // Mark blank cells as such.
          c.setBackground(COLOR_BLANK_CELL);
        } else if (against.hasName(name)) {
          // Perfect match!
          c.setBackground(COLOR_NAME_FULL_MATCH);
        } else if (against.hasName(name.getGenus())) {
          // Genus-match.
          c.setBackground(COLOR_NAME_GENUS_MATCH);
        } else {
          // No match!
          c.setBackground(COLOR_NAME_NO_MATCH);
        }
      }

    } else {
      // Not a name? Note that Strings will NOT make it here: we don't
      // push Strings through this. So this is really just for later.
      c.setBackground(COLOR_NULL);
    }

    // If the row is selected, make it darker.
    if (isSelected) c.setBackground(c.getBackground().darker());

    return c;
  }
Beispiel #21
0
 private void adjustColors(Color bg, Color fg) {
   for (Component c : panel.toAdjust) {
     c.setForeground(fg);
     c.setBackground(bg);
   }
 }