Source Code Cross Referenced for NormalLayout.java in  » Testing » KeY » visualdebugger » draw2d » 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 » Testing » KeY » visualdebugger.draw2d 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package visualdebugger.draw2d;
002:
003:        import java.util.List;
004:
005:        import org.eclipse.draw2d.Graphics;
006:        import org.eclipse.draw2d.IFigure;
007:        import org.eclipse.draw2d.PositionConstants;
008:        import org.eclipse.draw2d.geometry.Dimension;
009:        import org.eclipse.draw2d.geometry.Point;
010:        import org.eclipse.draw2d.geometry.Rectangle;
011:        import org.eclipse.draw2d.geometry.Transposer;
012:
013:        class NormalLayout extends BranchLayout {
014:
015:            NormalLayout(TreeBranch branch) {
016:                super (branch);
017:            }
018:
019:            /**
020:             * @see org.eclipse.draw2d.examples.tree.BranchLayout#calculateDepth()
021:             */
022:            void calculateDepth() {
023:                depth = 0;
024:                List subtrees = getSubtrees();
025:                for (int i = 0; i < subtrees.size(); i++)
026:                    depth = Math.max(depth, ((TreeBranch) subtrees.get(i))
027:                            .getDepth());
028:                depth++;
029:            }
030:
031:            protected Dimension calculatePreferredSize(IFigure container,
032:                    int wHint, int hHint) {
033:                Rectangle union = branch.getNodeBounds().getCopy();
034:                //	if (branch.isExpanded())
035:                union.union(branch.getContentsPane().getBounds());
036:
037:                return union.getSize();
038:            }
039:
040:            public void layout(IFigure f) {
041:                //	Animation.recordInitialState(f);
042:                //	if (Animation.playbackState(f))
043:                //		return;
044:
045:                Transposer transposer = getTransposer();
046:                IFigure contents = branch.getContentsPane();
047:                IFigure node = branch.getNode();
048:                contents.validate();
049:
050:                Rectangle branchBounds = transposer.t(branch.getBounds());
051:                Point topLeft = branchBounds.getTopLeft();
052:                Rectangle nodeLocation = new Rectangle(topLeft, transposer
053:                        .t(node.getPreferredSize()));
054:                nodeLocation.height = rowHeight - getMajorSpacing();
055:
056:                if (!contents.isVisible() || contents.getChildren().isEmpty()) {
057:                    nodeLocation.x += (branchBounds.width - nodeLocation.width) / 2;
058:                    node.setBounds(transposer.t(nodeLocation));
059:                    contents.setBounds(transposer.t(nodeLocation.getTranslated(
060:                            0, rowHeight).setSize(0, 0)));
061:                    return;
062:                }
063:
064:                Rectangle contentsLocation = new Rectangle(topLeft, transposer
065:                        .t(contents.getPreferredSize()));
066:                contents.setSize(contents.getPreferredSize());
067:                contentsLocation.y += rowHeight;
068:
069:                TreeBranch firstChild = (TreeBranch) contents.getChildren()
070:                        .get(0);
071:                TreeBranch lastChild = (TreeBranch) contents.getChildren().get(
072:                        contents.getChildren().size() - 1);
073:                int leftInset = firstChild.getContourLeft()[0]
074:                        + transposer.t(firstChild.getBounds()).x
075:                        - transposer.t(contents.getBounds()).x;
076:                int rightInset = lastChild.getContourRight()[0]
077:                        - transposer.t(lastChild.getBounds()).right()
078:                        + transposer.t(contents.getBounds()).right();
079:                rightInset = Math.max(rightInset, 0);
080:                leftInset = Math.max(leftInset, 0);
081:                int childrenSpan = contentsLocation.width - leftInset
082:                        - rightInset;
083:
084:                switch (branch.getAlignment()) {
085:                case PositionConstants.CENTER:
086:                    leftInset += (childrenSpan - nodeLocation.width) / 2;
087:                }
088:
089:                if (leftInset > 0)
090:                    nodeLocation.x += leftInset;
091:                else
092:                    contentsLocation.x -= leftInset;
093:
094:                int adjust = branchBounds.width
095:                        - Rectangle.SINGLETON.setBounds(contentsLocation)
096:                                .union(nodeLocation).width;
097:                adjust /= 2;
098:                nodeLocation.x += adjust;
099:                contentsLocation.x += adjust;
100:                if (node instanceof  SourceElementFigure
101:                        || node instanceof  MethodInvocationFigure
102:                        || node instanceof  MethodReturnFigure) //TODO
103:                    node.setBounds(transposer.t(nodeLocation));
104:                else
105:                    node.setBounds(transposer.t(nodeLocation).setSize(10, 10));
106:                //	Animation.setBounds(node, transposer.t(nodeLocation));
107:                //	Animation.setBounds(contents, transposer.t(contentsLocation));
108:                contents.setBounds(transposer.t(contentsLocation));
109:            }
110:
111:            void mergeContour(int[] destination, int[] source, int startdepth,
112:                    int offset) {
113:                for (int i = startdepth; i < source.length; i++)
114:                    destination[i + 1] = source[i] + offset;
115:            }
116:
117:            /**
118:             * @see org.eclipse.draw2d.examples.tree.BranchLayout#paintLines(org.eclipse.draw2d.Graphics)
119:             */
120:            void paintLines(Graphics g) {
121:
122:                if (true)
123:                    return; //TODO
124:
125:                if (getTransposer().isEnabled()) {
126:                    IFigure node = branch.getNode();
127:                    int left = node.getBounds().right();
128:                    int right = branch.getContentsPane().getBounds().x - 1;
129:                    int yMid = node.getBounds().getCenter().y;
130:                    int xMid = (left + right) / 2;
131:                    List children = getSubtrees();
132:                    if (children.size() == 0)
133:                        return;
134:                    g.drawLine(left, yMid, xMid, yMid);
135:                    int yMin = yMid;
136:                    int yMax = yMid;
137:                    for (int i = 0; i < children.size(); i++) {
138:                        int y = ((TreeBranch) children.get(i)).getNodeBounds()
139:                                .getCenter().y;
140:                        g.drawLine(xMid, y, right, y);
141:                        yMin = Math.min(yMin, y);
142:                        yMax = Math.max(yMax, y);
143:                    }
144:                    g.drawLine(xMid, yMin, xMid, yMax);
145:
146:                } else {
147:                    IFigure node = branch.getNode();
148:                    int xMid = node.getBounds().getCenter().x;
149:                    int top = node.getBounds().bottom();
150:                    int bottom = branch.getContentsPane().getBounds().y - 1;
151:                    int yMid = (top + bottom) / 2;
152:                    List children = getSubtrees();
153:                    if (children.size() == 0)
154:                        return;
155:                    g.drawLine(xMid, top, xMid, yMid);
156:                    int xMin = xMid;
157:                    int xMax = xMid;
158:                    for (int i = 0; i < children.size(); i++) {
159:                        int x = ((TreeBranch) children.get(i)).getNodeBounds()
160:                                .getCenter().x;
161:                        g.drawLine(x, yMid, x, bottom);
162:                        xMin = Math.min(xMin, x);
163:                        xMax = Math.max(xMax, x);
164:                    }
165:                    g.drawLine(xMin, yMid, xMax, yMid);
166:                }
167:            }
168:
169:            /**
170:             * @see org.eclipse.draw2d.examples.tree.BranchLayout#updateContours()
171:             */
172:            void updateContours() {
173:                Transposer transposer = getTransposer();
174:                //Make sure we layout first
175:                branch.validate();
176:
177:                cachedContourLeft = new int[getDepth()];
178:                cachedContourRight = new int[getDepth()];
179:
180:                Rectangle clientArea = transposer.t(branch.getNodeBounds()
181:                        .getUnion(branch.contents.getBounds()));
182:                Rectangle nodeBounds = transposer.t(branch.getNodeBounds());
183:                Rectangle contentsBounds = transposer.t(branch
184:                        .getContentsPane().getBounds());
185:
186:                cachedContourLeft[0] = nodeBounds.x - clientArea.x;
187:                cachedContourRight[0] = clientArea.right() - nodeBounds.right();
188:                //	if (!branch.isExpanded())
189:                //		return;
190:
191:                List subtrees = getSubtrees();
192:                TreeBranch subtree;
193:
194:                int currentDepth = 0;
195:                for (int i = 0; i < subtrees.size()
196:                        && currentDepth < getDepth(); i++) {
197:                    subtree = (TreeBranch) subtrees.get(i);
198:                    if (subtree.getDepth() > currentDepth) {
199:                        int leftContour[] = subtree.getContourLeft();
200:                        int leftOffset = transposer.t(subtree.getBounds()).x
201:                                - clientArea.x;
202:                        mergeContour(cachedContourLeft, leftContour,
203:                                currentDepth, leftOffset);
204:                        currentDepth = subtree.getDepth();
205:                    }
206:                }
207:
208:                currentDepth = 0;
209:                for (int i = subtrees.size() - 1; i >= 0
210:                        && currentDepth < getDepth(); i--) {
211:                    subtree = (TreeBranch) subtrees.get(i);
212:                    if (subtree.getDepth() > currentDepth) {
213:                        int rightContour[] = subtree.getContourRight();
214:                        int rightOffset = clientArea.right()
215:                                - transposer.t(subtree.getBounds()).right();
216:                        mergeContour(cachedContourRight, rightContour,
217:                                currentDepth, rightOffset);
218:                        currentDepth = subtree.getDepth();
219:                    }
220:                }
221:            }
222:
223:            /**
224:             * @see org.eclipse.draw2d.examples.tree.BranchLayout#updateRowHeights()
225:             */
226:            void updateRowHeights() {
227:                Transposer transposer = getTransposer();
228:                preferredRowHeights = new int[getDepth()];
229:
230:                preferredRowHeights[0] = transposer.t(branch.getNode()
231:                        .getPreferredSize()).height
232:                        + getMajorSpacing();
233:
234:                //	if (!branch.isExpanded())
235:                //		return;
236:
237:                List subtrees = getSubtrees();
238:                TreeBranch subtree;
239:
240:                for (int i = 0; i < subtrees.size(); i++) {
241:                    subtree = (TreeBranch) subtrees.get(i);
242:                    int rowHeights[] = subtree.getPreferredRowHeights();
243:                    for (int row = 0; row < rowHeights.length; row++)
244:                        preferredRowHeights[row + 1] = Math.max(
245:                                preferredRowHeights[row + 1], rowHeights[row]);
246:                }
247:            }
248:
249:            /**
250:             * @see org.eclipse.draw2d.examples.tree.BranchLayout#setRowHeights(int[], int)
251:             */
252:            void setRowHeights(int[] heights, int offset) {
253:                super .setRowHeights(heights, offset);
254:                if (true/*branch.isExpanded()*/) {
255:                    List subtrees = getSubtrees();
256:                    offset++;
257:                    for (int i = 0; i < subtrees.size(); i++)
258:                        ((TreeBranch) subtrees.get(i)).setRowHeights(heights,
259:                                offset);
260:                }
261:            }
262:
263:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.