[84] | 1 | package com.framsticks.gui.controls; |
---|
| 2 | |
---|
[101] | 3 | import com.framsticks.gui.Gui; |
---|
[84] | 4 | import com.framsticks.params.PrimitiveParam; |
---|
| 5 | |
---|
| 6 | import javax.swing.*; |
---|
[107] | 7 | import javax.swing.text.JTextComponent; |
---|
| 8 | |
---|
[84] | 9 | import java.awt.*; |
---|
| 10 | |
---|
| 11 | @SuppressWarnings("serial") |
---|
[107] | 12 | public class TextFieldControl extends TextOnlyControl { |
---|
[84] | 13 | |
---|
| 14 | |
---|
| 15 | private static final Color WRONG_COLOR = new Color(255, 180, 215); |
---|
| 16 | |
---|
| 17 | protected final JTextField textField; |
---|
[107] | 18 | private final Color correctColor; |
---|
[84] | 19 | |
---|
| 20 | @Override |
---|
| 21 | protected boolean notifyOfChange() { |
---|
| 22 | boolean result = super.notifyOfChange(); |
---|
[107] | 23 | textField.setBackground(result ? correctColor : WRONG_COLOR); |
---|
[84] | 24 | return result; |
---|
| 25 | } |
---|
| 26 | |
---|
[87] | 27 | public TextFieldControl(PrimitiveParam<?> valueParam) { |
---|
[84] | 28 | super(valueParam); |
---|
| 29 | textField = new JTextField(); |
---|
[90] | 30 | textField.setName("value"); |
---|
[107] | 31 | correctColor = textField.getBackground(); |
---|
[84] | 32 | |
---|
| 33 | textField.setMinimumSize(new Dimension(0, Control.LINE_HEIGHT)); |
---|
| 34 | this.setMaximumSize(new Dimension(Integer.MAX_VALUE, Control.LINE_HEIGHT)); |
---|
| 35 | |
---|
| 36 | addDefaultDocumentListener(textField); |
---|
| 37 | |
---|
[101] | 38 | Gui.addLeftToLabel(this, textField); |
---|
[84] | 39 | } |
---|
| 40 | |
---|
| 41 | |
---|
| 42 | @Override |
---|
[107] | 43 | protected JTextComponent getTextComponent() { |
---|
| 44 | return textField; |
---|
[84] | 45 | } |
---|
| 46 | |
---|
[98] | 47 | @Override |
---|
| 48 | protected void updateEnabled(boolean enabled) { |
---|
| 49 | textField.setEnabled(enabled); |
---|
| 50 | } |
---|
| 51 | |
---|
[84] | 52 | } |
---|