001: /*
002: * Javu WingS - Lightweight Java Component Set
003: * Copyright (c) 2005-2007 Krzysztof A. Sadlocha
004: * e-mail: ksadlocha@programics.com
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or (at your option) any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
019: */
020:
021: package com.javujavu.javux.demo;
022:
023: import java.awt.BorderLayout;
024: import java.awt.Color;
025: import java.awt.Font;
026: import java.awt.GridBagConstraints;
027: import java.awt.GridBagLayout;
028: import java.awt.Insets;
029: import java.awt.Toolkit;
030: import com.javujavu.javux.util.code.CodeUrl;
031: import com.javujavu.javux.wings.WingCombo;
032: import com.javujavu.javux.wings.WingFont;
033: import com.javujavu.javux.wings.WingLabel;
034: import com.javujavu.javux.wings.WingPanel;
035: import com.javujavu.javux.wings.extra.ColorItem;
036: import com.javujavu.javux.wings.extra.FontItem;
037: import com.javujavu.javux.wings.item.LabelItem;
038:
039: public class ComboPanel extends WingPanel {
040: public ComboPanel(WingSetPanel owner) {
041: this .setLayout(new GridBagLayout());
042: WingPanel panelAll, panel;
043: panelAll = new WingPanel(new BorderLayout());
044: panelAll.add(panel = new WingPanel(new GridBagLayout()),
045: BorderLayout.CENTER);
046: GridBagConstraints c = new GridBagConstraints();
047: c.insets = new Insets(10, 10, 10, 10);
048: c.anchor = GridBagConstraints.CENTER;
049: c.fill = GridBagConstraints.BOTH;
050: this .add(panelAll, c);
051:
052: String shortcuts = "Scrolling with MOUSE WHEEL works on Java>=1.4\nKeys:\nSpace,Alt+Down,Alt+Up - toggle popup\nEnter,Escape - close popup\nUp,Down - previous/next";
053:
054: c = new GridBagConstraints();
055: c.insets = new Insets(8, 5, 8, 5);
056: c.weighty = 1.0;
057: WingCombo cb;
058: c.gridwidth = 1;
059: c.anchor = GridBagConstraints.EAST;
060: panel.add(new WingLabel("not editable"), c);
061:
062: c.anchor = GridBagConstraints.WEST;
063: c.gridwidth = GridBagConstraints.REMAINDER;
064: panel.add(cb = new WingCombo(), c);
065: cb.addItem(new LabelItem("text and icon", WingSet.imgSmile));
066: cb.addItem(new LabelItem("animated", WingSet.imgAnim));
067: cb.addItem("text item 1");
068: cb.addItem("text item 2");
069: cb.addItem(WingSet.imgSmile);
070: cb.setTooltip(new LabelItem(
071: "not editable combo\ndefault style\n\n" + shortcuts,
072: WingSet.imgGlasses, LEFT, RIGHT));
073:
074: c.gridwidth = 1;
075: c.anchor = GridBagConstraints.EAST;
076: panel.add(new WingLabel("editable"), c);
077: c.anchor = GridBagConstraints.WEST;
078: c.gridwidth = GridBagConstraints.REMAINDER;
079: panel.add(cb = new WingCombo(true), c);
080: cb.setTooltip(new LabelItem("editable combo\ndefault style\n\n"
081: + shortcuts, WingSet.imgEye, LEFT, RIGHT));
082: cb.addItem("text item 1");
083: cb.addItem("text item 2");
084: cb.addItem(WingSet.imgSmile);
085: cb.addItem(new LabelItem("text and icon", WingSet.imgSmile));
086: cb.addItem(new LabelItem("animated", WingSet.imgAnim));
087:
088: c.gridwidth = 1;
089: c.anchor = GridBagConstraints.EAST;
090: panel.add(new WingLabel("custom style"), c);
091: c.anchor = GridBagConstraints.WEST;
092: c.gridwidth = GridBagConstraints.REMAINDER;
093: panel.add(cb = new WingCombo(false), c);
094: cb.setStyleId("custom_combo");
095: cb.addItem("text item 1");
096: cb.addItem("text item 2");
097: cb.addItem("text item 3");
098: cb.addItem("text item 4");
099: cb.addItem(new LabelItem("text and icon", WingSet.imgSmile));
100: cb
101: .setTooltip(new LabelItem(
102: "not editable combo with custom style\nstyle: custom_combo (stylesheet wingsetdemo.ini)\n\n"
103: + shortcuts, WingSet.imgGnash, LEFT,
104: RIGHT));
105:
106: c.gridwidth = 1;
107: c.anchor = GridBagConstraints.EAST;
108: panel.add(new WingLabel("custom renderer"), c);
109: c.anchor = GridBagConstraints.WEST;
110: c.gridwidth = GridBagConstraints.REMAINDER;
111: panel.add(cb = new WingCombo(), c);
112: cb.addItem(new ColorItem("color red", Color.red));
113: cb.addItem(new ColorItem("color green", Color.green));
114: cb.addItem(new ColorItem("color blue", Color.blue));
115: cb.addItem(new ColorItem("color magenta", Color.magenta));
116: cb.addItem(new ColorItem("color orange", Color.orange));
117: cb.addItem(new ColorItem("color yellow", Color.yellow));
118: for (int j = 0; j < 2; j++)
119: for (int i = 0, k = 20 + j * 80; i < k; i++) {
120: Color col = Color.getHSBColor((float) 1.0 / k * i,
121: (float) 0.9, (float) 0.8);
122: cb.addItem(new ColorItem(colorName(col) + " RGB #"
123: + CodeUrl.toHexString(col.getRGB(), 6), col));
124: }
125: cb.setTooltip(new LabelItem(
126: "not editable combo\ndemonstrating custom item renderer\ndefault style\n\n"
127: + shortcuts, WingSet.imgLaughing, LEFT, RIGHT));
128:
129: c.gridwidth = 1;
130: c.anchor = GridBagConstraints.EAST;
131: panel.add(new WingLabel("more custom"), c);
132: c.anchor = GridBagConstraints.WEST;
133: c.gridwidth = GridBagConstraints.REMAINDER;
134: panel.add(cb = new WingCombo(false), c);
135: cb.setStyleId("custom_combo");
136: cb.addItem(new ColorItem("color red", Color.red));
137: cb.addItem("text item 1");
138: cb.addItem(new ColorItem("color green", Color.green));
139: cb.addItem(WingSet.imgSmile);
140: cb.addItem(new ColorItem("blue", Color.blue));
141: cb.addItem(new LabelItem("text and icon", WingSet.imgSmile));
142: cb.addItem(new ColorItem("color magenta", Color.magenta));
143: cb.addItem("text item 2");
144: cb.addItem(new ColorItem("color orange", Color.orange));
145: cb.addItem(new LabelItem("aminated", WingSet.imgAnim));
146: cb.addItem(new ColorItem("color yellow", Color.yellow));
147: cb
148: .setTooltip(new LabelItem(
149: "not editable combo with custom style\nand mixed item classes\nstyle: custom_combo (stylesheet wingsetdemo.ini)\n\n"
150: + shortcuts, WingSet.imgUgly, LEFT,
151: RIGHT));
152:
153: c.gridwidth = 1;
154: c.anchor = GridBagConstraints.EAST;
155: panel.add(new WingLabel("custom renderer color/font"), c);
156: c.anchor = GridBagConstraints.WEST;
157: panel.add(cb = new WingCombo(), c);
158: for (int i = 0; i < 30; i++) {
159: Color col = Color.getHSBColor((float) 1.0 / 30 * i,
160: (float) 0.9, (float) 0.8);
161: cb.addItem(new ColorItem("RGB #"
162: + CodeUrl.toHexString(col.getRGB(), 6), col));
163: }
164: cb.setTooltip(new LabelItem(
165: "not editable combo\ndemonstrating custom item renderer\ndefault style\n\n"
166: + shortcuts, WingSet.imgLaughing, LEFT, RIGHT));
167: panel.add(cb = new WingCombo(), c);
168: String[] names = Toolkit.getDefaultToolkit().getFontList();
169: for (int i = 0; i < names.length; i++) {
170: cb.addItem(new FontItem(names[i], new WingFont(new Font(
171: names[i], 0, 12))));
172: }
173: cb.setTooltip(new LabelItem(
174: "not editable combo\ndemonstrating custom item renderer\ndefault style\n\n"
175: + shortcuts, WingSet.imgLaughing, LEFT, RIGHT));
176: c.gridwidth = GridBagConstraints.REMAINDER;
177: panel.add(cb = new WingCombo(), c);
178: for (int i = 10; i <= 20; i++) {
179: cb.addItem(new FontItem("Font size " + i, new WingFont(
180: new Font("Dialog", 0, i))));
181: }
182: cb.setTooltip(new LabelItem(
183: "not editable combo\ndemonstrating custom item renderer\ndefault style\n\n"
184: + shortcuts, WingSet.imgLaughing, LEFT, RIGHT));
185:
186: // c.gridwidth= 1;
187: // c.anchor= GridBagConstraints.EAST;
188: // panel.add(new WingLabel("boolean items"), c);
189: // c.anchor= GridBagConstraints.WEST;
190: // c.gridwidth= GridBagConstraints.REMAINDER;
191: // panel.add(cb= new WingCombo(), c);
192: // cb.addItem(new Boolean(true));
193: // cb.addItem(new Boolean(false));
194: // cb.setTooltip(new LabelItem("not editable combo with items of class Boolean\ndefault style\n\n"+shortcuts, WingSetPanel.imgCrying, LEFT, RIGHT));
195:
196: c.gridwidth = 1;
197: c.anchor = GridBagConstraints.EAST;
198: panel.add(new WingLabel("disabled"), c);
199: c.anchor = GridBagConstraints.WEST;
200: panel.add(cb = new WingCombo(), c);
201: cb.setEnabled(false);
202: cb.addItem("not editable");
203: cb.addItem("text item 2");
204: cb.setTooltip(new LabelItem(
205: "disabled not editable combo\ndefault style",
206: WingSet.imgGlasses, LEFT, RIGHT));
207: c.gridwidth = GridBagConstraints.REMAINDER;
208: panel.add(cb = new WingCombo(true), c);
209: cb.setEnabled(false);
210: cb.addItem("editable");
211: cb.addItem("text item 2");
212: cb.setTooltip(new LabelItem(
213: "disabled editable combo\ndefault style",
214: WingSet.imgTongue, LEFT, RIGHT));
215: }
216:
217: protected static String colorName(Color col) {
218: double hue = Color.RGBtoHSB(col.getRed(), col.getGreen(), col
219: .getBlue(), null)[0];
220: return (hue < 0.09) ? "Red"
221: : (hue < 0.15) ? "Orange"
222: : (hue < 0.18) ? "Yellow"
223: : (hue < 0.2) ? "Lime"
224: : (hue < 0.41) ? "Green"
225: : (hue < 0.47) ? "Turquoise"
226: : (hue < 0.52) ? "Cyan"
227: : (hue < 0.76) ? "Blue"
228: : (hue < 0.83) ? "Purple"
229: : (hue < 0.87) ? "Pink"
230: : "Red";
231: }
232:
233: }
|