Source Code Cross Referenced for TreeItem.java in  » Portal » Open-Portal » ob » tree » 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 » Portal » Open Portal » ob.tree 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Stingray Software Objective Blend
003:         * Copyright (C) 1996 Stingray Software, Inc.
004:         * All Rights Reserved
005:         *
006:         * This source code is only intended as a supplement to
007:         * the Stingray Objective Blend product.  See the Objective
008:         * Blend html help documentation for detailed information regarding
009:         * using OB classes.
010:         *
011:         * Author : LingFeng Wang
012:         * Description : TreeItem.java - Tree item
013:         *
014:         * CHANGELOG:
015:         * 7/09/96 	LFW	Created
016:         */
017:
018:        /**
019:         TreeItem class
020:
021:         This class is provided for partial backwards compatibility with the
022:         version 1.1 TreeItem control.  Much of the logic contained in the old
023:         version of the TreeItem class has been eliminated due to the new architecture
024:         of the TreeBase control; however, those developers who wish to have some
025:         of the same naming/constructions methods in place can still use this
026:         control as a subclass of the new Node class.
027:
028:         @see ob.tree.Node
029:         @see ob.tree.TreeBase
030:         */package ob.tree;
031:
032:        import java.awt.*;
033:        import com.sun.portal.log.common.PortalLogger;
034:        import java.util.Vector;
035:        import ob.tree.Node;
036:
037:        public class TreeItem extends Node {
038:
039:            /**
040:             * indicates an EXPANDed state for the tree item
041:             */
042:            public static final int EXPAND = 1;
043:            /**
044:             * indicates an UNEXPANDed state for the tree item
045:             */
046:            public static final int UNEXPAND = 2;
047:
048:            /**
049:             * parent of the tree item
050:             */
051:            boolean Visible = true;
052:
053:            int Image = -1;
054:            int SelImage = -1;
055:            int Status = EXPAND;
056:            int nChild = 0;
057:            int Indent = 0;
058:            Rectangle BaseBound;
059:            Object Data = null;
060:
061:            /**
062:             * constructor accepts a label for the item
063:             * @param label the label for the tree item
064:             */
065:            public TreeItem(String label) {
066:                super (label, -1, -1);
067:            }
068:
069:            /**
070:             * adds a TreeItem to be a child of this TreeItem.
071:             * @param item the new item to add as a child
072:             */
073:            public void addItem(TreeItem child) {
074:                super .addChild(child);
075:            }
076:
077:            /**
078:             * gets the label for the tree item
079:             * @return the label as type String
080:             * @see TreeItem#setLabel
081:             */
082:            public String getLabel() {
083:                return super .getText();
084:            }
085:
086:            /**
087:             * sets the label for the tree item
088:             * @param s label as type String
089:             * @see TreeItem#getLabel
090:             */
091:            public void setLabel(String s) {
092:                super .setText(s);
093:            }
094:
095:            /**
096:             * retrieves the data associated with this item
097:             * @return data as type Object
098:             * @see TreeItem#setData
099:             */
100:            public Object getData() {
101:                return Data;
102:            }
103:
104:            /**
105:             * sets the data associated with this item
106:             * @param data new data for this item as type Object
107:             * @see TreeItem#getData
108:             */
109:            public void setData(Object data) {
110:                this .Data = data;
111:            }
112:
113:            /**
114:             * gets the expanded status of the tree item.
115:             * @return expanded status as one of following int values: EXPAND or UNEXPAND
116:             * @see TreeItem#setStatus
117:             */
118:            public int getStatus() {
119:
120:                return Status;
121:            }
122:
123:            /**
124:             * sets the expanded status of the tree item
125:             * @param s can be EXPAND or UNEXPAND
126:             * @see getStatus
127:             */
128:            public void setStatus(int s) {
129:                this .Status = s;
130:                if (s == EXPAND) {
131:                    super .expand(true);
132:                }
133:            }
134:
135:            /**
136:             * returns the position of the tree item relative to the parent.
137:             * @return position of tree item.  If no parent, returns a -1.
138:             * @see TreeItem#getNextItem
139:             */
140:            public int getIndex() {
141:                int nCount = 1;
142:                TreeItem sib = (TreeItem) getFirstSibling();
143:                while (sib != this ) {
144:                    sib = (TreeItem) sib.getNextSibling();
145:                    nCount++;
146:                }
147:                return nCount;
148:            }
149:
150:            /**
151:             * retrieves the next sequential tree item on the same level with the
152:             * same parent.
153:             * @return the next tree item on this level with the same parent as type TreeItem.
154:             * if none found, then return null.
155:             * @see TreeItem#getIndex
156:             * @see TreeItem#getPrevItem
157:             */
158:            public TreeItem getNextItem() {
159:                return ((TreeItem) getNextSibling());
160:            }
161:
162:            /**
163:             * retrieves the previous sequential tree item on the same level with the
164:             * same parent.
165:             * @return the previous tree item on this level with the same parent; if none
166:             * found return null.
167:             * @see TreeItem#getIndex
168:             * @see TreeItem#getNextItem
169:             */
170:
171:            public TreeItem getPrevItem() {
172:                return ((TreeItem) getPrevSibling());
173:            }
174:
175:            /**
176:             * determines whether tree item has child items
177:             * @return true if children exist, otherwise false
178:             * @see TreeItem#getCount
179:             * @see TreeItem#getChild
180:             */
181:            public boolean hasChild() {
182:                return super .hasChildren();
183:            }
184:
185:            /**
186:             * returns the number of children the tree item has.
187:             * @return the number of children as type int
188:             * @see TreeItem#hasChild
189:             * @see TreeItem#getChild
190:             */
191:            public int getCount() {
192:                int nCount = 0;
193:                //System.out.println("In getCount function....");
194:                TreeItem ti = (TreeItem) getFirstChild();
195:                try {
196:                    //System.out.println("First Child is : "+ ti.getText());
197:                } catch (NullPointerException n) {
198:                }
199:                while (ti != null) {
200:                    //System.out.println("In While Loop");
201:                    try {
202:                        ti = (TreeItem) ti.getNextSibling();
203:                        //System.out.println("Next Child is : " + ti.getText());
204:                        nCount++;
205:                    } catch (NullPointerException n) {
206:                    }
207:                }
208:
209:                //System.out.println("Total count is ......: " + nCount);
210:                //System.out.println("Out of getcount Function");
211:                return nCount;
212:            }
213:
214:            /**
215:             * retrieves the bounding rectangle for the item
216:             * @return bounding rectangle as type Rectangle
217:             */
218:            public Rectangle bounds() {
219:                return BaseBound;
220:            }
221:
222:            /**
223:             * retrieves a child of the tree item
224:             * @param index which child to retrieve
225:             * @return the child as type TreeItem
226:             * @see TreeItem#hasChild
227:             * @see TreeItem#getCount
228:             */
229:            public TreeItem getChild(int index) {
230:                int nCount = 0;
231:                TreeItem ti = null;
232:
233:                ti = (TreeItem) getFirstChild();
234:
235:                while (ti != null && index < nCount) {
236:
237:                    if (ti != null)
238:                        ti = (TreeItem) ti.getNextSibling();
239:                    nCount++;
240:                }
241:                return ti;
242:            }
243:
244:            /**
245:             * determines whether item is the parent of a this item
246:             * @param item the item to check if it is a child of this item
247:             * @return whether the item is a child as type boolean
248:             */
249:            public boolean isParentOf(TreeItem item) {
250:
251:                if (item == null)
252:                    return false;
253:                return super .isParent(item);
254:            }
255:
256:            /**
257:             * determines whether this item is the child of one of the items
258:             * @param items the items to check if it is a parent of this item
259:             * @return whether this item is a child as type boolean
260:             */
261:            public boolean isChildOf(TreeItem[] items) {
262:
263:                for (int i = 0; i < items.length; i++) {
264:                    if (items[i].isParentOf(this ))
265:                        return true;
266:                }
267:
268:                return false;
269:            }
270:
271:            /**
272:             * removes a child item from the tree item
273:             * @param item item to remove
274:             */
275:            public void remove(TreeItem item) {
276:                item.detachFromTree();
277:            }
278:
279:            // VICKY: added methods
280:
281:            // we apparently used to have a removeAll() function
282:            public void removeAll() {
283:                System.out.println("in removeAll....");
284:                if (getSubItems().isEmpty()) {
285:
286:                    System.out.println("Vector is empty");
287:                } else {
288:                    System.out.println("Vector has elements ");
289:                    System.out
290:                            .println("Vector size is " + getSubItems().size());
291:                    getSubItems().removeAllElements();
292:                }
293:            }
294:
295:            /* recursive search through the tree control to find
296:                   the treeitem that matches my data object
297:             */
298:            public TreeItem findObject(Object o) {
299:                if (Data == o) {
300:                    //               System.out.println("Before Bina... Tree item is : " + this);
301:                    return this ;
302:                } else {
303:                    int i = 0;
304:                    int count = this .getCount();
305:                    //                     System.out.println("Bina.. Count is ......: " + count);
306:                    TreeItem ti = null;
307:                    while (ti == null && i < count) {
308:                        try {
309:                            ti = ((TreeItem) getItemChild(i)).findObject(o);
310:                            //                    System.out.println("Bina... Tree item is : " + ti);
311:                            i++;
312:                        } catch (NullPointerException n) {
313:                        }
314:                    }
315:                    //               System.out.println("Before returnBina... Tree item is : " + ti);
316:                    return ti;
317:                }
318:            }
319:
320:            /* recursive run through the tree control to print
321:            all the treeitems
322:             */
323:            public void printTree() {
324:                int i = 0;
325:
326:                // print this TreeItem
327:                //System.out.println(this.Label + "\n");
328:
329:                while (i < getCount()) {
330:                    getChild(i).printTree();
331:                    i++;
332:                }
333:
334:                return;
335:            }
336:
337:            ////BINA 
338:            /// added becuase getChild does not work ok with findObject
339:            ////
340:            public TreeItem getItemChild(int index) {
341:                int nChild = getSubItems().size();
342:                //System.out.println("In getItemCHild.... nChild is : " + nChild);
343:                //System.out.println("In getItemCHild.... Index passed is : " + index);
344:                if (index >= 0 && index < nChild) {
345:                    //System.out.println("Element at : " + index + " is " + getSubItems().elementAt(index));	 
346:                    return (TreeItem) getSubItems().elementAt(index);
347:                } else {
348:                    return null;
349:                }
350:            }
351:
352:            /////BINA
353:
354:            /* delete a child from the tree */
355:            public synchronized void deleteChild(TreeItem item) {
356:
357:                int i = 0;
358:                //System.out.println("IN deleteChild ....");
359:                TreeItem firstChild = (TreeItem) item.getFirstChild();
360:                while (firstChild != null) {
361:                    //System.out.println("Child is ........"+firstChild.getText());
362:                    item.remove(firstChild);
363:                    firstChild = (TreeItem) item.getFirstChild();
364:                }
365:            }
366:            // BINA
367:
368:            //VICKY: end added methods
369:
370:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.