+ private void addColorField(final MetaInfo<E> info) {
+ final JTextField field = new JTextField();
+ field.setToolTipText(info.getDescription());
+ field.setText(info.getString());
+
+ info.addReloadedListener(new Runnable() {
+ @Override
+ public void run() {
+ field.setText(info.getString());
+ }
+ });
+ info.addSaveListener(new Runnable() {
+ @Override
+ public void run() {
+ info.setString(field.getText());
+ }
+ });
+
+ this.add(label(info), BorderLayout.WEST);
+ JPanel pane = new JPanel(new BorderLayout());
+
+ final JButton colorWheel = new JButton();
+ colorWheel.setIcon(getIcon(17, info.getColor()));
+ colorWheel.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ Color initialColor = new Color(info.getColor(), true);
+ Color newColor = JColorChooser.showDialog(ConfigItem.this,
+ info.getName(), initialColor);
+ if (newColor != null) {
+ info.setColor(newColor.getRGB());
+ field.setText(info.getString());
+ colorWheel.setIcon(getIcon(17, info.getColor()));
+ }
+ }
+ });
+ pane.add(colorWheel, BorderLayout.WEST);
+ pane.add(field, BorderLayout.CENTER);
+ this.add(pane, BorderLayout.CENTER);
+ }
+
+ private void addBrowseField(final MetaInfo<E> info, final boolean dir) {
+ final JTextField field = new JTextField();
+ field.setToolTipText(info.getDescription());
+ field.setText(info.getString());
+
+ info.addReloadedListener(new Runnable() {
+ @Override
+ public void run() {
+ field.setText(info.getString());
+ }
+ });
+ info.addSaveListener(new Runnable() {
+ @Override
+ public void run() {
+ info.setString(field.getText());
+ }
+ });
+
+ 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) {
+ info.setString(file.getAbsolutePath());
+ field.setText(info.getString());
+ }
+ }
+ }
+ });
+
+ JPanel pane = new JPanel(new BorderLayout());
+ this.add(label(info), BorderLayout.WEST);
+ pane.add(browseButton, BorderLayout.WEST);
+ pane.add(field, BorderLayout.CENTER);
+ this.add(pane, BorderLayout.CENTER);
+ }
+
+ private void addComboboxField(final MetaInfo<E> info, boolean editable) {
+ // rawtypes for Java 1.6 (and 1.7 ?) support
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ final JComboBox field = new JComboBox(info.getAllowedValues());
+ field.setEditable(editable);
+ field.setSelectedItem(info.getString());
+
+ info.addReloadedListener(new Runnable() {
+ @Override
+ public void run() {
+ field.setSelectedItem(info.getString());
+ }
+ });
+ info.addSaveListener(new Runnable() {
+ @Override
+ public void run() {
+ info.setString(field.getSelectedItem().toString());
+ }
+ });
+
+ this.add(label(info), BorderLayout.WEST);
+ this.add(field, BorderLayout.CENTER);
+ }
+
+ private void addPasswordField(final MetaInfo<E> info) {
+ final JPasswordField field = new JPasswordField();
+ field.setToolTipText(info.getDescription());
+ field.setText(info.getString());
+
+ info.addReloadedListener(new Runnable() {
+ @Override
+ public void run() {
+ field.setText(info.getString());
+ }
+ });
+ info.addSaveListener(new Runnable() {
+ @Override
+ public void run() {
+ info.setString(new String(field.getPassword()));
+ }
+ });
+
+ this.add(label(info), BorderLayout.WEST);
+ this.add(field, BorderLayout.CENTER);
+ }
+
+ private void addIntField(final MetaInfo<E> info) {
+ final JTextField field = new JTextField();
+ field.setToolTipText(info.getDescription());
+ field.setText(info.getString());
+ field.setInputVerifier(new InputVerifier() {
+ @Override
+ public boolean verify(JComponent input) {
+ String text = field.getText().trim();
+ if (text.startsWith("-")) {
+ text = text.substring(1).trim();
+ }
+
+ return text.replaceAll("[0-9]", "").isEmpty();
+ }
+ });
+
+ info.addReloadedListener(new Runnable() {
+ @Override
+ public void run() {
+ field.setText(info.getString());
+ }
+ });
+ info.addSaveListener(new Runnable() {
+ @Override
+ public void run() {
+ info.setString(field.getText());
+ Integer value = info.getInteger();
+ if (value == null) {
+ info.setString("");
+ } else {
+ info.setInteger(value);
+ }
+ field.setText(info.getString());
+ }
+ });
+
+ JButton up = new BasicArrowButton(BasicArrowButton.NORTH);
+ JButton down = new BasicArrowButton(BasicArrowButton.SOUTH);
+
+ up.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent ae) {
+ int value = 0;
+ try {
+ value = Integer.parseInt(field.getText());
+ } catch (NumberFormatException e) {
+ }
+
+ field.setText(Integer.toString(value + 1));
+ }
+ });
+
+ down.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent ae) {
+ int value = 0;
+ try {
+ value = Integer.parseInt(field.getText());
+ } catch (NumberFormatException e) {
+ }
+
+ field.setText(Integer.toString(value - 1));
+ }
+ });
+
+ JPanel upDown = new JPanel(new BorderLayout());
+ upDown.add(up, BorderLayout.NORTH);
+ upDown.add(down, BorderLayout.SOUTH);
+
+ JPanel pane = new JPanel(new BorderLayout());
+ pane.add(upDown, BorderLayout.WEST);
+ pane.add(field, BorderLayout.CENTER);
+
+ this.add(label(info), BorderLayout.WEST);
+ this.add(pane, BorderLayout.CENTER);