コード例 #1
0
 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;
 }
コード例 #2
0
 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;
 }
コード例 #3
0
 /**
  * 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;
 }
コード例 #4
0
 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;
 }
コード例 #5
0
 @Override
 public Component getTableCellRendererComponent(
     JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
   if (isSelected) {
     setForeground(table.getSelectionForeground());
     setBackground(table.getSelectionBackground());
   } else {
     setForeground(table.getForeground());
     setBackground(table.getBackground());
   }
   setFont(table.getFont());
   setText(Objects.toString(value, ""));
   return this;
 }
コード例 #6
0
    @Override
    public Component getTableCellRendererComponent(
        JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
      if (isSelected) {
        setForeground(table.getSelectionForeground());
        super.setBackground(table.getSelectionBackground());
      } else {
        setForeground(table.getForeground());
        setBackground(table.getBackground());
      }

      // Select the current value
      setSelectedItem(value);
      return this;
    }
コード例 #7
0
    @NotNull
    @Override
    public Component getTableCellRendererComponent(
        @NotNull JTable table,
        Object value,
        boolean isSelected,
        boolean hasFocus,
        int row,
        int column) {
      final RegistryValue v = ((MyTableModel) table.getModel()).getRegistryValue(row);
      myLabel.setIcon(null);
      myLabel.setText(null);
      myLabel.setHorizontalAlignment(SwingConstants.LEFT);
      Color fg = isSelected ? table.getSelectionForeground() : table.getForeground();
      Color bg = isSelected ? table.getSelectionBackground() : table.getBackground();

      if (v != null) {
        switch (column) {
          case 0:
            myLabel.setIcon(v.isRestartRequired() ? RESTART_ICON : null);
            myLabel.setHorizontalAlignment(SwingConstants.CENTER);
            break;
          case 1:
            myLabel.setText(v.getKey());
            break;
          case 2:
            if (v.asColor(null) != null) {
              myLabel.setIcon(createColoredIcon(v.asColor(null)));
            } else if (v.isBoolean()) {
              final JCheckBox box = new JCheckBox();
              box.setSelected(v.asBoolean());
              box.setBackground(bg);
              return box;
            } else {
              myLabel.setText(v.asString());
            }
        }

        myLabel.setOpaque(true);

        myLabel.setFont(
            myLabel.getFont().deriveFont(v.isChangedFromDefault() ? Font.BOLD : Font.PLAIN));
        myLabel.setForeground(fg);
        myLabel.setBackground(bg);
      }

      return myLabel;
    }
コード例 #8
0
ファイル: ColorRenderer.java プロジェクト: adoGT/prismFDCTMC
  public Component getTableCellRendererComponent(
      JTable table,
      Setting owner,
      Object value,
      boolean isSelected,
      boolean hasFocus,
      boolean isEnabled,
      int row,
      int column) {
    // renderer.setMargin(new Insets(0, 2, 4, 2));

    if (isSelected) {
      renderer.setForeground(table.getSelectionForeground());
      panel.setBackground(table.getSelectionBackground());
      blank1.setBackground(table.getSelectionBackground());
      blank2.setBackground(table.getSelectionBackground());
    } else {
      renderer.setForeground(table.getForeground());
      panel.setBackground(table.getBackground());
      blank1.setBackground(table.getBackground());
      blank2.setBackground(table.getBackground());
    }

    if (hasFocus) {
      panel.setBorder(UIManager.getBorder("Table.focusCellHighlightBorder"));
    } else {
      panel.setBorder(new EmptyBorder(1, 2, 2, 1));
    }

    if (value instanceof Color) {
      Color col = (Color) value;

      // System.out.println("setting background to "+col.toString());

      renderer.setText("[" + col.getRed() + "," + col.getGreen() + "," + col.getBlue() + "]");

      renderer.setEnabled(isEnabled);

      renderer.setFont(font);

      colourPanel.setBackground(col);
    } else if (value instanceof ArrayList) {
      ArrayList values = (ArrayList) value;
      if (values.size() > 0) {
        // if we have multiple properties selected.
        Color last = null;
        boolean allSame = true;
        for (int i = 0; i < values.size(); i++) {
          if (values.get(i) instanceof Color) {
            Color str = (Color) values.get(i);
            if (last != null) {
              if (!str.equals(last)) {
                allSame = false;
                break;
              }
              last = str;
            } else {
              last = str;
            }
          }
        }
        if (allSame) {
          renderer.setText(
              "[" + last.getRed() + "," + last.getGreen() + "," + last.getBlue() + "]");

          renderer.setEnabled(isEnabled);

          renderer.setFont(font);

          colourPanel.setBackground(last);
        } else {
          renderer.setText("(Different values)");

          renderer.setEnabled(isEnabled);

          renderer.setFont(font);

          colourPanel.setBackground(Color.lightGray);
          panel.setBackground(Color.lightGray);
          blank1.setBackground(Color.lightGray);
          blank2.setBackground(Color.lightGray);
        }
      }
    }

    return panel;
  }