Source Code Cross Referenced for TreePanel.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.GridBagConstraints;
026:        import java.awt.GridBagLayout;
027:        import java.awt.GridLayout;
028:        import java.awt.Insets;
029:        import java.awt.event.ActionEvent;
030:        import java.awt.event.ActionListener;
031:        import java.awt.event.ItemEvent;
032:        import java.awt.event.ItemListener;
033:        import com.javujavu.javux.wings.WingButton;
034:        import com.javujavu.javux.wings.WingCheckBox;
035:        import com.javujavu.javux.wings.WingCombo;
036:        import com.javujavu.javux.wings.WingComponent;
037:        import com.javujavu.javux.wings.WingImage;
038:        import com.javujavu.javux.wings.WingLabel;
039:        import com.javujavu.javux.wings.WingPanel;
040:        import com.javujavu.javux.wings.WingScrollPane;
041:        import com.javujavu.javux.wings.WingTree;
042:        import com.javujavu.javux.wings.extra.ColorItem;
043:        import com.javujavu.javux.wings.item.DefaultItemEditor;
044:        import com.javujavu.javux.wings.item.ItemOwner;
045:        import com.javujavu.javux.wings.item.LabelItem;
046:        import com.javujavu.javux.wings.tree.TreeNode;
047:
048:        public class TreePanel extends WingPanel implements  ActionListener,
049:                ItemListener {
050:            private WingButton bAdd;
051:            private WingButton bInsert;
052:            private WingButton bRemove;
053:            private WingTree tree1;
054:            private WingTree target;
055:            private WingTree tree2;
056:            private WingTree tree3;
057:            private WingButton bBranch;
058:            private WingCheckBox cbEditable;
059:
060:            public TreePanel(WingSetPanel owner) {
061:                this .setLayout(new GridBagLayout());
062:                WingPanel panel = new WingPanel(new GridLayout(0, 2, 8, 8));
063:                GridBagConstraints c = new GridBagConstraints();
064:                c.insets = new Insets(10, 10, 10, 10);
065:                c.anchor = GridBagConstraints.CENTER;
066:                c.fill = GridBagConstraints.BOTH;
067:                c.weightx = 1.0;
068:                c.weighty = 1.0;
069:                c.gridwidth = GridBagConstraints.REMAINDER;
070:                this .add(panel, c);
071:
072:                WingTree tree;
073:                WingPanel panel2;
074:                panel.add(panel2 = new WingPanel(new BorderLayout()));
075:                panel2.add(new WingScrollPane(tree1 = tree = new WingTree()),
076:                        BorderLayout.CENTER);
077:                WingPanel panel3;
078:                panel2.add(panel3 = new WingPanel(new BorderLayout()),
079:                        BorderLayout.NORTH);
080:                panel3.setStyleId("border2");
081:                panel3.add(new WingLabel("root not visible", WingLabel.CENTER),
082:                        BorderLayout.CENTER);
083:                addItems(tree);
084:
085:                panel.add(panel2 = new WingPanel(new BorderLayout()));
086:                panel2.add(new WingScrollPane(tree2 = tree = new WingTree()),
087:                        BorderLayout.CENTER);
088:                WingPanel p3;
089:                panel2.add(p3 = new WingPanel(new GridBagLayout()),
090:                        BorderLayout.NORTH);
091:                GridBagConstraints c2 = new GridBagConstraints();
092:                c2.weightx = 1.0;
093:                p3.add(new WingLabel("root visible", WingLabel.CENTER), c2);
094:                WingButton b;
095:                c2.weightx = 0.0;
096:                p3.add(b = new WingButton("TopStyle"), c2);
097:                b.setStyleId("vpopup");
098:                b.setTextPosition(LEFT);
099:                b.setFastAction(true);
100:                b
101:                        .setTooltip(new LabelItem(
102:                                "modify TopStyle of this WingTree\nTopStyle is an extra style overriding stylesheet settings \ndynamically at run time\n\nclick button to change settings",
103:                                WingSet.imgIcon, LEFT, RIGHT));
104:                new TopStyleEditor(b, tree2, 0, 0, false);
105:                tree.setRootVisible(true);
106:                addItems(tree);
107:
108:                panel.add(panel2 = new WingPanel(new BorderLayout()));
109:                panel2.add(new WingScrollPane(tree3 = tree = new WingTree(
110:                        new TreeNode("root node"))), BorderLayout.CENTER);
111:                tree.setStyleId("custom_tree");
112:                panel2.add(new WingLabel("custom style", WingLabel.CENTER),
113:                        BorderLayout.NORTH);
114:                addItems(tree);
115:
116:                tree1.setEditor(new MyTreeItemEditor());
117:                tree2.setEditor(new MyTreeItemEditor());
118:                tree3.setEditor(new MyTreeItemEditor());
119:
120:                panel.add(panel2 = new WingPanel(new BorderLayout()));
121:                panel2.add(new WingScrollPane(tree = new WingTree()));
122:                panel2.add(new WingLabel("disabled tree", WingLabel.CENTER),
123:                        BorderLayout.NORTH);
124:                addItems(tree);
125:                tree.setEnabled(false);
126:
127:                String keys = "\n\nKeys:\nUp,Down - move\nLeft,Right,mouse doubleclick - expand/collapse\nEnter, F2, mouse doubleclick - open editor\nEnter,Esc - close editor";
128:                tree1.setTooltip(new LabelItem(
129:                        "WingTree\nroot not visible\ndefault style" + keys,
130:                        WingSet.imgGlasses, LEFT, RIGHT));
131:                tree2.setTooltip(new LabelItem(
132:                        "WingTree\nroot visible\ndefault style" + keys,
133:                        WingSet.imgCrying, LEFT, LEFT));
134:                tree3.setTooltip(new LabelItem(
135:                        "WingTree\nroot not visible\nstyle: custom_tree (stylesheet wingsetdemo.ini)"
136:                                + keys, WingSet.imgJokingly, RIGHT, LEFT));
137:                tree.setTooltip(new LabelItem(
138:                        "disabled WingTree\nroot not visible\ndefault style"
139:                                + keys, WingSet.imgConfused, RIGHT, RIGHT));
140:
141:                c.insets = new Insets(0, 10, 2, 10);
142:                c.weighty = 0.0;
143:                this .add(p3 = new WingPanel(new GridLayout(1, 0)), c);
144:                p3.add(bBranch = new WingButton("add branch"));
145:                p3.add(bAdd = new WingButton("add item"));
146:                p3.add(bInsert = new WingButton("insert item"));
147:                p3.add(bRemove = new WingButton("remove selected"));
148:
149:                c.gridwidth = 1;
150:                this .add(cbEditable = new WingCheckBox("editable", TOGGLE), c);
151:                cbEditable.setSelected(true);
152:                c.gridwidth = GridBagConstraints.REMAINDER;
153:                this 
154:                        .add(
155:                                new WingLabel(
156:                                        "TIP: doubleclick, Enter, F2 - open editor ; Esc, Enter - close"),
157:                                c);
158:
159:                this .addActionListener(this );
160:                this .addItemListener(this );
161:            }
162:
163:            protected static void addItems(WingTree tree) {
164:                TreeNode node, node2;
165:                tree.addNode(node = new TreeNode(new LabelItem(
166:                        "text and icon 1", WingSet.imgSmile)), null);
167:                tree.addNode(new TreeNode(new LabelItem("text and icon 2",
168:                        WingSet.imgGlasses)), node);
169:                tree.addNode(node2 = new TreeNode(new LabelItem(
170:                        "text and icon 3", WingSet.imgTongue)), node);
171:                tree.addNode(new TreeNode(new LabelItem("text and icon 4",
172:                        WingSet.imgSilence)), node2);
173:                tree.addNode(new TreeNode(new LabelItem("animated",
174:                        WingSet.imgAnim)), node2);
175:                tree.addNode(node = new TreeNode("text items"), null);
176:                tree.addNode(new TreeNode("text item 2"), node);
177:                tree.addNode(node2 = new TreeNode("text item 3"), node);
178:                tree.addNode(new TreeNode("text item 4"), node2);
179:                tree.addNode(node = new TreeNode(WingSet.imgSilence), null);
180:                tree.addNode(new TreeNode(WingSet.imgSmile), node);
181:                tree.addNode(node2 = new TreeNode(WingSet.imgGlasses), node);
182:                tree.addNode(new TreeNode(WingSet.imgTongue), node2);
183:                tree.addNode(node = new TreeNode(new ColorItem(
184:                        "custom renderer", Color.red)), null);
185:                tree.addNode(new TreeNode(new ColorItem("color green",
186:                        Color.green)), node);
187:                tree.addNode(node2 = new TreeNode(new ColorItem("color blue",
188:                        Color.blue)), node);
189:                tree.addNode(new TreeNode(new ColorItem("color magenta",
190:                        Color.magenta)), node2);
191:            }
192:
193:            public void actionPerformed(ActionEvent e) {
194:                if (target == null)
195:                    target = tree1;
196:                Object src = e.getSource();
197:                if (src == bBranch) {
198:                    TreeNode n = target.getSelected();
199:                    if (n == null)
200:                        n = target.getRoot();
201:                    target.addNode(makeNode(), n);
202:                    target.expandNode(n);
203:                } else if (src == bAdd) {
204:                    TreeNode n = target.getSelected();
205:                    if (n != null && n != target.getRoot()) {
206:                        target.addNode(makeNode(), n.getParent());
207:                    }
208:                } else if (src == bInsert) {
209:                    TreeNode n = target.getSelected();
210:                    if (n != null && n != target.getRoot()) {
211:                        TreeNode p = n.getParent();
212:                        target.insertNode(makeNode(), p, p.indexOf(n));
213:                    }
214:                } else if (src == bRemove) {
215:                    TreeNode n = target.getSelected();
216:                    if (n != null && n != target.getRoot()) {
217:                        target.removeNode(n);
218:                    }
219:                }
220:            }
221:
222:            private TreeNode makeNode() {
223:                Object[] its = ListPanel.getItems();
224:                return new TreeNode(its[(int) (Math.random() * its.length)]);
225:            }
226:
227:            public void itemStateChanged(ItemEvent e) {
228:                Object src = e.getSource();
229:                if (src == tree1)
230:                    target = tree1;
231:                else if (src == tree2)
232:                    target = tree2;
233:                else if (src == tree3)
234:                    target = tree3;
235:                else if (src == cbEditable) {
236:                    if (e.getStateChange() == ItemEvent.SELECTED) {
237:                        tree1.setEditor(new MyTreeItemEditor());
238:                        tree2.setEditor(new MyTreeItemEditor());
239:                        tree3.setEditor(new MyTreeItemEditor());
240:                    } else {
241:                        tree1.setEditor(null);
242:                        tree2.setEditor(null);
243:                        tree3.setEditor(null);
244:                    }
245:                }
246:            }
247:
248:            public static class MyTreeItemEditor extends DefaultItemEditor {
249:                public WingComponent getComponent(ItemOwner owner,
250:                        Object value, Object context) {
251:                    if (value instanceof  ColorItem) {
252:                        WingCombo editor = getComboEditor(owner, false);
253:                        editor.addItem(value);
254:                        Object[] items = ListPanel.getItems();
255:                        for (int i = 0; i < items.length; i++) {
256:                            if (items[i] instanceof  ColorItem)
257:                                editor.addItem(items[i]);
258:                        }
259:                        editor.setSelectedItem(value);
260:                        return editor;
261:                    }
262:                    if (value instanceof  WingImage) {
263:                        WingCombo editor = getComboEditor(owner, false);
264:                        editor.addItem(value);
265:                        Object[] items = ListPanel.getItems();
266:                        for (int i = 0; i < items.length; i++) {
267:                            if (items[i] instanceof  WingImage)
268:                                editor.addItem(items[i]);
269:                        }
270:                        editor.setSelectedItem(value);
271:                        return editor;
272:                    }
273:                    if (value instanceof  LabelItem) {
274:                        WingCombo editor = getComboEditor(owner, false);
275:                        editor.addItem(value);
276:                        Object[] items = ListPanel.getItems();
277:                        for (int i = 0; i < items.length; i++) {
278:                            if (items[i] instanceof  LabelItem)
279:                                editor.addItem(items[i]);
280:                        }
281:                        editor.setSelectedItem(value);
282:                        return editor;
283:                    }
284:                    return super.getComponent(owner, value, context);
285:                }
286:            }
287:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.