コード例 #1
0
  private StaticPanel createStaticTextPanel(PrimitiveForm primitiveForm, DOTProperty property) {
    StaticPanel theTextPanel =
        createStaticComboBoxPanel(
            primitiveForm, property, "Text: ", DOTPointPainter.STATIC_TEXT_ITEMS);
    final JComboBox theComboBox = theTextPanel.getComboBox();
    if (theComboBox == null) {
      return theTextPanel;
    }

    ItemListener comboBoxItemListener =
        new ItemListener() {
          public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
              if (theComboBox.getSelectedIndex() == DOTPointPainter.STATIC_TEXT_ITEMS.length - 1) {
                theComboBox.setEditable(true);
              } else {
                theComboBox.setEditable(false);
              }
            }
          }
        };
    theComboBox.addItemListener(comboBoxItemListener);

    ActionListener editorActionListener =
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            final int length = DOTPointPainter.STATIC_TEXT_ITEMS.length;
            final int index = length - 1;
            final ComboBoxEditor editor = theComboBox.getEditor();
            String editedItem = (String) editor.getItem();
            theComboBox.insertItemAt(editedItem, index);
            final DefaultComboBoxModel model = (DefaultComboBoxModel) theComboBox.getModel();
            if (model.getSize() > length) { // Sieht komisch aus, aber der direkte Weg ging nicht.
              model.removeElementAt(length);
            }
          }
        };
    theComboBox.getEditor().addActionListener(editorActionListener);

    return theTextPanel;
  }
コード例 #2
0
  private StaticPanel createStaticComboBoxPanel(
      PrimitiveForm primitiveForm, DOTProperty property, String labelText, Object[] items) {
    JLabel label = new JLabel(labelText);
    JComboBox comboBox = new JComboBox(items);
    comboBox.setMaximumSize(new Dimension(300, 25));
    comboBox.setEnabled(_dotDefinitionDialogFrame.isEditable());

    StaticPanel thePanel = new StaticPanel(primitiveForm, property);
    thePanel.setMaximumSize(new Dimension(300, 25));
    thePanel.setLayout(new SpringLayout());
    thePanel.setBorder(BorderFactory.createMatteBorder(2, 2, 2, 2, Color.BLACK));
    thePanel.add(label);
    thePanel.add(comboBox);
    SpringUtilities.makeCompactGrid(thePanel, 2, 5, 5);

    thePanel.setValue(comboBox);
    thePanel.addListener(comboBox);

    return thePanel;
  }
コード例 #3
0
  private StaticPanel createStaticSpinnerPanel(
      PrimitiveForm primitiveForm,
      DOTProperty property,
      String labelText,
      SpinnerModel spinnerModel) {
    JLabel label = new JLabel(labelText);
    JSpinner spinner = new JSpinner(spinnerModel);
    spinner.setMaximumSize(new Dimension(200, 20));
    spinner.setEnabled(_dotDefinitionDialogFrame.isEditable());

    StaticPanel thePanel = new StaticPanel(primitiveForm, property);
    thePanel.setLayout(new SpringLayout());
    thePanel.setBorder(BorderFactory.createMatteBorder(2, 2, 2, 2, Color.BLACK));
    thePanel.add(label);
    thePanel.add(spinner);
    SpringUtilities.makeCompactGrid(thePanel, 2, 5, 5);

    thePanel.setValue(spinner);
    thePanel.addListener(spinner);

    return thePanel;
  }