@Override
  protected void updateButtons() {
    final CommonActionsPanel p = getActionsPanel();
    if (p != null) {
      boolean someElementSelected;
      if (myTable.isEnabled()) {
        final int index = myTable.getSelectedRow();
        final int size = myTable.getModel().getRowCount();
        someElementSelected = 0 <= index && index < size;
        if (someElementSelected) {
          final boolean downEnable = myTable.getSelectionModel().getMaxSelectionIndex() < size - 1;
          final boolean upEnable = myTable.getSelectionModel().getMinSelectionIndex() > 0;
          final boolean editEnabled = myTable.getSelectedRowCount() == 1;
          p.setEnabled(CommonActionsPanel.Buttons.EDIT, editEnabled);
          p.setEnabled(CommonActionsPanel.Buttons.UP, upEnable);
          p.setEnabled(CommonActionsPanel.Buttons.DOWN, downEnable);
        } else {
          p.setEnabled(CommonActionsPanel.Buttons.EDIT, false);
          p.setEnabled(CommonActionsPanel.Buttons.UP, false);
          p.setEnabled(CommonActionsPanel.Buttons.DOWN, false);
        }
        p.setEnabled(
            CommonActionsPanel.Buttons.ADD, myProducer == null || myProducer.canCreateElement());
      } else {
        someElementSelected = false;
        p.setEnabled(CommonActionsPanel.Buttons.ADD, false);
        p.setEnabled(CommonActionsPanel.Buttons.EDIT, false);
        p.setEnabled(CommonActionsPanel.Buttons.UP, false);
        p.setEnabled(CommonActionsPanel.Buttons.DOWN, false);
      }

      p.setEnabled(CommonActionsPanel.Buttons.REMOVE, someElementSelected);
      updateExtraElementActions(someElementSelected);
    }
  }
Ejemplo n.º 2
0
 protected void paintBackground(Graphics g) {
   int draggedColumn = -1;
   if ((header != null) && (header.getTable() != null) && header.getDraggedColumn() != null) {
     draggedColumn =
         header.getColumnModel().getColumnIndex(header.getDraggedColumn().getIdentifier());
   }
   int w = getWidth();
   int h = getHeight();
   if ((table != null) && table.isEnabled() && (col == rolloverCol || col == draggedColumn)) {
     JTattooUtilities.fillHorGradient(
         g, AbstractLookAndFeel.getTheme().getRolloverColors(), 0, 0, w, h);
     if (drawRolloverBar()) {
       g.setColor(AbstractLookAndFeel.getFocusColor());
       g.drawLine(0, 0, w - 1, 0);
       g.drawLine(0, 1, w - 1, 1);
       g.drawLine(0, 2, w - 1, 2);
     }
   } else if (drawAllwaysActive() || JTattooUtilities.isFrameActive(header)) {
     if (header.getBackground() instanceof ColorUIResource) {
       JTattooUtilities.fillHorGradient(
           g, AbstractLookAndFeel.getTheme().getColHeaderColors(), 0, 0, w, h);
     } else {
       g.setColor(header.getBackground());
       g.fillRect(0, 0, w, h);
     }
   } else {
     if (header.getBackground() instanceof ColorUIResource) {
       JTattooUtilities.fillHorGradient(
           g, AbstractLookAndFeel.getTheme().getInActiveColors(), 0, 0, w, h);
     } else {
       g.setColor(header.getBackground());
       g.fillRect(0, 0, w, h);
     }
   }
 }
    @NotNull
    @Override
    public Component getTableCellRendererComponent(
        @NotNull JTable table,
        Object value,
        boolean isSelected,
        boolean hasFocus,
        int row,
        int column) {
      myTable = table;
      myRow = row;
      myColumn = column;
      boolean isEnabled = true;
      final DefaultMutableTreeNode node =
          (DefaultMutableTreeNode)
              ((TreeTable) table).getTree().getPathForRow(row).getLastPathComponent();
      Option key = null;
      if (node instanceof MyTreeNode) {
        isEnabled = ((MyTreeNode) node).isEnabled();
        key = ((MyTreeNode) node).getKey();
      }
      if (!table.isEnabled()) {
        isEnabled = false;
      }

      Color background = table.getBackground();
      if (value instanceof Boolean) {
        myCheckBox.setSelected(((Boolean) value).booleanValue());
        myCheckBox.setBackground(background);
        myCheckBox.setEnabled(isEnabled);
        return myCheckBox;
      } else if (value instanceof String) {
        /*
        myComboBox.removeAllItems();
        myComboBox.addItem(value);
        */
        myComboBox.setText((String) value);
        myComboBox.setBackground(background);
        myComboBox.setEnabled(isEnabled);
        return myComboBox;
      } else if (value instanceof Integer) {
        if (key instanceof IntOption && ((IntOption) key).isDefaultValue(value)) {
          myIntLabel.setText(((IntOption) key).getDefaultValueText());
        } else {
          myIntLabel.setText(value.toString());
        }
        return myIntLabel;
      }

      myCheckBox.putClientProperty("JComponent.sizeVariant", "small");
      myComboBox.putClientProperty("JComponent.sizeVariant", "small");

      myEmptyLabel.setBackground(background);
      return myEmptyLabel;
    }
Ejemplo n.º 4
0
  private static void updateButtons(
      JTable table,
      final RowEditableTableModel tableModel,
      final JButton addButton,
      final JButton removeButton,
      final JButton upButton,
      final JButton downButton) {
    if (table.isEnabled()) {
      int index = table.getSelectedRow();
      if (0 <= index && index < tableModel.getRowCount()) {
        removeButton.setEnabled(true);
        upButton.setEnabled(index > 0);
        downButton.setEnabled(index < tableModel.getRowCount() - 1);
      } else {
        removeButton.setEnabled(false);
        upButton.setEnabled(false);
        downButton.setEnabled(false);
      }

      addButton.setEnabled(true);
    }
  }
    public Component getTableCellRendererComponent(
        JTable table, Object value, boolean selected, boolean focused, int row, int column) {
      setEnabled(table == null || table.isEnabled());

      if (column == 0 || column == 1) {
        setHorizontalAlignment(SwingConstants.CENTER);
        setForeground(null);
        setBackground(null);
      } else {
        setHorizontalAlignment(SwingConstants.RIGHT);
        for (int i = 0; i < highlightIndex.size(); i++) {
          if (row == ((Integer) highlightIndex.elementAt(i)).intValue()) {
            setForeground(Color.blue);
            break;
          } else setForeground(null);
        }
        if (row == flashIndex) {
          setBackground(Color.orange);
        } else setBackground(null);
      }
      super.getTableCellRendererComponent(table, value, selected, focused, row, column);

      return this;
    }
Ejemplo n.º 6
0
 private boolean shouldIgnore(MouseEvent e) {
   return e.isConsumed() || (!(SwingUtilities.isLeftMouseButton(e) && table.isEnabled()));
 }