Source Code Cross Referenced for JGraphpadParallelSplineRouter.java in  » Graphic-Library » jgraphpad » com » jgraph » pad » 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 » Graphic Library » jgraphpad » com.jgraph.pad.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (c) 2001-2005, Gaudenz Alder
003:         * All rights reserved. 
004:         * 
005:         * See LICENSE file in distribution for license details
006:         */
007:        package com.jgraph.pad.util;
008:
009:        import java.awt.geom.Point2D;
010:        import java.util.ArrayList;
011:        import java.util.List;
012:
013:        import org.jgraph.graph.DefaultEdge;
014:        import org.jgraph.graph.DefaultGraphModel;
015:        import org.jgraph.graph.EdgeView;
016:        import org.jgraph.graph.GraphConstants;
017:        import org.jgraph.graph.GraphModel;
018:        import org.jgraph.graph.PortView;
019:
020:        public class JGraphpadParallelSplineRouter extends
021:                DefaultEdge.LoopRouting {
022:
023:            protected static GraphModel emptyModel = new DefaultGraphModel();
024:
025:            public static JGraphpadParallelSplineRouter sharedInstance = new JGraphpadParallelSplineRouter();
026:
027:            /**
028:             * The distance between the control point and the middle line. A larger
029:             * number will lead to a more "bubbly" appearance of the bezier edges.
030:             */
031:            public double edgeSeparation = 25;
032:
033:            private JGraphpadParallelSplineRouter() {
034:                // empty
035:            }
036:
037:            /**
038:             * Returns the array of parallel edges.
039:             * 
040:             * @param edge
041:             */
042:            public Object[] getParallelEdges(EdgeView edge) {
043:                // FIXME: The model is stored in the cells only in the default
044:                // implementations. Otherwise we must use the real model here.
045:                return DefaultGraphModel.getEdgesBetween(emptyModel, edge
046:                        .getSource().getParentView().getCell(), edge
047:                        .getTarget().getParentView().getCell(), false);
048:            }
049:
050:            public List routeEdge(EdgeView edge) {
051:                List newPoints = new ArrayList();
052:
053:                // Check presence of source/target nodes
054:                if ((null == edge.getSource()) || (null == edge.getTarget())
055:                        || (null == edge.getSource().getParentView())
056:                        || (null == edge.getTarget().getParentView())) {
057:                    return null;
058:                }
059:                newPoints.add(edge.getSource());
060:
061:                Object[] edges = getParallelEdges(edge);
062:                // Find the position of the current edge that we are currently routing
063:                if (edges == null)
064:                    return null;
065:                int position = 0;
066:                for (int i = 0; i < edges.length; i++) {
067:                    Object e = edges[i];
068:                    if (e == edge.getCell()) {
069:                        position = i;
070:                    }
071:                }
072:
073:                // If there is only 1 edge between the two vertices, we don't need this
074:                // special routing
075:                if (edges.length >= 2) {
076:
077:                    // Find the end point positions
078:                    Point2D from = ((PortView) edge.getSource()).getLocation();
079:                    Point2D to = ((PortView) edge.getTarget()).getLocation();
080:
081:                    if (from != null && to != null) {
082:                        // calculate mid-point of the main edge
083:                        double midX = Math.min(from.getX(), to.getX())
084:                                + Math.abs((from.getX() - to.getX()) / 2);
085:                        double midY = Math.min(from.getY(), to.getY())
086:                                + Math.abs((from.getY() - to.getY()) / 2);
087:
088:                        // compute the normal slope. The normal of a slope is the
089:                        // negative
090:                        // inverse of the original slope.
091:                        double m = (from.getY() - to.getY())
092:                                / (from.getX() - to.getX());
093:                        double theta = Math.atan(-1 / m);
094:
095:                        // modify the location of the control point along the axis of
096:                        // the
097:                        // normal using the edge position
098:                        double r = edgeSeparation
099:                                * (Math.floor(position / 2) + 1);
100:                        if ((position % 2) == 0) {
101:                            r = -r;
102:                        }
103:
104:                        // convert polar coordinates to cartesian and translate axis to
105:                        // the
106:                        // mid-point
107:                        double ex = r * Math.cos(theta) + midX;
108:                        double ey = r * Math.sin(theta) + midY;
109:                        Point2D controlPoint = new Point2D.Double(ex, ey);
110:
111:                        // add the control point to the points list
112:                        newPoints.add(controlPoint);
113:                    }
114:                }
115:                newPoints.add(edge.getTarget());
116:                return newPoints;
117:            }
118:
119:            public int getEdgeStyle() {
120:                return GraphConstants.STYLE_SPLINE;
121:            }
122:
123:            /**
124:             * @return Returns the edgeSeparation.
125:             */
126:            public double getEdgeSeparation() {
127:                return edgeSeparation;
128:            }
129:
130:            /**
131:             * @param edgeSeparation
132:             *            The edgeSeparation to set.
133:             */
134:            public void setEdgeSeparation(double edgeSeparation) {
135:                this .edgeSeparation = edgeSeparation;
136:            }
137:
138:            /**
139:             * @return Returns the sharedInstance.
140:             */
141:            public static JGraphpadParallelSplineRouter getSharedInstance() {
142:                return sharedInstance;
143:            }
144:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.