37 |
|
|
38 |
package nongnu.cashews.eclipse.composer.parts; |
package nongnu.cashews.eclipse.composer.parts; |
39 |
|
|
40 |
import nongnu.cashews.eclipse.composer.model.Connection; |
import nongnu.cashews.eclipse.composer.figures.PerformanceNodeFigure; |
41 |
|
import nongnu.cashews.eclipse.composer.model.ConnectionElement; |
42 |
|
import nongnu.cashews.eclipse.composer.model.PerformanceElement; |
43 |
|
import nongnu.cashews.eclipse.composer.model.Node; |
44 |
|
|
45 |
|
import org.eclipse.draw2d.Ellipse; |
46 |
|
import org.eclipse.draw2d.FigureListener; |
47 |
|
import org.eclipse.draw2d.IFigure; |
48 |
|
import org.eclipse.draw2d.Label; |
49 |
import org.eclipse.draw2d.PolygonDecoration; |
import org.eclipse.draw2d.PolygonDecoration; |
50 |
import org.eclipse.draw2d.PolylineConnection; |
import org.eclipse.draw2d.PolylineConnection; |
51 |
|
import org.eclipse.draw2d.RoundedRectangle; |
52 |
|
import org.eclipse.draw2d.geometry.Dimension; |
53 |
|
import org.eclipse.draw2d.geometry.Point; |
54 |
import org.eclipse.draw2d.geometry.PointList; |
import org.eclipse.draw2d.geometry.PointList; |
55 |
|
import org.eclipse.draw2d.geometry.Rectangle; |
56 |
|
import org.eclipse.gef.GraphicalEditPart; |
57 |
import org.eclipse.gef.editparts.AbstractConnectionEditPart; |
import org.eclipse.gef.editparts.AbstractConnectionEditPart; |
58 |
|
import org.eclipse.gef.editparts.AbstractGraphicalEditPart; |
59 |
|
|
60 |
public class ConnectionPart |
public class ConnectionPart |
61 |
extends AbstractConnectionEditPart |
extends AbstractConnectionEditPart |
64 |
// ------------------------------------------------------------------------ |
// ------------------------------------------------------------------------ |
65 |
// Abstract methods from AbstractEditPart |
// Abstract methods from AbstractEditPart |
66 |
|
|
67 |
|
private String name; |
68 |
|
|
69 |
|
private Ellipse ellipseFigure; |
70 |
|
|
71 |
|
private Label label; |
72 |
|
|
73 |
protected void createEditPolicies() |
protected void createEditPolicies() |
74 |
{ |
{ |
75 |
// none at present |
// none at present |
77 |
|
|
78 |
protected void refreshVisuals() |
protected void refreshVisuals() |
79 |
{ |
{ |
80 |
PolylineConnection figure = (PolylineConnection) getFigure(); |
try |
81 |
Connection connx = (Connection) getModel(); |
{ |
82 |
|
PolylineConnection figure = (PolylineConnection) getFigure(); |
83 |
|
ConnectionElement connx = (ConnectionElement) getModel(); |
84 |
// figure.setRoutingConstraint(MagicHelper.getConnectionBendpoints(connx)); |
// figure.setRoutingConstraint(MagicHelper.getConnectionBendpoints(connx)); |
85 |
|
|
86 |
PolygonDecoration decoration = new PolygonDecoration(); |
PolygonDecoration decoration = new PolygonDecoration(); |
92 |
decoration.setFill(true); |
decoration.setFill(true); |
93 |
decoration.setTemplate(decorationPointList); |
decoration.setTemplate(decorationPointList); |
94 |
figure.setTargetDecoration(decoration); |
figure.setTargetDecoration(decoration); |
95 |
|
|
96 |
|
if (figure.getChildren().size() > 1) |
97 |
|
{ |
98 |
|
figure.remove(ellipseFigure); |
99 |
|
} |
100 |
|
|
101 |
|
ellipseFigure = new Ellipse(); |
102 |
|
Dimension d = new Dimension(40, 40); |
103 |
|
label = new Label(); |
104 |
|
|
105 |
|
ellipseFigure.setLocation(midPoint(connx.getSource().getLocation(), connx.getTarget().getLocation())); |
106 |
|
|
107 |
|
|
108 |
|
figure.add(ellipseFigure); |
109 |
|
|
110 |
|
figure.addFigureListener |
111 |
|
( |
112 |
|
new FigureListener() |
113 |
|
{ |
114 |
|
|
115 |
|
public void figureMoved(IFigure source) |
116 |
|
{ |
117 |
|
ConnectionElement connx = (ConnectionElement) getModel(); |
118 |
|
ellipseFigure.setLocation(midPoint(connx.getSource().getLocation(), connx.getTarget().getLocation())); |
119 |
|
} |
120 |
|
|
121 |
|
} |
122 |
|
); |
123 |
|
|
124 |
|
} |
125 |
|
catch(Exception e) |
126 |
|
{ |
127 |
|
e.printStackTrace(); |
128 |
|
System.out.println("Refresh Visuals"); |
129 |
|
} |
130 |
|
|
131 |
|
} |
132 |
|
public Point midPoint(Point x, Point y) |
133 |
|
{ |
134 |
|
Point p = new Point ( (x.x + y.x)/2, (x.y + y.y) /2 ); |
135 |
|
return p; |
136 |
} |
} |
137 |
} |
} |