01: package org.enhydra.jawe.components.graph;
02:
03: import java.awt.Point;
04: import java.awt.Rectangle;
05: import java.util.HashMap;
06: import java.util.Iterator;
07: import java.util.Map;
08:
09: /**
10: * Used to hold information to properly "graph paste" copied/cut selection.
11: *
12: * @author Sasa Bojanic
13: */
14: public class CopyOrCutInfo {
15:
16: private Point referencePoint;
17: private Map actInfoToActRect;
18: private Point pasteTo;
19: private Map graphToOffsetPoint = new HashMap();
20:
21: public CopyOrCutInfo(Point refPoint, Map ainfo) {
22: this .referencePoint = refPoint;
23: this .actInfoToActRect = ainfo;
24: }
25:
26: public Point getReferencePoint() {
27: return referencePoint;
28: }
29:
30: public void setPastePoint(Point pastePoint) {
31: this .pasteTo = pastePoint;
32: }
33:
34: public Point getPastePoint() {
35: return pasteTo;
36: }
37:
38: public Point getOffsetPoint(Graph g) {
39: //System.err.println("Asking for offset point for graph "+g);
40: //System.err.println(" ... offset map = "+graphToOffsetPoint);
41: Point offset = (Point) graphToOffsetPoint.get(g);
42: if (offset == null) {
43: //System.err.println(" ......new offset point created");
44: offset = new Point(10, 10);
45: graphToOffsetPoint.put(g, offset);
46: }
47: return offset;
48: }
49:
50: public void incrementOffsetPoint(Graph g) {
51: //System.err.println("Incrementing offset point for graph "+g);
52: Point offset = getOffsetPoint(g);
53: offset = new Point(offset.x + 10, offset.y + 10);
54: if (offset.x > 150 || offset.y > 150) {
55: //System.err.println(" .........Reseting offset point");
56: offset = new Point(10, 10);
57: }
58: graphToOffsetPoint.put(g, offset);
59: }
60:
61: public Rectangle getActivityBounds(CopiedActivityInfo ai) {
62: Iterator it = actInfoToActRect.entrySet().iterator();
63: while (it.hasNext()) {
64: Map.Entry me = (Map.Entry) it.next();
65: CopiedActivityInfo cai = (CopiedActivityInfo) me.getKey();
66: // System.err.println(" ..... . Comparing ai "+ai+" to cai "+cai);
67: Rectangle r = (Rectangle) me.getValue();
68: // System.err.println(" ... gacomp");
69: if (ai.getParIdEA().equals(cai.getParIdEA())) {
70: // System.err.println(" ... gabsuc1");
71: if (ai.getOffsetPoint().equals(cai.getOffsetPoint())) {
72: // System.err.println(" ... gabsuc2");
73: return r;
74: }
75: }
76: }
77: return null;
78: }
79:
80: public void removeGraphInfo(Graph g) {
81: graphToOffsetPoint.remove(g);
82: }
83:
84: public String toString() {
85: String ret = "---------CopyOrCutInfo----------------";
86: ret += "\nReferencePoint=" + referencePoint;
87: ret += "\nPasteTo=" + pasteTo;
88: ret += "\nActInfoToRectg=" + actInfoToActRect;
89: ret += "--------- End of CopyOrCutInfo----------------";
90: return ret;
91: }
92: }
|