From: Niki Roo Date: Thu, 30 May 2019 16:44:05 +0000 (+0200) Subject: ConigItemColor: text and colour sync X-Git-Url: http://git.nikiroo.be/?a=commitdiff_plain;h=725fb761d23ef9076db698c0bde1b13b53a8d10f;p=fanfix-jexer.git ConigItemColor: text and colour sync --- diff --git a/src/be/nikiroo/utils/ui/ConfigItemColor.java b/src/be/nikiroo/utils/ui/ConfigItemColor.java index cbb8084..40cb9e9 100644 --- a/src/be/nikiroo/utils/ui/ConfigItemColor.java +++ b/src/be/nikiroo/utils/ui/ConfigItemColor.java @@ -5,6 +5,8 @@ import java.awt.Color; import java.awt.Graphics2D; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.awt.event.KeyAdapter; +import java.awt.event.KeyEvent; import java.awt.image.BufferedImage; import java.util.HashMap; import java.util.Map; @@ -23,6 +25,7 @@ public class ConfigItemColor> extends ConfigItem { private static final long serialVersionUID = 1L; private Map fields = new HashMap(); + private Map panels = new HashMap(); /** * Create a new {@link ConfigItemColor} for the given {@link MetaInfo}. @@ -55,7 +58,11 @@ public class ConfigItemColor> extends ConfigItem { if (field != null) { field.setText(value == null ? "" : value.toString()); } - // TODO: change color too + + JButton colorWheel = panels.get(getField(item)); + if (colorWheel != null) { + colorWheel.setIcon(getIcon(17, getFromInfoColor(item))); + } } @Override @@ -63,6 +70,16 @@ public class ConfigItemColor> extends ConfigItem { info.setString((String) value, item); } + /** + * Get the colour currently present in the linked info for the given item. + * + * @param item + * the item number to get for an array of values, or -1 to get + * the whole value (has no effect if {@link MetaInfo#isArray()} + * is FALSE) + * + * @return a colour + */ private int getFromInfoColor(int item) { Integer color = info.getColor(item, true); if (color == null) { @@ -94,10 +111,20 @@ public class ConfigItemColor> extends ConfigItem { } }); + field.addKeyListener(new KeyAdapter() { + @Override + public void keyTyped(KeyEvent e) { + info.setString(field.getText() + e.getKeyChar(), item); + int color = getFromInfoColor(item); + colorWheel.setIcon(getIcon(17, color)); + } + }); + pane.add(colorWheel, BorderLayout.WEST); pane.add(field, BorderLayout.CENTER); fields.put(pane, field); + panels.put(pane, colorWheel); return pane; }