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(""));
}
}
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;
}
Aggregations