11
11
import pipe.gui.Zoomer;
14
* <b>PlaceTransitionObject</b> - Petri-Net PLace or Transition SuperClass<b> - <i>Abstract</i></b>
16
* @see <p><a href="..\PNMLSchema\index.html">PNML - Petri-Net XMLSchema (stNet.xsd)</a>
17
* @see </p><p><a href="..\..\..\UML\dataLayer.html">UML - PNML Package </a></p>
14
* <b>PlaceTransitionObject</b> - Petri-Net PLace or Transition SuperClass<b> -
18
* <a href="..\PNMLSchema\index.html">PNML - Petri-Net XMLSchema
22
* <a href="..\..\..\UML\dataLayer.html">UML - PNML Package </a>
19
25
* @author James D Bloom
21
* @author Edwin Chung 16 Mar 2007: modified the constructor and several
22
* other functions so that DataLayer objects can be created outside the
27
* @author Edwin Chung 16 Mar 2007: modified the constructor and several other
28
* functions so that DataLayer objects can be created outside the GUI
25
public abstract class PlaceTransitionObject
26
extends PetriNetObject
27
implements Cloneable {
30
public abstract class PlaceTransitionObject extends PetriNetObject implements
32
36
private static final long serialVersionUID = -6629006415467929184L;
33
/** X-axis Position on screen*/
37
/** X-axis Position on screen */
34
38
protected double positionX;
35
/** Y-axis Position on screen*/
39
/** Y-axis Position on screen */
36
40
protected double positionY;
38
/** X-axis Position on screen*/
42
/** X-axis Position on screen */
39
43
protected double nameOffsetX;
40
/** Y-axis Position on screen*/
44
/** Y-axis Position on screen */
41
45
protected double nameOffsetY;
43
47
protected double componentWidth;
62
65
// i.e. the y position at 100% zoom.
63
66
private double locationY;
67
69
* Create Petri-Net Object
68
* @param positionXInput X-axis Position
69
* @param positionYInput Y-axis Position
70
* @param idInput Place id
71
* @param nameInput Name
72
* @param nameOffsetXInput Name X-axis Position
73
* @param nameOffsetYInput Name Y-axis Position
71
* @param positionXInput
73
* @param positionYInput
79
* @param nameOffsetXInput
80
* Name X-axis Position
81
* @param nameOffsetYInput
82
* Name Y-axis Position
75
public PlaceTransitionObject(double positionXInput,
76
double positionYInput,
79
double nameOffsetXInput,
84
public PlaceTransitionObject(double positionXInput, double positionYInput,
85
String idInput, String nameInput, double nameOffsetXInput,
80
86
double nameOffsetYInput) {
81
this(positionXInput, positionYInput, idInput);
87
this(positionXInput, positionYInput);
82
89
nameOffsetX = nameOffsetXInput;
83
90
nameOffsetY = nameOffsetYInput;
84
pnName.setPosition((int)nameOffsetX, (int)nameOffsetY);
90
* Create Petri-Net Object
91
* @param positionXInput X-axis Position
92
* @param positionYInput Y-axis Position
93
* @param idInput Place id
95
public PlaceTransitionObject(double positionXInput,
96
double positionYInput,
98
this(positionXInput, positionYInput);
104
* Create Petri-Net Object
105
* This constructor does all the work, the others just call it.
106
* @param positionXInput X-axis Position
107
* @param positionYInput Y-axis Position
91
pnName.setPosition((int) nameOffsetX, (int) nameOffsetY);
92
// setName(nameInput);
96
* Create Petri-Net Object This constructor does all the work, the others
99
* @param positionXInput
101
* @param positionYInput
109
104
public PlaceTransitionObject(double positionXInput, double positionYInput) {
111
106
setPositionX(positionXInput);
112
setPositionY(positionYInput);
107
setPositionY(positionYInput);
114
109
nameOffsetX = Pipe.DEFAULT_OFFSET_X;
115
110
nameOffsetY = Pipe.DEFAULT_OFFSET_Y;
118
113
pnName = new NameLabel(zoom);
123
117
* Set X-axis position
124
* @param positionXInput Double value for X-axis position
119
* @param positionXInput
120
* Double value for X-axis position
126
122
public void setPositionX(double positionXInput) {
127
positionX = positionXInput;
123
positionX = positionXInput;
128
124
locationX = Zoomer.getUnzoomedValue(positionX, zoom);
133
128
* Set Y-axis position
134
* @param positionYInput Double value for Y-axis position
130
* @param positionYInput
131
* Double value for Y-axis position
136
133
public void setPositionY(double positionYInput) {
137
134
positionY = positionYInput;
138
135
locationY = Zoomer.getUnzoomedValue(positionY, zoom);
144
* @param nameInput String value for Place name;
142
* String value for Place name;
147
145
public void setName(String nameInput) {
148
//sets the text within the label
149
//System.out.println("setting name to: " + nameInput);
146
// sets the text within the label
147
// System.out.println("setting name to: " + nameInput);
150
148
pnName.setName(nameInput);
155
152
* Set X-axis offset for name position
156
* @param nameOffsetXInput Double value for name X-axis offset
154
* @param nameOffsetXInput
155
* Double value for name X-axis offset
158
157
public void setNameOffsetX(double nameOffsetXInput) {
159
158
nameOffsetX += Zoomer.getUnzoomedValue(nameOffsetXInput, zoom);
164
162
* Set Y-axis offset for name position
165
* @param nameOffsetYInput Double value for name Y-axis offset
164
* @param nameOffsetYInput
165
* Double value for name Y-axis offset
167
167
public void setNameOffsetY(double nameOffsetYInput) {
168
nameOffsetY += Zoomer.getUnzoomedValue(nameOffsetYInput, zoom);
168
nameOffsetY += Zoomer.getUnzoomedValue(nameOffsetYInput, zoom);
173
172
* Get X-axis position
174
174
* @return Double value for X-axis position
176
176
public double getPositionX() {
177
177
return positionX;
182
181
* Get Y-axis position
183
183
* @return Double value for Y-axis position
185
185
public double getPositionY() {
186
186
return positionY;
192
* @param idInput String value for Place id;
193
* String value for Place id;
195
196
public void setId(String idInput) {
198
// System.out.println("setting id to: " + idInput);
199
// System.out.println("setting id to: " + idInput);
204
205
* @return String value for Place id;
207
208
public String getId() {
208
return (id!=null) ? id : pnName.getName();
209
return (id != null) ? id : pnName.getName();
214
215
* @return String value for Place name;
217
218
public String getName() {
218
return (pnName!=null) ? pnName.getName() : id;
219
return (pnName != null) ? pnName.getName() : id;
222
222
public double getNameOffsetX() {
223
223
return nameOffsetX;
227
226
public double getNameOffsetY() {
228
227
return nameOffsetY;
233
231
* Get X-axis offset for ...
234
233
* @return Double value for X-axis offset of ...
236
235
public Double getNameOffsetXObject() {
237
236
return this.nameOffsetX;
241
/** Moved to PlaceTransitionObject
242
* Get Y-axis offset for ...
240
* Moved to PlaceTransitionObject Get Y-axis offset for ...
243
242
* @return Double value for Y-axis offset of ...
245
244
public Double getNameOffsetYObject() {
246
245
return this.nameOffsetY;
251
249
* Get X-axis position, returns null if value not yet entered
252
251
* @return Double value for X-axis position
254
253
public Double getPositionXObject() {
255
254
return new Double(locationX);
256
//return new Double(positionX);
255
// return new Double(positionX);
261
259
* Get Y-axis position, returns null if value not yet entered
262
261
* @return Double value for Y-axis position
264
263
public Double getPositionYObject() {
265
264
return new Double(locationY);
266
//return new Double(positionY);
265
// return new Double(positionY);
270
/** Implemented in subclasses as involves some tailoring according to the shape
271
* @param e Mouse Event
269
* Implemented in subclasses as involves some tailoring according to the
274
276
public void paintComponent(Graphics g) {
275
277
super.paintComponent(g);
277
Graphics2D g2 = (Graphics2D)g;
279
Graphics2D g2 = (Graphics2D) g;
278
280
g2.translate(COMPONENT_DRAW_OFFSET, COMPONENT_DRAW_OFFSET);
279
281
g2.transform(Zoomer.getTransform(zoom));
283
284
public Point2D getIntersectOffset(Point2D start) {
284
285
return new Point2D.Double();
288
/** Returns the distance between the outside of the component to the centre,
289
* in order to position the centre of the place where the mouse clicks on the
289
* Returns the distance between the outside of the component to the centre,
290
* in order to position the centre of the place where the mouse clicks on
291
293
* @return Top offset of Place
293
295
public int centreOffsetTop() {
294
return (int)(Zoomer.getZoomedValue(componentHeight/2.0, zoom));
296
return (int) (Zoomer.getZoomedValue(componentHeight / 2.0, zoom));
298
/** Returns the distance between the outside of the component to the centre,
299
* in order to position the centre of the place where the mouse clicks on the
300
* Returns the distance between the outside of the component to the centre,
301
* in order to position the centre of the place where the mouse clicks on
301
304
* @return Left offset of Place
303
306
public int centreOffsetLeft() {
304
return (int)(Zoomer.getZoomedValue(componentWidth/2.0, zoom));
307
return (int) (Zoomer.getZoomedValue(componentWidth / 2.0, zoom));
308
310
/** Calculates the BoundsOffsets used for setBounds() method */
309
311
public void updateBounds() {
310
312
double scaleFactor = Zoomer.getScaleFactor(zoom);
311
313
positionX = locationX * scaleFactor;
312
314
positionY = locationY * scaleFactor;
313
bounds.setBounds((int)positionX,
315
(int)(componentWidth * scaleFactor),
316
(int)(componentHeight * scaleFactor));
315
bounds.setBounds((int) positionX, (int) positionY,
316
(int) (componentWidth * scaleFactor),
317
(int) (componentHeight * scaleFactor));
317
318
bounds.grow(COMPONENT_DRAW_OFFSET, COMPONENT_DRAW_OFFSET);
318
319
setBounds(bounds);
322
322
/** Adds outwards arc to place/transition */
323
323
public void addConnectTo(Arc newArc) {
324
// System.out.println("DEBUG: added arc (to)!:" + newArc + " de " + this);
324
// System.out.println("DEBUG: added arc (to)!:" + newArc + " de " +
325
326
connectTo.add(newArc);
329
329
/** Adds inwards arc to place/transition */
330
330
public void addConnectFrom(Arc newArc) {
331
// System.out.println("DEBUG: added arc (from)!:" + newArc + " de " + this);
331
// System.out.println("DEBUG: added arc (from)!:" + newArc + " de " +
332
333
connectFrom.add(newArc);
336
336
public void removeFromArc(Arc oldArc) {
337
337
if (connectFrom.remove(oldArc)) {
338
// System.out.println("DEBUG: removeFromArc_ok");
338
// System.out.println("DEBUG: removeFromArc_ok");
340
// System.out.println("DEBUG: removeFromArc_ko");
340
// System.out.println("DEBUG: removeFromArc_ko");
345
344
public void removeToArc(Arc oldArc) {
346
345
if (connectTo.remove(oldArc)) {
347
// System.out.println("DEBUG: removeToArc_ok");
346
// System.out.println("DEBUG: removeToArc_ok");
349
// System.out.println("DEBUG: removeToArc_ko");
348
// System.out.println("DEBUG: removeToArc_ko");
354
352
/** Updates location of any attached arcs */
355
353
public void updateConnected() {
356
354
Iterator<Arc> arcsFrom = connectFrom.iterator();
373
370
/** Translates the component by x,y */
374
371
public void translate(int x, int y) {
375
372
setPositionX(positionX + x);
376
setPositionY(positionY + y);
373
setPositionY(positionY + y);
381
377
/** Sets the center of the component to position x, y */
382
public void setCentre(double x,double y) {
383
setPositionX(x - (getWidth()/2.0));
384
setPositionY(y - (getHeight()/2.0));
389
public void update() {
391
updateLabelLocation();
378
public void setCentre(double x, double y) {
379
setPositionX(x - (getWidth() / 2.0));
380
setPositionY(y - (getHeight() / 2.0));
384
public void update(boolean displayConstantNames) {
396
388
public Point2D.Double getCentre() {
397
return new Point2D.Double(positionX + getWidth()/2.0,
398
positionY + getHeight()/2.0);
389
return new Point2D.Double(positionX + getWidth() / 2.0, positionY
390
+ getHeight() / 2.0);
402
393
protected void updateLabelLocation() {
403
pnName.setPosition(Grid.getModifiedX((int)(positionX +
404
Zoomer.getZoomedValue(nameOffsetX, zoom))),
405
Grid.getModifiedY((int)(positionY +
406
Zoomer.getZoomedValue(nameOffsetY, zoom))));
395
Grid.getModifiedX((int) (positionX + Zoomer.getZoomedValue(nameOffsetX, zoom))),
396
Grid.getModifiedY((int) (positionY + Zoomer.getZoomedValue(nameOffsetY, zoom)))
411
401
public void delete() {
484
public void incrementCopyNumber(){
485
if (original != null){
476
public void incrementCopyNumber() {
477
if (original != null) {
486
478
original.copyNumber++;
491
482
public void newCopy(PlaceTransitionObject ptObject) {
492
483
if (original != null) {
493
484
original.lastCopy = ptObject;
498
488
public PlaceTransitionObject getLastCopy() {
503
492
public void resetLastCopy() {
508
public void setOriginal(PlaceTransitionObject ptObject) {
496
public void setOriginal(PlaceTransitionObject ptObject) {
509
497
original = ptObject;
513
500
public PlaceTransitionObject getOriginal() {
518
504
public abstract void showEditor();
521
public void setAttributesVisible(boolean flag){
522
attributesVisible = flag;
506
public void setAttributesVisible(boolean flag) {
507
attributesVisible = flag;
526
public boolean getAttributesVisible(){
510
public boolean getAttributesVisible() {
527
511
return attributesVisible;
532
515
public int getLayerOffset() {
533
516
return Pipe.PLACE_TRANSITION_LAYER_OFFSET;
537
519
public abstract void toggleAttributesVisible();
540
521
public void zoomUpdate(int value) {
546
526
// XXX - kyrke now also clones arcs
547
527
// Clone object and deep copy the pnNames
549
529
public PlaceTransitionObject clone() {
550
PlaceTransitionObject toReturn = (PlaceTransitionObject)super.clone();
530
PlaceTransitionObject toReturn = (PlaceTransitionObject) super.clone();
551
531
toReturn.pnName = (NameLabel) pnName.clone();
553
533
toReturn.connectFrom = this.connectFrom;