Source Code Cross Referenced for MenuPanel.java in  » Web-Framework » wingS » com » javujavu » javux » demo » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Web Framework » wingS » com.javujavu.javux.demo 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


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.Dimension;
026:        import java.awt.Graphics;
027:        import java.awt.GridBagConstraints;
028:        import java.awt.GridBagLayout;
029:        import java.awt.GridLayout;
030:        import java.awt.Insets;
031:        import java.awt.event.ActionEvent;
032:        import java.awt.event.ActionListener;
033:        import java.awt.event.ItemEvent;
034:        import java.awt.event.ItemListener;
035:        import java.awt.event.KeyEvent;
036:        import com.javujavu.javux.wings.MenuRadioGroup;
037:        import com.javujavu.javux.wings.Style;
038:        import com.javujavu.javux.wings.WingButton;
039:        import com.javujavu.javux.wings.WingComponent;
040:        import com.javujavu.javux.wings.WingMenu;
041:        import com.javujavu.javux.wings.WingMenuItem;
042:        import com.javujavu.javux.wings.WingPanel;
043:        import com.javujavu.javux.wings.WingScrollPane;
044:        import com.javujavu.javux.wings.WingTextField;
045:        import com.javujavu.javux.wings.WingTree;
046:        import com.javujavu.javux.wings.extra.ColorItem;
047:        import com.javujavu.javux.wings.item.DefaultItemEditor;
048:        import com.javujavu.javux.wings.item.DefaultItemRenderer;
049:        import com.javujavu.javux.wings.item.ItemOwner;
050:        import com.javujavu.javux.wings.item.LabelItem;
051:        import com.javujavu.javux.wings.tree.TreeNode;
052:
053:        public class MenuPanel extends WingPanel implements  ActionListener,
054:                ItemListener {
055:            private WingButton bPopup;
056:            private WingMenu popup;
057:            private WingButton bPopup2;
058:            private WingMenu popup2;
059:            private WingTree tree;
060:            private WingButton bInsertItem;
061:            private WingButton bInsertCheck;
062:            private WingButton bInsertMenu;
063:            private WingButton bRemove;
064:            private WingButton bInsertSeparator;
065:
066:            public MenuPanel(WingSetPanel owner) {
067:                this .setLayout(new GridBagLayout());
068:                WingPanel panel = new WingPanel(new BorderLayout(10, 10));
069:                GridBagConstraints c = new GridBagConstraints();
070:                c.insets = new Insets(10, 10, 10, 10);
071:                c.anchor = GridBagConstraints.CENTER;
072:                c.fill = GridBagConstraints.BOTH;
073:                c.weightx = 1.0;
074:                c.weighty = 1.0;
075:                this .add(panel, c);
076:
077:                WingMenuItem mi;
078:                WingMenu m, m2, m3, mTop, mLeft, mRight, mBottom;
079:
080:                mTop = m = new WingMenu("top", 0, 0, HORIZONTAL);
081:                panel.add(m, BorderLayout.NORTH);
082:                m.add(m2 = new WingMenu("\u0332Menu1", KeyEvent.VK_M,
083:                        KeyEvent.ALT_MASK));
084:                m2.add(new WingMenuItem("Menu item en\u0332abled", NORMAL,
085:                        KeyEvent.VK_A, KeyEvent.ALT_MASK));
086:                m2.add(mi = new WingMenuItem("Menu item disa\u0332bled",
087:                        NORMAL, KeyEvent.VK_B, KeyEvent.ALT_MASK
088:                                | KeyEvent.CTRL_MASK));
089:                mi.setEnabled(false);
090:                m2.addSeparator();
091:                m2.add(new WingMenuItem("\u0332Che\u0332ckbox enabled",
092:                        CHECKBOX, KeyEvent.VK_C, KeyEvent.ALT_MASK));
093:                m2.add(mi = new WingMenuItem(
094:                        "Checkbox enable\u0332d selecte\u0332d", CHECKBOX,
095:                        KeyEvent.VK_D, KeyEvent.ALT_MASK));
096:                mi.setSelected(true);
097:                m2.add(mi = new WingMenuItem("\u0332Checkbox disabled",
098:                        CHECKBOX, KeyEvent.VK_C, KeyEvent.ALT_MASK
099:                                | KeyEvent.CTRL_MASK));
100:                mi.setEnabled(false);
101:                m2.add(mi = new WingMenuItem(
102:                        "Checkbox \u0332disabled selected", CHECKBOX,
103:                        KeyEvent.VK_D, KeyEvent.ALT_MASK | KeyEvent.CTRL_MASK));
104:                mi.setSelected(true);
105:                mi.setEnabled(false);
106:                m2.addSeparator();
107:                m2.add(new WingMenuItem("Radio \u0332enabled", RADIO,
108:                        KeyEvent.VK_E, 0));
109:                m2.add(mi = new WingMenuItem("Radio enabled selected", RADIO,
110:                        KeyEvent.VK_F, KeyEvent.ALT_MASK));
111:                mi.setSelected(true);
112:                m2
113:                        .add(mi = new WingMenuItem("Radio disabled", RADIO,
114:                                KeyEvent.VK_E, KeyEvent.SHIFT_MASK
115:                                        | KeyEvent.CTRL_MASK));
116:                mi.setEnabled(false);
117:                m2
118:                        .add(mi = new WingMenuItem("Radio disabled selected",
119:                                RADIO, KeyEvent.VK_F, KeyEvent.ALT_MASK
120:                                        | KeyEvent.SHIFT_MASK));
121:                mi.setSelected(true);
122:                mi.setEnabled(false);
123:                m2.addSeparator();
124:                m2.add(m3 = new WingMenu("\u0332Submenu enabled",
125:                        KeyEvent.VK_S, KeyEvent.ALT_MASK));
126:                for (int i = 1; i < 4; i++)
127:                    m3.add("item" + i);
128:                m2.add(m3 = new WingMenu("Submenu disabled", KeyEvent.VK_S,
129:                        KeyEvent.ALT_MASK | KeyEvent.SHIFT_MASK));
130:                m3.setEnabled(false);
131:                for (int i = 1; i < 4; i++)
132:                    m3.add("item" + i);
133:
134:                m.add(m2 = new WingMenu("Menu2", 0, 0));
135:                MenuRadioGroup g = new MenuRadioGroup();
136:                for (int i = 1; i < 7; i++) {
137:                    m2.add(mi = new WingMenuItem("Radio grouped " + i, RADIO,
138:                            0, 0));
139:                    g.add(mi);
140:                }
141:                mi.setSelected(true);
142:                m2.addSeparator();
143:                g = new MenuRadioGroup();
144:                for (int i = 1; i < 7; i++) {
145:                    m2.add(mi = new WingMenuItem("Checkbox grouped " + i,
146:                            CHECKBOX, 0, 0));
147:                    g.add(mi);
148:                }
149:                mi.setSelected(true);
150:                m.add(m2 = new WingMenu("Long Me\u0332nu", KeyEvent.VK_N,
151:                        KeyEvent.ALT_MASK));
152:                for (int i = 1; i < 22; i++)
153:                    m2.add("item" + i);
154:                m2.add(m3 = new WingMenu("men\u0332u22", KeyEvent.VK_U,
155:                        KeyEvent.ALT_MASK));
156:                m3.add("item1");
157:                m3.add("item2");
158:                m3.add("item3333333333333333333333333333");
159:                m.add(m2 = new WingMenu("\u0332Very Long Menu", KeyEvent.VK_V,
160:                        KeyEvent.ALT_MASK));
161:                for (int i = 1; i < 420; i++)
162:                    m2.add("Itemmmm.........................mmm " + i);
163:                m.addSeparator();
164:                m.addSeparator();
165:                m.add(makeSubs("Wild Submenus", 8));
166:                m.addSeparator();
167:                m.addSeparator();
168:                m.add(new WingMenuItem("\u0332Item1", NORMAL, KeyEvent.VK_I,
169:                        KeyEvent.ALT_MASK));
170:                m.add("Item2");
171:                m.addSeparator();
172:                m.add(new WingMenuItem("Ch\u0332eckbox", CHECKBOX,
173:                        KeyEvent.VK_E, KeyEvent.ALT_MASK));
174:
175:                m
176:                        .setTooltip(new LabelItem(
177:                                "WingMenu orientation HORIZONTAL\ndefault style\n\nWingMenu is just a component\ncan be added to container\nas a classic component\nand focused with Tab key\n",
178:                                WingSet.imgBomb, LEFT, LEFT));
179:
180:                mRight = m = new WingMenu("right", 0, 0, VERTICAL);
181:                panel.add(m, BorderLayout.EAST);
182:                m
183:                        .add(new WingMenuItem("I\u0332tem1 ", NORMAL,
184:                                KeyEvent.VK_T, 0));
185:                m.add(new WingMenuItem("Item\u03323 ", NORMAL, KeyEvent.VK_3,
186:                        KeyEvent.CTRL_MASK));
187:                m.add(mi = new WingMenuItem("Item \u03324", NORMAL,
188:                        KeyEvent.VK_4, KeyEvent.ALT_MASK | KeyEvent.CTRL_MASK));
189:                mi.setEnabled(false);
190:                m.addSeparator();
191:                m.add(new WingMenuItem("Check \u03321", CHECKBOX,
192:                        KeyEvent.VK_1, KeyEvent.ALT_MASK));
193:                m.add(mi = new WingMenuItem("Check 2", CHECKBOX, 0, 0));
194:                mi.setSelected(true);
195:                m
196:                        .add(mi = new WingMenuItem("Check \u03323", CHECKBOX,
197:                                KeyEvent.VK_3, KeyEvent.SHIFT_MASK
198:                                        | KeyEvent.CTRL_MASK));
199:                mi.setEnabled(false);
200:                m.add(mi = new WingMenuItem("Check 4", CHECKBOX, 0, 0));
201:                mi.setSelected(true);
202:                mi.setEnabled(false);
203:                m.addSeparator();
204:                g = new MenuRadioGroup();
205:                m.add(mi = new WingMenuItem("\u0332Radio 1", RADIO,
206:                        KeyEvent.VK_R, KeyEvent.SHIFT_MASK));
207:                g.add(mi);
208:                m.add(mi = new WingMenuItem("Radi\u0332o 2", RADIO,
209:                        KeyEvent.VK_O, 0));
210:                g.add(mi);
211:                mi.setSelected(true);
212:                m.add(mi = new WingMenuItem("Radio 3", RADIO, 0, 0));
213:                mi.setEnabled(false);
214:                m.add(mi = new WingMenuItem("Radio 4", RADIO, 0, 0));
215:                mi.setSelected(true);
216:                mi.setEnabled(false);
217:                m.addSeparator();
218:                m.add(m3 = new WingMenu("\u0332Menu 1", KeyEvent.VK_M,
219:                        KeyEvent.SHIFT_MASK));
220:                for (int i = 1; i < 4; i++)
221:                    m3.add("item " + i);
222:                m.add(m3 = new WingMenu("Menu 2", 0, 0));
223:                m3.setEnabled(false);
224:                for (int i = 1; i < 4; i++)
225:                    m3.add("item " + i);
226:
227:                m
228:                        .setTooltip(new LabelItem(
229:                                "WingMenu orientation VERTICAL\ndefault style\n\nOn focused WingMenu shortcuts work also\n without their modifier keys (Alt,Shift,Ctrl)",
230:                                WingSet.imgYawn, RIGHT, RIGHT));
231:
232:                mBottom = m = new WingMenu("bottom", 0, 0, HORIZONTAL);
233:                panel.add(m, BorderLayout.SOUTH);
234:
235:                m.add(mi = new WingMenuItem("Check2", CHECKBOX, 0, 0));
236:                mi.setSelected(true);
237:                m.add(mi = new WingMenuItem("Check3", CHECKBOX, 0, 0));
238:                mi.setEnabled(false);
239:                m.add(mi = new WingMenuItem("Check4", CHECKBOX, 0, 0));
240:                mi.setSelected(true);
241:                mi.setEnabled(false);
242:                m.addSeparator();
243:                m.add(m2 = new WingMenu(new LabelItem("Menu",
244:                        WingSet.imgLaughing, LEFT, LEFT)));
245:                for (int i = 1; i < 6; i++)
246:                    m2.add("item " + i);
247:                m.add(new LabelItem("Item", WingSet.imgCrying));
248:                m.addSeparator();
249:                g = new MenuRadioGroup();
250:                m.add(mi = new WingMenuItem("Radio1", RADIO, 0, 0));
251:                g.add(mi);
252:                m.add(mi = new WingMenuItem("Radio2", RADIO, 0, 0));
253:                g.add(mi);
254:                m.add(mi = new WingMenuItem("Radio4", RADIO, 0, 0));
255:                g.add(mi);
256:                mi.setSelected(true);
257:                mi.setEnabled(false);
258:
259:                m
260:                        .setTooltip(new LabelItem(
261:                                "WingMenu orientation HORIZONTAL\ndefault style\n\nWingMenu is just a component\ncan be added to container\nas a classic component\nand focused with Tab key\n",
262:                                WingSet.imgBomb, LEFT, LEFT));
263:
264:                mLeft = m = new WingMenu("left", 0, 0, VERTICAL);
265:                m.setStyleId("custom_menu");
266:                panel.add(m, BorderLayout.WEST);
267:                m.add(m3 = new WingMenu("custom submenu", 0, 0, VERTICAL));
268:                m3.setStyleId("custom_menu");
269:                for (int i = 1; i < 9; i++)
270:                    m3.add("item.............." + i);
271:                m3.add(m3 = new WingMenu("submenu", 0, 0, VERTICAL));
272:                m3.setStyleId("custom_menu");
273:                for (int i = 1; i < 9; i++)
274:                    m3.add("item.............." + i);
275:                m
276:                        .add(m3 = new WingMenu("horizontal submenu", 0, 0,
277:                                HORIZONTAL));
278:                m3.setStyleId("custom_popup");
279:                for (int i = 1; i < 9; i++)
280:                    m3.add("item" + i);
281:                m.add(m3 = new WingMenu("custom renderer"));
282:                {
283:                    m3.add(new ColorItem("color magenta", Color.magenta));
284:                    m3.add(new ColorItem("color red", Color.red));
285:                    m3.add(new ColorItem("color yellow", Color.yellow));
286:                    m3.add(new ColorItem("color blue", Color.blue));
287:                    m3.add(new ColorItem("color green", Color.green));
288:                    m3.add(new ColorItem("color orange", Color.orange));
289:                }
290:                m.add(m3 = new WingMenu("transparent submenu", 0, 0, VERTICAL));
291:                m3.setStyleId("alpha_menu");
292:                m3.add(new LabelItem("transparency\nworks on Java>=1.2",
293:                        WingSet.imgBigsmileA));
294:                for (int i = 1; i < 7; i++)
295:                    m3.add("item................" + i);
296:                m3.add(m3 = new WingMenu("submenu", 0, 0, VERTICAL));
297:                m3.setStyleId("alpha_menu");
298:                for (int i = 1; i < 9; i++)
299:                    m3.add("item................." + i);
300:
301:                m.add(m3 = new WingMenu("more transparent", 0, 0, VERTICAL));
302:                m3.setStyleId("alpha_menu2");
303:                m3.add(new LabelItem("transparency\nworks on Java>=1.2",
304:                        WingSet.imgBigsmileA));
305:                for (int i = 1; i < 7; i++)
306:                    m3.add("item................" + i);
307:                m3.add(m3 = new WingMenu("submenu", 0, 0, VERTICAL));
308:                m3.setStyleId("alpha_menu2");
309:                for (int i = 1; i < 9; i++)
310:                    m3.add("item................" + i);
311:                m.addSeparator();
312:
313:                m.add(new WingMenuItem("item", CHECKBOX, KeyEvent.VK_9,
314:                        KeyEvent.CTRL_MASK));
315:                m.add(new LabelItem("multiline\nitem", WingSet.imgSeek));
316:                m.add(new ColorItem("color magenta", Color.magenta));
317:                g = new MenuRadioGroup();
318:                m.add(mi = new WingMenuItem("radio1", RADIO));
319:                g.add(mi);
320:                m.add(mi = new WingMenuItem("radio2", RADIO));
321:                g.add(mi);
322:                mi.setSelected(true);
323:
324:                m
325:                        .setTooltip(new LabelItem(
326:                                "WingMenu orientation VERTICAL\nstyle: custom_menu (stylesheet wingsetdemo.ini)",
327:                                WingSet.imgScared, LEFT, LEFT));
328:
329:                WingPanel p2;
330:                panel.add(p2 = new WingPanel(new GridBagLayout()),
331:                        BorderLayout.CENTER);
332:                c = new GridBagConstraints();
333:                c.insets = new Insets(0, 0, 1, 1);
334:                c.weightx = 1.0;
335:                c.gridwidth = GridBagConstraints.REMAINDER;
336:                c.anchor = GridBagConstraints.WEST;
337:                WingButton b;
338:                p2.add(b = new WingButton("Font/Color/Style Menu"), c);
339:                b.setStyleId("vpopup");
340:                b.setFastAction(true);
341:                b
342:                        .setTooltip(new LabelItem(
343:                                "button with a TopStyle\nTopStyle is an extra style overriding stylesheet settings \ndynamically at run time\nclick to change settings\n\nstyle: vmenu (stylesheet wingsetdemo.ini)",
344:                                WingSet.imgIcon, LEFT, RIGHT));
345:                TopStyleEditor ts = new TopStyleEditor(b, b, 18, 8, true);
346:                c.anchor = GridBagConstraints.EAST;
347:                p2.add(bPopup = new WingButton("Open wild popup"), c);
348:                bPopup.setStyleId("vpopup");
349:                bPopup.setTextPosition(LEFT);
350:                bPopup.setFastAction(true);
351:                c.anchor = GridBagConstraints.WEST;
352:                c.insets = new Insets(0, 0, 4, 0);
353:                p2.add(bPopup2 = new WingButton("Open horizontal popup"), c);
354:                bPopup2.setStyleId("hpopup");
355:                bPopup2.setFastAction(true);
356:                bPopup2.setTextPosition(LEFT);
357:                c.anchor = GridBagConstraints.CENTER;
358:
359:                c.weighty = 1.0;
360:                c.fill = GridBagConstraints.BOTH;
361:                p2.add(new WingScrollPane(tree = new WingTree()), c);
362:                c.insets = new Insets(0, 0, 0, 0);
363:                c.weighty = 0.0;
364:                WingPanel p3;
365:                p2.add(p3 = new WingPanel(new GridLayout(0, 2, 4, 4)), c);
366:                p3.add(bInsertItem = new WingButton("insert item"));
367:                p3.add(bInsertCheck = new WingButton("insert check"));
368:                p3.add(bInsertMenu = new WingButton("insert menu"));
369:                p3.add(bInsertSeparator = new WingButton("insert separator"));
370:                p3.add(bRemove = new WingButton("remove"));
371:                tree
372:                        .setTooltip(new LabelItem(
373:                                "doubleclick, Enter, F2 - edit label",
374:                                WingSet.imgAngel));
375:
376:                popup = makeSubs("Wild Popup", 8);
377:
378:                popup2 = new WingMenu("horizontal popup", 0, 0, HORIZONTAL);
379:                popup2.setStyleId("custom_popup");
380:                popup2.addSeparator();
381:                popup2.add("item1");
382:                popup2.add("item2");
383:                popup2.addSeparator();
384:                popup2.add(mi = new WingMenuItem("check 1", CHECKBOX));
385:                popup2.add(mi = new WingMenuItem("check 2", CHECKBOX));
386:                mi.setSelected(true);
387:                popup2.addSeparator();
388:                popup2.add(m2 = new WingMenu("submenu"));
389:                for (int i = 1; i < 4; i++)
390:                    m2.add("item " + i);
391:                popup2.addSeparator();
392:                popup2.addSeparator();
393:
394:                fillTree(tree.getRoot(), mTop);
395:                fillTree(tree.getRoot(), mLeft);
396:                fillTree(tree.getRoot(), mRight);
397:                fillTree(tree.getRoot(), mBottom);
398:                fillTree(tree.getRoot(), popup);
399:                fillTree(tree.getRoot(), popup2);
400:                fillTree(tree.getRoot(), ts.menu());
401:
402:                tree.setItemRenderer(new MyItemRenderer12());
403:                tree.setEditor(new MyTreeItemEditor12());
404:
405:                tree.setSelected(tree.getRoot().childAt(0));
406:                updateTreeSelection();
407:
408:                this .addActionListener(this );
409:                this .addItemListener(this );
410:            }
411:
412:            private void fillTree(TreeNode node, WingMenu m) {
413:                TreeNode n2 = new TreeNode(m.getFaceItem());
414:                tree.addNode(n2, node);
415:                for (int i = 0; i < m.getItemCount(); i++) {
416:                    WingMenuItem mi = m.getItem(i);
417:                    if (mi.getSubMenu() == null) {
418:                        tree.addNode(new TreeNode(mi), n2);
419:                    } else {
420:                        fillTree(n2, mi.getSubMenu());
421:                    }
422:                }
423:            }
424:
425:            protected static WingMenu makeSubs(String title, int deep) {
426:                WingMenu m = new WingMenu(title);
427:                int s = 0;
428:                for (int i = 1, n = (int) ((Math.random() * 4) + 4); i < n; i++) {
429:                    int p = (int) (Math.random() * 12);
430:                    if (deep > 0 && s < 3 && (p > 7 || (i * 3 > n && s == 0))) {
431:                        m.add(makeSubs("submenu " + i, deep - 1 - s));
432:                        s++;
433:                    } else if (p > 3)
434:                        m.add("item " + i);
435:                    else if (p > 1) {
436:                        int ic = (int) (Math.random() * 5);
437:                        int a = (int) (Math.random() * 3);
438:                        int tp = (int) (Math.random() * 2);
439:                        m
440:                                .add(new LabelItem(
441:                                        "item " + i,
442:                                        (ic == 0) ? WingSet.imgGlasses
443:                                                : (ic == 1) ? WingSet.imgTongue
444:                                                        : (ic == 2) ? WingSet.imgGnash
445:                                                                : (ic == 3) ? WingSet.imgYawn
446:                                                                        : WingSet.imgSilence,
447:                                        (a == 0) ? LEFT : (a == 1) ? RIGHT
448:                                                : CENTER, (tp == 0) ? LEFT
449:                                                : RIGHT));
450:                    } else
451:                        m.add("itemm...........mm " + i);
452:                }
453:                return m;
454:            }
455:
456:            public void actionPerformed(ActionEvent e) {
457:                Object src = e.getSource();
458:                if (src == bPopup) {
459:                    Dimension s = bPopup.getSize();
460:                    popup
461:                            .showPopup(bPopup, 0, 0, s.width, s.height,
462:                                    HORIZONTAL);
463:                } else if (src == bPopup2) {
464:                    Dimension s = bPopup2.getSize();
465:                    popup2
466:                            .showPopup(bPopup2, 0, 0, s.width, s.height,
467:                                    VERTICAL);
468:                } else if (src == bRemove) {
469:                    TreeNode sel = tree.getSelected();
470:                    WingMenuItem mi = (WingMenuItem) sel.getItem();
471:                    mi.getOwner().removeItem(mi);
472:                    tree.removeNode(sel);
473:                    updateTreeSelection();
474:                } else if (src == bInsertItem || src == bInsertCheck
475:                        || src == bInsertMenu || src == bInsertSeparator) {
476:                    TreeNode sel = tree.getSelected();
477:                    WingMenuItem nmi, mi = (WingMenuItem) sel.getItem();
478:                    WingMenu m = mi.getOwner();
479:                    int index = sel.getParent().indexOf(sel);
480:                    WingMenu nm = null;
481:                    nmi = (src == bInsertItem) ? new WingMenuItem("new item")
482:                            : (src == bInsertCheck) ? new WingMenuItem(
483:                                    "new check", CHECKBOX)
484:                                    : (src == bInsertMenu) ? (nm = new WingMenu(
485:                                            "new menu")).getFaceItem()
486:                                            : new WingMenuItem(null, SEPARATOR);
487:                    m.insert(nmi, index);
488:                    TreeNode nn;
489:                    tree.insertNode(nn = new TreeNode(nmi), sel.getParent(),
490:                            index);
491:                    if (nm != null) {
492:                        WingMenuItem nmi2;
493:                        nm.insert(nmi2 = new WingMenuItem("new item"), 0);
494:                        tree.insertNode(new TreeNode(nmi2), nn, 0);
495:                    }
496:                    tree.editNode(nn);
497:                    updateTreeSelection();
498:                }
499:            }
500:
501:            public void itemStateChanged(ItemEvent e) {
502:                if (e.getSource() == tree) {
503:                    updateTreeSelection();
504:                }
505:            }
506:
507:            private void updateTreeSelection() {
508:                TreeNode sel = tree.getSelected();
509:                boolean toplevel = (sel.getParent() == tree.getRoot());
510:                bInsertCheck.setEnabled(!toplevel);
511:                bInsertItem.setEnabled(!toplevel);
512:                bInsertMenu.setEnabled(!toplevel);
513:                bInsertSeparator.setEnabled(!toplevel);
514:                bRemove.setEnabled(!toplevel);
515:            }
516:
517:            public class MyItemRenderer12 extends DefaultItemRenderer {
518:                private Object transferItem(Object item) {
519:                    if (item == null)
520:                        return null;
521:                    WingMenuItem mi = (WingMenuItem) item;
522:                    int kind = mi.getKind();
523:                    if (kind == SEPARATOR)
524:                        return "==== SEPARATOR ====";
525:                    return mi.getLabel();
526:                }
527:
528:                public void drawItem(Graphics g, int x, int y, int width,
529:                        int height, Object item, WingComponent owner,
530:                        Style style, Insets margin, int alignment,
531:                        int textPosition, Object context) {
532:                    super .drawItem(g, x, y, width, height, transferItem(item),
533:                            owner, style, margin, alignment, textPosition,
534:                            context);
535:                }
536:
537:                public Dimension getItemSize(Object item, WingComponent owner,
538:                        Style style, Object context) {
539:                    return super .getItemSize(transferItem(item), owner, style,
540:                            context);
541:                }
542:            }
543:
544:            public class MyTreeItemEditor12 extends DefaultItemEditor {
545:                private WingMenuItem edited;
546:
547:                public WingComponent getComponent(ItemOwner owner,
548:                        Object value, Object context) {
549:                    WingMenuItem mi = (WingMenuItem) value;
550:                    if (mi.getKind() == SEPARATOR || mi.getOwner() == null)
551:                        return null;
552:                    edited = mi;
553:                    WingTextField r = getTextFieldEditor(owner);
554:                    r.setText(mi.getLabel().toString());
555:                    return r;
556:                }
557:
558:                public Object getCommitedValue() {
559:                    Object value = super.getCommitedValue();
560:                    edited.setLabel(value);
561:                    return edited;
562:                }
563:            }
564:
565:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.