18
18
import pipe.dataLayer.PetriNetObject;
19
19
import pipe.dataLayer.PlaceTransitionObject;
23
* @author Peter Kyme, Michael Camacho
24
* Class to handle selection rectangle functionality
22
* @author Peter Kyme, Michael Camacho Class to handle selection rectangle
26
public class SelectionManager
27
extends javax.swing.JComponent
28
implements java.awt.event.MouseListener,
29
java.awt.event.MouseWheelListener,
30
java.awt.event.MouseMotionListener {
25
public class SelectionManager extends javax.swing.JComponent implements
26
java.awt.event.MouseListener, java.awt.event.MouseWheelListener,
27
java.awt.event.MouseMotionListener {
35
32
private static final long serialVersionUID = 9057152447545103393L;
36
private Point startPoint;
37
private Rectangle selectionRectangle = new Rectangle(-1,-1);
38
private boolean isSelecting;
39
private static final Color selectionColor = new Color(000, 000, 255, 030);
40
private static final Color selectionColorOutline = new Color(000, 000, 100);
42
private boolean enabled = true;
45
public SelectionManager(GuiView _view) {
46
addMouseListener(this);
47
addMouseMotionListener(this);
48
addMouseWheelListener(this);
53
public void updateBounds() {
54
if (enabled == true) {
55
setBounds(0,0,view.getWidth(),view.getHeight());
60
public void enableSelection() {
61
if (enabled == false) {
69
public void disableSelection() {
70
if (enabled == true) {
77
private void processSelection(MouseEvent e) {
78
if (!e.isShiftDown()){
82
// Get all the objects in the current window
83
ArrayList <PetriNetObject> pnObjects = view.getPNObjects();
84
for (PetriNetObject pnObject : pnObjects) {
85
pnObject.select(selectionRectangle);
91
public void paintComponent(Graphics g) {
92
super.paintComponent(g);
93
Graphics2D g2d = (Graphics2D) g;
94
g2d.setPaint(selectionColor);
95
g2d.fill(selectionRectangle);
96
g2d.setPaint(selectionColorOutline);
97
g2d.draw(selectionRectangle);
101
public void deleteSelection() {
102
// Get all the objects in the current window
103
ArrayList <PetriNetObject> pnObjects = view.getPNObjects();
104
for (int i = 0; i < pnObjects.size(); i++) {
105
if (pnObjects.get(i).isSelected()) {
106
pnObjects.get(i).delete();
109
view.updatePreferredSize();
113
public void clearSelection() {
114
// Get all the objects in the current window
115
ArrayList <PetriNetObject> pnObjects = view.getPNObjects();
116
for (PetriNetObject pnObject : pnObjects) {
117
if (pnObject.isSelectable()) {
33
private Point startPoint;
34
private Rectangle selectionRectangle = new Rectangle(-1, -1);
35
private boolean isSelecting;
36
private static final Color selectionColor = new Color(000, 000, 255, 030);
37
private static final Color selectionColorOutline = new Color(000, 000, 100);
38
private DrawingSurfaceImpl drawingSurface;
39
private boolean enabled = true;
41
public SelectionManager(DrawingSurfaceImpl _view) {
42
addMouseListener(this);
43
addMouseMotionListener(this);
44
addMouseWheelListener(this);
45
this.drawingSurface = _view;
48
public void updateBounds() {
49
if (enabled == true) {
50
setBounds(0, 0, drawingSurface.getWidth(), drawingSurface.getHeight());
54
public void enableSelection() {
55
if (enabled == false) {
56
drawingSurface.add(this);
62
public void disableSelection() {
63
if (enabled == true) {
64
this.clearSelection();
65
drawingSurface.remove(this);
70
private void processSelection(MouseEvent e) {
71
if (!e.isShiftDown()) {
75
// Get all the objects in the current window
76
ArrayList<PetriNetObject> pnObjects = drawingSurface.getPNObjects();
77
for (PetriNetObject pnObject : pnObjects) {
78
pnObject.select(selectionRectangle);
83
public void paintComponent(Graphics g) {
84
super.paintComponent(g);
85
Graphics2D g2d = (Graphics2D) g;
86
g2d.setPaint(selectionColor);
87
g2d.fill(selectionRectangle);
88
g2d.setPaint(selectionColorOutline);
89
g2d.draw(selectionRectangle);
92
public void deleteSelection() {
93
// Get all the objects in the current window
94
ArrayList<PetriNetObject> pnObjects = drawingSurface.getPNObjects();
95
for (int i = 0; i < pnObjects.size(); i++) {
96
if (pnObjects.get(i).isSelected()) {
97
pnObjects.get(i).delete();
100
drawingSurface.updatePreferredSize();
103
public void clearSelection() {
104
// Get all the objects in the current window
105
ArrayList<PetriNetObject> pnObjects = drawingSurface.getPNObjects();
106
for (PetriNetObject pnObject : pnObjects) {
107
if (pnObject.isSelectable()) {
124
113
public void translateSelection(int transX, int transY) {
126
if (transX == 0 && transY == 0) {
130
// First see if translation will put anything at a negative location
132
Point topleft = null;
134
// Get all the objects in the current window
135
ArrayList <PetriNetObject> pnObjects = view.getPNObjects();
136
for (PetriNetObject pnObject : pnObjects) {
137
if (pnObject.isSelected()){
138
point = pnObject.getLocation();
139
if (topleft == null) {
142
if (point.x < topleft.x) {
145
if (point.y < topleft.y) {
152
if (topleft != null) {
153
topleft.translate(transX, transY);
160
if (transX == 0 && transY == 0){
165
for (PetriNetObject pnObject : pnObjects) {
166
if (pnObject.isSelected()) {
167
pnObject.translate(transX, transY);
170
view.updatePreferredSize();
174
public ArrayList<PetriNetObject> getSelection() {
175
ArrayList<PetriNetObject> selection = new ArrayList<PetriNetObject>();
177
// Get all the objects in the current window
178
ArrayList <PetriNetObject> pnObjects = view.getPNObjects();
179
for (PetriNetObject pnObject : pnObjects) {
180
if (pnObject.isSelected()){
181
selection.add(pnObject);
189
* @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent)
191
public void mousePressed(MouseEvent e) {
192
if (e.getButton() == MouseEvent.BUTTON1 && !(e.isControlDown())) {
194
view.setLayer(this, Pipe.SELECTION_LAYER_OFFSET);
195
startPoint = e.getPoint();
196
selectionRectangle.setRect(startPoint.getX(), startPoint.getY(), 0, 0);
197
// Select anything that intersects with the rectangle.
201
startPoint = e.getPoint();
207
* @see java.awt.event.MouseListener#mouseReleased(java.awt.event.MouseEvent)
209
public void mouseReleased(MouseEvent e) {
210
if (isSelecting == true) {
211
// Select anything that intersects with the rectangle.
214
view.setLayer(this, Pipe.LOWEST_LAYER_OFFSET);
215
selectionRectangle.setRect(-1, -1, 0, 0);
222
* @see java.awt.event.MouseMotionListener#mouseDragged(java.awt.event.MouseEvent)
224
public void mouseDragged(MouseEvent e) {
226
selectionRectangle.setSize(
227
(int)Math.abs(e.getX() - startPoint.getX()),
228
(int)Math.abs(e.getY() - startPoint.getY()));
229
selectionRectangle.setLocation(
230
(int)Math.min(startPoint.getX(), e.getX()),
231
(int)Math.min(startPoint.getY(), e.getY()));
232
// Select anything that intersects with the rectangle.
236
view.drag(startPoint, e.getPoint());
241
public void mouseWheelMoved(MouseWheelEvent e) {
242
if (e.isControlDown()) {
243
if (e.getWheelRotation()> 0) {
251
public void mouseClicked(MouseEvent e) {
256
public void mouseEntered(MouseEvent e) {
261
public void mouseExited(MouseEvent e) {
267
* @see java.awt.event.MouseMotionListener#mouseMoved(java.awt.event.MouseEvent)
269
public void mouseMoved(MouseEvent e) {
274
public int getSelectionCount() {
275
Component netObj[] = view.getComponents();
276
int selectionCount = 0;
277
// Get all the objects in the current window
278
for (int i=0; i< netObj.length; i++) {
279
// Handle Arcs and Arc Points
280
if ((netObj[i] instanceof Arc) && ((PetriNetObject)netObj[i]).isSelectable()) {
281
Arc thisArc = (Arc)netObj[i];
282
ArcPath thisArcPath = thisArc.getArcPath();
283
for (int j=1; j < thisArcPath.getEndIndex(); j++){
284
if (thisArcPath.isPointSelected(j)) {
290
// Handle PlaceTransition Objects
291
if ((netObj[i] instanceof PlaceTransitionObject) &&
292
((PetriNetObject)netObj[i]).isSelectable()) {
293
if (((PlaceTransitionObject)netObj[i]).isSelected()) {
298
return selectionCount;
115
if (transX == 0 && transY == 0) {
119
// First see if translation will put anything at a negative location
121
Point topleft = null;
123
// Get all the objects in the current window
124
ArrayList<PetriNetObject> pnObjects = drawingSurface.getPNObjects();
125
for (PetriNetObject pnObject : pnObjects) {
126
if (pnObject.isSelected()) {
127
point = pnObject.getLocation();
128
if (topleft == null) {
131
if (point.x < topleft.x) {
134
if (point.y < topleft.y) {
141
if (topleft != null) {
142
topleft.translate(transX, transY);
149
if (transX == 0 && transY == 0) {
154
for (PetriNetObject pnObject : pnObjects) {
155
if (pnObject.isSelected()) {
156
pnObject.translate(transX, transY);
159
drawingSurface.updatePreferredSize();
162
public ArrayList<PetriNetObject> getSelection() {
163
ArrayList<PetriNetObject> selection = new ArrayList<PetriNetObject>();
165
// Get all the objects in the current window
166
ArrayList<PetriNetObject> pnObjects = drawingSurface.getPNObjects();
167
for (PetriNetObject pnObject : pnObjects) {
168
if (pnObject.isSelected()) {
169
selection.add(pnObject);
178
* @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent)
180
public void mousePressed(MouseEvent e) {
181
if (e.getButton() == MouseEvent.BUTTON1 && !(e.isControlDown())) {
183
drawingSurface.setLayer(this, Pipe.SELECTION_LAYER_OFFSET);
184
startPoint = e.getPoint();
185
selectionRectangle.setRect(startPoint.getX(), startPoint.getY(), 0,
187
// Select anything that intersects with the rectangle.
191
startPoint = e.getPoint();
199
* java.awt.event.MouseListener#mouseReleased(java.awt.event.MouseEvent)
201
public void mouseReleased(MouseEvent e) {
202
if (isSelecting == true) {
203
// Select anything that intersects with the rectangle.
206
drawingSurface.setLayer(this, Pipe.LOWEST_LAYER_OFFSET);
207
selectionRectangle.setRect(-1, -1, 0, 0);
216
* java.awt.event.MouseMotionListener#mouseDragged(java.awt.event.MouseEvent
219
public void mouseDragged(MouseEvent e) {
221
selectionRectangle.setSize((int) Math.abs(e.getX()
222
- startPoint.getX()), (int) Math.abs(e.getY()
223
- startPoint.getY()));
224
selectionRectangle.setLocation((int) Math.min(startPoint.getX(), e
225
.getX()), (int) Math.min(startPoint.getY(), e.getY()));
226
// Select anything that intersects with the rectangle.
230
drawingSurface.drag(startPoint, e.getPoint());
234
public void mouseWheelMoved(MouseWheelEvent e) {
235
if (e.isControlDown()) {
236
if (e.getWheelRotation() > 0) {
237
drawingSurface.zoomIn();
239
drawingSurface.zoomOut();
244
public void mouseClicked(MouseEvent e) {
248
public void mouseEntered(MouseEvent e) {
252
public void mouseExited(MouseEvent e) {
260
* java.awt.event.MouseMotionListener#mouseMoved(java.awt.event.MouseEvent)
262
public void mouseMoved(MouseEvent e) {
266
public int getSelectionCount() {
267
Component netObj[] = drawingSurface.getComponents();
268
int selectionCount = 0;
269
// Get all the objects in the current window
270
for (int i = 0; i < netObj.length; i++) {
271
// Handle Arcs and Arc Points
272
if ((netObj[i] instanceof Arc)
273
&& ((PetriNetObject) netObj[i]).isSelectable()) {
274
Arc thisArc = (Arc) netObj[i];
275
ArcPath thisArcPath = thisArc.getArcPath();
276
for (int j = 1; j < thisArcPath.getEndIndex(); j++) {
277
if (thisArcPath.isPointSelected(j)) {
283
// Handle PlaceTransition Objects
284
if ((netObj[i] instanceof PlaceTransitionObject)
285
&& ((PetriNetObject) netObj[i]).isSelectable()) {
286
if (((PlaceTransitionObject) netObj[i]).isSelected()) {
291
return selectionCount;