private void updateParameter() { JTextComponent textComp = getTextComponent(); if (textComp != null && getComboBox().isEditable()) { setParameterValue(textComp); } else { Object newValue = getComboBox().getSelectedItem(); getParameter().setValueAsText(newValue != null ? newValue.toString() : "", getExceptionHandler()); } } }
@Override public void updateUI() { super.updateUI(); JComboBox comboBox = getComboBox(); String text = getParameter().getValueAsText(); JTextComponent textComp = getTextComponent(); if (text != null && !text.equals(textComp.getText())) { if (textComp != null) { if (!textComp.getText().equals(text)) { textComp.setText(text); } } Object selItem = comboBox.getSelectedItem(); if (selItem == null || !selItem.equals(text)) { comboBox.setSelectedItem(text); } } if (comboBox.isEnabled() != isEnabled()) { comboBox.setEnabled(isEnabled()); } }
@Override protected void initUI() { setDefaultLabelComponent(true); _comboBox = new JComboBox(); nameEditorComponent(_comboBox); // Configure combo box if (getParameter().getProperties().getDescription() != null) { _comboBox.setToolTipText(getParameter().getProperties().getDescription()); } if (getParameter().getProperties().getValueSet() != null) { _comboBox.setModel(new DefaultComboBoxModel(getParameter().getProperties().getValueSet())); } _comboBox.setEnabled(!getParameter().getProperties().isReadOnly()); _comboBox.setEditable(!getParameter().getProperties().isValueSetBound()); JTextComponent textComp = getTextComponent(); if (textComp != null) { textComp.setInputVerifier(getDefaultInputVerifier()); } _comboBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { updateParameter(); } }); java.awt.Font font = _comboBox.getFont(); if (font != null) { _comboBox.setFont(new java.awt.Font(font.getName(), Font.PLAIN, font.getSize())); } }
@Override public void reconfigureUI() { JComboBox jComboBox = getComboBox(); ItemListener[] itemListeners = (ItemListener[]) jComboBox.getListeners(ItemListener.class); ActionListener[] actionListeners = (ActionListener[]) jComboBox.getListeners(ActionListener.class); String[] valueSet = getParameter().getProperties().getValueSet(); if (valueSet != null) { for (int i = 0; i < valueSet.length; i++) { setEnabled(!getParameter().getProperties().isReadOnly()); jComboBox.setEditable(!getParameter().getProperties().isValueSetBound()); jComboBox.setSelectedItem(getParameter().getValueAsText());
public void testComboBoxEditor() { final ParamProperties properties = new ParamProperties(String[].class); properties.setLabel(LABEL_NAME); properties.setPhysicalUnit(UNIT_NAME); properties.setDefaultValue("ich"); properties.setValueSet(new String[]{"ich", "du", "er", "sie", "es"}); properties.setValueSetBound(true); properties.setEditorClass(ComboBoxEditor.class); final Parameter parameter = new Parameter(PARAM_NAME, properties); ParamEditor editor = parameter.getEditor(); assertTrue(editor instanceof ComboBoxEditor); final ComboBoxEditor comboBoxEditor = (ComboBoxEditor) editor; final JComponent editorComponent = comboBoxEditor.getEditorComponent(); assertEquals(JComboBox.class.getName(), editorComponent.getClass().getName()); assertEquals("theParamName.Editor", editorComponent.getName()); assertEquals("theParamName.Label", comboBoxEditor.getLabelComponent().getName()); assertEquals(LABEL_NAME + ": ", comboBoxEditor.getLabelComponent().getText()); assertNull(comboBoxEditor.getPhysUnitLabelComponent()); }
/** * Gets the UI component used to edit the parameter's value. */ public JComponent getEditorComponent() { return getComboBox(); }
editor = new ListEditor(parameter); } else { editor = new ComboBoxEditor(parameter);