Source Code Cross Referenced for TreeLayout.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.AbstractLayout;
006:        import org.eclipse.draw2d.IFigure;
007:        import org.eclipse.draw2d.geometry.Dimension;
008:        import org.eclipse.draw2d.geometry.Point;
009:        import org.eclipse.draw2d.geometry.Rectangle;
010:        import org.eclipse.draw2d.geometry.Transposer;
011:
012:        /**
013:         * Performs a layout on a container containing {@link AbstractBranch} figures. This layout is
014:         * similar to FlowLayout, except that the children are squeezed together to overlap by
015:         * comparing their left and right contours.
016:         * @author hudsonr
017:         * Created on Apr 18, 2003
018:         */
019:        public class TreeLayout extends AbstractLayout {
020:
021:            private int pointOfContact;
022:
023:            /**
024:             * @see org.eclipse.draw2d.AbstractLayout#calculatePreferredSize(org.eclipse.draw2d.IFigure, int, int)
025:             */
026:            protected Dimension calculatePreferredSize(IFigure container,
027:                    int wHint, int hHint) {
028:                container.validate();
029:                List children = container.getChildren();
030:                Rectangle result = new Rectangle().setLocation(container
031:                        .getClientArea().getLocation());
032:                for (int i = 0; i < children.size(); i++)
033:                    result.union(((IFigure) children.get(i)).getBounds());
034:                result.resize(container.getInsets().getWidth(), container
035:                        .getInsets().getHeight());
036:                return result.getSize();
037:            }
038:
039:            private int[] calculateNewRightContour(int old[], int add[],
040:                    int shift) {
041:                if (old == null)
042:                    return add;
043:                //	if (shift < 0)
044:                //		shift = 0;
045:                int result[] = new int[Math.max(old.length, add.length)];
046:                System.arraycopy(add, 0, result, 0, add.length);
047:                for (int i = add.length; i < result.length; i++)
048:                    result[i] = old[i] + shift;
049:                return result;
050:            }
051:
052:            private int calculateOverlap(int leftSubtree[], int rightSubtree[]) {
053:                pointOfContact = 0;
054:                if (leftSubtree == null)
055:                    return 0;
056:                int min = Math.min(leftSubtree.length, rightSubtree.length);
057:                int result = Integer.MAX_VALUE;
058:                for (int i = 0; i < min; i++) {
059:                    int current = leftSubtree[i] + rightSubtree[i];
060:                    if (i > 0)
061:                        current -= 5;
062:                    if (current < result) {
063:                        result = current;
064:                        pointOfContact = i + 1;
065:                    }
066:                }
067:                return result;
068:            }
069:
070:            /**
071:             * @see org.eclipse.draw2d.LayoutManager#layout(org.eclipse.draw2d.IFigure)
072:             */
073:            public void layout(IFigure container) {
074:                //	Animation.recordInitialState(container);
075:                //	if (Animation.playbackState(container))
076:                //		return;
077:                TreeRoot root = ((TreeBranch) container.getParent()).getRoot();
078:                Transposer transposer = root.getTransposer();
079:                int gap = root.getMinorSpacing();
080:                List subtrees = container.getChildren();
081:                TreeBranch subtree;
082:                int previousSubtreeDepth = 0;
083:                int rightContour[] = null;
084:                int leftContour[];
085:                int contactDepth;
086:
087:                Point reference = transposer.t(container.getBounds()
088:                        .getLocation());
089:                Point currentXY = reference.getCopy();
090:
091:                for (int i = 0; i < subtrees.size(); i++) {
092:                    subtree = (TreeBranch) subtrees.get(i);
093:
094:                    //Give the subtree its preferred size before asking for contours
095:                    Dimension subtreeSize = subtree.getPreferredSize();
096:                    subtree.setSize(subtreeSize);
097:                    subtreeSize = transposer.t(subtreeSize);
098:
099:                    leftContour = subtree.getContourLeft();
100:                    int overlap = calculateOverlap(rightContour, leftContour);
101:                    //if (!subtree.getRoot().isCompressed())
102:                    overlap = 0;
103:                    contactDepth = pointOfContact;
104:                    subtree.setLocation(transposer.t(currentXY.getTranslated(
105:                            -overlap, 0)));
106:
107:                    //Setup value for next sibling
108:                    int advance = gap + subtreeSize.width - overlap;
109:                    rightContour = calculateNewRightContour(rightContour,
110:                            subtree.getContourRight(), advance);
111:                    currentXY.x += advance;
112:
113:                    /* 
114:                     * In some cases, the current child may extend beyond the left edge of the
115:                     * container because of the way it overlaps with the previous child. When this
116:                     * happens, shift all children right. 
117:                     */
118:                    int shiftRight = reference.x
119:                            - transposer.t(subtree.getBounds()).x;
120:                    if (shiftRight > 0) {
121:                        currentXY.x += shiftRight;
122:                        Point correction = transposer
123:                                .t(new Point(shiftRight, 0));
124:                        for (int j = 0; j <= i; j++)
125:                            ((IFigure) subtrees.get(j)).translate(correction.x,
126:                                    correction.y);
127:                    }
128:
129:                    /*
130:                     * In some cases, the current child "i" only touches the contour of a distant
131:                     * sibling "i-n", where n>1.  This means that there is extra space that can be
132:                     * distributed among the intermediate siblings
133:                     */
134:
135:                    if (contactDepth > previousSubtreeDepth) {
136:                        TreeBranch branch = (TreeBranch) subtrees.get(i - 1);
137:                        int slack = transposer.t(subtree.getBounds()).x
138:                                - transposer.t(branch.getBounds()).right()
139:                                - gap
140:                                + calculateOverlap(branch.getContourRight(),
141:                                        subtree.getContourLeft());
142:                        int end = i;
143:                        int begin = end - 1;
144:                        while (begin > 0
145:                                && ((TreeBranch) subtrees.get(begin))
146:                                        .getDepth() < contactDepth)
147:                            begin--;
148:
149:                        for (int j = begin + 1; j < end; j++) {
150:                            branch = (TreeBranch) subtrees.get(j);
151:                            Point shift = transposer.t(new Point(slack
152:                                    * (j - begin) / (end - begin), 0));
153:                            branch.translate(shift.x, shift.y);
154:                        }
155:                    }
156:                    previousSubtreeDepth = subtree.getDepth();
157:                }
158:            }
159:
160:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.