コード例 #1
0
ファイル: TestbedSidePanel.java プロジェクト: 4thjuly/jbox2d
 private void addSettings(JPanel argPanel, TestbedSettings argSettings, SettingType argIgnore) {
   for (TestbedSetting setting : argSettings.getSettings()) {
     if (setting.settingsType == argIgnore) {
       continue;
     }
     switch (setting.constraintType) {
       case RANGE:
         JLabel text = new JLabel(setting.name + ": " + setting.value);
         JSlider slider = new JSlider(setting.min, setting.max, setting.value);
         slider.setMaximumSize(new Dimension(200, 20));
         slider.addChangeListener(this);
         slider.setName(setting.name);
         slider.putClientProperty(SETTING_TAG, setting);
         slider.putClientProperty(LABEL_TAG, text);
         argPanel.add(text);
         argPanel.add(slider);
         break;
       case BOOLEAN:
         JCheckBox checkbox = new JCheckBox(setting.name);
         checkbox.setSelected(setting.enabled);
         checkbox.addChangeListener(this);
         checkbox.putClientProperty(SETTING_TAG, setting);
         argPanel.add(checkbox);
         break;
     }
   }
 }
コード例 #2
0
    @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;
    }
コード例 #3
0
 public MyValueEditor() {
   final ActionListener itemChoosen =
       new ActionListener() {
         @Override
         public void actionPerformed(@NotNull ActionEvent e) {
           if (myCurrentNode != null) {
             myCurrentNode.setValue(getCellEditorValue());
             somethingChanged();
           }
         }
       };
   myBooleanEditor.addActionListener(itemChoosen);
   myOptionsEditor.addActionListener(itemChoosen);
   myBooleanEditor.putClientProperty("JComponent.sizeVariant", "small");
   myOptionsEditor.putClientProperty("JComponent.sizeVariant", "small");
 }
コード例 #4
0
  private void updateStatesPanel() {
    // Group the states first into individual panels
    List<BooleanTokenOverlay> overlays =
        new ArrayList<BooleanTokenOverlay>(TabletopTool.getCampaign().getTokenStatesMap().values());
    Map<String, JPanel> groups = new TreeMap<String, JPanel>();
    groups.put("", new JPanel(new FormLayout("0px:grow 2px 0px:grow 2px 0px:grow 2px 0px:grow")));
    for (BooleanTokenOverlay overlay : overlays) {
      String group = overlay.getGroup();
      if (group != null && (group = group.trim()).length() != 0) {
        JPanel panel = groups.get(group);
        if (panel == null) {
          panel = new JPanel(new FormLayout("0px:grow 2px 0px:grow 2px 0px:grow 2px 0px:grow"));
          panel.setBorder(BorderFactory.createTitledBorder(group));
          groups.put(group, panel);
        }
      }
    }
    // Add the group panels and bar panel to the states panel
    JPanel panel = getStatesPanel();
    panel.removeAll();
    FormLayout layout = new FormLayout("0px:grow");
    panel.setLayout(layout);
    int row = 1;
    for (JPanel gPanel : groups.values()) {
      layout.appendRow(new RowSpec("pref"));
      layout.appendRow(new RowSpec("2px"));
      panel.add(gPanel, new CellConstraints(1, row));
      row += 2;
    }
    layout.appendRow(new RowSpec("pref"));
    layout.appendRow(new RowSpec("2px"));
    JPanel barPanel = new JPanel(new FormLayout("right:pref 2px pref 5px right:pref 2px pref"));
    panel.add(barPanel, new CellConstraints(1, row));

    // Add the individual check boxes.
    for (BooleanTokenOverlay state : overlays) {
      String group = state.getGroup();
      panel = groups.get("");
      if (group != null && (group = group.trim()).length() != 0) panel = groups.get(group);
      int x = panel.getComponentCount() % 4;
      int y = panel.getComponentCount() / 4;
      if (x == 0) {
        layout = (FormLayout) panel.getLayout();
        if (y != 0) layout.appendRow(new RowSpec("2px"));
        layout.appendRow(new RowSpec("pref"));
      }
      panel.add(new JCheckBox(state.getName()), new CellConstraints(x * 2 + 1, y * 2 + 1));
    }
    // Add sliders to the bar panel
    if (TabletopTool.getCampaign().getTokenBarsMap().size() > 0) {
      layout = (FormLayout) barPanel.getLayout();
      barPanel.setName("bar");
      barPanel.setBorder(BorderFactory.createTitledBorder("Bars"));
      int count = 0;
      row = 0;
      for (BarTokenOverlay bar : TabletopTool.getCampaign().getTokenBarsMap().values()) {
        int working = count % 2;
        if (working == 0) { // slider row
          layout.appendRow(new RowSpec("pref"));
          row += 1;
        }
        JPanel labelPanel = new JPanel(new FormLayout("pref", "pref 2px:grow pref"));
        barPanel.add(labelPanel, new CellConstraints(1 + working * 4, row));
        labelPanel.add(
            new JLabel(bar.getName() + ":"),
            new CellConstraints(1, 1, CellConstraints.RIGHT, CellConstraints.TOP));
        JSlider slider = new JSlider(0, 100);
        JCheckBox hide = new JCheckBox("Hide");
        hide.putClientProperty("JSlider", slider);
        hide.addChangeListener(
            new ChangeListener() {
              @Override
              public void stateChanged(ChangeEvent e) {
                JSlider js = (JSlider) ((JCheckBox) e.getSource()).getClientProperty("JSlider");
                js.setEnabled(!((JCheckBox) e.getSource()).isSelected());
              }
            });
        labelPanel.add(hide, new CellConstraints(1, 3, CellConstraints.RIGHT, CellConstraints.TOP));
        slider.setName(bar.getName());
        slider.setPaintLabels(true);
        slider.setPaintTicks(true);
        slider.setMajorTickSpacing(20);
        slider.createStandardLabels(20);
        slider.setMajorTickSpacing(10);
        barPanel.add(slider, new CellConstraints(3 + working * 4, row));
        if (working != 0) { // spacer row
          layout.appendRow(new RowSpec("2px"));
          row += 1;
        }
        count += 1;
      }
    }
  }