|
1 | 1 | package fn10.bedrockr.windows.componets; |
2 | 2 |
|
3 | | -import javax.swing.ImageIcon; |
4 | | -import javax.swing.JButton; |
5 | | -import javax.swing.JLabel; |
| 3 | +import javax.annotation.Nonnull; |
6 | 4 | import javax.annotation.Nullable; |
7 | 5 | import javax.swing.*; |
8 | 6 | import java.awt.*; |
| 7 | +import java.awt.event.ItemEvent; |
| 8 | +import java.awt.event.ItemListener; |
9 | 9 | import java.lang.reflect.Type; |
10 | | - |
11 | | -import javax.swing.SpringLayout; |
12 | 10 | import javax.swing.border.LineBorder; |
| 11 | +import fn10.bedrockr.Launcher; |
13 | 12 |
|
14 | 13 | public class RElementValue extends JPanel { |
15 | 14 |
|
16 | 15 | private SpringLayout Lay = new SpringLayout(); |
17 | 16 | private JLabel Name = new JLabel(); |
18 | 17 | private JButton Help = new JButton(new ImageIcon(getClass().getResource("/ui/Help.png"))); |
| 18 | + private Component Input; |
| 19 | + private JCheckBox EnableDis = new JCheckBox(); |
19 | 20 |
|
20 | | - private final static Dimension Size = new Dimension(320, 60); |
| 21 | + private final static Dimension Size = new Dimension(335, 40); |
| 22 | + private String Target = ""; |
21 | 23 |
|
22 | | - public RElementValue(Type InputType, String TargetField, String DisplayName, Boolean Optional, @Nullable String HelpString ) { |
| 24 | + public RElementValue(@Nonnull Type InputType, String TargetField, String DisplayName, Boolean Optional, |
| 25 | + @Nullable String HelpString) { |
23 | 26 | super(); |
| 27 | + |
| 28 | + this.Target = TargetField; |
| 29 | + |
24 | 30 | setMaximumSize(Size); |
25 | 31 | setPreferredSize(Size); |
| 32 | + setBorder(new LineBorder(Color.DARK_GRAY)); |
| 33 | + setLayout(Lay); |
26 | 34 |
|
27 | | - // for testing |
28 | | - setBorder(new LineBorder(Color.white)); |
| 35 | + Help.setSize(6, 6); |
| 36 | + Help.putClientProperty("JButton.buttonType", "help" ); |
| 37 | + //Help.setBorder(new FlatLineBorder(new Insets(3, 3, 3, 3), Color.white, 1, 32)); |
| 38 | + |
| 39 | + Launcher.LOG.info(InputType.getTypeName()); |
| 40 | + if (InputType.equals(Boolean.class)) { |
| 41 | + String[] vals = { "true", "false" }; |
| 42 | + Input = new JComboBox<String>(vals); |
| 43 | + } else { |
| 44 | + Input = new JTextField(); |
| 45 | + } |
| 46 | + |
| 47 | + EnableDis.addItemListener(new ItemListener() { |
| 48 | + |
| 49 | + @Override |
| 50 | + public void itemStateChanged(ItemEvent e) { |
| 51 | + EnableDis.setEnabled(e.getStateChange() == e.SELECTED ? true : false); |
| 52 | + } |
| 53 | + |
| 54 | + }); |
29 | 55 |
|
30 | | - Help.setSize(30, 30); |
31 | | - |
32 | 56 | Name.setText(DisplayName); |
33 | 57 |
|
34 | | - add(Name); |
| 58 | + Lay.putConstraint(SpringLayout.VERTICAL_CENTER, Name, 0, SpringLayout.VERTICAL_CENTER, this); |
| 59 | + Lay.putConstraint(SpringLayout.WEST, Name, 13, SpringLayout.WEST, this); |
| 60 | + |
| 61 | + Lay.putConstraint(SpringLayout.WEST, Input, 3, SpringLayout.EAST, Name); |
| 62 | + Lay.putConstraint(SpringLayout.NORTH, Input, 3, SpringLayout.NORTH, this); |
| 63 | + Lay.putConstraint(SpringLayout.SOUTH, Input, -3, SpringLayout.SOUTH, this); |
| 64 | + Lay.putConstraint(SpringLayout.EAST, Input, -3, SpringLayout.WEST, EnableDis); |
| 65 | + |
| 66 | + Lay.putConstraint(SpringLayout.EAST, EnableDis, -3, SpringLayout.EAST, this); |
| 67 | + Lay.putConstraint(SpringLayout.VERTICAL_CENTER, EnableDis, 0, SpringLayout.VERTICAL_CENTER, this); |
| 68 | + |
| 69 | + if (!Optional) { |
| 70 | + EnableDis.setEnabled(false); |
| 71 | + } |
| 72 | + |
| 73 | + Launcher.LOG.info(Input.toString()); |
35 | 74 | add(Help); |
| 75 | + add(Name); |
| 76 | + add(Input); |
| 77 | + add(EnableDis); |
| 78 | + |
| 79 | + |
| 80 | + |
36 | 81 | } |
37 | 82 | } |
0 commit comments