~tapaal-contributor/tapaal/change-export-batch-shortcut-1820012

« back to all changes in this revision

Viewing changes to src/pipe/gui/SelectionManager.java

  • Committer: Kenneth Yrke Jørgensen
  • Date: 2019-03-13 07:17:48 UTC
  • mfrom: (989 tapaal)
  • mto: This revision was merged to the branch mainline in revision 991.
  • Revision ID: kenneth@yrke.dk-20190313071748-fm6dc00yy27un3xd
Merged with trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
                java.awt.event.MouseListener, java.awt.event.MouseWheelListener,
29
29
                java.awt.event.MouseMotionListener {
30
30
 
31
 
        /**
32
 
         * 
33
 
         */
34
31
        private static final long serialVersionUID = 9057152447545103393L;
35
32
        private Point startPoint;
36
33
        private Rectangle selectionRectangle = new Rectangle(-1, -1);
91
88
                g2d.draw(selectionRectangle);
92
89
        }
93
90
 
94
 
        public void deleteSelection() {
95
 
                // Get all the objects in the current window
96
 
                ArrayList<PetriNetObject> pnObjects = drawingSurface.getPNObjects();
97
 
                for (int i = 0; i < pnObjects.size(); i++) {
98
 
                        if (pnObjects.get(i).isSelected()) {
99
 
                                pnObjects.get(i).delete();
100
 
                        }
101
 
                }
102
 
                drawingSurface.updatePreferredSize();
103
 
        }
104
 
 
105
91
        public void clearSelection() {
106
92
                // Get all the objects in the current window
107
93
                ArrayList<PetriNetObject> pnObjects = drawingSurface.getPNObjects();
174
160
                return selection;
175
161
        }
176
162
 
177
 
        /*
178
 
         * (non-Javadoc)
179
 
         * 
180
 
         * @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent)
181
 
         */
182
163
        public void mousePressed(MouseEvent e) {
183
164
                CreateGui.getCurrentTab().removeConstantHighlights();
184
165
                if (e.getButton() == MouseEvent.BUTTON1 && !(e.isControlDown())) {
185
166
                        isSelecting = true;
186
167
                        drawingSurface.setLayer(this, Pipe.SELECTION_LAYER_OFFSET);
187
168
                        startPoint = e.getPoint();
188
 
                        selectionRectangle.setRect(startPoint.getX(), startPoint.getY(), 0,
189
 
                                        0);
 
169
                        selectionRectangle.setRect(startPoint.getX(), startPoint.getY(), 0, 0);
190
170
                        // Select anything that intersects with the rectangle.
191
171
                        processSelection(e);
192
172
                        repaint();
195
175
                }
196
176
        }
197
177
 
198
 
        /*
199
 
         * (non-Javadoc)
200
 
         * 
201
 
         * @see
202
 
         * java.awt.event.MouseListener#mouseReleased(java.awt.event.MouseEvent)
203
 
         */
204
178
        public void mouseReleased(MouseEvent e) {
205
179
                if (isSelecting) {
206
180
                        // Select anything that intersects with the rectangle.
212
186
                }
213
187
        }
214
188
 
215
 
        /*
216
 
         * (non-Javadoc)
217
 
         * 
218
 
         * @see
219
 
         * java.awt.event.MouseMotionListener#mouseDragged(java.awt.event.MouseEvent
220
 
         * )
221
 
         */
222
189
        public void mouseDragged(MouseEvent e) {
223
190
                if(CreateGui.getApp().getGUIMode().equals(GUIMode.animation)) return;
224
191
                
255
222
        public void mouseExited(MouseEvent e) {
256
223
        }
257
224
 
258
 
        /*
259
 
         * (non-Javadoc)
260
 
         * 
261
 
         * @see
262
 
         * java.awt.event.MouseMotionListener#mouseMoved(java.awt.event.MouseEvent)
263
 
         */
264
225
        public void mouseMoved(MouseEvent e) {
265
226
        }
266
227
 
272
233
                drawingSurface.repaint();
273
234
        }
274
235
 
275
 
        public int getSelectionCount() {
276
 
                Component[] netObj = drawingSurface.getComponents();
277
 
                int selectionCount = 0;
278
 
                // Get all the objects in the current window
279
 
                for (int i = 0; i < netObj.length; i++) {
280
 
                        // Handle Arcs and Arc Points
281
 
                        if ((netObj[i] instanceof Arc)
282
 
                                        && ((PetriNetObject) netObj[i]).isSelectable()) {
283
 
                                Arc thisArc = (Arc) netObj[i];
284
 
                                ArcPath thisArcPath = thisArc.getArcPath();
285
 
                                for (int j = 1; j < thisArcPath.getEndIndex(); j++) {
286
 
                                        if (thisArcPath.isPointSelected(j)) {
287
 
                                                selectionCount++;
288
 
                                        }
289
 
                                }
290
 
                        }
291
 
 
292
 
                        // Handle PlaceTransition Objects
293
 
                        if ((netObj[i] instanceof PlaceTransitionObject)
294
 
                                        && ((PetriNetObject) netObj[i]).isSelectable()) {
295
 
                                if (((PlaceTransitionObject) netObj[i]).isSelected()) {
296
 
                                        selectionCount++;
297
 
                                }
298
 
                        }
299
 
                }
300
 
                return selectionCount;
301
 
        }
302
 
 
303
236
}