コード例 #1
0
 public Object getValueAt(int rowIndex, int columnIndex) {
   RegistryValue value = getRegistryValue(rowIndex);
   switch (columnIndex) {
     case 0:
       return "";
     case 1:
       return value.getKey();
     case 2:
       return value.asString();
     default:
       return value;
   }
 }
コード例 #2
0
 @Override
 public boolean stopCellEditing() {
   if (myValue != null) {
     if (myValue.isBoolean()) {
       myValue.setValue(myCheckBox.isSelected());
     } else {
       myValue.setValue(myField.getText().trim());
     }
     keyChanged(myValue.getKey());
   }
   revaliateActions();
   return super.stopCellEditing();
 }
コード例 #3
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;
    }
コード例 #4
0
 @Override
 @Nullable
 public Component getTableCellEditorComponent(
     JTable table, Object value, boolean isSelected, int row, int column) {
   myValue = ((MyTableModel) table.getModel()).getRegistryValue(row);
   if (myValue.asColor(null) != null) {
     final Color color =
         ColorChooser.chooseColor(table, "Choose color", myValue.asColor(Color.WHITE));
     if (color != null) {
       myValue.setValue(color.getRed() + "," + color.getGreen() + "," + color.getBlue());
       keyChanged(myValue.getKey());
     }
     return null;
   } else if (myValue.isBoolean()) {
     myCheckBox.setSelected(myValue.asBoolean());
     myCheckBox.setBackground(table.getBackground());
     return myCheckBox;
   } else {
     myField.setText(myValue.asString());
     myField.setBorder(null);
     myField.selectAll();
     return myField;
   }
 }