Source Code Cross Referenced for ParentMap.java in  » Graphic-Library » jgraph » org » jgraph » graph » 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 » Graphic Library » jgraph » org.jgraph.graph 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * @(#)ParentMap.java	1.0 03-JUL-04
003:         * 
004:         * Copyright (c) 2001-2004 Gaudenz Alder
005:         *  
006:         */
007:        package org.jgraph.graph;
008:
009:        import java.io.Serializable;
010:        import java.util.ArrayList;
011:        import java.util.HashSet;
012:        import java.util.Hashtable;
013:        import java.util.Iterator;
014:        import java.util.Map;
015:        import java.util.Set;
016:
017:        /**
018:         * An object that describes relations between childs and parents.
019:         * 
020:         * @version 1.0 1/1/02
021:         * @author Gaudenz Alder
022:         */
023:
024:        public class ParentMap implements  Serializable {
025:
026:            /** Contents of the parent map. */
027:            protected ArrayList entries = new ArrayList();
028:
029:            /**
030:             * Set of changed changedNodes for the parent map. Includes childs and
031:             * parents.
032:             */
033:            protected Set changedNodes = new HashSet();
034:
035:            /** Maps parents to integers with the future number of childs. */
036:            protected Map childCount = new Hashtable();
037:
038:            /**
039:             * Constructs a <code>ParentMap</code> object.
040:             */
041:            public ParentMap() {
042:                // empty
043:            }
044:
045:            /**
046:             * Constructs a <code>ParentMap</code> object.
047:             */
048:            public ParentMap(Object[] children, Object parent) {
049:                addEntries(children, parent);
050:            }
051:
052:            /**
053:             * Returns a parent map that represents the insertion or removal of
054:             * <code>cells</code> in <code>model</code> based on <code>remove</code>.
055:             * Unselected childs of selected nodes are moved to the first unselected
056:             * parent of that node.
057:             * <p>
058:             * <strong>Note:</strong> Consequently, cells "move up" one level when
059:             * their parent is removed. <strong>Note:</strong> onlyUsePassedInCells can
060:             * be used to indicate if only cells from the passed-in cell array are
061:             * allowed parents. This is only used if remove is not true.
062:             */
063:            public static ParentMap create(GraphModel m, Object[] c,
064:                    boolean remove, boolean onlyUsePassedInCells) {
065:                Set cellSet = new HashSet();
066:                for (int i = 0; i < c.length; i++) {
067:                    // Do not add null cells otherwise the while loop lower down runs
068:                    // in an infinite loop
069:                    if (c[i] != null) {
070:                        cellSet.add(c[i]);
071:                    }
072:                }
073:                ParentMap parentMap = new ParentMap();
074:                for (int i = 0; i < c.length; i++) {
075:                    // Collect Parent Information
076:                    Object parent = m.getParent(c[i]);
077:                    if (parent != null
078:                            && (!onlyUsePassedInCells || (!remove && cellSet
079:                                    .contains(parent))))
080:                        parentMap.addEntry(c[i], (remove) ? null : parent);
081:                    if (remove) {
082:                        // Move Orphans to First Unselected Parent
083:                        while (cellSet.contains(parent)) {
084:                            // Make sure there are no nulls in the cell set or the
085:                            // while will get stuck in a loop
086:                            parent = m.getParent(parent);
087:                        }
088:                        for (int j = 0; j < m.getChildCount(c[i]); j++) {
089:                            Object child = m.getChild(c[i], j);
090:                            if (!cellSet.contains(child))
091:                                parentMap.addEntry(child, parent);
092:                        }
093:                    }
094:                }
095:                return parentMap;
096:            }
097:
098:            /**
099:             * Add a new entry for this child, parent pair to the parent map. The child
100:             * and parent are added to the set of changed nodes. Note: The previous
101:             * parent is changed on execution of this parent map and must be added by
102:             * the GraphModel and reflected by the GraphChange.getChanged method. TODO:
103:             * In general, the GraphModel should be in charge of computing the set of
104:             * changed cells.
105:             */
106:            public void addEntry(Object child, Object parent) {
107:                if (child != null) {
108:                    entries.add(new Entry(child, parent));
109:                    // Update Changed Nodes
110:                    changedNodes.add(child);
111:                    if (parent != null)
112:                        changedNodes.add(parent);
113:                }
114:            }
115:
116:            /**
117:             * Adds all child parent pairs using addEntry.
118:             */
119:            public void addEntries(Object[] children, Object parent) {
120:                for (int i = 0; i < children.length; i++)
121:                    addEntry(children[i], parent);
122:            }
123:
124:            /**
125:             * Returns the number of entries.
126:             */
127:            public int size() {
128:                return entries.size();
129:            }
130:
131:            /**
132:             * Returns an <code>Iterator</code> for the entries in the map.
133:             */
134:            public Iterator entries() {
135:                return entries.iterator();
136:            }
137:
138:            /**
139:             * Returns a <code>Set</code> for the nodes, childs and parents, in this
140:             * parent map.
141:             */
142:            public Set getChangedNodes() {
143:                return changedNodes;
144:            }
145:
146:            /**
147:             * Creates a new parent map based on this parent map, where the child and
148:             * parents are mapped using <code>map</code>. If one the cells is not in
149:             * <code>map</code>, then the original cell is used instead.
150:             * <p>
151:             */
152:            public ParentMap clone(Map map) {
153:                ParentMap pm = new ParentMap();
154:                Iterator it = entries();
155:                while (it.hasNext()) {
156:                    Entry e = (Entry) it.next();
157:                    Object child = map.get(e.getChild());
158:                    Object parent = map.get(e.getParent());
159:                    if (child == null)
160:                        child = e.getChild();
161:                    if (parent == null)
162:                        parent = e.getParent();
163:                    if (child != null && parent != null)
164:                        pm.addEntry(child, parent);
165:                }
166:                return pm;
167:            }
168:
169:            /**
170:             * Object that represents the relation between a child an a parent.
171:             */
172:            public class Entry implements  Serializable {
173:
174:                /** Child and parent of the relation this entry describes. */
175:                protected Object child, parent;
176:
177:                /**
178:                 * Constructs a new relation between <code>child</code> and
179:                 * <code>parent</code>.
180:                 */
181:                public Entry(Object child, Object parent) {
182:                    this .child = child;
183:                    this .parent = parent;
184:                }
185:
186:                /**
187:                 * Returns the child of the relation.
188:                 */
189:                public Object getChild() {
190:                    return child;
191:                }
192:
193:                /**
194:                 * Returns the parent of the relation.
195:                 */
196:                public Object getParent() {
197:                    return parent;
198:                }
199:            }
200:
201:            public String toString() {
202:                String s = super .toString() + "\n";
203:                Iterator it = entries();
204:                while (it.hasNext()) {
205:                    Entry entry = (Entry) it.next();
206:                    s += " child=" + entry.getChild() + " parent="
207:                            + entry.getParent() + "\n";
208:                }
209:                return s;
210:            }
211:
212:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.