1 package be
.nikiroo
.utils
.ui
;
3 import java
.awt
.BorderLayout
;
4 import java
.awt
.Dimension
;
6 import javax
.swing
.JCheckBox
;
7 import javax
.swing
.JLabel
;
8 import javax
.swing
.JPanel
;
9 import javax
.swing
.JTextField
;
11 import be
.nikiroo
.utils
.resources
.Bundle
;
12 import be
.nikiroo
.utils
.resources
.Meta
.Format
;
13 import be
.nikiroo
.utils
.resources
.MetaInfo
;
16 * A graphical item that reflect a configuration option from the given
22 * the type of {@link Bundle} to edit
24 public class ConfigItem
<E
extends Enum
<E
>> extends JPanel
{
25 private static final long serialVersionUID
= 1L;
27 public ConfigItem(final MetaInfo
<E
> info
) {
28 this.setLayout(new BorderLayout());
30 if (info
.getFormat() == Format
.BOOLEAN
) {
31 final JCheckBox field
= new JCheckBox();
32 field
.setToolTipText(info
.getDescription());
33 Boolean state
= info
.getBoolean();
35 info
.getDefaultBoolean();
41 .println("No default value given for BOOLEAN parameter \""
43 + "\", we consider it is FALSE");
47 field
.setSelected(state
);
49 info
.addReloadedListener(new Runnable() {
52 Boolean state
= info
.getBoolean();
54 info
.getDefaultBoolean();
60 field
.setSelected(state
);
63 info
.addSaveListener(new Runnable() {
66 info
.setBoolean(field
.isSelected());
70 field
.setText(info
.getName());
71 this.add(field
, BorderLayout
.CENTER
);
73 final JTextField field
= new JTextField();
74 field
.setToolTipText(info
.getDescription());
75 field
.setText(info
.getString());
77 info
.addReloadedListener(new Runnable() {
80 field
.setText(info
.getString());
83 info
.addSaveListener(new Runnable() {
86 info
.setString(field
.getText());
90 this.add(label(info
.getName()), BorderLayout
.WEST
);
91 this.add(field
, BorderLayout
.CENTER
);
96 * Create a label which width is constrained in lock steps.
99 * the text of the label
103 private JLabel
label(String text
) {
104 final JLabel label
= new JLabel(text
);
106 Dimension ps
= label
.getPreferredSize();
108 ps
= label
.getSize();
113 for (int i
= 2 * step
; i
< 10 * step
; i
+= step
) {
122 label
.setPreferredSize(ps
);