Source Code Cross Referenced for TreePanel.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/TreePanel.java,v 1.1 2005/04/20 22:21:33 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 javax.swing.JPanel;
022:
023:        /**
024:         * @author Paul Byrne
025:         * @version $Id: TreePanel.java,v 1.1 2005/04/20 22:21:33 paulby Exp $
026:         */
027:        public class TreePanel extends JPanel {
028:            private TreeNode root;
029:
030:            private int width = 300;
031:
032:            private int height = 300;
033:
034:            private int xOrigin = 0; // Origin of canvas, used when subtreeSize
035:            private int yOrigin = 0; // origin is not 0,0
036:
037:            private static int MARGIN = 15;
038:
039:            private double scale = 1.0;
040:
041:            private TreeLayout treeLayout;
042:
043:            /** Construct a tree panel using SimpleTreeLayout
044:             */
045:            public TreePanel() {
046:                this (new SimpleTreeLayout());
047:            }
048:
049:            /** Create a panel with the specified layout manager
050:             * @param treeLayout The treeLayout manager to use
051:             * @see TreeLayout.CircularTreeLayout
052:             * @see TreeLayout.SimpleTreeLayout
053:             */
054:            public TreePanel(TreeLayout treeLayout) {
055:                super ();
056:                this .treeLayout = treeLayout;
057:            }
058:
059:            public void setTree(TreeNode root) {
060:                this .root = root;
061:                root.setContainer(this );
062:            }
063:
064:            public TreeNode getTree() {
065:                return root;
066:            }
067:
068:            /** Set the treeLayout strategy
069:             * @see SimpleTreeLayout, CircularTreeLayout
070:             */
071:            public void setTreeLayout(TreeLayout treeLayout) {
072:                this .treeLayout = treeLayout;
073:            }
074:
075:            public TreeLayout getTreeLayout() {
076:                return treeLayout;
077:            }
078:
079:            public void layoutTree() {
080:                treeLayout.doLayout(root);
081:                width = (int) (root.getSubtreeSize().width * scale);
082:                height = (int) (root.getSubtreeSize().height * scale);
083:                xOrigin = root.getSubtreeSize().x;
084:                yOrigin = root.getSubtreeSize().y;
085:            }
086:
087:            /** Search the tree and return the node that contains the point
088:             * x,y. Returns null if no node is found
089:             */
090:            public TreeNode pickNode(int x, int y) {
091:                if (root == null)
092:                    return null;
093:
094:                x = (int) (x / scale) + xOrigin;
095:                y = (int) (y / scale) + yOrigin;
096:
097:                return treeLayout.doPick(root, x, y);
098:            }
099:
100:            public double getScale() {
101:                return scale;
102:            }
103:
104:            /**
105:             * Scale must be <= 1.0
106:             */
107:            public void setScale(double scale) {
108:                this .scale = scale;
109:
110:                if (scale > 1.0)
111:                    throw new RuntimeException("Illegal scale " + scale);
112:
113:                width = (int) (root.getSubtreeSize().width * scale);
114:                height = (int) (root.getSubtreeSize().height * scale);
115:
116:                setSize(width, height);
117:
118:                repaint();
119:            }
120:
121:            public void scrollRectToVisible(Rectangle rect) {
122:                System.out.println("ScrollRectToVisible " + rect);
123:
124:                // TODO fix this to correctly handle scale
125:
126:                rect.x -= xOrigin;
127:                rect.y -= yOrigin;
128:                super .scrollRectToVisible(rect);
129:            }
130:
131:            public void paintComponent(Graphics g) {
132:                super .paintComponent(g);
133:                // Should check and ensure we don't paint over the
134:                // borders of the component
135:                Graphics2D g2 = (Graphics2D) g.create();
136:
137:                g2.scale(scale, scale);
138:                g2.translate(-xOrigin, -yOrigin);
139:
140:                //System.out.println("Paint scale "+scale+" "+(-xOrigin)+", "+(-yOrigin)+" w "+width+" h "+height);
141:
142:                if (root != null)
143:                    root.paint(g2);
144:
145:                g2.dispose();
146:            }
147:
148:            public Dimension getPreferredSize() {
149:                return new Dimension(width + MARGIN, height + MARGIN);
150:            }
151:
152:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.