~yrke/tapaal/slimImageIcons-2

« back to all changes in this revision

Viewing changes to src/pipe/gui/graphicElements/tapn/TimedTransportArcComponent.java

  • Committer: Jiri Srba
  • Date: 2020-04-28 19:15:28 UTC
  • mfrom: (998.2.376 testbranch)
  • Revision ID: srba@cs.aau.dk-20200428191528-3xxjqa1r4jcob5ur
merged in lp:~yrke/tapaal/testbranch doing majour refactoring of the GUI

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
package pipe.gui.graphicElements.tapn;
2
2
 
3
 
import java.awt.Color;
4
3
import java.awt.Polygon;
5
4
import java.util.Hashtable;
6
5
 
7
 
import pipe.dataLayer.DataLayer;
8
6
import pipe.gui.CreateGui;
9
 
import pipe.gui.DrawingSurfaceImpl;
10
7
import pipe.gui.Pipe;
11
8
import pipe.gui.graphicElements.PlaceTransitionObject;
12
9
import pipe.gui.handler.TransportArcHandler;
13
10
import pipe.gui.undo.ArcTimeIntervalEdit;
14
 
import pipe.gui.undo.TransportArcGroupEdit;
15
11
import dk.aau.cs.gui.undo.Command;
16
12
import dk.aau.cs.model.tapn.ConstantBound;
17
13
import dk.aau.cs.model.tapn.ConstantWeight;
30
26
        public TimedTransportArcComponent(PlaceTransitionObject newSource, int groupNr, boolean isInPreSet) {
31
27
                super(new TimedOutputArcComponent(newSource));
32
28
                this.isInPreSet = isInPreSet;
33
 
                setHead();
 
29
 
34
30
                setGroup(groupNr);
35
31
                // hack to reprint the label of the arc
36
32
                updateLabel(true);
37
33
                isPrototype = true;
38
 
 
39
 
                //XXX: se note in funcation
40
 
                addMouseHandler();
41
34
        }
42
35
 
43
36
        public TimedTransportArcComponent(TimedInputArcComponent timedArc, int group, boolean isInPreSet) {
44
37
                super(timedArc, "");
45
38
                this.isInPreSet = isInPreSet;
46
 
                setHead();
 
39
 
47
40
                this.setGroup(group);
48
41
                // hack to reprint the label of the arc
49
42
                updateLabel(true);
50
 
 
51
 
                //XXX: se note in funcation
52
 
                addMouseHandler();
53
43
        }
54
44
 
55
 
        private void addMouseHandler() {
 
45
        @Override
 
46
        protected void addMouseHandler() {
56
47
                //XXX: kyrke 2018-09-06, this is bad as we leak "this", think its ok for now, as it alwas constructed when
57
48
                //XXX: handler is called. Make static constructor and add handler from there, to make it safe.
58
49
                mouseHandler = new TransportArcHandler(this);
68
59
                return underlyingTransportArc;
69
60
        }
70
61
 
71
 
        private void setHead() {
72
 
                head = new Polygon(new int[] { 0, 5, 0, -5 }, new int[] { 0, -11, -18,
73
 
                                -11 }, 4);
74
 
        }
75
 
 
76
 
        public void setColor() {
77
 
                getGraphics().setColor(Color.RED);
78
 
                repaint();
79
 
        }
80
 
 
81
 
        public Command setGroupNr(int groupNr) {
82
 
                int oldGroup = this.getGroup();
 
62
        @Override
 
63
        protected void setHead() {
 
64
                setHead(new Polygon(new int[] { 0, 5, 0, -5 }, new int[] { 0, -11, -18, -11 }, 4), true);;
 
65
        }
 
66
 
 
67
        public void setGroupNr(int groupNr) {
83
68
                setGroup(groupNr);
84
69
 
85
70
                // hacks - I use the weight to display the TimeInterval
86
71
                updateLabel(true);
87
72
                repaint();
88
73
 
89
 
                return new TransportArcGroupEdit(this, oldGroup, this.getGroup());
90
74
        }
91
75
 
92
76
        public int getGroupNr() {
97
81
        public void updateLabel(boolean displayConstantNames) {
98
82
                if (isInPreSet && underlyingTransportArc != null) {
99
83
                        if (CreateGui.getApp().showZeroToInfinityIntervals()){
100
 
                                pnName.setText(underlyingTransportArc.interval().toString(
 
84
                                getNameLabel().setText(underlyingTransportArc.interval().toString(
101
85
                                                displayConstantNames)
102
86
                                                + " : " + getGroup());
103
87
                        }
105
89
                                if (underlyingTransportArc.interval().toString(
106
90
                                                displayConstantNames).equals("[0,inf)")) {
107
91
 
108
 
                                        pnName.setText(" : " + String.valueOf(getGroup()));
 
92
                                        getNameLabel().setText(" : " + getGroup());
109
93
 
110
94
                                }
111
95
                                else {
112
 
                                        pnName.setText(underlyingTransportArc.interval().toString(
 
96
                                        getNameLabel().setText(underlyingTransportArc.interval().toString(
113
97
                                                        displayConstantNames)
114
98
                                                        + " : " + getGroup());
115
99
                                }                               
143
127
                                }
144
128
                        }
145
129
                        if(focusedConstant){
146
 
                                pnName.setForeground(Pipe.SELECTION_TEXT_COLOUR);
 
130
                                getNameLabel().setForeground(Pipe.SELECTION_TEXT_COLOUR);
147
131
                        }else{
148
 
                                pnName.setForeground(Pipe.ELEMENT_TEXT_COLOUR);
 
132
                                getNameLabel().setForeground(Pipe.ELEMENT_TEXT_COLOUR);
149
133
                        }
150
134
                        pnName.setVisible(isvisible);
151
135
                        
152
136
                } else if (!isInPreSet) {
153
 
                        pnName.setText(" : " + String.valueOf(getGroup()));
 
137
                        getNameLabel().setText(" : " + getGroup());
154
138
                } else {
155
 
                        pnName.setText("");
 
139
                        getNameLabel().setText("");
156
140
                }
157
141
                
158
142
                if(underlyingTransportArc != null){
159
 
                                        pnName.setText(getWeight().toString(displayConstantNames)+" "+pnName.getText());
 
143
                        getNameLabel().setText(getWeight().toString(displayConstantNames)+" "+getNameLabel().getText());
160
144
                }
161
145
                
162
146
                this.setLabelPosition();
163
147
        }
164
148
 
165
 
        @Override
166
 
        public void delete() {
167
 
                if (underlyingTransportArc != null) {
168
 
                        underlyingTransportArc.delete();
169
 
                        underlyingTransportArc = null;
170
 
                        connectedTo.underlyingTransportArc = null;
171
 
                }
172
 
 
173
 
                // kyrke - do ekstra suff when deleting a transport arc
174
 
 
175
 
                super.delete();
176
 
 
177
 
                //Avoid delete loop (but we need to save connected to for undo redo)
178
 
                TimedTransportArcComponent a = connectedTo;
179
 
                connectedTo = null;
180
 
                if (a != null && a.connectedTo != null) {
181
 
                        a.delete();
182
 
                }
183
 
                connectedTo = a;
184
 
 
185
 
        }
186
 
 
187
 
        @Override
188
 
        public void undelete(DrawingSurfaceImpl view) {
189
 
                super.undelete(view);
190
 
 
191
 
                //Avoid loop
192
 
                TimedTransportArcComponent a = connectedTo;
193
 
                connectedTo = null;
194
 
                if (a.connectedTo != null) {
195
 
                        a.undelete(view);
196
 
                        a.connectedTo = this;
197
 
                }
198
 
                connectedTo = a;
199
 
        }
200
 
 
201
149
        public boolean isInPreSet() {
202
150
                return isInPreSet;
203
151
        }
220
168
        }
221
169
 
222
170
        @Override
223
 
        public String getGuardAsString() {
224
 
                return getGuardAsString(true);
225
 
        }
226
 
 
227
 
        public String getGuardAsString(boolean showZeroToInfinityIntervals) {
228
 
                if (!showZeroToInfinityIntervals && !CreateGui.getApp().showZeroToInfinityIntervals() && underlyingTransportArc.interval().toString().equals("[0,inf)")) {
229
 
                        return "";
230
 
                } 
231
 
                return underlyingTransportArc.interval().toString();
232
 
        }
233
 
        
234
 
 
235
 
        @Override
236
171
        public TimeInterval getGuard() {
237
172
                return underlyingTransportArc.interval();
238
173
        }
269
204
                arc.setUnderlyingArc(tapn.getTransportArcFromPlaceTransitionAndPlace(tapn.getPlaceByName(underlyingTransportArc.source().name()), 
270
205
                                                                                                                                                         tapn.getTransitionByName(underlyingTransportArc.transition().name()), 
271
206
                                                                                                                                                         tapn.getPlaceByName(underlyingTransportArc.destination().name())));
272
 
                
273
 
                arc.getSource().addConnectFrom(arc);
274
 
                arc.getTarget().addConnectTo(arc);
 
207
 
275
208
                
276
209
                return arc;
277
210
        }