Source Code Cross Referenced for SimpleTreeModel.java in  » GIS » openjump » com » vividsolutions » jump » util » 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 » openjump » com.vividsolutions.jump.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * The Unified Mapping Platform (JUMP) is an extensible, interactive GUI 
003:         * for visualizing and manipulating spatial features with geometry and attributes.
004:         *
005:         * Copyright (C) 2003 Vivid Solutions
006:         * 
007:         * This program is free software; you can redistribute it and/or
008:         * modify it under the terms of the GNU General Public License
009:         * as published by the Free Software Foundation; either version 2
010:         * of the License, or (at your option) any later version.
011:         * 
012:         * This program 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
015:         * GNU General Public License for more details.
016:         * 
017:         * You should have received a copy of the GNU General Public License
018:         * along with this program; if not, write to the Free Software
019:         * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
020:         * 
021:         * For more information, contact:
022:         *
023:         * Vivid Solutions
024:         * Suite #1A
025:         * 2328 Government Street
026:         * Victoria BC  V8T 5G5
027:         * Canada
028:         *
029:         * (250)385-6040
030:         * www.vividsolutions.com
031:         */
032:        package com.vividsolutions.jump.util;
033:
034:        import java.util.ArrayList;
035:        import java.util.Iterator;
036:        import java.util.List;
037:
038:        import javax.swing.event.TreeModelEvent;
039:        import javax.swing.event.TreeModelListener;
040:        import javax.swing.tree.TreeModel;
041:        import javax.swing.tree.TreePath;
042:
043:        import com.vividsolutions.jts.util.Assert;
044:
045:        public abstract class SimpleTreeModel implements  TreeModel {
046:
047:            public static abstract class Folder {
048:                private Class childrenClass;
049:                private String name;
050:                private Object parent;
051:
052:                public Folder(String name, Object parent, Class childrenClass) {
053:                    this .name = name;
054:                    this .parent = parent;
055:                    this .childrenClass = childrenClass;
056:                }
057:
058:                public abstract List getChildren();
059:
060:                public String toString() {
061:                    return name;
062:                }
063:
064:                public int hashCode() {
065:                    //JTree puts nodes in a Hashtable. To keep things simple, just return 0,
066:                    //which will cause linear searches (fine for small trees). [Jon Aquino]
067:                    return 0;
068:                }
069:
070:                public boolean equals(Object other) {
071:                    //Folders are value objects. [Jon Aquino]
072:                    if (!(other instanceof  Folder)) {
073:                        return false;
074:                    }
075:                    Folder otherFolder = (Folder) other;
076:                    return parent == otherFolder.parent
077:                            && name.equals(otherFolder.name);
078:                }
079:
080:                public Class getChildrenClass() {
081:                    return childrenClass;
082:                }
083:
084:                public Object getParent() {
085:                    return parent;
086:                }
087:
088:            }
089:
090:            private Object root;
091:
092:            public SimpleTreeModel(Object root) {
093:                this .root = root;
094:            }
095:
096:            public Object getRoot() {
097:                return root;
098:            }
099:
100:            public boolean isLeaf(Object node) {
101:                return !(node instanceof  Folder) && getChildCount(node) == 0;
102:            }
103:
104:            public void valueForPathChanged(TreePath path, Object newValue) {
105:            }
106:
107:            public int getIndexOfChild(Object parent, Object child) {
108:                for (int i = 0; i < getChildCount(parent); i++) {
109:                    //Folders are value objects. [Jon Aquino]
110:                    if (child instanceof  Folder
111:                            && getChild(parent, i) instanceof  Folder
112:                            && getChild(parent, i).toString().equals(
113:                                    child.toString())) {
114:                        return i;
115:                    }
116:                    if (getChild(parent, i) == child) {
117:                        return i;
118:                    }
119:                }
120:                Assert.shouldNeverReachHere(parent + ", " + child);
121:                return -1;
122:            }
123:
124:            private ArrayList listeners = new ArrayList();
125:            private boolean firingEvents = true;
126:
127:            public void addTreeModelListener(TreeModelListener listener) {
128:                listeners.add(listener);
129:            }
130:
131:            public void removeTreeModelListener(TreeModelListener listener) {
132:                listeners.remove(listener);
133:            }
134:
135:            /**
136:             * No need to handle Folders
137:             * @param parent not a Folder
138:             */
139:            public abstract List getChildren(Object parent);
140:
141:            public Object getChild(Object parent, int index) {
142:                return children(parent).get(index);
143:            }
144:
145:            private List children(Object parent) {
146:                return parent instanceof  Folder ? ((Folder) parent)
147:                        .getChildren() : getChildren(parent);
148:            }
149:
150:            public int getChildCount(Object parent) {
151:                return children(parent).size();
152:            }
153:
154:            public void fireTreeNodesChanged(TreeModelEvent e) {
155:                if (!firingEvents) {
156:                    return;
157:                }
158:                for (Iterator i = listeners.iterator(); i.hasNext();) {
159:                    TreeModelListener l = (TreeModelListener) i.next();
160:                    l.treeNodesChanged(e);
161:                }
162:            }
163:
164:            public void fireTreeNodesInserted(TreeModelEvent e) {
165:                if (!firingEvents) {
166:                    return;
167:                }
168:                for (Iterator i = listeners.iterator(); i.hasNext();) {
169:                    TreeModelListener l = (TreeModelListener) i.next();
170:                    l.treeNodesInserted(e);
171:                }
172:            }
173:
174:            public void fireTreeNodesRemoved(TreeModelEvent e) {
175:                if (!firingEvents) {
176:                    return;
177:                }
178:                for (Iterator i = listeners.iterator(); i.hasNext();) {
179:                    TreeModelListener l = (TreeModelListener) i.next();
180:                    l.treeNodesRemoved(e);
181:                }
182:            }
183:
184:            public void fireTreeStructureChanged(TreeModelEvent e) {
185:                if (!firingEvents) {
186:                    return;
187:                }
188:                for (Iterator i = listeners.iterator(); i.hasNext();) {
189:                    TreeModelListener l = (TreeModelListener) i.next();
190:                    l.treeStructureChanged(e);
191:                }
192:            }
193:
194:            public void setFiringEvents(boolean firingEvents) {
195:                this.firingEvents = firingEvents;
196:            }
197:
198:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.