Line | |
---|
1 | package com.framsticks.gui.components; |
---|
2 | |
---|
3 | import com.framsticks.params.types.ValueParam; |
---|
4 | import com.framsticks.util.Strings; |
---|
5 | |
---|
6 | import javax.swing.*; |
---|
7 | import java.awt.*; |
---|
8 | |
---|
9 | @SuppressWarnings("serial") |
---|
10 | public class TextFieldControl extends ValueControl { |
---|
11 | |
---|
12 | |
---|
13 | private static final Color CORRECT_COLOR = new Color(180, 255, 215); |
---|
14 | private static final Color WRONG_COLOR = new Color(255, 180, 215); |
---|
15 | |
---|
16 | private JTextField textField = new JTextField(); |
---|
17 | |
---|
18 | @Override |
---|
19 | protected boolean notifyOfChange() { |
---|
20 | boolean result = super.notifyOfChange(); |
---|
21 | textField.setBackground(result ? CORRECT_COLOR : WRONG_COLOR); |
---|
22 | return result; |
---|
23 | } |
---|
24 | |
---|
25 | public TextFieldControl(ValueParam valueParam) { |
---|
26 | super(valueParam); |
---|
27 | |
---|
28 | textField.setMinimumSize(new Dimension(0, Control.LINE_HEIGHT)); |
---|
29 | this.setMaximumSize(new Dimension(Integer.MAX_VALUE, Control.LINE_HEIGHT)); |
---|
30 | |
---|
31 | textField.setEditable(!isReadOnly()); |
---|
32 | |
---|
33 | textField.getDocument().addDocumentListener(createDocumentListener(this)); |
---|
34 | |
---|
35 | addAsOnlyChild(textField); |
---|
36 | } |
---|
37 | |
---|
38 | @Override |
---|
39 | public void setValueImpl(Object text) { |
---|
40 | textField.setText(Strings.toStringNullProof(text)); |
---|
41 | } |
---|
42 | |
---|
43 | @Override |
---|
44 | public Object getValue() { |
---|
45 | return textField.getText(); |
---|
46 | } |
---|
47 | |
---|
48 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.