private void setTextComponent(JTextComponent textComponent) { if (_textComponent != null) { _textComponent.removeFocusListener(_focusListener); _focusListener = null; } _textComponent = textComponent; if (_textComponent != null) { _focusListener = createFocusListener(); _textComponent.addFocusListener(_focusListener); } if (_textComponent instanceof JTextArea) { _textComponent.setBorder(null); final JScrollPane pane = new JScrollPane(_textComponent); nameComponent(_component, "ScrollPane"); pane.setMinimumSize(_textComponent.getPreferredSize()); _component = pane; } else { _component = _textComponent; } }
@Override public void updateUI() { super.updateUI(); String text = getParameter().getValueAsText(); if (!getTextComponent().getText().equals(text)) { getTextComponent().setText(text); } if (getTextComponent().isEnabled() != isEnabled()) { if (getParameter().getProperties().isReadOnly()) { getTextComponent().setEnabled(false); getComponent().setEnabled(false); } else { getTextComponent().setEnabled(isEnabled()); getComponent().setEnabled(isEnabled()); } } }
int numCols = getParamProps().getNumCols(); int numRows = getParamProps().getNumRows(); nameEditorComponent(textComponent); if (getParameter().isTypeOf(Character.class)) { textComponent.setColumns(2); } else if (getParameter().isTypeOf(Byte.class)) { textComponent.setColumns(4); } else if (getParameter().isTypeOf(Short.class)) { textComponent.setColumns(6); } else if (getParameter().isTypeOf(Integer.class)) { textComponent.setColumns(8); } else if (getParameter().isTypeOf(Long.class)) { textComponent.setColumns(8); } else if (getParameter().isTypeOf(Float.class)) { textComponent.setColumns(8); } else if (getParameter().isTypeOf(Double.class)) { textComponent.setColumns(8); } else { if (getParameter().isTypeOf(Number.class)) { textComponent.setHorizontalAlignment(JTextField.RIGHT); textComponent.addActionListener(getDefaultActionListener()); setTextComponent(textComponent); } else { JTextArea textComponent = new JTextArea(); nameEditorComponent(textComponent);
public void testTextFieldEditor() { final ParamProperties properties = new ParamProperties(String.class); properties.setLabel(LABEL_NAME); properties.setPhysicalUnit(UNIT_NAME); properties.setDefaultValue("ich"); final Parameter parameter = new Parameter(PARAM_NAME, properties); ParamEditor editor = parameter.getEditor(); assertTrue(editor instanceof TextFieldEditor); final TextFieldEditor textFieldEditor = (TextFieldEditor) editor; final JComponent editorComponent = textFieldEditor.getEditorComponent(); assertEquals("theParamName.Editor", editorComponent.getName()); assertEquals(JTextField.class.getName(), editorComponent.getClass().getName()); assertEquals("theParamName.Label", textFieldEditor.getLabelComponent().getName()); assertEquals(LABEL_NAME + ": ", textFieldEditor.getLabelComponent().getText()); assertEquals("theParamName.Unit", textFieldEditor.getPhysUnitLabelComponent().getName()); assertEquals(" " + UNIT_NAME, textFieldEditor.getPhysUnitLabelComponent().getText()); }
private ParamProperties getParamProps() { return getParameter().getProperties(); }
editor = new TextFieldEditor(parameter);
private FocusAdapter createFocusListener() { final ParamProperties paramProperties = getParameter().getProperties(); final boolean selectAll = paramProperties.getPropertyValue(ParamProperties.SELECT_ALL_ON_FOCUS_KEY, true); if (selectAll) { return new FocusAdapter() { @Override public void focusGained(final FocusEvent e) { final JTextComponent tc = ((JTextComponent) e.getComponent()); tc.setCaretPosition(tc.getText().length()); tc.moveCaretPosition(0); } }; } else { return new FocusAdapter() { }; } } }