+ private void addStringField(final MetaInfo<E> info, int nhgap) {
+ final JTextField field = new JTextField();
+ field.setToolTipText(info.getDescription());
+ String value = info.getString(false);
+ reload(value);
+ field.setText(value);
+
+ info.addReloadedListener(new Runnable() {
+ @Override
+ public void run() {
+ String value = info.getString(false);
+ reload(value);
+ field.setText(value);
+ }
+ });
+ info.addSaveListener(new Runnable() {
+ @Override
+ public void run() {
+ String value = field.getText();
+ if (isChanged(value)) {
+ info.setString(value);
+ }
+ }
+ });
+
+ this.add(label(info, nhgap), BorderLayout.WEST);
+ this.add(field, BorderLayout.CENTER);
+
+ setPreferredSize(field);
+ }
+
+ private void addBooleanField(final MetaInfo<E> info, int nhgap) {
+ final JCheckBox field = new JCheckBox();
+ field.setToolTipText(info.getDescription());
+ Boolean state = info.getBoolean(true);
+
+ // Should not happen!
+ if (state == null) {
+ System.err
+ .println("No default value given for BOOLEAN parameter \""
+ + info.getName() + "\", we consider it is FALSE");
+ state = false;
+ }
+
+ reload(state);
+ field.setSelected(state);
+
+ info.addReloadedListener(new Runnable() {
+ @Override
+ public void run() {
+ Boolean state = info.getBoolean(true);
+ if (state == null) {
+ state = false;
+ }
+
+ reload(state);
+ field.setSelected(state);
+ }
+ });
+ info.addSaveListener(new Runnable() {
+ @Override
+ public void run() {
+ boolean state = field.isSelected();
+ if (isChanged(state)) {
+ info.setBoolean(state);
+ }
+ }
+ });
+
+ this.add(label(info, nhgap), BorderLayout.WEST);
+ this.add(field, BorderLayout.CENTER);
+
+ setPreferredSize(field);
+ }
+
+ private void addColorField(final MetaInfo<E> info, int nhgap) {
+ final JTextField field = new JTextField();
+ field.setToolTipText(info.getDescription());
+ String value = info.getString(false);
+ reload(value);
+ field.setText(value);
+
+ info.addReloadedListener(new Runnable() {
+ @Override
+ public void run() {
+ String value = info.getString(false);
+ reload(value);
+ field.setText(value);
+ }
+ });
+ info.addSaveListener(new Runnable() {
+ @Override
+ public void run() {
+ String value = field.getText();
+ if (isChanged(value)) {
+ info.setString(value);
+ }
+ }
+ });
+
+ this.add(label(info, nhgap), BorderLayout.WEST);
+ JPanel pane = new JPanel(new BorderLayout());
+
+ final JButton colorWheel = new JButton();
+ colorWheel.setIcon(getIcon(17, info.getColor(true)));
+ colorWheel.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ Integer icol = info.getColor(true);
+ if (icol == null) {
+ icol = new Color(255, 255, 255, 255).getRGB();
+ }
+ Color initialColor = new Color(icol, true);
+ Color newColor = JColorChooser.showDialog(ConfigItem.this,
+ info.getName(), initialColor);
+ if (newColor != null) {
+ info.setColor(newColor.getRGB());
+ field.setText(info.getString(false));
+ colorWheel.setIcon(getIcon(17, info.getColor(true)));
+ }
+ }
+ });
+ pane.add(colorWheel, BorderLayout.WEST);
+ pane.add(field, BorderLayout.CENTER);
+ this.add(pane, BorderLayout.CENTER);
+
+ setPreferredSize(pane);
+ }
+
+ private void addBrowseField(final MetaInfo<E> info, int nhgap,
+ final boolean dir) {
+ final JTextField field = new JTextField();
+ field.setToolTipText(info.getDescription());
+ String value = info.getString(false);
+ reload(value);
+ field.setText(value);
+
+ info.addReloadedListener(new Runnable() {
+ @Override
+ public void run() {
+ String value = info.getString(false);
+ reload(value);
+ field.setText(value);
+ }
+ });
+ info.addSaveListener(new Runnable() {
+ @Override
+ public void run() {
+ String value = field.getText();
+ if (isChanged(value)) {
+ info.setString(value);
+ }
+ }
+ });
+
+ JButton browseButton = new JButton("...");
+ browseButton.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ JFileChooser chooser = new JFileChooser();
+ chooser.setCurrentDirectory(null);
+ chooser.setFileSelectionMode(dir ? JFileChooser.DIRECTORIES_ONLY
+ : JFileChooser.FILES_ONLY);
+ if (chooser.showOpenDialog(ConfigItem.this) == JFileChooser.APPROVE_OPTION) {
+ File file = chooser.getSelectedFile();
+ if (file != null) {
+ String value = file.getAbsolutePath();
+ if (isChanged(value)) {
+ info.setString(value);
+ }
+ field.setText(value);
+ }
+ }
+ }
+ });
+
+ JPanel pane = new JPanel(new BorderLayout());
+ this.add(label(info, nhgap), BorderLayout.WEST);
+ pane.add(browseButton, BorderLayout.WEST);
+ pane.add(field, BorderLayout.CENTER);
+ this.add(pane, BorderLayout.CENTER);
+
+ setPreferredSize(pane);
+ }
+
+ private void addComboboxField(final MetaInfo<E> info, int nhgap,
+ boolean editable) {
+ // rawtypes for Java 1.6 (and 1.7 ?) support
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ final JComboBox field = new JComboBox(info.getAllowedValues());
+ field.setEditable(editable);
+ String value = info.getString(false);
+ reload(value);
+ field.setSelectedItem(value);
+
+ info.addReloadedListener(new Runnable() {
+ @Override
+ public void run() {
+ String value = info.getString(false);
+ reload(value);
+ field.setSelectedItem(value);
+ }
+ });
+ info.addSaveListener(new Runnable() {
+ @Override
+ public void run() {
+ String value = field.getSelectedItem().toString();
+ if (isChanged(value)) {
+ info.setString(value);
+ }
+ }
+ });
+
+ this.add(label(info, nhgap), BorderLayout.WEST);
+ this.add(field, BorderLayout.CENTER);
+
+ setPreferredSize(field);
+ }
+
+ private void addPasswordField(final MetaInfo<E> info, int nhgap) {
+ final JPasswordField field = new JPasswordField();
+ field.setToolTipText(info.getDescription());
+ String value = info.getString(false);
+ reload(value);
+ field.setText(value);
+
+ info.addReloadedListener(new Runnable() {
+ @Override
+ public void run() {
+ String value = info.getString(false);
+ reload(value);
+ field.setText(value);
+ }
+ });
+ info.addSaveListener(new Runnable() {
+ @Override
+ public void run() {
+ String value = new String(field.getPassword());
+ if (isChanged(value)) {
+ info.setString(value);
+ }
+ }
+ });
+
+ this.add(label(info, nhgap), BorderLayout.WEST);
+ this.add(field, BorderLayout.CENTER);
+
+ setPreferredSize(field);
+ }
+
+ private void addIntField(final MetaInfo<E> info, int nhgap) {
+ final JSpinner field = new JSpinner();
+ field.setToolTipText(info.getDescription());
+ int value = info.getInteger(true) == null ? 0 : info.getInteger(true);
+ reload(value);
+ field.setValue(value);
+
+ info.addReloadedListener(new Runnable() {
+ @Override
+ public void run() {
+ int value = info.getInteger(true) == null ? 0 : info
+ .getInteger(true);
+ reload(value);
+ field.setValue(value);
+ }
+ });
+ info.addSaveListener(new Runnable() {
+ @Override
+ public void run() {
+ int value = field.getValue() == null ? 0 : (Integer) field
+ .getValue();
+ if (isChanged(value)) {
+ info.setInteger(value);
+ }
+ }
+ });
+
+ this.add(label(info, nhgap), BorderLayout.WEST);
+ this.add(field, BorderLayout.CENTER);
+
+ setPreferredSize(field);