001: package visualdebugger.views;
002:
003: import java.util.*;
004:
005: import org.eclipse.draw2d.*;
006: import org.eclipse.draw2d.Label;
007: import org.eclipse.draw2d.geometry.Dimension;
008: import org.eclipse.draw2d.geometry.Insets;
009: import org.eclipse.draw2d.geometry.Point;
010: import org.eclipse.draw2d.geometry.Rectangle;
011: import org.eclipse.draw2d.graph.DirectedGraph;
012: import org.eclipse.draw2d.graph.DirectedGraphLayout;
013: import org.eclipse.draw2d.graph.Edge;
014: import org.eclipse.draw2d.graph.Node;
015: import org.eclipse.jface.dialogs.MessageDialog;
016: import org.eclipse.swt.SWT;
017: import org.eclipse.swt.events.SelectionAdapter;
018: import org.eclipse.swt.events.SelectionEvent;
019: import org.eclipse.swt.graphics.FontData;
020: import org.eclipse.swt.layout.GridData;
021: import org.eclipse.swt.layout.GridLayout;
022: import org.eclipse.swt.widgets.*;
023: import org.eclipse.swt.widgets.Button;
024: import org.eclipse.ui.PlatformUI;
025: import org.eclipse.ui.part.ViewPart;
026:
027: import visualdebugger.draw2d.ArrayObjectFigure;
028: import visualdebugger.draw2d.FixedConnectionAnchor;
029: import visualdebugger.draw2d.ObjectFigure;
030: import de.uka.ilkd.key.logic.*;
031: import de.uka.ilkd.key.logic.op.IteratorOfProgramVariable;
032: import de.uka.ilkd.key.logic.op.ProgramVariable;
033: import de.uka.ilkd.key.visualdebugger.DebuggerEvent;
034: import de.uka.ilkd.key.visualdebugger.DebuggerListener;
035: import de.uka.ilkd.key.visualdebugger.VisualDebugger;
036: import de.uka.ilkd.key.visualdebugger.statevisualisation.StateVisualization;
037: import de.uka.ilkd.key.visualdebugger.statevisualisation.SymbolicArrayObject;
038: import de.uka.ilkd.key.visualdebugger.statevisualisation.SymbolicObject;
039: import de.uka.ilkd.key.visualdebugger.statevisualisation.SymbolicObjectDiagram;
040:
041: public class SymbolicStateView extends ViewPart implements
042: DebuggerListener {
043:
044: private SymbolicObjectDiagram currentState = null;
045:
046: private boolean preState = true;
047:
048: private StateVisualization stateVis = null;
049:
050: private SetOfTerm[] possibleIndexTerms;
051:
052: private Shell shell;
053:
054: private Composite parent;
055:
056: private FigureCanvas figureCanvas;
057:
058: private Layer figures;
059:
060: private IFigure root;
061:
062: private ConnectionLayer connections;
063:
064: private Slider prestateForTracesSlider;
065:
066: private org.eclipse.swt.widgets.List constraintsList;
067:
068: private LinkedList symbolicObjects;
069:
070: private Object selectedAttr;
071:
072: private final VisualDebugger vd;
073:
074: private Slider arrayIndexSlider;
075:
076: private Button preButton;
077:
078: private Button postButton;
079:
080: private FanRouter frouter;
081:
082: public SymbolicStateView() {
083: vd = VisualDebugger.getVisualDebugger();
084: vd.addListener(this );
085: }
086:
087: /**
088: * This is a callback that will allow us to create the viewer and initialize
089: * it.
090: */
091: public void createPartControl(Composite parent) {
092: shell = parent.getShell();
093: this .parent = parent;
094: parent.setLayout(new GridLayout(2, false));
095: figureCanvas = new FigureCanvas(parent, SWT.NONE);
096: figureCanvas.getViewport().setContentsTracksHeight(true);
097: figureCanvas.getViewport().setContentsTracksWidth(true);
098: figureCanvas.getViewport().setContentsTracksHeight(true);
099: figureCanvas.getViewport().setContentsTracksWidth(true);
100: figureCanvas.setLayoutData(new GridData(GridData.FILL_BOTH));
101:
102: root = new LayeredPane();
103: figures = new Layer();
104: connections = new ConnectionLayer();
105: frouter = new FanRouter();
106: frouter.setSeparation(40);
107: frouter
108: .setNextRouter(new ShortestPathConnectionRouter(figures));
109: connections.setAntialias(SWT.ON);
110: root.add(figures);
111: root.add(connections);
112: FlowLayout layout = new FlowLayout();
113: layout.setHorizontal(false);
114: layout.setStretchMinorAxis(false);
115: layout.setMajorSpacing(50);
116: layout.setMinorSpacing(50);
117: figures.setLayoutManager(layout);
118: figures.setLayoutManager(new XYLayout());
119: figureCanvas.setContents(root);
120: hookShell();
121: shell.redraw();
122: shell.open();
123: if (vd.getCurrentState() != null) {
124: stateVis = vd.getCurrentState();
125: refreshPCStates();
126: }
127: }
128:
129: private void hookShell() {
130: Composite localShell = new Composite(parent, 0);
131: localShell.setLayoutData(new GridData(GridData.FILL_VERTICAL));
132:
133: localShell.setLayout(new GridLayout());
134: Group rootGroup = new Group(localShell, 0);
135: rootGroup.setText("Instance Configuation");
136: rootGroup.setLayoutData(new GridData(200, SWT.DEFAULT));
137: FontData data = rootGroup.getFont().getFontData()[0];
138: data.setStyle(SWT.BOLD);
139: rootGroup.setLayout(new GridLayout());
140:
141: prestateForTracesSlider = new Slider(rootGroup, SWT.HORIZONTAL);
142:
143: prestateForTracesSlider.setEnabled(true);
144: prestateForTracesSlider.setMaximum(1);
145: prestateForTracesSlider.setMinimum(0);
146: prestateForTracesSlider.setSelection(0);
147: prestateForTracesSlider.setIncrement(1);
148: prestateForTracesSlider.setPageIncrement(1);
149:
150: prestateForTracesSlider
151: .addSelectionListener(new SelectionAdapter() {
152: public void widgetSelected(SelectionEvent e) {
153: final int sel = prestateForTracesSlider
154: .getSelection();
155: possibleIndexTerms = stateVis
156: .getPossibleIndexTermsForPcState(sel);
157: if (possibleIndexTerms.length > 0)
158: currentState = stateVis.getSymbolicState(
159: sel, possibleIndexTerms[0], true);
160: else
161: throw new RuntimeException();
162: arrayIndexSlider.setSelection(0);
163: arrayIndexSlider
164: .setMaximum(possibleIndexTerms.length);
165: refreshVisualizedState();
166: }
167: });
168:
169: Group rootGroup2 = new Group(localShell, 0);
170: rootGroup2.setLayoutData(new GridData(200, SWT.DEFAULT));
171: rootGroup2.setText("Array Index Configuration");
172: rootGroup2.setLayout(new GridLayout());
173:
174: arrayIndexSlider = new Slider(rootGroup2, SWT.HORIZONTAL);
175: arrayIndexSlider.setEnabled(true);
176: arrayIndexSlider.setMaximum(1);
177: arrayIndexSlider.setMinimum(0);
178: arrayIndexSlider.setSelection(0);
179: arrayIndexSlider.setIncrement(1);
180: arrayIndexSlider.setPageIncrement(1);
181:
182: arrayIndexSlider.addSelectionListener(new SelectionAdapter() {
183: public void widgetSelected(SelectionEvent e) {
184: if (preState)
185: currentState = stateVis
186: .getSymbolicState(
187: prestateForTracesSlider
188: .getSelection(),
189: (SetOfTerm) possibleIndexTerms[arrayIndexSlider
190: .getSelection()], true);
191: else
192: currentState = stateVis
193: .getSymbolicState(
194: prestateForTracesSlider
195: .getSelection(),
196: (SetOfTerm) possibleIndexTerms[arrayIndexSlider
197: .getSelection()], false);
198: refreshVisualizedState();
199: }
200: });
201:
202: Group rootGroup3 = new Group(localShell, 0);
203: rootGroup3.setLayoutData(new GridData(200, SWT.DEFAULT));
204: rootGroup3.setLayout(new GridLayout());
205:
206: preButton = new Button(rootGroup3, SWT.RADIO);
207: preButton.setText("Prestate");
208: preButton.setSelection(true);
209: preButton.addSelectionListener(new SelectionAdapter() {
210: public void widgetSelected(SelectionEvent e) {
211: //preButton.getS
212: preState = preButton.getSelection();
213: currentState = stateVis.getSymbolicState(
214: prestateForTracesSlider.getSelection(),
215: possibleIndexTerms[arrayIndexSlider
216: .getSelection()], true);
217: refreshVisualizedState();
218: }
219: });
220:
221: postButton = new Button(rootGroup3, SWT.RADIO);
222: postButton.setText("Poststate");
223: postButton.setSelection(false);
224: postButton.addSelectionListener(new SelectionAdapter() {
225: public void widgetSelected(SelectionEvent e) {
226: preState = !postButton.getSelection();
227: currentState = stateVis.getSymbolicState(
228: prestateForTracesSlider.getSelection(),
229: (SetOfTerm) possibleIndexTerms[arrayIndexSlider
230: .getSelection()], false);
231: refreshVisualizedState();
232: }
233: });
234:
235: Group bcGroup = new Group(localShell, 0);
236: bcGroup.setBackground(ColorConstants.white);
237: bcGroup.setText("Constraints");
238: bcGroup.setLayoutData(new GridData(GridData.FILL_BOTH));
239: bcGroup.setLayout(new GridLayout());
240: constraintsList = new org.eclipse.swt.widgets.List(bcGroup,
241: SWT.WRAP | SWT.V_SCROLL | SWT.H_SCROLL);
242: constraintsList.setLayoutData(new GridData(GridData.FILL_BOTH));
243: constraintsList.setBackground(ColorConstants.white);
244:
245: }
246:
247: private void startRefreshThread() {
248: Display display = shell.getDisplay();
249: final Thread barThread = new Thread(
250: "Refresh Symbolic State View Thread") {
251: public void run() {
252: refreshPCStates();
253: }
254: };
255: display.asyncExec(barThread);
256: }
257:
258: private void refreshPCStates() {
259: prestateForTracesSlider.setMinimum(0);
260: if (stateVis != null) {
261: prestateForTracesSlider.setMaximum(stateVis
262: .numberOfPCStates());
263: prestateForTracesSlider.setIncrement(1);
264: prestateForTracesSlider.setPageIncrement(1);
265: prestateForTracesSlider.setThumb(1);
266: prestateForTracesSlider.setSelection(0);
267: prestateForTracesSlider.setEnabled(true);
268:
269: preButton.setSelection(true);
270: postButton.setSelection(false);
271: preButton.setEnabled(true);
272: postButton.setEnabled(true);
273: preState = true;
274: possibleIndexTerms = stateVis
275: .getPossibleIndexTermsForPcState(0);
276: if (possibleIndexTerms.length > 0)
277: currentState = stateVis.getSymbolicState(0,
278: possibleIndexTerms[0], true);
279: else
280: throw new RuntimeException("No States to visualize");
281: arrayIndexSlider.setMaximum(possibleIndexTerms.length);
282: arrayIndexSlider.setSelection(0);
283: arrayIndexSlider.setEnabled(true);
284: refreshVisualizedState();
285: } else {
286: prestateForTracesSlider.setEnabled(false);
287: prestateForTracesSlider.setMaximum(1);
288: prestateForTracesSlider.setMinimum(0);
289: prestateForTracesSlider.setSelection(0);
290: prestateForTracesSlider.setIncrement(1);
291: prestateForTracesSlider.setPageIncrement(1);
292: arrayIndexSlider.setEnabled(false);
293: arrayIndexSlider.setMaximum(1);
294: arrayIndexSlider.setMinimum(0);
295: arrayIndexSlider.setSelection(0);
296: arrayIndexSlider.setIncrement(1);
297: arrayIndexSlider.setPageIncrement(1);
298: preButton.setSelection(true);
299: postButton.setSelection(false);
300: preButton.setEnabled(false);
301: postButton.setEnabled(false);
302: figures.removeAll();
303: connections.removeAll();
304: this .setConstraints(null, null, null);
305: }
306: }
307:
308: private synchronized void refreshVisualizedState() {
309: if (currentState == null)
310: return;
311: symbolicObjects = currentState.getSymbolicObjects();
312:
313: figures.removeAll();
314: connections.removeAll();
315: final HashMap node2figure = new HashMap();
316: final HashMap figure2node = new HashMap();
317:
318: final DirectedGraph graph = new DirectedGraph();
319: graph.setDefaultPadding(new Insets(50));
320:
321: // create object figure and nodes
322: for (Iterator soIt = symbolicObjects.iterator(); soIt.hasNext();) {
323: final SymbolicObject so = (SymbolicObject) soIt.next();
324: if (!so.isNull()) {
325: final ObjectFigure f = createFigure(so);
326: final Node n = new Node();
327: f.validate();
328: n.setSize(f.getPreferredSize());
329: graph.nodes.add(n);
330: node2figure.put(n, f);
331: figure2node.put(f, n);
332: }
333: }
334:
335: // create edges
336:
337: for (Iterator ofIt = figure2node.keySet().iterator(); ofIt
338: .hasNext();) {
339: final ObjectFigure ofStart = (ObjectFigure) ofIt.next();
340: for (Iterator soEndsIt = ofStart.getSymbolicObject()
341: .getAllAssociationEnds().iterator(); soEndsIt
342: .hasNext();) {
343: SymbolicObject soEnd = (SymbolicObject) soEndsIt.next();
344: if (!soEnd.isNull()) {
345: final ObjectFigure ofEnd = getOFbySO(figure2node
346: .keySet(), soEnd);
347: if (ofEnd != ofStart) {
348: final Edge edge = new Edge((Node) figure2node
349: .get(ofStart), (Node) figure2node
350: .get(ofEnd));
351:
352: edge.setPadding(100);
353: graph.edges.add(edge);
354: }
355: }
356: }
357: }
358:
359: // layout graph
360: graph.setDirection(PositionConstants.EAST);
361: new DirectedGraphLayout().visit(graph);
362:
363: // add figures
364: for (int i = 0; i < graph.nodes.size(); i++) {
365: Node node = graph.nodes.getNode(i);
366: buildNodeFigure(figures, node, (ObjectFigure) node2figure
367: .get(node));
368: }
369:
370: figures.validate(); // TODO warum ?
371: int offset = 0;
372:
373: // create and add connections
374: for (Iterator ofIt = figure2node.keySet().iterator(); ofIt
375: .hasNext();) {
376: final ObjectFigure ofStart = (ObjectFigure) ofIt.next();
377:
378: for (IteratorOfProgramVariable pvIt = ofStart
379: .getSymbolicObject().getNonPrimAttributes()
380: .iterator(); pvIt.hasNext();) {
381: ProgramVariable pv = pvIt.next();
382: final SymbolicObject soEnd = ofStart
383: .getSymbolicObject().getAssociationEnd(pv);
384: if (!soEnd.isNull()) {
385: final ObjectFigure ofEnd = getOFbySO(figure2node
386: .keySet(), soEnd);
387:
388: if (ofStart == ofEnd) { // loop connection
389: connections.add((createSelfConnection(ofStart,
390: pv.getProgramElementName()
391: .getProgramName().toString(),
392: offset++)));
393: } else {
394: connections.add((createConnection(ofStart,
395: ofEnd, pv.getProgramElementName()
396: .getProgramName().toString())));
397: }
398: }
399: }
400:
401: if (ofStart instanceof ArrayObjectFigure
402: && !((SymbolicArrayObject) ((ArrayObjectFigure) ofStart)
403: .getSymbolicObject()).isPrimitiveType()) {
404: ArrayObjectFigure aofStart = (ArrayObjectFigure) ofStart;
405: SymbolicArrayObject saoStart = ((SymbolicArrayObject) aofStart
406: .getSymbolicObject());
407:
408: for (IteratorOfTerm indexIt = saoStart
409: .getAllIndexTerms().iterator(); indexIt
410: .hasNext();) {
411: Term index = indexIt.next();
412: SymbolicObject soEnd = ((SymbolicArrayObject) aofStart
413: .getSymbolicObject())
414: .getAssociationEndForIndex(index);
415: if (!soEnd.isStatic()) {
416: final HashMap index2y = aofStart.getIndexY();
417: final ObjectFigure ofEnd = getOFbySO(
418: figure2node.keySet(), soEnd);
419: connections.add((createArrayConnection(ofStart,
420: ((Integer) index2y.get(index))
421: .intValue(), ofEnd, "")));
422: }
423:
424: }
425: }
426:
427: }
428: }
429:
430: static void buildNodeFigure(Figure contents, Node node,
431: ObjectFigure of) {
432: contents.add(of, new Rectangle(node.x, node.y, node.width,
433: node.height));
434: new Dragger(of);
435: }
436:
437: private ObjectFigure getOFbySO(Collection objectFigures,
438: SymbolicObject toFind) {
439: Iterator it = objectFigures.iterator();
440: while (it.hasNext()) {
441: ObjectFigure of = (ObjectFigure) it.next();
442: if (of.getSymbolicObject() == toFind) {
443: return of;
444: }
445:
446: }
447: System.err.println("ObjectFigure not found");
448: return null;
449: }
450:
451: private ObjectFigure createFigure(SymbolicObject o) {
452: if (o instanceof SymbolicArrayObject)
453:
454: return new ArrayObjectFigure((SymbolicArrayObject) o,
455: new MouseListener.Stub() {
456: public void mousePressed(MouseEvent me) {
457: setSelected(me.getSource());
458: }
459:
460: public void mouseDoubleClicked(MouseEvent me) {
461: // doExpandCollapse();
462: }
463: }, currentState, this .preState);
464:
465: else
466:
467: return new ObjectFigure(o, new MouseListener.Stub() {
468: public void mousePressed(MouseEvent me) {
469: setSelected(me.getSource());
470: }
471:
472: public void mouseDoubleClicked(MouseEvent me) {
473:
474: }
475: }, currentState, this .preState);
476: }
477:
478: private void setSelected(Object o) {
479: if (o instanceof ObjectFigure.AttributeLabel) {
480: ObjectFigure.AttributeLabel al = (ObjectFigure.AttributeLabel) o;
481: if (this .selectedAttr != null) {
482: if (selectedAttr instanceof ObjectFigure.AttributeLabel)
483: ((ObjectFigure.AttributeLabel) selectedAttr)
484: .setSelected(false);
485: else
486: ((ArrayObjectFigure.IndexLabel) selectedAttr)
487: .setSelected(false);
488: }
489: al.setSelected(true);
490: this .selectedAttr = al;
491: if (al.getSo().getAttributes().contains(al.getPv()))
492: this .setConstraints(al.getSo().getAttrConstraints(
493: al.getPv()), symbolicObjects, al.getSo());
494: else {
495: this .setConstraints(currentState.getConstraints(al
496: .getValueterm()), symbolicObjects, al.getSo());
497: }
498:
499: // else
500: // this.setConstraints(null,null,null);
501: } else if (o instanceof ArrayObjectFigure.IndexLabel) {
502: ArrayObjectFigure.IndexLabel al = (ArrayObjectFigure.IndexLabel) o;
503: if (this .selectedAttr != null) {
504: if (selectedAttr instanceof ObjectFigure.AttributeLabel)
505: ((ObjectFigure.AttributeLabel) selectedAttr)
506: .setSelected(false);
507: else
508: ((ArrayObjectFigure.IndexLabel) selectedAttr)
509: .setSelected(false);
510:
511: }
512: al.setSelected(true);
513: this .selectedAttr = al;
514: if (al.getSo().getConstraintsForIndex(al.getIndex()) != SLListOfTerm.EMPTY_LIST)
515: setConstraints(al.getSo().getConstraintsForIndex(
516: al.getIndex()), symbolicObjects, al.getSo());
517: else
518: setConstraints(null, null, null);
519:
520: } else if (o instanceof ArrayObjectFigure.IndexConstraintLabel) {
521: ArrayObjectFigure.IndexConstraintLabel al = (ArrayObjectFigure.IndexConstraintLabel) o;
522: this .currentState.getIndexTerms();
523: SetOfTerm indexConstr = al.getIndexConstraints();
524: for (Iterator it = this .symbolicObjects.iterator(); it
525: .hasNext();) {
526: SymbolicObject next = (SymbolicObject) it.next();
527: if (next instanceof SymbolicArrayObject) {
528: SymbolicArrayObject sao = (SymbolicArrayObject) next;
529: if (sao != al.getSo()) {
530: indexConstr = indexConstr.union(sao
531: .getIndexConfiguration());
532: }
533: }
534:
535: }
536:
537: int result = -1;
538: int i = 0;
539: for (int j = 0; j < possibleIndexTerms.length; j++) {
540: SetOfTerm next = (SetOfTerm) possibleIndexTerms[j];
541: // System.out.println("checking"+next);
542: if (next.subset(indexConstr)
543: && indexConstr.subset(next)) {
544: result = i;
545: }
546: i++;
547: }
548:
549: if (result > -1) {
550: if (!preState) {
551: currentState = stateVis.getSymbolicState(
552: prestateForTracesSlider.getSelection(),
553: possibleIndexTerms[result], false);
554: } else {
555: currentState = stateVis.getSymbolicState(
556: prestateForTracesSlider.getSelection(),
557: possibleIndexTerms[result], true);
558: }
559: arrayIndexSlider.setSelection(result);
560: refreshVisualizedState();
561: } else {
562: MessageDialog
563: .openInformation(
564: PlatformUI.getWorkbench()
565: .getActiveWorkbenchWindow()
566: .getShell(),
567: "Array Index Constraints Infeasible",
568: "The chosen array index constraints are infeasible."
569: + "Please choose another combination or use the slider "
570: + "in order to discover all possible combinations");
571: }
572: }
573: }
574:
575: private void setConstraints(ListOfTerm cons, LinkedList sos,
576: SymbolicObject so) {
577: if (cons != null) {
578: final Term[] conArray = cons.toArray();
579: final String[] termsString = new String[conArray.length];
580: //text.setItems();
581: for (int i = 0; i < conArray.length; i++) {
582: termsString[i] = (vd.prettyPrint(conArray[i], sos, so));
583: }
584: this .constraintsList.setItems(termsString);
585: } else
586: constraintsList.setItems(new String[0]);
587: }
588:
589: private Connection createSelfConnection(IFigure figFrom,
590: String text, int offset) {
591: PolylineConnection con = new PolylineConnection();
592: Rectangle bounds = figFrom.getBounds();
593:
594: FixedConnectionAnchor fcAnchor = new FixedConnectionAnchor(
595: figFrom);
596: fcAnchor.setOffsetH(bounds.width / 4);
597: con.setSourceAnchor(fcAnchor);
598:
599: fcAnchor = new FixedConnectionAnchor(figFrom);
600: fcAnchor.setOffsetH(bounds.width / 4 + bounds.width / 2);
601:
602: con.setTargetAnchor(fcAnchor);
603:
604: BendpointConnectionRouter router = new BendpointConnectionRouter();
605: con.setConnectionRouter(router);
606: ArrayList list = new ArrayList();
607:
608: RelativeBendpoint b = new RelativeBendpoint(con);
609: b.setWeight(0.2f);
610: Dimension d1 = new Dimension(0, -25 - offset * 20);
611: Dimension d2 = new Dimension(0, -25 - offset * 20);
612:
613: b.setRelativeDimensions(d1, d2);
614: list.add(b);
615:
616: b = new RelativeBendpoint(con);
617: b.setWeight(0.8f);
618: d1 = new Dimension(0, -25 - offset * 20);
619: d2 = new Dimension(0, -25 - offset * 20);
620: b.setRelativeDimensions(d1, d2);
621:
622: list.add(b);
623:
624: con.setRoutingConstraint(list);
625: con.setRoutingConstraint(list);
626: PolygonDecoration decoration = new PolygonDecoration();
627: decoration.setTemplate(PolygonDecoration.TRIANGLE_TIP);
628: decoration.setScale(8, 4);
629: con.setTargetDecoration(decoration);
630: Label label = createConnectionLabel(text);
631: con.add(label, new MidpointLocator(con, 1));
632: return con;
633:
634: }
635:
636: private Label createConnectionLabel(String text) {
637: Label result = new Label(text);
638: result.setBackgroundColor(ColorConstants.white);
639: result.setBorder(new LineBorder(ColorConstants.black));
640: result.setOpaque(true);
641: return result;
642: }
643:
644: private Connection createConnection(IFigure figFrom, IFigure figTo,
645: String text) {
646:
647: figFrom.validate();
648:
649: PolylineConnection con = new PolylineConnection();
650: con.setSourceAnchor(new ChopboxAnchor(figFrom));
651: con.setTargetAnchor(new ChopboxAnchor(figTo));
652:
653: con.setConnectionRouter(frouter);
654:
655: PolygonDecoration decoration = new PolygonDecoration();
656: decoration.setTemplate(PolygonDecoration.TRIANGLE_TIP);
657: decoration.setScale(8, 4);
658: con.setTargetDecoration(decoration);
659: Label label = createConnectionLabel(text);
660:
661: con.add(label, new MidpointLocator(con, 0));
662: return con;
663:
664: }
665:
666: private Connection createArrayConnection(IFigure figFrom, int y,
667: IFigure figTo, String text) {
668: PolylineConnection con = new PolylineConnection();
669: con.setConnectionRouter(frouter);
670:
671: con.setTargetAnchor(new ChopboxAnchor(figTo));
672:
673: FixedConnectionAnchor fcAnchor = new FixedConnectionAnchor(
674: figFrom);
675: //System.out.println("Fig bounds " + figFrom.getBounds());
676: fcAnchor.setOffsetH(figFrom.getBounds().width);
677:
678: fcAnchor.setOffsetV(y);
679: con.setSourceAnchor(fcAnchor);
680:
681: PolygonDecoration decoration = new PolygonDecoration();
682: decoration.setTemplate(PolygonDecoration.TRIANGLE_TIP);
683: decoration.setScale(8, 4);
684: con.setTargetDecoration(decoration);
685: // Label label = createConnectionLabel(text);
686: //
687: // con.add(label, new MidpointLocator(con, 0));
688: return con;
689: }
690:
691: /**
692: * Passing the focus request to the viewer's control.
693: */
694: public void setFocus() {
695:
696: }
697:
698: public synchronized void update(DebuggerEvent event) {
699: if (event.getType() == DebuggerEvent.VIS_STATE) {
700: stateVis = (StateVisualization) event.getSubject();
701: startRefreshThread();
702: } else if (event.getType() == DebuggerEvent.PROJECT_LOADED_SUCCESSFUL) {
703: stateVis = null;
704: startRefreshThread();
705: }
706: }
707:
708: static class Dragger extends MouseMotionListener.Stub implements
709: MouseListener {
710: public Dragger(IFigure figure) {
711: figure.removeMouseMotionListener(this );
712: figure.removeMouseListener(this );
713:
714: figure.addMouseMotionListener(this );
715: figure.addMouseListener(this );
716: }
717:
718: Point last;
719:
720: public void mouseReleased(MouseEvent e) {
721: }
722:
723: public void mouseClicked(MouseEvent e) {
724: }
725:
726: public void mouseDoubleClicked(MouseEvent e) {
727: }
728:
729: public void mousePressed(MouseEvent e) {
730: last = e.getLocation();
731: e.consume();
732: }
733:
734: public void mouseDragged(MouseEvent e) {
735: Point p = e.getLocation();
736:
737: if (last != null) {
738: // {
739: Dimension delta = p.getDifference(last);
740: Figure f = ((Figure) e.getSource());
741: f.setBounds(f.getBounds().getTranslated(delta.width,
742: delta.height));
743: }
744: last = p;
745: }
746: }
747:
748: }
|