3
3
import java.awt.Color;
4
4
import java.awt.Graphics;
5
5
import java.awt.Polygon;
6
import java.util.Hashtable;
7
import pipe.gui.GuiView;
8
import pipe.gui.DrawingSurfaceImpl;
9
import pipe.gui.handler.TransportArcHandler;
10
import pipe.gui.undo.ArcTimeIntervalEdit;
8
11
import pipe.gui.undo.TransportArcGroupEdit;
9
import pipe.gui.undo.UndoableEdit;
12
import dk.aau.cs.gui.undo.Command;
13
import dk.aau.cs.model.tapn.TimeInterval;
14
import dk.aau.cs.model.tapn.TimedArcPetriNet;
15
import dk.aau.cs.model.tapn.TransportArc;
11
public class TransportArc extends TimedArc {
17
public class TransportArcComponent extends TimedInputArcComponent {
15
18
private static final long serialVersionUID = 3728885532894319528L;
17
private boolean isInPreSet;
18
private TransportArc connectedTo=null;
20
public TransportArc(PlaceTransitionObject newSource, int groupNr, boolean isInPreSet) {
21
super(new NormalArc(newSource));
20
private boolean isInPreSet;
21
private TransportArcComponent connectedTo = null;
22
private TransportArc underlyingTransportArc;
24
public TransportArcComponent(PlaceTransitionObject newSource, int groupNr,
26
super(new TimedOutputArcComponent(newSource));
22
27
this.isInPreSet = isInPreSet;
25
//hack to reprint the label of the arc
30
// hack to reprint the label of the arc
31
updateWeightLabel(true);
28
public TransportArc(TimedArc timedArc, int group, boolean isInPreSet) {
29
super(timedArc, timedArc.getGuard());
34
public TransportArcComponent(TimedInputArcComponent timedArc, int group,
30
37
this.isInPreSet = isInPreSet;
32
39
this.setGroup(group);
33
//hack to reprint the label of the arc
36
private void setHead(){
37
head = new Polygon(new int[]{0, 5, 0, -5}, new int[]{0, -11, -18, -11}, 4);
39
public void setColor(){
40
// hack to reprint the label of the arc
41
updateWeightLabel(true);
44
public void setUnderlyingArc(TransportArc arc) {
45
this.underlyingTransportArc = arc; // must explicitly set underlying arc
47
updateWeightLabel(true);
50
public TransportArc underlyingTransportArc() {
51
return underlyingTransportArc;
54
private void setHead() {
55
head = new Polygon(new int[] { 0, 5, 0, -5 }, new int[] { 0, -11, -18,
59
public void setColor() {
40
60
getGraphics().setColor(Color.RED);
43
public UndoableEdit setGroupNr(int groupNr){
64
public Command setGroupNr(int groupNr) {
44
65
int oldGroup = this.getGroup();
47
//hacks - I use the weight to display the TimeInterval
68
// hacks - I use the weight to display the TimeInterval
69
updateWeightLabel(true);
51
72
return new TransportArcGroupEdit(this, oldGroup, this.getGroup());
53
public int getGroupNr(){
75
public int getGroupNr() {
58
public void updateWeightLabel(){
60
weightLabel.setText(timeInterval+" : "+getGroup());
80
public void updateWeightLabel(boolean displayConstantNames) {
81
if (isInPreSet && underlyingTransportArc != null) {
82
weightLabel.setText(underlyingTransportArc.interval().toString(
84
+ " : " + getGroup());
85
} else if (!isInPreSet) {
86
weightLabel.setText(String.valueOf(getGroup()));
62
weightLabel.setText(""+getGroup());
88
weightLabel.setText("");
64
90
this.setWeightLabelPosition();
68
public TransportArc copy() {
94
public TransportArcComponent copy() {
74
100
public void delete() {
101
if (underlyingTransportArc != null) {
102
underlyingTransportArc.delete();
103
underlyingTransportArc = null;
104
connectedTo.underlyingTransportArc = null;
77
107
// kyrke - do ekstra suff when deleting a transport arc
81
111
// xxx - hack to awoid delete loop
83
TransportArc a = connectedTo;
113
TransportArcComponent a = connectedTo;
84
114
connectedTo = null;
85
if (a != null && a.connectedTo != null){
115
if (a != null && a.connectedTo != null) {
94
public void undelete(DataLayer model, GuiView view) {
95
super.undelete(model, view);
97
TransportArc a = connectedTo;
123
public void undelete(DrawingSurfaceImpl view) {
124
super.undelete(view);
126
TransportArcComponent a = connectedTo;
98
127
connectedTo = null;
99
if (a.connectedTo != null){
100
a.undelete(model,view);
128
if (a.connectedTo != null) {
101
130
a.connectedTo = this;
107
public TransportArc paste(double despX, double despY, boolean toAnotherView) {
136
public TransportArcComponent paste(double despX, double despY,
137
boolean toAnotherView) {
112
public TransportArc getBuddy() {
113
TransportArc toReturn = null;
115
HashMap<TransportArc, TransportArc> transportArcMap =
116
(HashMap<TransportArc, TransportArc>) ((HashMap) CreateGui.getModel().getTransportArcMap() ).
117
get( this.getTarget() );
119
toReturn = transportArcMap.get(this);
121
HashMap<TransportArc, TransportArc> transportArcMap =
122
(HashMap<TransportArc, TransportArc>) ((HashMap) CreateGui.getModel().getTransportArcMap() ).
123
get( this.getSource() );
124
for ( TransportArc ta : transportArcMap.keySet() ){
125
if (transportArcMap.get(ta) == this){
143
* public TransportArc getBuddy() { TransportArc toReturn = null; if
144
* (isInPreSet){ HashMap<TransportArc, TransportArc> transportArcMap =
145
* (HashMap<TransportArc, TransportArc>) ((HashMap)
146
* CreateGui.getModel().getTransportArcMap() ). get( this.getTarget() );
148
* toReturn = transportArcMap.get(this); }else { HashMap<TransportArc,
149
* TransportArc> transportArcMap = (HashMap<TransportArc, TransportArc>)
150
* ((HashMap) CreateGui.getModel().getTransportArcMap() ). get(
151
* this.getSource() ); for ( TransportArc ta : transportArcMap.keySet() ){
152
* if (transportArcMap.get(ta) == this){ toReturn = ta; } } } return
132
155
public boolean isInPreSet() {
133
156
return isInPreSet;
135
public TransportArc getConnectedTo() {
159
public TransportArcComponent getConnectedTo() {
136
160
return connectedTo;
139
public void setConnectedTo(TransportArc connectedTo) {
163
public void setConnectedTo(TransportArcComponent connectedTo) {
140
164
this.connectedTo = connectedTo;
144
168
public void paintComponent(Graphics g) {
145
169
super.paintComponent(g);
152
176
public int getGroup() {
181
public String getGuardAsString() {
182
return underlyingTransportArc.interval().toString();
186
public TimeInterval getGuard() {
187
return underlyingTransportArc.interval();
191
public Command setGuard(TimeInterval guard) {
193
TimeInterval oldTimeInterval = underlyingTransportArc.interval();
194
underlyingTransportArc.setTimeInterval(guard);
196
// hacks - I use the weight to display the TimeInterval
197
updateWeightLabel(true);
200
return new ArcTimeIntervalEdit(this, oldTimeInterval,
201
underlyingTransportArc.interval());
204
public TransportArcComponent copy(TimedArcPetriNet tapn, DataLayer guiModel, Hashtable<PlaceTransitionObject, PlaceTransitionObject> oldToNewMapping) {
205
TransportArcComponent arc = new TransportArcComponent(this, group, isInPreSet);
206
arc.setSource(oldToNewMapping.get(this.getSource()));
207
arc.setTarget(oldToNewMapping.get(this.getTarget()));
209
arc.setUnderlyingArc(tapn.getTransportArcFromPlaceTransitionAndPlace(tapn.getPlaceByName(underlyingTransportArc.source().name()),
210
tapn.getTransitionByName(underlyingTransportArc.transition().name()),
211
tapn.getPlaceByName(underlyingTransportArc.destination().name())));
213
arc.getSource().addConnectFrom(arc);
214
arc.getTarget().addConnectTo(arc);
216
TransportArcHandler transportArcHandler = new TransportArcHandler((DrawingSurfaceImpl)getParent(), arc);
217
arc.addMouseListener(transportArcHandler);
218
arc.addMouseWheelListener(transportArcHandler);
219
arc.addMouseMotionListener(transportArcHandler);
221
arc.setGuiModel(guiModel);