001: package visualdebugger.draw2d;
002:
003: import java.util.Iterator;
004:
005: import org.eclipse.draw2d.*;
006: import org.eclipse.draw2d.geometry.Dimension;
007: import org.eclipse.draw2d.geometry.Rectangle;
008:
009: import de.uka.ilkd.key.proof.Node;
010:
011: public class TreeBranch extends Figure {
012:
013: class AnimatingLayer extends Layer {
014:
015: /**
016: * @see org.eclipse.draw2d.Figure#setBounds(org.eclipse.draw2d.geometry.Rectangle)
017: */
018: public void setBounds(Rectangle rect) {
019:
020: int x = bounds.x, y = bounds.y;
021:
022: boolean resize = (rect.width != bounds.width)
023: || (rect.height != bounds.height), translate = (rect.x != x)
024: || (rect.y != y);
025:
026: if (isVisible() && (resize || translate))
027: erase();
028: if (translate) {
029: int dx = rect.x - x;
030: int dy = rect.y - y;
031: primTranslate(dx, dy);
032: }
033: bounds.width = rect.width;
034: bounds.height = rect.height;
035: // if (resize) Layouts dont depend on size.
036: // invalidate();
037: if (resize || translate) {
038: fireMoved();
039: repaint();
040: }
041: }
042:
043: }
044:
045: int aligment = PositionConstants.CENTER;
046:
047: IFigure contents = new AnimatingLayer();
048:
049: boolean expanded = true;
050:
051: IFigure node;
052:
053: TreeBranch parentTB = null;
054:
055: private Connection connection;
056:
057: public TreeBranch(IFigure title, TreeBranch parent) {
058: setLayoutManager(new NormalLayout(this ));
059: this .parentTB = parent;
060: contents.setLayoutManager(new TreeLayout());
061: // setLayoutManager(new ToolbarLayout());
062: // contents.setLayoutManager(new FlowLayout());
063:
064: // if (title.getBorder() == null) TODO
065: // title.setBorder(new LineBorder(ColorConstants.gray, 2));
066: this .node = title;
067: add(contents);
068: add(title);
069:
070: }
071:
072: public void addBranch(TreeBranch b) {
073: contents.add(b);
074: repaint();
075: }
076:
077: public void addBranch(TreeBranch b, String label) {
078: contents.add(b);
079: repaint();
080: }
081:
082: /**
083: * @see org.eclipse.draw2d.Figure#containsPoint(int, int)
084: */
085: public boolean containsPoint(int x, int y) {
086: return node.containsPoint(x, y) || contents.containsPoint(x, y);
087: }
088:
089: public int getAlignment() {
090: return aligment;
091: }
092:
093: protected BranchLayout getBranchLayout() {
094: return (BranchLayout) getLayoutManager();
095: }
096:
097: public IFigure getContentsPane() {
098: return contents;
099: }
100:
101: public int[] getContourLeft() {
102: return getBranchLayout().getContourLeft();
103: }
104:
105: public int[] getContourRight() {
106: return getBranchLayout().getContourRight();
107: }
108:
109: public int getDepth() {
110: return getBranchLayout().getDepth();
111: }
112:
113: /**
114: * @see org.eclipse.draw2d.Figure#getMinimumSize(int, int)
115: */
116: public Dimension getMinimumSize(int wHint, int hHint) {
117: return super .getMinimumSize(wHint, hHint);
118: }
119:
120: public IFigure getNode() {
121: return node;
122: }
123:
124: public Rectangle getNodeBounds() {
125: return node.getBounds();
126: }
127:
128: public int[] getPreferredRowHeights() {
129: return getBranchLayout().getPreferredRowHeights();
130:
131: }
132:
133: /**
134: * @see org.eclipse.draw2d.Figure#getPreferredSize(int, int)
135: */
136: public Dimension getPreferredSize(int wHint, int hHint) {
137: validate();
138: return super .getPreferredSize(wHint, hHint);
139: }
140:
141: public TreeRoot getRoot() {
142: return ((TreeBranch) getParent().getParent()).getRoot();
143: }
144:
145: /**
146: * @see org.eclipse.draw2d.Figure#paintFigure(org.eclipse.draw2d.Graphics)
147: */
148: protected void paintFigure(Graphics graphics) {
149: super .paintFigure(graphics);
150: }
151:
152: public void setNode(IFigure node) {
153: remove(this .node);
154: add(node, 0);
155: }
156:
157: public void setRowHeights(int heights[], int offset) {
158: getBranchLayout().setRowHeights(heights, offset);
159: }
160:
161: /**
162: * @see java.lang.Object#toString()
163: */
164: public String toString() {
165: return toString(0);
166: }
167:
168: public String toString(int level) {
169: String result = "";
170: for (int i = 0; i < level; i++)
171: result += " ";
172: result += getChildren().get(1) + "\n";
173: for (int i = 0; i < contents.getChildren().size(); i++)
174: result += ((TreeBranch) contents.getChildren().get(i))
175: .toString(level + 1);
176: return result;
177: }
178:
179: /**
180: * @see org.eclipse.draw2d.Figure#validate()
181: */
182: public void validate() {
183: if (isValid())
184: return;
185:
186: //System.out.println("hallo");
187:
188: repaint();
189: super .validate();
190: }
191:
192: public void setConnection(Connection con) {
193: this .connection = con;
194: }
195:
196: public Connection getConnection() {
197: return this .connection;
198: }
199:
200: public TreeBranch getParentTB() {
201: return parentTB;
202: }
203:
204: // public String toString(){
205: //
206: // }
207:
208: public void markBranch() {
209: if (connection != null)
210: connection.setForegroundColor(ColorConstants.red);
211: if (!(getParentTB() instanceof TreeRoot)
212: && getParentTB() != null) {
213: getParentTB().markBranch();
214: }
215:
216: }
217:
218: public TreeBranch findNode(Node n) {
219: if (getNode() instanceof LeafNode) {
220: LeafNode ln = (LeafNode) getNode();
221: if (ln.getETLeafNode().representsProofTreeNode(n))
222: return this ;
223: }
224: Iterator children = getContentsPane().getChildren().iterator();
225: while (children.hasNext()) {
226: TreeBranch cp = (TreeBranch) children.next();
227: TreeBranch result = cp.findNode(n);
228: if (result != null)
229: return result;
230:
231: }
232: return null;
233: }
234:
235: }
|