3593d7ce3c8ded39e42289f08285f32b131accdf
1 package be
.nikiroo
.utils
.ui
;
3 import java
.awt
.BorderLayout
;
4 import java
.awt
.Dimension
;
5 import java
.util
.ArrayList
;
8 import javax
.swing
.JLabel
;
9 import javax
.swing
.JPanel
;
10 import javax
.swing
.JTextField
;
11 import javax
.swing
.border
.EmptyBorder
;
13 import be
.nikiroo
.utils
.resources
.Bundle
;
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;
26 private final Bundle
<E
> bundle
;
30 private JTextField valueField
;
32 public ConfigItem(Class
<E
> type
, Bundle
<E
> bundle
, E id
) {
36 this.setLayout(new BorderLayout());
37 this.setBorder(new EmptyBorder(2, 10, 2, 10));
39 JLabel nameLabel
= new JLabel(id
.toString());
40 nameLabel
.setPreferredSize(new Dimension(400, 0));
41 this.add(nameLabel
, BorderLayout
.WEST
);
43 valueField
= new JTextField();
44 valueField
.setText(value
);
47 this.add(valueField
, BorderLayout
.CENTER
);
51 * Reload the value from the {@link Bundle}.
53 public void reload() {
54 value
= bundle
.getString(id
);
55 valueField
.setText(value
);
59 * Save the current value to the {@link Bundle}.
62 value
= valueField
.getText();
63 bundle
.setString(id
, value
);
67 * Create a list of {@link ConfigItem}, one for each of the item in the
68 * given {@link Bundle}.
71 * a class instance of the item type to work on
73 * the {@link Bundle} to sort through
77 static public <E
extends Enum
<E
>> List
<ConfigItem
<E
>> getItems(
78 Class
<E
> type
, Bundle
<E
> bundle
) {
79 List
<ConfigItem
<E
>> list
= new ArrayList
<ConfigItem
<E
>>();
80 for (E id
: type
.getEnumConstants()) {
81 list
.add(new ConfigItem
<E
>(type
, bundle
, id
));