Source Code Cross Referenced for DiagramCell.java in  » Web-Framework » argun » biz » hammurapi » diagram » 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 » Web Framework » argun » biz.hammurapi.diagram 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * argun 1.0
003:         * Web 2.0 delivery framework 
004:         * Copyright (C) 2007  Hammurapi Group
005:         *
006:         * This program is free software; you can redistribute it and/or
007:         * modify it under the terms of the GNU Lesser General Public
008:         * License as published by the Free Software Foundation; either
009:         * version 2 of the License, or (at your option) any later version.
010:         *
011:         * This program is distributed in the hope that it will be useful,
012:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014:         * Lesser General Public License for more details.
015:         *
016:         * You should have received a copy of the GNU Lesser General Public
017:         * License along with this library; if not, write to the Free Software
018:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
019:         *
020:         * URL: http://www.hammurapi.biz
021:         * e-Mail: support@hammurapi.biz 
022:         */
023:        package biz.hammurapi.diagram;
024:
025:        import java.awt.Color;
026:        import java.awt.Font;
027:        import java.awt.Frame;
028:        import java.awt.event.ActionEvent;
029:        import java.awt.geom.Point2D;
030:        import java.awt.geom.Rectangle2D;
031:        import java.math.BigInteger;
032:        import java.util.ArrayList;
033:        import java.util.Enumeration;
034:        import java.util.Hashtable;
035:        import java.util.Iterator;
036:        import java.util.List;
037:        import java.util.Map;
038:        import java.util.Properties;
039:
040:        import javax.swing.AbstractAction;
041:        import javax.swing.JPopupMenu;
042:        import javax.swing.SwingConstants;
043:        import javax.swing.SwingUtilities;
044:
045:        import org.jgraph.JGraph;
046:        import org.jgraph.graph.CellView;
047:        import org.jgraph.graph.DefaultGraphCell;
048:        import org.jgraph.graph.DefaultPort;
049:        import org.jgraph.graph.GraphConstants;
050:        import org.jgraph.graph.GraphLayoutCache;
051:        import org.jgraph.graph.Port;
052:
053:        import biz.hammurapi.diagram.data.Cell;
054:        import biz.hammurapi.diagram.data.Point;
055:        import biz.hammurapi.diagram.data.Property;
056:
057:        public class DiagramCell extends DefaultGraphCell implements 
058:                DiagramElement {
059:
060:            private DiagramModel owner;
061:            private String description;
062:            private String name;
063:            private int id;
064:            protected Cell data;
065:
066:            public DiagramCell(DiagramModel owner,
067:                    biz.hammurapi.diagram.data.Cell data) {
068:                this .owner = owner;
069:                if (data == null) {
070:                    id = owner.nextElementId();
071:                    setName("Cell " + id);
072:                } else {
073:                    id = data.getElementId().intValue();
074:                    setName(data.getName());
075:                    setDescription(data.getDescription());
076:
077:                    Property[] pa = data.getPropertyArray();
078:                    for (int i = 0; pa != null && i < pa.length; ++i) {
079:                        setProperty(pa[i].getName(), pa[i].getStringValue());
080:                    }
081:
082:                    pa = data.getViewPropertyArray();
083:                    for (int i = 0; pa != null && i < pa.length; ++i) {
084:                        setViewProperty(pa[i].getName(), pa[i].getStringValue());
085:                    }
086:
087:                    this .data = data;
088:                }
089:            }
090:
091:            public void setUserObject(Object userObject) {
092:                String newName = userObject.toString();
093:                setName(newName);
094:            }
095:
096:            public Object getUserObject() {
097:                return getName();
098:            }
099:
100:            public String getDescription() {
101:                return description;
102:            }
103:
104:            public String getName() {
105:                return name;
106:            }
107:
108:            public DiagramModel getModel() {
109:                return owner;
110:            }
111:
112:            public void setDescription(String description) {
113:                this .description = description;
114:            }
115:
116:            public void setName(String name) {
117:                this .name = name;
118:                super .setUserObject(name);
119:            }
120:
121:            public void store(JGraph graph,
122:                    biz.hammurapi.diagram.data.Cell data,
123:                    boolean nestConnections) {
124:                data.setName(getName());
125:                data.setElementId(new BigInteger(String.valueOf(id)));
126:                data.setDescription(getDescription());
127:                data.setType(getClass().getName());
128:
129:                CellView pageView = graph.getGraphLayoutCache().getMapping(
130:                        this , false);
131:                Rectangle2D bounds = pageView.getBounds();
132:                data.setX(bounds.getX());
133:                data.setY(bounds.getY());
134:
135:                Enumeration pne = getPropertyNames();
136:                while (pne.hasMoreElements()) {
137:                    String name = (String) pne.nextElement();
138:                    Property property = data.addNewProperty();
139:                    property.setName(name);
140:                    property.setStringValue(properties.getProperty(name));
141:                }
142:
143:                Enumeration vpne = getViewPropertyNames();
144:                while (vpne.hasMoreElements()) {
145:                    String name = (String) vpne.nextElement();
146:                    Property property = data.addNewViewProperty();
147:                    property.setName(name);
148:                    property.setStringValue(viewProperties.getProperty(name));
149:                }
150:
151:                if (nestConnections) {
152:                    Iterator it = getChildren().iterator();
153:                    while (it.hasNext()) {
154:                        Object next = it.next();
155:                        if (next instanceof  DefaultPort) {
156:                            DefaultPort pNext = (DefaultPort) next;
157:                            Object pName = pNext.getUserObject();
158:                            biz.hammurapi.diagram.data.Port port = data
159:                                    .addNewPort();
160:                            if (!isBlank(pName)) {
161:                                port.setName(pName.toString());
162:                            }
163:
164:                            Iterator eit = pNext.getEdges().iterator();
165:                            while (eit.hasNext()) {
166:                                Object edge = eit.next();
167:                                if (edge instanceof  DiagramEdge) {
168:                                    DiagramEdge dEdge = (DiagramEdge) edge;
169:                                    if (dEdge.getSource() == pNext) {
170:                                        biz.hammurapi.diagram.data.Edge edgeData = port
171:                                                .addNewEdge();
172:                                        dEdge.store(graph, edgeData,
173:                                                nestConnections);
174:                                    }
175:                                }
176:                            }
177:                        }
178:                    }
179:                }
180:            }
181:
182:            public int getId() {
183:                return id;
184:            }
185:
186:            public void setAttributes(Map attributes) {
187:                GraphConstants.setGradientColor(attributes, Color.LIGHT_GRAY);
188:                // Add a Border Color Attribute to the Map
189:                GraphConstants.setBorderColor(attributes, Color.BLACK);
190:
191:                // Add a White Background
192:                GraphConstants.setBackground(attributes, Color.white);
193:                // Make Vertex Opaque
194:                GraphConstants.setOpaque(attributes, true);
195:
196:                //GraphConstants.setConstrained(map, true);
197:                GraphConstants.setAutoSize(attributes, true);
198:
199:                GraphConstants.setInset(attributes, 5);
200:                GraphConstants.setHorizontalAlignment(attributes,
201:                        SwingConstants.CENTER);
202:
203:                Font font = GraphConstants.DEFAULTFONT;
204:                GraphConstants.setFont(attributes, font.deriveFont(Font.PLAIN,
205:                        10));
206:            }
207:
208:            public static boolean isBlank(Object obj) {
209:                return obj == null || obj.toString().trim().length() == 0;
210:            }
211:
212:            public DefaultPort getPort(String name) {
213:                Iterator it = getChildren().iterator();
214:                while (it.hasNext()) {
215:                    Object next = it.next();
216:                    if (next instanceof  DefaultPort) {
217:                        DefaultPort pNext = (DefaultPort) next;
218:                        Object pName = pNext.getUserObject();
219:                        if (isBlank(name)) {
220:                            if (isBlank(pName)) {
221:                                return pNext;
222:                            }
223:                        } else if (pName != null
224:                                && name.equals(pName.toString())) {
225:                            return pNext;
226:                        }
227:                    }
228:                }
229:                return null;
230:            }
231:
232:            void setId(int id) {
233:                this .id = id;
234:            }
235:
236:            public void connect() {
237:                if (data != null) {
238:                    GraphLayoutCache glc = owner.getGraph()
239:                            .getGraphLayoutCache();
240:                    biz.hammurapi.diagram.data.Port[] portArray = data
241:                            .getPortArray();
242:                    for (int k = 0; k < portArray.length; ++k) {
243:                        Port source = getPort(portArray[k].getName());
244:                        if (source != null) {
245:                            biz.hammurapi.diagram.data.Edge[] ea = portArray[k]
246:                                    .getEdgeArray();
247:                            for (int i = 0; i < ea.length; ++i) {
248:                                DiagramEdge edge = (DiagramEdge) owner
249:                                        .createElement(ea[i]);
250:                                if (edge != null) {
251:                                    Map edgeAttributes = new Hashtable();
252:                                    ((DiagramElement) edge)
253:                                            .setAttributes(edgeAttributes);
254:
255:                                    edge.getAttributes().applyMap(
256:                                            edgeAttributes);
257:
258:                                    BigInteger targetId = ea[i].getTarget();
259:                                    if (targetId != null) {
260:                                        DiagramCell targetCell = (DiagramCell) owner
261:                                                .getDiagramElement(targetId
262:                                                        .intValue());
263:                                        if (targetCell != null) {
264:                                            Port target = targetCell
265:                                                    .getPort(ea[i]
266:                                                            .getTargetPort());
267:
268:                                            if (target != null) {
269:                                                // Insert the Edge and its Attributes			
270:                                                glc.insertEdge(edge, source,
271:                                                        target);
272:
273:                                                Point[] pa = ea[i]
274:                                                        .getPointArray();
275:                                                if (pa != null && pa.length > 0) {
276:                                                    List allPoints = new ArrayList();
277:                                                    allPoints.add(source);
278:                                                    for (int j = 0; j < pa.length; ++j) {
279:                                                        allPoints
280:                                                                .add(new Point2D.Double(
281:                                                                        pa[j]
282:                                                                                .getX(),
283:                                                                        pa[j]
284:                                                                                .getY()));
285:                                                    }
286:                                                    allPoints.add(target);
287:                                                    Map newAttributes = new Hashtable();
288:                                                    GraphConstants.setPoints(
289:                                                            newAttributes,
290:                                                            allPoints);
291:                                                    glc.editCell(edge,
292:                                                            newAttributes);
293:                                                }
294:                                            }
295:                                        }
296:                                    }
297:                                }
298:                            }
299:                        }
300:                    }
301:                }
302:            }
303:
304:            protected Properties properties = new Properties();
305:
306:            public void setProperty(String name, String value) {
307:                properties.setProperty(name, value);
308:            }
309:
310:            public String getProperty(String name) {
311:                return properties.getProperty(name);
312:            }
313:
314:            public Enumeration getPropertyNames() {
315:                return properties.propertyNames();
316:            }
317:
318:            protected Properties viewProperties = new Properties();
319:
320:            public void setViewProperty(String name, String value) {
321:                viewProperties.setProperty(name, value);
322:            }
323:
324:            public String getViewProperty(String name) {
325:                return viewProperties.getProperty(name);
326:            }
327:
328:            public Enumeration getViewPropertyNames() {
329:                return viewProperties.propertyNames();
330:            }
331:
332:            public void populatePopupMenu(final DiagramApplet applet,
333:                    final java.awt.Point pt, final JPopupMenu menu) {
334:                // Edit
335:                menu.add(new AbstractAction("Edit") {
336:                    public void actionPerformed(ActionEvent e) {
337:                        Frame frame = (Frame) SwingUtilities
338:                                .getAncestorOfClass(Frame.class, applet
339:                                        .getGraph());
340:                        DiagramPropertiesDialog pd = new DiagramPropertiesDialog(
341:                                frame, DiagramCell.this );
342:                        if (pd.edit()) {
343:                            JGraph graph = applet.getGraph();
344:                            GraphLayoutCache graphLayoutCache = graph
345:                                    .getGraphLayoutCache();
346:                            CellView cellView = graphLayoutCache.getMapping(
347:                                    DiagramCell.this , false);
348:                            graph.updateAutoSize(cellView);
349:                        }
350:                    }
351:                });
352:            }
353:
354:            /**
355:             * @return true if cell shall be rendered with rounded corners
356:             */
357:            public boolean isRounded() {
358:                return true;
359:            }
360:
361:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.