6
6
import java.awt.Polygon;
7
7
import java.awt.RenderingHints;
8
8
import java.awt.geom.AffineTransform;
10
import pipe.gui.CreateGui;
9
import java.util.Hashtable;
11
import dk.aau.cs.model.tapn.TimedArcPetriNet;
13
import pipe.gui.DrawingSurfaceImpl;
11
14
import pipe.gui.Pipe;
12
15
import pipe.gui.Zoomer;
13
import pipe.gui.undo.ArcWeightEdit;
14
import pipe.gui.undo.ClearInverseArcEdit;
15
import pipe.gui.undo.JoinInverseArcEdit;
16
import pipe.gui.undo.SetInverseArcEdit;
17
import pipe.gui.undo.SplitInverseArcEdit;
18
import pipe.gui.undo.TagArcEdit;
19
import pipe.gui.undo.UndoableEdit;
16
import pipe.gui.handler.ArcHandler;
23
19
* <b>Arc</b> - Petri-Net Normal Arc Class
25
* @see <p><a href="..\PNMLSchema\index.html">PNML - Petri-Net XMLSchema (stNet.xsd)</a>
26
* @see </p><p><a href="..\..\..\UML\dataLayer.html">UML - PNML Package </a></p>
22
* <a href="..\PNMLSchema\index.html">PNML - Petri-Net XMLSchema
26
* <a href="..\..\..\UML\dataLayer.html">UML - PNML Package </a>
29
public class NormalArc
30
public class TimedOutputArcComponent extends Arc {
34
34
private static final long serialVersionUID = 5588142404135607382L;
36
/*CB Joakim Byg - probably not needed
37
public final static String type = "normal";
39
protected Polygon head =
40
new Polygon(new int[]{0, 5, 0, -5}, new int[]{0, -10, -7, -10}, 4);
43
private boolean joined = false;
45
// Whether or not exists an inverse arc
46
private NormalArc inverse = null;
49
/** Whether or not the Arc is capable of carrying tagged tokens
50
* By default it is not
52
private Boolean tagged = false;
56
* Create Petri-Net Arc object
57
* @param startPositionXInput Start X-axis Position
58
* @param startPositionYInput Start Y-axis Position
59
* @param endPositionXInput End X-axis Position
60
* @param endPositionYInput End Y-axis Position
61
* @param sourceInput Arc source
62
* @param targetInput Arc target
63
* @param idInput Arc id
65
public NormalArc(double startPositionXInput, double startPositionYInput,
66
double endPositionXInput, double endPositionYInput,
67
PlaceTransitionObject sourceInput,
68
PlaceTransitionObject targetInput,
72
super(startPositionXInput, startPositionYInput,
73
endPositionXInput, endPositionYInput,
78
setTagged(taggedInput);
83
* Create Petri-Net Arc object
85
public NormalArc(PlaceTransitionObject newSource) {
90
public NormalArc(NormalArc arc) {
91
weightLabel = new NameLabel(zoom);
93
for (int i = 0; i <= arc.myPath.getEndIndex(); i++){
94
this.myPath.addPoint(arc.myPath.getPoint(i).getX(),
95
arc.myPath.getPoint(i).getY(),
96
arc.myPath.getPointType(i));
98
this.myPath.createPath();
101
this.setSource(arc.getSource());
102
this.setTarget(arc.getTarget());
103
this.setWeight(arc.getWeight());
104
this.inView = arc.inView;
105
this.joined = arc.joined;
109
public NormalArc paste(double despX, double despY, boolean toAnotherView){
110
PlaceTransitionObject source = this.getSource().getLastCopy();
111
PlaceTransitionObject target = this.getTarget().getLastCopy();
113
if (source == null && target == null) {
114
// don't paste an arc with neither source nor target
120
// if the source belongs to another Petri Net, the arc can't be
124
source = this.getSource();
130
// if the target belongs to another Petri Net, the arc can't be
134
target = this.getTarget();
138
NormalArc copy = new NormalArc(0, 0, //startPoint
143
source.getId() + " to " + target.getId(),
146
copy.myPath.delete();
147
for (int i = 0; i <= this.myPath.getEndIndex(); i++){
148
copy.myPath.addPoint(this.myPath.getPoint(i).getX() + despX,
149
this.myPath.getPoint(i).getY() + despY,
150
this.myPath.getPointType(i));
151
copy.myPath.selectPoint(i);
154
source.addConnectFrom(copy);
155
target.addConnectTo(copy);
157
copy.inView = this.inView;
158
copy.joined = this.joined;
164
public NormalArc copy(){
165
return new NormalArc(this);
168
/*CB Joakim Byg - This is sortof ugly, since it is only used one place
169
and we would like to make an other type of arc that inherits from NormalArc
170
public String getType(){
176
public UndoableEdit setWeight(int weightInput){
177
int oldWeight = weight;
179
weight = weightInput;
181
return new ArcWeightEdit(this, oldWeight, weight);
186
/** Accessor function to set whether or not the Arc is tagged */
187
public UndoableEdit setTagged(boolean flag){
188
/**Set the timed transition attribute (for GSPNs)*/
192
// If it becomes tagged we must remove any existing weight....
193
// ...and thus we can reuse the weightLabel to display that it's tagged!!!
194
// Because remember that a tagged arc must have a weight of 1...
197
weightLabel.setText("TAG");
198
setWeightLabelPosition();
199
weightLabel.updateSize();
201
weightLabel.setText((weight > 1)?Integer.toString(weight) : "");
204
return new TagArcEdit(this);
208
/** Accessor function to check whether or not the Arc is tagged */
209
public boolean isTagged(){
214
public void updateWeightLabel(){
215
if (hasInverse() && !inView) {
216
inverse.updateWeightLabel();
218
if (!hasInvisibleInverse()){
220
weightLabel.setText("");
222
weightLabel.setText(Integer.toString(weight));
225
if (weight == 1 && inverse.weight == 1){
226
weightLabel.setText("");
228
if (getSource() instanceof Place){
229
weightLabel.setText(weight + "(PT) / " + inverse.getWeight() + "(TP)");
231
weightLabel.setText(inverse.getWeight() + "(PT) / " + weight + "(TP)");
235
setWeightLabelPosition();
240
public void setInView(boolean flag) {
245
public void setJoined(boolean flag) {
250
public UndoableEdit clearInverse() {
251
NormalArc oldInverse = inverse;
253
inverse.inView = true;
256
inverse.joined = false;
259
inverse.updateWeightLabel();
262
inverse.inverse = null;
265
return new ClearInverseArcEdit(this, oldInverse, false);
269
public boolean hasInverse() {
270
return inverse != null;
274
public NormalArc getInverse() {
279
public UndoableEdit setInverse(NormalArc _inverse, boolean joined) {
281
inverse.inverse = this;
283
return new SetInverseArcEdit(this, inverse, joined);
287
private void updateArc(boolean isJoined){
289
inverse.inView = !isJoined;
292
inverse.removeFromView();
293
Transition transition = this.getTransition();
294
transition.removeFromArc(inverse);
295
transition.removeArcCompareObject(inverse);
296
transition.updateConnected();
303
public boolean isJoined() {
308
public UndoableEdit split() {
310
if (!this.inverse.inView) {
311
CreateGui.getView().add(inverse);
312
inverse.getSource().addConnectFrom(inverse);
313
inverse.getTarget().addConnectTo(inverse);
316
CreateGui.getView().add(this);
317
this.getSource().addConnectFrom(this);
318
this.getTarget().addConnectTo(this);
322
inverse.inView = true;
325
inverse.joined = false;
327
this.updateWeightLabel();
328
inverse.updateWeightLabel();
330
this.updateArcPosition();
331
inverse.updateArcPosition();
333
return new SplitInverseArcEdit(this);
337
public UndoableEdit join() {
338
this.updateArc(true);
339
//((NormalArc)arc.getInverse()).setInView(false);
340
//arc.getParent().remove(arc.getInverse());
341
inverse.removeFromView();
342
this.setJoined(true);
343
if (this.getParent() != null) {
344
this.getParent().repaint();
347
return new JoinInverseArcEdit(this);
351
public boolean hasInvisibleInverse() {
352
return ((this.inverse!=null) && !(this.inverse.inView()));
357
public void paintComponent(Graphics g) {
358
super.paintComponent(g);
359
Graphics2D g2 = (Graphics2D)g;
361
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
362
RenderingHints.VALUE_ANTIALIAS_ON);
364
g2.translate(COMPONENT_DRAW_OFFSET + zoomGrow - myPath.getBounds().getX(),
365
COMPONENT_DRAW_OFFSET + zoomGrow - myPath.getBounds().getY());
367
AffineTransform reset = g2.getTransform();
369
if (selected && !ignoreSelection){
370
g2.setPaint(Pipe.SELECTION_LINE_COLOUR);
372
g2.setPaint(Pipe.ELEMENT_LINE_COLOUR);
376
g2.translate(myPath.getPoint(0).getX(), myPath.getPoint(0).getY());
377
g2.rotate(myPath.getStartAngle() + Math.PI);
378
g2.transform(Zoomer.getTransform(zoom));
379
g2.fillPolygon(head);
380
g2.setTransform(reset);
383
g2.setStroke(new BasicStroke(0.01f * zoom));
386
g2.translate(myPath.getPoint(myPath.getEndIndex()).getX(),
387
myPath.getPoint(myPath.getEndIndex()).getY());
389
g2.rotate(myPath.getEndAngle()+Math.PI);
390
g2.setColor(java.awt.Color.WHITE);
392
g2.transform(Zoomer.getTransform(zoom));
393
g2.setPaint(Pipe.ELEMENT_LINE_COLOUR);
395
if (selected && !ignoreSelection){
396
g2.setPaint(Pipe.SELECTION_LINE_COLOUR);
398
g2.setPaint(Pipe.ELEMENT_LINE_COLOUR);
401
g2.setStroke(new BasicStroke(0.8f));
402
g2.fillPolygon(head);
408
public NormalArc clone(){
410
NormalArc toReturn = (NormalArc)super.clone();
411
toReturn.setTagged(tagged);
36
protected Polygon head = new Polygon(new int[] { 0, 5, 0, -5 }, new int[] {
37
0, -10, -7, -10 }, 4);
39
private dk.aau.cs.model.tapn.TimedOutputArc outputArc;
42
* Create Petri-Net Arc object
44
* @param startPositionXInput
45
* Start X-axis Position
46
* @param startPositionYInput
47
* Start Y-axis Position
48
* @param endPositionXInput
50
* @param endPositionYInput
59
public TimedOutputArcComponent(double startPositionXInput,
60
double startPositionYInput, double endPositionXInput,
61
double endPositionYInput, PlaceTransitionObject sourceInput,
62
PlaceTransitionObject targetInput, int weightInput, String idInput,
63
boolean taggedInput) {
64
super(startPositionXInput, startPositionYInput, endPositionXInput,
65
endPositionYInput, sourceInput, targetInput, weightInput,
70
* Create Petri-Net Arc object
72
public TimedOutputArcComponent(PlaceTransitionObject newSource) {
76
public TimedOutputArcComponent(TimedOutputArcComponent arc) {
77
weightLabel = new NameLabel(zoom);
79
this.myPath = new ArcPath(this);
80
for (int i = 0; i <= arc.myPath.getEndIndex(); i++) {
81
this.myPath.addPoint(arc.myPath.getPoint(i).getX(), arc.myPath.getPoint(i).getY(), arc.myPath.getPointType(i));
83
this.myPath.createPath();
86
this.setSource(arc.getSource());
87
this.setTarget(arc.getTarget());
88
this.setWeight(arc.getWeight());
89
this.inView = arc.inView;
92
public TimedOutputArcComponent paste(double despX, double despY,
93
boolean toAnotherView) {
94
PlaceTransitionObject source = this.getSource().getLastCopy();
95
PlaceTransitionObject target = this.getTarget().getLastCopy();
97
if (source == null && target == null) {
98
// don't paste an arc with neither source nor target
102
if (source == null) {
104
// if the source belongs to another Petri Net, the arc can't be
108
source = this.getSource();
112
if (target == null) {
114
// if the target belongs to another Petri Net, the arc can't be
118
target = this.getTarget();
122
TimedOutputArcComponent copy = new TimedOutputArcComponent(0, 0, // startPoint
124
source, target, this.getWeight(), source.getId() + " to "
125
+ target.getId(), false);
127
copy.myPath.delete();
128
for (int i = 0; i <= this.myPath.getEndIndex(); i++) {
129
copy.myPath.addPoint(this.myPath.getPoint(i).getX() + despX,
130
this.myPath.getPoint(i).getY() + despY, this.myPath
132
copy.myPath.selectPoint(i);
135
source.addConnectFrom(copy);
136
target.addConnectTo(copy);
138
copy.inView = this.inView;
143
public TimedOutputArcComponent copy() {
144
return new TimedOutputArcComponent(this);
147
public void updateWeightLabel(boolean displayConstantNames) {
148
weightLabel.setText("");
149
setWeightLabelPosition();
153
public void delete() {
154
if (outputArc != null)
160
public void paintComponent(Graphics g) {
161
super.paintComponent(g);
162
Graphics2D g2 = (Graphics2D) g;
164
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
165
RenderingHints.VALUE_ANTIALIAS_ON);
167
g2.translate(COMPONENT_DRAW_OFFSET + zoomGrow
168
- myPath.getBounds().getX(), COMPONENT_DRAW_OFFSET + zoomGrow
169
- myPath.getBounds().getY());
171
AffineTransform reset = g2.getTransform();
173
if (selected && !ignoreSelection) {
174
g2.setPaint(Pipe.SELECTION_LINE_COLOUR);
176
g2.setPaint(Pipe.ELEMENT_LINE_COLOUR);
179
g2.setStroke(new BasicStroke(0.01f * zoom));
182
g2.translate(myPath.getPoint(myPath.getEndIndex()).getX(), myPath
183
.getPoint(myPath.getEndIndex()).getY());
185
g2.rotate(myPath.getEndAngle() + Math.PI);
186
g2.setColor(java.awt.Color.WHITE);
188
g2.transform(Zoomer.getTransform(zoom));
189
g2.setPaint(Pipe.ELEMENT_LINE_COLOUR);
191
if (selected && !ignoreSelection) {
192
g2.setPaint(Pipe.SELECTION_LINE_COLOUR);
194
g2.setPaint(Pipe.ELEMENT_LINE_COLOUR);
197
g2.setStroke(new BasicStroke(0.8f));
198
g2.fillPolygon(head);
203
public dk.aau.cs.model.tapn.TimedOutputArc underlyingArc() {
207
public void setUnderlyingArc(dk.aau.cs.model.tapn.TimedOutputArc outputArc) {
208
this.outputArc = outputArc;
211
public TimedOutputArcComponent copy(TimedArcPetriNet tapn, DataLayer guiModel, Hashtable<PlaceTransitionObject, PlaceTransitionObject> oldToNewMapping) {
212
TimedOutputArcComponent arc = new TimedOutputArcComponent(this);
213
arc.setSource(oldToNewMapping.get(this.getSource()));
214
arc.setTarget(oldToNewMapping.get(this.getTarget()));
215
arc.setUnderlyingArc(tapn.getOutputArcFromTransitionAndPlace(tapn.getTransitionByName(outputArc.source().name()), tapn.getPlaceByName(outputArc.destination().name())));
217
arc.getSource().addConnectFrom(arc);
218
arc.getTarget().addConnectTo(arc);
220
ArcHandler arcHandler = new ArcHandler((DrawingSurfaceImpl)getParent(), arc);
221
arc.addMouseListener(arcHandler);
222
arc.addMouseWheelListener(arcHandler);
223
arc.addMouseMotionListener(arcHandler);
225
arc.setGuiModel(guiModel);