コード例 #1
0
 private void setValue(final JComponent component) {
   final String primitiveFormName = _primitiveForm.getName();
   if (_dotDefinitionDialogFrame.isPropertyStatic(primitiveFormName, _property)) {
     Object object =
         _dotDefinitionDialogFrame.getValueOfStaticProperty(primitiveFormName, _property);
     if (component instanceof JComboBox) {
       final String currentValue;
       if (object instanceof Color) {
         currentValue = ColorManager.getInstance().getColorName((Color) object);
       } else if (object instanceof Integer) {
         Integer i = (Integer) object;
         if (i.equals(Font.PLAIN)) {
           currentValue = STANDARD_FONT;
         } else if (i.equals(Font.BOLD)) {
           currentValue = BOLD_FONT;
         } else if (i.equals(Font.ITALIC)) {
           currentValue = ITALIC_FONT;
         } else {
           currentValue = "Unbekannter Font";
         }
       } else {
         currentValue = (String) object;
       }
       JComboBox comboBox = (JComboBox) component;
       comboBox.setSelectedItem(currentValue);
     } else if (component instanceof JSpinner) {
       JSpinner spinner = (JSpinner) component;
       if (object instanceof Integer) {
         spinner.setValue((Integer) object);
       } else {
         spinner.setValue((Double) object);
       }
     }
   } else {
     if (component instanceof JComboBox) {
       JComboBox comboBox = (JComboBox) component;
       comboBox.setSelectedItem(DOTPoint.getDefaultValue(_property));
     } else if (component instanceof JSpinner) {
       JSpinner spinner = (JSpinner) component;
       spinner.setValue(DOTPoint.getDefaultValue(_property));
     }
   }
 }
コード例 #2
0
    @SuppressWarnings("serial")
    class DOTItemDialog extends JDialog {

      private final PrimitiveForm _primitiveForm;

      private final DOTProperty _property;

      private JComboBox _colorComboBox = new JComboBox(ColorManager.getInstance().getColorNames());

      private JComboBox _textStyleComboBox = new JComboBox(FONT_ITEMS);

      private JComboBox _textComboBox = new JComboBox(DOTPointPainter.DYNAMIC_TEXT_ITEMS);

      private JSpinner _diameterSpinner = new JSpinner(getNewDiameterSpinnerModel());

      private JSpinner _strokeWidthSpinner = new JSpinner(getNewStrokeWidthSpinnerModel());

      private JSpinner _transparencySpinner = new JSpinner(getNewTransparencySpinnerModel());

      private JSpinner _textSizeSpinner = new JSpinner(getNewTextSizeSpinnerModel());

      private final DynamicDefinitionComponent _dynamicDefinitionComponent;

      JComponent _component = null;

      @SuppressWarnings("unchecked")
      private Object initDynamicDefinitionComponent() {
        final String selectedPrimitiveFormName =
            _dotDefinitionDialogFrame.getSelectedPrimitiveForm();
        final DOTProperty currentProperty = _dotDefinitionDialogFrame.getSelectedProperty();
        PrimitiveFormPropertyPair pfpPair =
            new PrimitiveFormPropertyPair(selectedPrimitiveFormName, currentProperty);
        final JTable workWithThisTable = _dynamicTables.get(pfpPair);

        int selectedRow = workWithThisTable.getSelectedRow();
        if (selectedRow == -1) {
          if (workWithThisTable.getModel().getRowCount() > 0) {
            selectedRow = 0;
          } else {
            return null;
          }
        }
        selectedRow = workWithThisTable.convertRowIndexToModel(selectedRow);
        final TableModel model = workWithThisTable.getModel();
        DynamicDOTItemManager dynamicDOTItemManager = (DynamicDOTItemManager) model;
        final DisplayObjectTypeItemWithInterval dotItemWithInterval =
            dynamicDOTItemManager.get(selectedRow);
        _dynamicDefinitionComponent.fillComponents(dotItemWithInterval);
        return dotItemWithInterval.getItem().getPropertyValue();
      }

      private void addButtonListeners(JButton saveButton, JButton cancelButton) {
        ActionListener actionListenerSave =
            new ActionListener() {
              public void actionPerformed(ActionEvent e) {

                Object propertyValue = null;
                String errorString = null;
                if (_property == DOTProperty.DURCHMESSER) {
                  propertyValue = _diameterSpinner.getValue();
                  errorString = "Bitte wählen Sie einen Durchmesser aus!";
                } else if (_property == DOTProperty.FARBE || _property == DOTProperty.FUELLUNG) {
                  propertyValue = _colorComboBox.getSelectedItem();
                  errorString = "Bitte wählen Sie eine Farbe aus!";
                } else if (_property == DOTProperty.GROESSE) {
                  propertyValue = _textSizeSpinner.getValue();
                  errorString = "Bitte wählen Sie eine Schriftgröße aus!";
                } else if (_property == DOTProperty.STRICHBREITE) {
                  propertyValue = _strokeWidthSpinner.getValue();
                  errorString = "Bitte wählen Sie eine Strichbreite  aus!";
                } else if (_property == DOTProperty.TEXT) {
                  propertyValue = _textComboBox.getSelectedItem();
                  errorString = "Bitte wählen Sie einen Text aus!";
                } else if (_property == DOTProperty.TEXTSTIL) {
                  propertyValue = _textStyleComboBox.getSelectedItem();
                  errorString = "Bitte wählen Sie einen Textstil aus!";
                } else if (_property == DOTProperty.TRANSPARENZ) {
                  propertyValue = _transparencySpinner.getValue();
                  errorString = "Bitte wählen Sie eine Tranparenz aus!";
                } else {
                  errorString = "DOTPointDialog.addButtonListeners(): unbehandelte Eigenschaft!";
                }
                if (propertyValue == null) {
                  JOptionPane.showMessageDialog(
                      new JFrame(), errorString, "Fehler", JOptionPane.ERROR_MESSAGE);
                  return;
                }

                final String description = _dynamicDefinitionComponent.getInfoText();
                if (description == null) {
                  JOptionPane.showMessageDialog(
                      new JFrame(),
                      "Bitte geben Sie einen Info-Text ein!",
                      "Fehler",
                      JOptionPane.ERROR_MESSAGE);
                  return;
                }

                final String attributeGroupName =
                    _dynamicDefinitionComponent.getAttributeGroupName();
                if (attributeGroupName == null) {
                  JOptionPane.showMessageDialog(
                      new JFrame(),
                      "Bitte wählen Sie eine Attributgruppe aus!",
                      "Fehler",
                      JOptionPane.ERROR_MESSAGE);
                  return;
                }

                final String aspectName = _dynamicDefinitionComponent.getAspectName();
                if (aspectName == null) {
                  JOptionPane.showMessageDialog(
                      new JFrame(),
                      "Bitte wählen Sie einen Aspekt aus!",
                      "Fehler",
                      JOptionPane.ERROR_MESSAGE);
                  return;
                }

                final String attributeName = _dynamicDefinitionComponent.getAttributeName();
                if (attributeName == null) {
                  int error = _dynamicDefinitionComponent.checkAttributeName();
                  if (error == 1) {
                    JOptionPane.showMessageDialog(
                        new JFrame(),
                        "Bitte wählen Sie ein Attribut aus!",
                        "Fehler",
                        JOptionPane.ERROR_MESSAGE);
                    return;
                  } else if (error == 2) {
                    JOptionPane.showMessageDialog(
                        new JFrame(),
                        "Der Attributname ist ungültig!",
                        "Fehler",
                        JOptionPane.ERROR_MESSAGE);
                    return;
                  }
                }

                final Double fromValue = _dynamicDefinitionComponent.getFromValue();
                if (fromValue == null) {
                  int error = _dynamicDefinitionComponent.checkFromValue();
                  if (error == 1) {
                    JOptionPane.showMessageDialog(
                        new JFrame(),
                        "Bitte tragen Sie einen Von-Wert ein!",
                        "Fehler",
                        JOptionPane.ERROR_MESSAGE);
                    return;
                  } else if ((error == 2) || (error == 3)) {
                    JOptionPane.showMessageDialog(
                        new JFrame(),
                        "Bitte korrigieren Sie den Von-Wert!",
                        "Fehler",
                        JOptionPane.ERROR_MESSAGE);
                    return;
                  }
                }

                final Double toValue = _dynamicDefinitionComponent.getToValue();
                if (toValue == null) {
                  int error = _dynamicDefinitionComponent.checkToValue();
                  if (error == 1) {
                    JOptionPane.showMessageDialog(
                        new JFrame(),
                        "Bitte tragen Sie einen Bis-Wert ein!",
                        "Fehler",
                        JOptionPane.ERROR_MESSAGE);
                    return;
                  } else if ((error == 2) || (error == 3)) {
                    JOptionPane.showMessageDialog(
                        new JFrame(),
                        "Bitte korrigieren Sie den Bis-Wert!",
                        "Fehler",
                        JOptionPane.ERROR_MESSAGE);
                    return;
                  }
                }

                if ((fromValue != null) && (toValue != null) && fromValue > toValue) {
                  JOptionPane.showMessageDialog(
                      new JFrame(),
                      "Der Von-Wert ist größer als der Bis-Wert!",
                      "Fehler",
                      JOptionPane.ERROR_MESSAGE);
                  return;
                }

                DynamicDOTItem dItem =
                    new DynamicDOTItem(
                        attributeGroupName, aspectName, attributeName, description, propertyValue);
                _dotDefinitionDialogFrame
                    .getScratchDisplayObjectType()
                    .setValueOfDynamicProperty(
                        _primitiveForm.getName(), _property, dItem, fromValue, toValue);
                _dotDefinitionDialogFrame.setSomethingChanged(true);
              }
            };
        saveButton.addActionListener(actionListenerSave);

        ActionListener actionListenerCancel =
            new ActionListener() {

              public void actionPerformed(ActionEvent e) {
                dispose();
              }
            };
        cancelButton.addActionListener(actionListenerCancel);
      }

      DOTItemDialog() {
        super();
        _primitiveForm = primitiveForm;
        _property = property;

        _dynamicDefinitionComponent =
            new DynamicDefinitionComponent(_configuration, new DOTPointPlugin());
        final Object propertyValue = initDynamicDefinitionComponent();

        final JPanel panel = new JPanel();
        panel.setLayout(new SpringLayout());

        JLabel aLabel = null;
        if (_property == DOTProperty.DURCHMESSER) {
          aLabel = new JLabel("Durchmesser: ");
          if (propertyValue != null) {
            _diameterSpinner.setValue(propertyValue);
          }
          _component = _diameterSpinner;
        } else if (_property == DOTProperty.FARBE || _property == DOTProperty.FUELLUNG) {
          aLabel = new JLabel("Farbe: ");
          if (propertyValue != null) {
            _colorComboBox.setSelectedItem(propertyValue);
          }
          _component = _colorComboBox;
        } else if (_property == DOTProperty.GROESSE) {
          aLabel = new JLabel("Schriftgröße: ");
          if (propertyValue != null) {
            _textSizeSpinner.setValue(propertyValue);
          }
          _component = _textSizeSpinner;
        } else if (_property == DOTProperty.STRICHBREITE) {
          aLabel = new JLabel("Strichbreite: ");
          if (propertyValue != null) {
            _strokeWidthSpinner.setValue(propertyValue);
          }
          _component = _strokeWidthSpinner;
        } else if (_property == DOTProperty.TEXT) {
          aLabel = new JLabel("Text: ");
          prepareTextComboBox(propertyValue);
          _component = _textComboBox;
        } else if (_property == DOTProperty.TEXTSTIL) {
          aLabel = new JLabel("Textstil: ");
          if (propertyValue != null) {
            _textStyleComboBox.setSelectedItem(propertyValue);
          }
          _component = _textStyleComboBox;
        } else if (_property == DOTProperty.TRANSPARENZ) {
          aLabel = new JLabel("Tranzparenz: ");
          if (propertyValue != null) {
            _transparencySpinner.setValue(propertyValue);
          }
          _component = _transparencySpinner;
        }
        panel.add(aLabel);
        panel.add(_component);

        panel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 0));
        SpringUtilities.makeCompactGrid(panel, 2, 20, 5);

        final JButton saveButton = new JButton("Speichern");
        saveButton.setEnabled(_dotDefinitionDialogFrame.isEditable());
        final JButton cancelButton = new JButton("Dialog schließen");

        final JPanel buttonsPanel = new JPanel();
        buttonsPanel.setLayout(new SpringLayout());

        buttonsPanel.add(saveButton);
        buttonsPanel.add(cancelButton);

        buttonsPanel.setBorder(BorderFactory.createEmptyBorder(5, 10, 5, 10));
        SpringUtilities.makeCompactGrid(buttonsPanel, 2, 20, 5);
        addButtonListeners(saveButton, cancelButton);

        setTitle("GND: Darstellungsfestlegung für Punkte");
        setLayout(new BorderLayout());
        add(new JScrollPane(panel), BorderLayout.NORTH);
        add(new JScrollPane(_dynamicDefinitionComponent), BorderLayout.CENTER);
        add(buttonsPanel, BorderLayout.SOUTH);
        pack();
        setSize(700, 550);
        final Rectangle bounds = getBounds();
        setLocation(
            new Point((int) (bounds.getHeight() / 1.5 + 300), (int) (bounds.getWidth() / 1.5)));
      }

      private void prepareTextComboBox(final Object propertyValue) {
        // _textComboBox wird in der letzten Zeile editierbar gemacht, und es wird
        // der übergebene Wert in diese Zeile eingetragen und selektiert, wenn er nicht
        // einem der anderen Einträge entspricht.

        if (propertyValue != null) {
          String propertyValueAsString = (String) propertyValue;
          final int size = _textComboBox.getModel().getSize();
          boolean propertyValueFound = false;
          for (int i = 0; i < size - 1; i++) {
            if (propertyValueAsString.equals((String) _textComboBox.getItemAt(i))) {
              propertyValueFound = true;
              _textComboBox.setSelectedIndex(i);
              break;
            }
          }
          if (!propertyValueFound) {
            _textComboBox.removeItemAt(size - 1);
            _textComboBox.addItem(propertyValueAsString);
            _textComboBox.setSelectedIndex(size - 1);
          }
        }

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

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

      public void runDialog() {
        setVisible(true);
      }
    }
コード例 #3
0
 private StaticPanel createStaticColorPanel(PrimitiveForm primitiveForm, DOTProperty property) {
   return createStaticComboBoxPanel(
       primitiveForm, property, "Farbe: ", ColorManager.getInstance().getColorNames());
 }