01: package visualdebugger.draw2d;
02:
03: import java.util.List;
04:
05: import org.eclipse.draw2d.AbstractLayout;
06: import org.eclipse.draw2d.Graphics;
07: import org.eclipse.draw2d.geometry.Transposer;
08:
09: public abstract class BranchLayout extends AbstractLayout {
10:
11: private Transposer transposer;
12: final TreeBranch branch;
13: int[] cachedContourLeft;
14: int[] cachedContourRight;
15: int depth = -1;
16:
17: public boolean horizontal = true;
18: int[] preferredRowHeights;
19: int rowHeight;
20:
21: public BranchLayout(TreeBranch branch) {
22: this .branch = branch;
23: }
24:
25: abstract void calculateDepth();
26:
27: public int[] getContourLeft() {
28: if (cachedContourLeft == null)
29: updateContours();
30: return cachedContourLeft;
31: }
32:
33: public int[] getContourRight() {
34: if (cachedContourRight == null)
35: updateContours();
36: return cachedContourRight;
37: }
38:
39: public int getDepth() {
40: // if (!branch.isExpanded())
41: // return 1;
42: if (depth == -1)
43: calculateDepth();
44: return depth;
45: }
46:
47: public int[] getPreferredRowHeights() {
48: if (preferredRowHeights == null)
49: updateRowHeights();
50: return preferredRowHeights;
51: }
52:
53: List getSubtrees() {
54: return branch.getContentsPane().getChildren();
55: }
56:
57: Transposer getTransposer() {
58: if (transposer == null)
59: transposer = branch.getRoot().getTransposer();
60: return transposer;
61: }
62:
63: int getMajorSpacing() {
64: return branch.getRoot().getMajorSpacing();
65: }
66:
67: public void invalidate() {
68: preferredRowHeights = null;
69: cachedContourLeft = null;
70: cachedContourRight = null;
71: depth = -1;
72: super .invalidate();
73: }
74:
75: public boolean isHorizontal() {
76: return horizontal;
77: }
78:
79: abstract void paintLines(Graphics g);
80:
81: public void setHorizontal(boolean value) {
82: horizontal = value;
83: }
84:
85: void setRowHeights(int heights[], int offset) {
86: if (rowHeight != heights[offset]) {
87: rowHeight = heights[offset];
88: branch.revalidate();
89: }
90: }
91:
92: abstract void updateContours();
93:
94: abstract void updateRowHeights();
95:
96: }
|