Search in sources :

Example 1 with ClonedComboBoxModel

use of org.freeplane.features.attribute.mindmapmode.AssignAttributeDialog.ClonedComboBoxModel in project freeplane by freeplane.

the class AddAttributeAction method selectedAttributeChanged.

protected void selectedAttributeChanged(final Object selectedAttributeName, final JComboBox values) {
    final MapModel map = Controller.getCurrentController().getMap();
    final AttributeRegistry attributes = AttributeRegistry.getRegistry(map);
    try {
        final AttributeRegistryElement element = attributes.getElement(selectedAttributeName.toString());
        final ComboBoxModel selectedValues = element.getValues();
        values.setModel(new ClonedComboBoxModel(selectedValues));
        try {
            final Object firstValue = selectedValues.getElementAt(0);
            values.setSelectedItem(firstValue);
        } catch (final ArrayIndexOutOfBoundsException ex) {
        }
        values.setEditable(!element.isRestricted());
    } catch (final NoSuchElementException ex) {
        values.setEditable(!selectedAttributeName.toString().equals(""));
    }
}
Also used : AttributeRegistry(org.freeplane.features.attribute.AttributeRegistry) AttributeRegistryElement(org.freeplane.features.attribute.AttributeRegistryElement) MapModel(org.freeplane.features.map.MapModel) ClonedComboBoxModel(org.freeplane.features.attribute.mindmapmode.AssignAttributeDialog.ClonedComboBoxModel) ClonedComboBoxModel(org.freeplane.features.attribute.mindmapmode.AssignAttributeDialog.ClonedComboBoxModel) ComboBoxModel(javax.swing.ComboBoxModel) NoSuchElementException(java.util.NoSuchElementException)

Example 2 with ClonedComboBoxModel

use of org.freeplane.features.attribute.mindmapmode.AssignAttributeDialog.ClonedComboBoxModel in project freeplane by freeplane.

the class AddAttributeAction method getPanel.

/**
 * This method creates the input dialog
 *
 * @return : the input dialog
 */
private JPanel getPanel() {
    final JPanel panel = new JPanel();
    panel.setLayout(new GridBagLayout());
    panel.setBorder(new EtchedBorder());
    final GridBagConstraints gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 0;
    gridBagConstraints.anchor = GridBagConstraints.CENTER;
    gridBagConstraints.insets = new Insets(20, 10, 2, 10);
    // Size of JComboBoxes
    final String pattern = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
    final JLabel patternLabel = new JLabel(pattern);
    final Dimension comboBoxMaximumSize = patternLabel.getPreferredSize();
    comboBoxMaximumSize.width += 4;
    comboBoxMaximumSize.height += 10;
    // Label: name
    final JLabel nameLabel = new JLabel(TextUtils.getText("attribute_name"));
    panel.add(nameLabel, gridBagConstraints);
    gridBagConstraints.gridx++;
    // Label: value
    final JLabel valueLabel = new JLabel(TextUtils.getText("attribute_value"));
    panel.add(valueLabel, gridBagConstraints);
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy++;
    // Attribute name combo-box
    gridBagConstraints.insets = new Insets(2, 10, 20, 10);
    attributeNames = new JComboBoxWithBorder();
    final MapModel map = Controller.getCurrentController().getMap();
    final AttributeRegistry attributes = AttributeRegistry.getRegistry(map);
    final ComboBoxModel names = attributes.getComboBoxModel();
    attributeNames.setModel(new ClonedComboBoxModel(names));
    attributeNames.setEditable(true);
    attributeNames.setMaximumSize(comboBoxMaximumSize);
    attributeNames.setPreferredSize(comboBoxMaximumSize);
    attributeNames.addItemListener(new ItemListener() {

        public void itemStateChanged(final ItemEvent e) {
            selectedAttributeChanged(e.getItem(), attributeValues);
        }
    });
    panel.add(attributeNames, gridBagConstraints);
    // Attribute value combo-box
    attributeValues = new JComboBoxWithBorder();
    attributeValues.setRenderer(new TypedListCellRenderer());
    attributeValues.setMaximumSize(comboBoxMaximumSize);
    attributeValues.setPreferredSize(comboBoxMaximumSize);
    gridBagConstraints.gridx++;
    panel.add(attributeValues, gridBagConstraints);
    // set focus to attributeNames
    panel.addHierarchyListener(new HierarchyListener() {

        public void hierarchyChanged(HierarchyEvent e) {
            final Component component = e.getComponent();
            if (component.isShowing()) {
                attributeNames.requestFocus();
                component.removeHierarchyListener(this);
            }
        }
    });
    return panel;
}
Also used : JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) ItemEvent(java.awt.event.ItemEvent) Insets(java.awt.Insets) GridBagLayout(java.awt.GridBagLayout) JLabel(javax.swing.JLabel) Dimension(java.awt.Dimension) MapModel(org.freeplane.features.map.MapModel) HierarchyListener(java.awt.event.HierarchyListener) EtchedBorder(javax.swing.border.EtchedBorder) TypedListCellRenderer(org.freeplane.core.ui.components.TypedListCellRenderer) AttributeRegistry(org.freeplane.features.attribute.AttributeRegistry) HierarchyEvent(java.awt.event.HierarchyEvent) ItemListener(java.awt.event.ItemListener) ClonedComboBoxModel(org.freeplane.features.attribute.mindmapmode.AssignAttributeDialog.ClonedComboBoxModel) JComboBoxWithBorder(org.freeplane.core.ui.components.JComboBoxWithBorder) Component(java.awt.Component) ClonedComboBoxModel(org.freeplane.features.attribute.mindmapmode.AssignAttributeDialog.ClonedComboBoxModel) ComboBoxModel(javax.swing.ComboBoxModel)

Aggregations

ComboBoxModel (javax.swing.ComboBoxModel)2 AttributeRegistry (org.freeplane.features.attribute.AttributeRegistry)2 ClonedComboBoxModel (org.freeplane.features.attribute.mindmapmode.AssignAttributeDialog.ClonedComboBoxModel)2 MapModel (org.freeplane.features.map.MapModel)2 Component (java.awt.Component)1 Dimension (java.awt.Dimension)1 GridBagConstraints (java.awt.GridBagConstraints)1 GridBagLayout (java.awt.GridBagLayout)1 Insets (java.awt.Insets)1 HierarchyEvent (java.awt.event.HierarchyEvent)1 HierarchyListener (java.awt.event.HierarchyListener)1 ItemEvent (java.awt.event.ItemEvent)1 ItemListener (java.awt.event.ItemListener)1 NoSuchElementException (java.util.NoSuchElementException)1 JLabel (javax.swing.JLabel)1 JPanel (javax.swing.JPanel)1 EtchedBorder (javax.swing.border.EtchedBorder)1 JComboBoxWithBorder (org.freeplane.core.ui.components.JComboBoxWithBorder)1 TypedListCellRenderer (org.freeplane.core.ui.components.TypedListCellRenderer)1 AttributeRegistryElement (org.freeplane.features.attribute.AttributeRegistryElement)1