Source Code Cross Referenced for TermtBorderItemLocator.java in  » Workflow-Engines » osbl-1_0 » newprocess » diagram » cust » locator » 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 » Workflow Engines » osbl 1_0 » newprocess.diagram.cust.locator 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * 
003:         */package newprocess.diagram.cust.locator;
004:
005:        import java.util.Iterator;
006:        import java.util.List;
007:
008:        import newprocess.diagram.cust.figures.TermDefaultSizeNodeFigure;
009:        import newprocess.diagram.edit.parts.ConditionTermConditionProxyEditPart;
010:        import newprocess.diagram.edit.parts.ConditionTermEditPart;
011:
012:        import org.eclipse.draw2d.IFigure;
013:        import org.eclipse.draw2d.PositionConstants;
014:        import org.eclipse.draw2d.geometry.Point;
015:        import org.eclipse.draw2d.geometry.Rectangle;
016:        import org.eclipse.gef.EditPart;
017:        import org.eclipse.gef.RootEditPart;
018:        import org.eclipse.gmf.runtime.diagram.ui.figures.BorderItemLocator;
019:
020:        /**
021:         * @author sh
022:         *
023:         */
024:        public class TermtBorderItemLocator extends BorderItemLocator {
025:
026:            public TermtBorderItemLocator(IFigure borderItem,
027:                    IFigure parentFigure, Rectangle constraint) {
028:                super (borderItem, parentFigure, constraint);
029:            }
030:
031:            public TermtBorderItemLocator(IFigure parentFigure,
032:                    int preferredSide) {
033:                super (parentFigure, preferredSide);
034:            }
035:
036:            public TermtBorderItemLocator(IFigure parentFigure) {
037:                super (parentFigure);
038:            }
039:
040:            /**
041:             * 
042:             * If the Parent shape has been resized, this method calculates the new
043:             * positions of the border items especially the spacings between them
044:             * @see org.eclipse.gmf.runtime.diagram.ui.figures.BorderItemLocator#relocate(org.eclipse.draw2d.IFigure)
045:             * 
046:             * @author sh
047:             */
048:            public void relocate(IFigure borderItem) {
049:                // get the parent border
050:                Rectangle parentBorder = getParentBorder();
051:
052:                // get the sizes
053:                int itemX = parentBorder.x;
054:                int borderWidth = getParentBorder().width;
055:                int numberPorts = borderItem.getParent().getChildren().size() - 1;
056:                int portWidth = borderItem.getBounds().width;
057:                // check the position in the children collection
058:                int index = getPositionIndex(borderItem);
059:
060:                // Get the preferred location. If none has been previously set, use the
061:                // preferred side to take an initial guess.
062:                Point preferredLocation = getPreferredLocation(borderItem);
063:                int preferredSide = getPreferredSideOfParent();
064:
065:                // calculate the horizontal gap between the ports
066:                int horizontal_gap = (borderWidth - numberPorts * portWidth)
067:                        / (numberPorts + 1);
068:
069:                // place all ports with the same spacing
070:                preferredLocation.x = itemX + horizontal_gap * index
071:                        + (index - 1) * portWidth;
072:
073:                Point ptNewLocation = locateOnBorder(preferredLocation,
074:                        preferredSide, 0, borderItem, horizontal_gap);
075:                borderItem.setLocation(ptNewLocation);
076:
077:                // set the current/next side of the parent
078:                setCurrentSideOfParent(findClosestSideOfParent(new Rectangle(
079:                        ptNewLocation, borderItem.getBounds().getSize()),
080:                        getParentBorder()));
081:            }
082:
083:            /**
084:             * The preferred side takes precendence.
085:             * 
086:             * @param suggestedLocation
087:             * @param suggestedSide
088:             * @param circuitCount
089:             *            recursion count to avoid an infinite loop
090:             * @return point
091:             */
092:
093:            private Point locateOnBorder(Point suggestedLocation,
094:                    int suggestedSide, int circuitCount, IFigure borderItem,
095:                    int gab) {
096:                return locateOnParent(suggestedLocation, suggestedSide,
097:                        borderItem);
098:            }
099:
100:            /**
101:             * Ensure the suggested location actually lies on the parent boundary. The
102:             * side takes precendence.
103:             * 
104:             * @param suggestedLocation
105:             * @param suggestedSide
106:             * @return point
107:             */
108:            private Point locateOnParent(Point suggestedLocation,
109:                    int suggestedSide, IFigure borderItem) {
110:
111:                Rectangle bounds = getParentBorder();
112:                int parentFigureWidth = bounds.width;
113:                int parentFigureHeight = bounds.height;
114:                int parentFigureX = bounds.x;
115:                int parentFigureY = bounds.y;
116:                Rectangle borderItemBounds = borderItem.getBounds();
117:                int newX = suggestedLocation.x;
118:                int newY = suggestedLocation.y;
119:                int westX = parentFigureX - borderItemBounds.width
120:                        + getBorderItemOffset().width;
121:                int eastX = parentFigureX + parentFigureWidth
122:                        - getBorderItemOffset().width;
123:                int southY = parentFigureY + parentFigureHeight
124:                        - getBorderItemOffset().height;
125:                int northY = parentFigureY - borderItemBounds.height
126:                        + getBorderItemOffset().height;
127:
128:                if (suggestedSide == PositionConstants.WEST) {
129:                    if (suggestedLocation.x != westX) {
130:                        newX = westX;
131:                    }
132:                    if (suggestedLocation.y < bounds.getTopLeft().y) {
133:                        newY = northY + borderItemBounds.height;
134:                    } else if (suggestedLocation.y > bounds.getBottomLeft().y
135:                            - borderItemBounds.height) {
136:                        newY = southY - borderItemBounds.height;
137:                    }
138:                } else if (suggestedSide == PositionConstants.EAST) {
139:                    if (suggestedLocation.x != eastX) {
140:                        newX = eastX;
141:                    }
142:                    if (suggestedLocation.y < bounds.getTopLeft().y) {
143:                        newY = northY + borderItemBounds.height;
144:                    } else if (suggestedLocation.y > bounds.getBottomLeft().y
145:                            - borderItemBounds.height) {
146:                        newY = southY - borderItemBounds.height;
147:                    }
148:                } else if (suggestedSide == PositionConstants.SOUTH) {
149:                    if (suggestedLocation.y != southY) {
150:                        newY = southY;
151:                    }
152:                    if (suggestedLocation.x < bounds.getBottomLeft().x) {
153:                        newX = westX + borderItemBounds.width;
154:                    } else if (suggestedLocation.x > bounds.getBottomRight().x
155:                            - borderItemBounds.width) {
156:                        newX = eastX - borderItemBounds.width;
157:                    }
158:                } else {
159:                    // NORTH
160:                    if (suggestedLocation.y != northY) {
161:                        newY = northY;
162:                    }
163:                    if (suggestedLocation.x < bounds.getBottomLeft().x) {
164:                        newX = westX + borderItemBounds.width;
165:                    } else if (suggestedLocation.x > bounds.getBottomRight().x
166:                            - borderItemBounds.width) {
167:                        newX = eastX - borderItemBounds.width;
168:                    }
169:                }
170:                return new Point(newX, newY);
171:            }
172:
173:            /**
174:             * 	
175:             * get a x coordinate of the connection to the proxy
176:             * 
177:             * @author sh
178:             *
179:             * @param fig
180:             * @return
181:             */
182:            private int aquireProxyX(IFigure fig) {
183:                if (fig instanceof  TermDefaultSizeNodeFigure) {
184:                    EditPart myPart = ((TermDefaultSizeNodeFigure) fig)
185:                            .getMyPort();
186:                    List conList = null;
187:                    if (myPart instanceof  RootEditPart) {
188:                        //conList = ((RootEditPart)myPart).getSourceConnections();
189:                    } else if (myPart instanceof  ConditionTermEditPart) {
190:                        conList = ((ConditionTermEditPart) myPart)
191:                                .getSourceConnections();
192:                    }
193:                    if (conList == null || conList.isEmpty())
194:                        return 0;
195:                    ConditionTermConditionProxyEditPart con = (ConditionTermConditionProxyEditPart) conList
196:                            .get(0);
197:                    return con.getConnectionFigure().getTargetAnchor()
198:                            .getLocation(new Point(0, 0)).x;
199:                }
200:                return 0;
201:            }
202:
203:            /**
204:             * 
205:             * Calculate the position index based on referenced proxies as little pretty layout  
206:             * 
207:             * @author ts + sh
208:             * 
209:             * @param borderItem
210:             * @return
211:             */
212:            private int getPositionIndex(IFigure borderItem) {
213:                List portList = borderItem.getParent().getChildren();
214:                Iterator<IFigure> it = portList.iterator();
215:                int order = 1;
216:                while (it.hasNext()) {
217:                    IFigure item = it.next();
218:                    if (item != borderItem
219:                            && item instanceof  TermDefaultSizeNodeFigure) {
220:                        int bx = aquireProxyX(borderItem);
221:                        int ix = aquireProxyX(item);
222:                        if (bx > ix)
223:                            ++order;
224:                        if (bx == ix) {
225:                            int bi = portList.indexOf(borderItem);
226:                            int ii = portList.indexOf(item);
227:                            if (bi < ii) {
228:                                ++order;
229:                            }
230:                        }
231:                    }
232:                }
233:                return order;
234:            }
235:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.