Source Code Cross Referenced for DefaultTreeNode.java in  » 6.0-JDK-Modules » java-3d » org » jdesktop » j3dedit » treelayout » 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 » 6.0 JDK Modules » java 3d » org.jdesktop.j3dedit.treelayout 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  $Header: /cvs/j3dfly/J3dEditor/src/org/jdesktop/j3dedit/treelayout/DefaultTreeNode.java,v 1.1 2005/04/20 22:21:32 paulby Exp $
003:         *
004:         *                         Sun Public License Notice
005:         *
006:         *  The contents of this file are subject to the Sun Public License Version
007:         *  1.0 (the "License"). You may not use this file except in compliance with
008:         *  the License. A copy of the License is available at http://www.sun.com/
009:         *  
010:         *  The Original Code is the Java 3D(tm) Scene Graph Editor.
011:         *  The Initial Developer of the Original Code is Paul Byrne.
012:         *  Portions created by Paul Byrne are Copyright (C) 2002.
013:         *  All Rights Reserved.
014:         *  
015:         *  Contributor(s): Paul Byrne.
016:         *  
017:         **/
018:        package org.jdesktop.j3dedit.treelayout;
019:
020:        import java.awt.*;
021:        import java.util.Vector;
022:
023:        /**
024:         * A simple Default TreeNode, just draws the node as a rectangle
025:         *
026:         * @author	Paul Byrne
027:         * @version	$Id: DefaultTreeNode.java,v 1.1 2005/04/20 22:21:32 paulby Exp $
028:         */
029:        public class DefaultTreeNode implements  TreeNode {
030:
031:            Vector children = new Vector();
032:
033:            protected TreePanel container;
034:            TreeNode parent;
035:            Rectangle subtreeSize = new Rectangle();
036:            Link link;
037:            protected Dimension nodeSize;
038:            protected Point computedPosition = new Point();
039:            Dimension preferredSize;
040:
041:            private Rectangle pickArea;
042:            protected Point linkExitPoint = new Point();
043:            protected Point linkEntryPoint = new Point();
044:
045:            protected LayoutData layoutData;
046:
047:            public DefaultTreeNode() {
048:                nodeSize = new Dimension(10, 10);
049:                preferredSize = new Dimension(nodeSize.width + 6,
050:                        nodeSize.height);
051:                pickArea = new Rectangle(nodeSize);
052:                link = null;
053:            }
054:
055:            public DefaultTreeNode(int width, int height, int spacing) {
056:                nodeSize = new Dimension(width, height);
057:                preferredSize = new Dimension(nodeSize.width * 10 / 6,
058:                        nodeSize.height);
059:                pickArea = new Rectangle(nodeSize);
060:                link = null;
061:            }
062:
063:            public void setLink(Link link) {
064:                this .link = link;
065:            }
066:
067:            public Link getLink() {
068:                return link;
069:            }
070:
071:            public void setContainer(TreePanel panel) {
072:                container = panel;
073:
074:                for (int i = 0; i < numChildren(); i++)
075:                    getChild(i).setContainer(panel);
076:            }
077:
078:            public TreePanel getContainer() {
079:                return container;
080:            }
081:
082:            public int numChildren() {
083:                return children.size();
084:            }
085:
086:            public TreeNode getChild(int index) {
087:                return (TreeNode) children.get(index);
088:            }
089:
090:            public void addChild(TreeNode child) {
091:                children.addElement(child);
092:                child.setParent(this );
093:            }
094:
095:            public void removeChild(TreeNode child) {
096:                if (!children.remove(child))
097:                    throw (new RuntimeException(
098:                            "Attempt to Remove non-existant child"));
099:                child.setParent(null);
100:            }
101:
102:            public int getNodeCount() {
103:                int count = 1; // 1 for this node
104:
105:                if (numChildren() > 0) {
106:                    for (int i = 0; i < numChildren(); i++)
107:                        count += getChild(i).getNodeCount();
108:                }
109:
110:                return count;
111:            }
112:
113:            public TreeNode getParent() {
114:                return parent;
115:            }
116:
117:            public void setParent(TreeNode parent) {
118:                this .parent = parent;
119:            }
120:
121:            public Point getLinkExit() {
122:                return linkExitPoint;
123:            }
124:
125:            public Point getLinkEntry() {
126:                return linkEntryPoint;
127:            }
128:
129:            public Point getComputedPosition() {
130:                return computedPosition;
131:            }
132:
133:            public void setComputedPosition(Point pos) {
134:                computedPosition = pos;
135:                pickArea.x = pos.x;
136:                pickArea.y = pos.y;
137:
138:                computeLinkPoints(pos);
139:            }
140:
141:            public void computeLinkPoints(Point pos) {
142:                linkExitPoint.x = pos.x + nodeSize.width / 2;
143:                linkExitPoint.y = pos.y + nodeSize.height;
144:
145:                linkEntryPoint.x = pos.x + nodeSize.width / 2;
146:                linkEntryPoint.y = pos.y;
147:            }
148:
149:            public Rectangle getSubtreeSize() {
150:                return subtreeSize;
151:            }
152:
153:            public void setSubtreeSize(Rectangle size) {
154:                subtreeSize = size;
155:            }
156:
157:            public Dimension getPreferredSize() {
158:                return preferredSize;
159:            }
160:
161:            public Dimension getMinimumSize() {
162:                return nodeSize;
163:            }
164:
165:            public Dimension getNodeSize() {
166:                return nodeSize;
167:            }
168:
169:            public void paint(Graphics g) {
170:                drawNode(g);
171:
172:                if (numChildren() > 0) {
173:                    link.paint(g);
174:                    g.setColor(Color.red);
175:                    g.drawRect(subtreeSize.x, subtreeSize.y, subtreeSize.width,
176:                            subtreeSize.height);
177:                    g.setColor(Color.black);
178:                }
179:
180:                for (int i = 0; i < numChildren(); i++)
181:                    getChild(i).paint(g);
182:            }
183:
184:            /**
185:             * Subclasses should override this method to draw different shapes
186:             * to represent this node
187:             */
188:            public void drawNode(Graphics g) {
189:                g.drawRect(computedPosition.x, computedPosition.y,
190:                        nodeSize.width, nodeSize.height);
191:            }
192:
193:            public boolean picked(int x, int y) {
194:                if (pickArea.contains(x, y))
195:                    return true;
196:                else
197:                    return false;
198:            }
199:
200:            public void setLayoutData(LayoutData layoutData) {
201:                this .layoutData = layoutData;
202:            }
203:
204:            public LayoutData getLayoutData() {
205:                return layoutData;
206:            }
207:
208:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.