[Thinlet-development] thinlet/src/java/thinlet/examples/demo Demo.java,1.1,1.2 demo.xml,1.1,1.2
Brought to you by:
bajzat
From: <ab...@us...> - 2003-08-18 23:42:10
|
Update of /cvsroot/thinlet/thinlet/src/java/thinlet/examples/demo In directory sc8-pr-cvs1:/tmp/cvs-serv13283 Modified Files: Demo.java demo.xml Log Message: Add theme editor. Index: Demo.java =================================================================== RCS file: /cvsroot/thinlet/thinlet/src/java/thinlet/examples/demo/Demo.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- Demo.java 26 Jun 2003 15:21:55 -0000 1.1 +++ Demo.java 18 Aug 2003 23:42:07 -0000 1.2 @@ -13,6 +13,34 @@ */ public class Demo extends Thinlet { + // current theme index + private int ct = 0; + // theme definitions + private int[][] defT = { + { + 0xece9d8, 0x000000, 0xf5f4f0, + 0x919b9a, 0xb0b0b0, 0xededed, + 0xb9b9b9, 0xff899a, 0xc5c5dd + }, + { + 0xe6e6e6, 0x000000, 0xffffff, + 0x909090, 0xb0b0b0, 0xededed, + 0xb9b9b9, 0x89899a, 0xc5c5dd + }, + { + 0xeeeecc, 0x000000, 0xffffff, + 0x999966, 0xb0b096, 0xededcb, + 0xcccc99, 0xcc6600, 0xffcc66 + }, + { + 0x6375d6, 0xffffff, 0x7f8fdd, + 0xd6dff5, 0x9caae5, 0x666666, + 0x003399, 0xff3333, 0x666666 + } + }; + + private int[][] t = new int[4][9]; + /** * */ @@ -20,13 +48,18 @@ try { add(parse("demo.xml")); } catch (Exception exc) { exc.printStackTrace(); } + // copy values from defaults to current + for (int i = 0; i < 4; i++) + for (int j = 0; j < 9; j++) + t[i][j] = defT[i][j]; + actionTheme("t0"); } /** * */ public static void main(String[] args) { - new FrameLauncher("Demo", new Demo(), 320, 320); + new FrameLauncher("Demo", new Demo(), 340, 340); } boolean textinit; @@ -59,26 +92,69 @@ } public void actionTheme(String idx) { - int index = idx.charAt(1) - '0'; - switch (index) { - case 0: //xp - setColors(0xece9d8, 0x000000, 0xf5f4f0, - 0x919b9a, 0xb0b0b0, 0xededed, 0xb9b9b9, 0xff899a, 0xc5c5dd); - break; - case 1: //gray - setColors(0xe6e6e6, 0x000000, 0xffffff, - 0x909090, 0xb0b0b0, 0xededed, 0xb9b9b9, 0x89899a, 0xc5c5dd); - break; - case 2: //yellow - setColors(0xeeeecc, 0x000000, 0xffffff, - 0x999966, 0xb0b096, 0xededcb, 0xcccc99, 0xcc6600, 0xffcc66); - break; - case 3: //blue - setColors(0x6375d6, 0xffffff, 0x7f8fdd, - 0xd6dff5, 0x9caae5, 0x666666, 0x003399, 0xff3333, 0x666666); - break; + ct = idx.charAt(1) - '0'; + setColors( + t[ct][0], t[ct][1], t[ct][2], + t[ct][3], t[ct][4], t[ct][5], + t[ct][6], t[ct][7], t[ct][8]); + + adjustColors(null); + + } + + public void resetColors() { + for (int i = 0; i < 9; i++) + t[ct][i] = defT[ct][i]; + actionTheme("t" + ct); + } + + public void adjustColors(Object spin) { + if (spin == null) { + // set the spinboxes after theme change + for (int i = 0; i < 9; i++) { + Object sp = find(i + "_r"); + setString(sp, "text", String.valueOf(new Color(t[ct][i]).getRed())); + sp = find(i + "_g"); + setString(sp, "text", String.valueOf(new Color(t[ct][i]).getGreen())); + sp = find(i + "_b"); + setString(sp, "text", String.valueOf(new Color(t[ct][i]).getBlue())); + sp = find(i + "_h"); + setString(sp, "text", "#" + toHexString(t[ct][i])); + } + return; } + String name = getString(spin, "name"); + int idx = 0; + try { + idx = Integer.parseInt(name.substring(0, 1)); + } catch (Exception e) {}; + Color c = new Color(t[ct][idx]); + int r = c.getRed(); + int g = c.getGreen(); + int b = c.getBlue(); + int val = getInteger(spin, "value"); + if (name.endsWith("r")) { + r = val; + } else if (name.endsWith("g")) { + g = val; + } else b = val; + c = new Color(r, g, b); + t[ct][idx] = c.getRGB(); + Object sp = find(idx + "_h"); + setString(sp, "text", "#" + toHexString(t[ct][idx])); + setColors( + t[ct][0], t[ct][1], t[ct][2], + t[ct][3], t[ct][4], t[ct][5], + t[ct][6], t[ct][7], t[ct][8]); + } + + private String toHexString(int num) { + String res = Integer.toHexString(0x00ffffff & num); + int len = res.length(); + if (len < 6) for (int i = 0; i < 6 - len; i++) res = "0" + res; + return res; } + /** * */ @@ -242,7 +318,6 @@ this.pb_saturation = pb_saturation; this.pb_brightness = pb_brightness; this.rgb_label = rgb_label; - actionTheme("t0"); } /** Index: demo.xml =================================================================== RCS file: /cvsroot/thinlet/thinlet/src/java/thinlet/examples/demo/demo.xml,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- demo.xml 26 Jun 2003 15:21:55 -0000 1.1 +++ demo.xml 18 Aug 2003 23:42:07 -0000 1.2 @@ -178,6 +178,80 @@ </panel> </tab> + + <tab text="Themes"> + <panel columns="3" top="4" left="4" gap="4"> + <label text="Adjust colors of the current theme" colspan="2" /> + <button text="Reset" action="resetColors"/> + <label text="Color" font="bold" halign="center"/> + <label text="R G B" font="bold" halign="center"/> + <label text="Hex value" font="bold" halign="center"/> + <separator colspan="3"/> + <label text="Panel background" alignment="right" /> + <panel gap="1"> + <spinbox columns="3" name="0_r" maximum="255" text="0" action="adjustColors(this)" /> + <spinbox columns="3" name="0_g" maximum="255" text="0" action="adjustColors(this)" /> + <spinbox columns="3" name="0_b" maximum="255" text="0" action="adjustColors(this)" /> + </panel> + <label text="" name="0_h" font="courier"/> + <label text="Text foreground" alignment="right" /> + <panel gap="1"> + <spinbox columns="3" name="1_r" maximum="255" text="0" action="adjustColors(this)" /> + <spinbox columns="3" name="1_g" maximum="255" text="0" action="adjustColors(this)" /> + <spinbox columns="3" name="1_b" maximum="255" text="0" action="adjustColors(this)" /> + </panel> + <label text="" name="1_h" font="courier"/> + <label text="Text background" alignment="right" /> + <panel gap="1"> + <spinbox columns="3" name="2_r" maximum="255" text="0" action="adjustColors(this)" /> + <spinbox columns="3" name="2_g" maximum="255" text="0" action="adjustColors(this)" /> + <spinbox columns="3" name="2_b" maximum="255" text="0" action="adjustColors(this)" /> + </panel> + <label text="" name="2_h" font="courier"/> + <label text="Border" alignment="right" /> + <panel gap="1"> + <spinbox columns="3" name="3_r" maximum="255" text="0" action="adjustColors(this)" /> + <spinbox columns="3" name="3_g" maximum="255" text="0" action="adjustColors(this)" /> + <spinbox columns="3" name="3_b" maximum="255" text="0" action="adjustColors(this)" /> + </panel> + <label text="" name="3_h" font="courier"/> + <label text="Disabled foreground" alignment="right" /> + <panel gap="1"> + <spinbox columns="3" name="4_r" maximum="255" text="0" action="adjustColors(this)" /> + <spinbox columns="3" name="4_g" maximum="255" text="0" action="adjustColors(this)" /> + <spinbox columns="3" name="4_b" maximum="255" text="0" action="adjustColors(this)" /> + </panel> + <label text="" name="4_h" font="courier"/> + <label text="Hover background" alignment="right" /> + <panel gap="1"> + <spinbox columns="3" name="5_r" maximum="255" text="0" action="adjustColors(this)" /> + <spinbox columns="3" name="5_g" maximum="255" text="0" action="adjustColors(this)" /> + <spinbox columns="3" name="5_b" maximum="255" text="0" action="adjustColors(this)" /> + </panel> + <label text="" name="5_h" font="courier"/> + <label text="Pressed / gradient" alignment="right" /> + <panel gap="1"> + <spinbox columns="3" name="6_r" maximum="255" text="0" action="adjustColors(this)" /> + <spinbox columns="3" name="6_g" maximum="255" text="0" action="adjustColors(this)" /> + <spinbox columns="3" name="6_b" maximum="255" text="0" action="adjustColors(this)" /> + </panel> + <label text="" name="6_h" font="courier"/> + <label text="Focus" alignment="right" /> + <panel gap="1"> + <spinbox columns="3" name="7_r" maximum="255" text="0" action="adjustColors(this)" /> + <spinbox columns="3" name="7_g" maximum="255" text="0" action="adjustColors(this)" /> + <spinbox columns="3" name="7_b" maximum="255" text="0" action="adjustColors(this)" /> + </panel> + <label text="" name="7_h" font="courier"/> + <label text="Selected background" alignment="right" /> + <panel gap="1"> + <spinbox columns="3" name="8_r" maximum="255" text="0" action="adjustColors(this)" /> + <spinbox columns="3" name="8_g" maximum="255" text="0" action="adjustColors(this)" /> + <spinbox columns="3" name="8_b" maximum="255" text="0" action="adjustColors(this)" /> + </panel> + <label text="" name="8_h" font="courier"/> + </panel> + </tab> <tab text="Other"> <panel halign="fill" weightx="1" valign="fill" weighty="1" gap="4" top="4" columns="3"> <panel halign="fill" weightx="1" columns="1" gap="2"> |