|
@@ -81,7 +81,21 @@ public class VisualisationInteractor implements MouseInputListener,
|
|
|
* Current y Position of the dragged device
|
|
|
*/
|
|
|
public int dragged_y;
|
|
|
-
|
|
|
+
|
|
|
+ public int dragged_x_start;
|
|
|
+
|
|
|
+ public int dragged_y_start;
|
|
|
+
|
|
|
+ public LinkedList<SmartDevice> selectedDevices = new LinkedList<SmartDevice>();
|
|
|
+
|
|
|
+ public static final byte NOTHING = 0;
|
|
|
+ public static final byte RIGHTCLICK_MENU = 1;
|
|
|
+ public static final byte DRAG_DEVICE = 2;
|
|
|
+ public static final byte DRAG_CONNECTION = 3;
|
|
|
+ public static final byte DRAG_SELECT = 4;
|
|
|
+ public static final byte SELECTED = 5;
|
|
|
+ public byte mode = NOTHING;
|
|
|
+
|
|
|
/**
|
|
|
* SmartDevice that was clicked
|
|
|
*/
|
|
@@ -124,6 +138,7 @@ public class VisualisationInteractor implements MouseInputListener,
|
|
|
popUp.setLocationRelativeTo(panel);
|
|
|
popUp.setEnabled(true);
|
|
|
popUp.setVisible(true);
|
|
|
+ mode = NOTHING;
|
|
|
|
|
|
});
|
|
|
|
|
@@ -137,6 +152,7 @@ public class VisualisationInteractor implements MouseInputListener,
|
|
|
controller.deleteSmartDevice(clicked);
|
|
|
clicked = null;
|
|
|
controller.notifyObservers();
|
|
|
+ mode = NOTHING;
|
|
|
});
|
|
|
|
|
|
rightClickMenu.add(itemDelete);
|
|
@@ -186,11 +202,11 @@ public class VisualisationInteractor implements MouseInputListener,
|
|
|
.getStatus() == Connection.TERMINATED)
|
|
|
terminated.add(c);
|
|
|
for (Packet p : c.getTerminationPackages(1000))
|
|
|
- System.out.println(p.toString());
|
|
|
+ System.out.println(p.getTextualRepresentation());
|
|
|
});
|
|
|
model.getConnections().removeAll(terminated);
|
|
|
controller.notifyObservers();
|
|
|
-
|
|
|
+ mode = NOTHING;
|
|
|
});
|
|
|
rightClickMenu.add(itemDebug);
|
|
|
|
|
@@ -253,6 +269,7 @@ public class VisualisationInteractor implements MouseInputListener,
|
|
|
rightClickMenu.show(panel, mousePos.x, mousePos.y);
|
|
|
rightClickMenu.setEnabled(true);
|
|
|
rightClickMenu.setVisible(true);
|
|
|
+ mode = RIGHTCLICK_MENU;
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -263,16 +280,24 @@ public class VisualisationInteractor implements MouseInputListener,
|
|
|
dragged_y = e.getY();
|
|
|
// Check if SmartDevice was clicked
|
|
|
SmartDevice pressedOn = getSmartDeviceAtPosition(e.getX(), e.getY());
|
|
|
- if (pressedOn == null)
|
|
|
+ if (pressedOn == null){
|
|
|
+ //Click drag - multi select
|
|
|
+ dragged_x_start = e.getX();
|
|
|
+ dragged_y_start = e.getY();
|
|
|
+ mode = DRAG_SELECT;
|
|
|
+ selectedDevices.clear();
|
|
|
return;
|
|
|
+ }
|
|
|
|
|
|
// Recognize possible drag operation
|
|
|
if (e.getButton() == MouseEvent.BUTTON1 && connectionFrom == null) {
|
|
|
dragged = pressedOn;
|
|
|
dragged_x = pressedOn.getX();
|
|
|
dragged_y = pressedOn.getY();
|
|
|
+ mode = DRAG_DEVICE;
|
|
|
} else if (e.getButton() == MouseEvent.BUTTON3 && dragged == null) {
|
|
|
connectionFrom = pressedOn;
|
|
|
+ mode = DRAG_CONNECTION;
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -280,9 +305,15 @@ public class VisualisationInteractor implements MouseInputListener,
|
|
|
public void mouseReleased(MouseEvent e) {
|
|
|
// Finish drag operation
|
|
|
// if (e.getButton() == MouseEvent.BUTTON1)
|
|
|
- finishDrag();
|
|
|
+ if(mode == DRAG_SELECT){
|
|
|
+ mode = SELECTED;
|
|
|
+ panel.repaint();
|
|
|
+ }
|
|
|
+ if(mode == DRAG_DEVICE)
|
|
|
+ finishDrag();
|
|
|
// else if(e.getButton() == MouseEvent.BUTTON3){
|
|
|
- finishConnectionCreation();
|
|
|
+ if(mode == DRAG_CONNECTION)
|
|
|
+ finishConnectionCreation();
|
|
|
// }
|
|
|
}
|
|
|
|
|
@@ -304,21 +335,56 @@ public class VisualisationInteractor implements MouseInputListener,
|
|
|
@Override
|
|
|
public void mouseDragged(MouseEvent e) {
|
|
|
// move dragged object on screen along y Axis
|
|
|
- if (e.getX() <= control.getDevice_visualization_radius())
|
|
|
- dragged_x = control.getDevice_visualization_radius();
|
|
|
- else if (e.getX() >= model.getWidth() - control.getDevice_visualization_radius())
|
|
|
- dragged_x = model.getWidth() - control.getDevice_visualization_radius();
|
|
|
- else
|
|
|
- dragged_x = e.getX();
|
|
|
- // move dragged object on screen along y Axis
|
|
|
- if (e.getY() <= control.getDevice_visualization_radius())
|
|
|
- dragged_y = control.getDevice_visualization_radius();
|
|
|
- else if (e.getY() >= model.getHeight() - control.getDevice_visualization_radius())
|
|
|
- dragged_y = model.getHeight() - control.getDevice_visualization_radius();
|
|
|
- else
|
|
|
- dragged_y = e.getY();
|
|
|
+ switch (mode) {
|
|
|
+ case DRAG_SELECT:
|
|
|
+ case DRAG_CONNECTION:
|
|
|
+ if (e.getX() < 0)
|
|
|
+ dragged_x = 0;
|
|
|
+ else if (e.getX() >= model.getWidth())
|
|
|
+ dragged_x = model.getWidth()-1;
|
|
|
+ else
|
|
|
+ dragged_x = e.getX();
|
|
|
+ // move dragged object on screen along y Axis
|
|
|
+ if (e.getY() < 0)
|
|
|
+ dragged_y = 0;
|
|
|
+ else if (e.getY() >= model.getHeight())
|
|
|
+ dragged_y = model.getHeight()-1;
|
|
|
+ else
|
|
|
+ dragged_y = e.getY();
|
|
|
+ if(mode == DRAG_CONNECTION)break;
|
|
|
+ int min_x = Math.min(dragged_x, dragged_x_start);
|
|
|
+ int min_y = Math.min(dragged_y, dragged_y_start);
|
|
|
+ int max_x = Math.max(dragged_x, dragged_x_start);
|
|
|
+ int max_y = Math.max(dragged_y, dragged_y_start);
|
|
|
+ selectedDevices.removeIf(s->(s.getX()<min_x||s.getX()>max_x||s.getY()<min_y||s.getY()>max_y));
|
|
|
+ for(SmartDevice sel:model.getDevices()){
|
|
|
+ if(sel.getX()>=min_x&&sel.getX()<=max_x&&sel.getY()>=min_y&&sel.getY()<=max_y&&!selectedDevices.contains(sel)){
|
|
|
+ selectedDevices.add(sel);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case DRAG_DEVICE:
|
|
|
+ if (e.getX() <= control.getDevice_visualization_radius())
|
|
|
+ dragged_x = control.getDevice_visualization_radius();
|
|
|
+ else if (e.getX() >= model.getWidth() - control.getDevice_visualization_radius())
|
|
|
+ dragged_x = model.getWidth() - control.getDevice_visualization_radius();
|
|
|
+ else
|
|
|
+ dragged_x = e.getX();
|
|
|
+ // move dragged object on screen along y Axis
|
|
|
+ if (e.getY() <= control.getDevice_visualization_radius())
|
|
|
+ dragged_y = control.getDevice_visualization_radius();
|
|
|
+ else if (e.getY() >= model.getHeight() - control.getDevice_visualization_radius())
|
|
|
+ dragged_y = model.getHeight() - control.getDevice_visualization_radius();
|
|
|
+ else
|
|
|
+ dragged_y = e.getY();
|
|
|
+ break;
|
|
|
+
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
// repaint the dragged smartDevice or new connection
|
|
|
- if (dragged != null || connectionFrom != null)
|
|
|
+ if (dragged != null || connectionFrom != null||mode==DRAG_SELECT)
|
|
|
panel.repaint();
|
|
|
}
|
|
|
|
|
@@ -338,6 +404,7 @@ public class VisualisationInteractor implements MouseInputListener,
|
|
|
dragged.getZ());
|
|
|
dragged = null;
|
|
|
model.notifyObservers();
|
|
|
+ mode = NOTHING;
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -376,6 +443,7 @@ public class VisualisationInteractor implements MouseInputListener,
|
|
|
connectionFrom = null;
|
|
|
}
|
|
|
control.notifyObservers();
|
|
|
+ mode = NOTHING;
|
|
|
}
|
|
|
|
|
|
/**
|