Source Code Cross Referenced for Trees.java in  » GIS » GeoTools-2.4.1 » org » geotools » gui » swing » 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 » GIS » GeoTools 2.4.1 » org.geotools.gui.swing.tree 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *    GeoTools - OpenSource mapping toolkit
003:         *    http://geotools.org
004:         *    (C) 2003-2006, Geotools Project Managment Committee (PMC)
005:         *    (C) 2001, Institut de Recherche pour le Développement
006:         *
007:         *    This library is free software; you can redistribute it and/or
008:         *    modify it under the terms of the GNU Lesser General Public
009:         *    License as published by the Free Software Foundation; either
010:         *    version 2.1 of the License, or (at your option) any later version.
011:         *
012:         *    This library is distributed in the hope that it will be useful,
013:         *    but WITHOUT ANY WARRANTY; without even the implied warranty of
014:         *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
015:         *    Lesser General Public License for more details.
016:         */
017:        package org.geotools.gui.swing.tree;
018:
019:        // J2SE dependencies
020:        import java.util.List;
021:        import java.util.ArrayList;
022:        import javax.swing.tree.TreeNode;
023:        import javax.swing.tree.TreePath;
024:        import javax.swing.tree.TreeModel;
025:        import org.w3c.dom.Node;
026:
027:        // Geotools dependencies
028:        import org.geotools.resources.XArray;
029:        import org.geotools.resources.Arguments;
030:        import org.geotools.resources.OptionalDependencies;
031:
032:        /**
033:         * Convenience static methods for trees operations.
034:         *
035:         * @since 2.0
036:         * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/extension/widgets-swing/src/main/java/org/geotools/gui/swing/tree/Trees.java $
037:         * @version $Id: Trees.java 26890 2007-09-07 11:05:40Z desruisseaux $
038:         * @author Martin Desruisseaux
039:         */
040:        public final class Trees {
041:            /**
042:             * Interdit la création d'objets de cette classe.
043:             */
044:            private Trees() {
045:            }
046:
047:            /**
048:             * Returns the path to the specified
049:             * {@linkplain org.geotools.gui.swing.tree.TreeNode#getUserObject user object}. For each tree
050:             * node which are actually instance of Geotools {@link org.geotools.gui.swing.tree.TreeNode},
051:             * this method compares the specified {@code value} against the user object returned by the
052:             * {@link org.geotools.gui.swing.tree.TreeNode#getUserObject} method.
053:             *
054:             * @param  model The tree model to inspect.
055:             * @param  value User object to compare to
056:             *         {@link org.geotools.gui.swing.tree.TreeNode#getUserObject}.
057:             * @return The paths to the specified value, or an empty array if none.
058:             */
059:            public static TreePath[] getPathsToUserObject(
060:                    final TreeModel model, final Object value) {
061:                final List paths = new ArrayList(8);
062:                final Object[] path = new Object[8];
063:                path[0] = model.getRoot();
064:                getPathsToUserObject(model, value, path, 1, paths);
065:                return (TreePath[]) paths.toArray(new TreePath[paths.size()]);
066:            }
067:
068:            /**
069:             * Implémentation de la recherche des chemins. Cette
070:             * méthode s'appele elle-même d'une façon récursive.
071:             *
072:             * @param  model  Modèle dans lequel rechercher le chemin.
073:             * @param  value  Objet à rechercher dans
074:             *                {@link org.geotools.gui.swing.tree.TreeNode#getUserObject}.
075:             * @param  path   Chemin parcouru jusqu'à maintenant.
076:             * @param  length Longueur valide de {@code path}.
077:             * @param  list   Liste dans laquelle ajouter les {@link TreePath} trouvés.
078:             * @return {@code path}, ou un nouveau tableau s'il a fallu l'agrandir.
079:             */
080:            private static Object[] getPathsToUserObject(final TreeModel model,
081:                    final Object value, Object[] path, final int length,
082:                    final List list) {
083:                final Object parent = path[length - 1];
084:                if (parent instanceof  org.geotools.gui.swing.tree.TreeNode) {
085:                    final Object nodeValue = ((org.geotools.gui.swing.tree.TreeNode) parent)
086:                            .getUserObject();
087:                    if (nodeValue == value
088:                            || (value != null && value.equals(nodeValue))) {
089:                        list.add(new TreePath(XArray.resize(path, length)));
090:                    }
091:                }
092:                final int count = model.getChildCount(parent);
093:                for (int i = 0; i < count; i++) {
094:                    if (length >= path.length) {
095:                        path = XArray.resize(path, length << 1);
096:                    }
097:                    path[length] = model.getChild(parent, i);
098:                    path = getPathsToUserObject(model, value, path, length + 1,
099:                            list);
100:                }
101:                return path;
102:            }
103:
104:            /**
105:             * Creates a Swing root tree node from a XML root tree node. Together with
106:             * {@link #toString(TreeNode)}, this method provides a convenient way to print
107:             * the content of a XML document for debugging purpose.
108:             */
109:            public static TreeNode xmlToSwing(final Node node) {
110:                return OptionalDependencies.xmlToSwing(node);
111:            }
112:
113:            /**
114:             * Returns a graphical representation of the specified tree model. This representation can
115:             * be printed to the {@linkplain System#out standard output stream} (for example) if it uses
116:             * a monospaced font and supports unicode.
117:             *
118:             * @param  tree The tree to format.
119:             * @return A string representation of the tree, or {@code null} if it doesn't contain any node.
120:             */
121:            public static String toString(final TreeModel tree) {
122:                return OptionalDependencies.toString(tree);
123:            }
124:
125:            /**
126:             * Returns a graphical representation of the specified tree. This representation can be
127:             * printed to the {@linkplain System#out standard output stream} (for example) if it uses
128:             * a monospaced font and supports unicode.
129:             *
130:             * @param  node The root node of the tree to format.
131:             * @return A string representation of the tree, or {@code null} if it doesn't contain any node.
132:             */
133:            public static String toString(final TreeNode node) {
134:                return OptionalDependencies.toString(node);
135:            }
136:
137:            /**
138:             * Prints the specified tree model to the {@linkplain System#out standard output stream}.
139:             * This method is mostly a convenience for debugging purpose.
140:             *
141:             * @since 2.4
142:             */
143:            public static void print(final TreeModel tree) {
144:                Arguments.getPrintWriter(System.out).println(toString(tree));
145:            }
146:
147:            /**
148:             * Prints the specified tree to the {@linkplain System#out standard output stream}.
149:             * This method is mostly a convenience for debugging purpose.
150:             *
151:             * @since 2.4
152:             */
153:            public static void print(final TreeNode node) {
154:                Arguments.getPrintWriter(System.out).println(toString(node));
155:            }
156:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.