Mercurial > dive4elements > river
changeset 1291:1d04f35b2cc0
New methods for color transformation (html to rgb; rgb to html).
flys-client/trunk@2891 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Raimund Renkert <raimund.renkert@intevation.de> |
---|---|
date | Wed, 05 Oct 2011 09:26:13 +0000 |
parents | f4deeafa60b3 |
children | bdc270ea6195 |
files | flys-client/ChangeLog flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/StyleEditorWindow.java |
diffstat | 2 files changed, 43 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-client/ChangeLog Tue Oct 04 16:04:16 2011 +0000 +++ b/flys-client/ChangeLog Wed Oct 05 09:26:13 2011 +0000 @@ -1,3 +1,8 @@ +2011-10-05 Raimund Renkert <raimund.renkert@intevation.de> + + * src/main/java/de/intevation/flys/client/client/ui/chart/StyleEditorWindow.java: + New methods for color transformation (html to rgb; rgb to html). + 2011-10-04 Raimund Renkert <raimund.renkert@intevation.de> * src/main/java/de/intevation/flys/client/client/ui/chart/StyleEditorWindow.java:
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/StyleEditorWindow.java Tue Oct 04 16:04:16 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/StyleEditorWindow.java Wed Oct 05 09:26:13 2011 +0000 @@ -141,6 +141,7 @@ SpinnerItem s = new SpinnerItem(name, dname); s.setMin(1); s.setMax(10); + s.setValue(value); f = s; } else if (type.equals("boolean")) { @@ -155,20 +156,55 @@ f = c; } else if (type.equals("Color")) { - f = new ColorPickerItem(name, dname); + ColorPickerItem c = new ColorPickerItem(name, dname); + c.setValue(rgbToHtml(value)); + f = c; } else if (type.equals("Dash")) { f = new ComboBoxItem(name, dname); + f.setValue(value); } else { f = new FormItem(); } - f.setValue(value); f.setTitleStyle("color:#000; width:120px"); f.setTitleAlign(Alignment.LEFT); df.setFields(f); return df; } + + protected String rgbToHtml(String rgb) { + String[] parts = rgb.split(","); + int values[] = new int[parts.length]; + for (int i = 0; i < parts.length; i++) { + parts[i] = parts[i].trim(); + try { + values[i] = Integer.parseInt(parts[i]); + } + catch(NumberFormatException nfe) { + return "#000000"; + } + } + String hex = "#"; + for (int i = 0; i < values.length; i++) { + hex += Integer.toHexString(values[i]); + } + return hex; + } + + protected String htmlToRgb(String html) { + if (!html.startsWith("#")) { + return "0, 0, 0"; + } + + GWT.log("sub: " + html.substring(1, 3)); + int r = Integer.valueOf(html.substring(1, 3), 16); + int g = Integer.valueOf(html.substring(3, 5), 16); + int b = Integer.valueOf(html.substring(5, 7), 16); + + return r + ", " + g + ", " + b; + } + } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :