|
@@ -16,11 +16,14 @@ import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.Link;
|
|
import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.Model;
|
|
import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.Model;
|
|
import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.Packet;
|
|
import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.Packet;
|
|
import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.SmartDevice;
|
|
import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.SmartDevice;
|
|
|
|
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.simpleImplementation.SimpleConnection;
|
|
|
|
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.simpleImplementation.SimpleLink;
|
|
|
|
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.simpleImplementation.SimpleProtocol;
|
|
|
|
|
|
/**
|
|
/**
|
|
* Listener which detects User Interaction with the {@link VisualisationPanel},
|
|
* Listener which detects User Interaction with the {@link VisualisationPanel},
|
|
* stores interaction information, triggers the controller and helps
|
|
* stores interaction information, triggers the controller and helps
|
|
- * visualisation of the interaction
|
|
|
|
|
|
+ * visualization of the interaction
|
|
*
|
|
*
|
|
* @author Andreas T. Meyer-Berg
|
|
* @author Andreas T. Meyer-Berg
|
|
*/
|
|
*/
|
|
@@ -77,6 +80,7 @@ public class VisualisationInteractor implements MouseInputListener, MouseMotionL
|
|
*/
|
|
*/
|
|
private SmartDevice clicked = null;
|
|
private SmartDevice clicked = null;
|
|
|
|
|
|
|
|
+ public SmartDevice connectionFrom = null;
|
|
|
|
|
|
/**
|
|
/**
|
|
* Creates a new VisualisationInteractor
|
|
* Creates a new VisualisationInteractor
|
|
@@ -130,9 +134,12 @@ public class VisualisationInteractor implements MouseInputListener, MouseMotionL
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public void mouseClicked(MouseEvent e) {
|
|
public void mouseClicked(MouseEvent e) {
|
|
|
|
+ //Finish operations
|
|
if(dragged!=null){
|
|
if(dragged!=null){
|
|
finishDrag();
|
|
finishDrag();
|
|
}
|
|
}
|
|
|
|
+ connectionFrom =null;
|
|
|
|
+
|
|
/*
|
|
/*
|
|
* FindSmartDevice that was clicked
|
|
* FindSmartDevice that was clicked
|
|
*/
|
|
*/
|
|
@@ -153,7 +160,7 @@ public class VisualisationInteractor implements MouseInputListener, MouseMotionL
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * Shows the RightClick Menu on the Visualisation Panel, with Options for the given SmartDevice clickedOn,
|
|
|
|
|
|
+ * Shows the RightClick Menu on the Visualization Panel, with Options for the given SmartDevice clickedOn,
|
|
* if clickedOn is null, the RightClick Menu contains Options for creation of new SmartDevices.
|
|
* if clickedOn is null, the RightClick Menu contains Options for creation of new SmartDevices.
|
|
* The Menu will be shown at the Mouse position on the VisualisationPanel.
|
|
* The Menu will be shown at the Mouse position on the VisualisationPanel.
|
|
* @param clickedOn Device which was clicked, null if no
|
|
* @param clickedOn Device which was clicked, null if no
|
|
@@ -183,24 +190,27 @@ public class VisualisationInteractor implements MouseInputListener, MouseMotionL
|
|
@Override
|
|
@Override
|
|
public void mousePressed(MouseEvent e) {
|
|
public void mousePressed(MouseEvent e) {
|
|
// Check if SmartDevice was clicked
|
|
// Check if SmartDevice was clicked
|
|
- for (SmartDevice d : model.getDevices()) {
|
|
|
|
- if (Math.abs(d.getX() - e.getX()) < panel.getVisualisationRadius()
|
|
|
|
- && Math.abs(d.getY() - e.getY()) < panel.getVisualisationRadius()) {
|
|
|
|
- // Recognize possible drag operation
|
|
|
|
- if (e.getButton() == MouseEvent.BUTTON1) {
|
|
|
|
- dragged = d;
|
|
|
|
- dragged_x = d.getX();
|
|
|
|
- dragged_y = d.getY();
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ SmartDevice pressedOn = getSmartDeviceAtPosition(e.getX(), e.getY());
|
|
|
|
+ if(pressedOn == null)return;
|
|
|
|
+
|
|
|
|
+ // Recognize possible drag operation
|
|
|
|
+ if (e.getButton() == MouseEvent.BUTTON1 && connectionFrom == null) {
|
|
|
|
+ dragged = pressedOn;
|
|
|
|
+ dragged_x = pressedOn.getX();
|
|
|
|
+ dragged_y = pressedOn.getY();
|
|
|
|
+ } else if(e.getButton() == MouseEvent.BUTTON3 && dragged == null){
|
|
|
|
+ connectionFrom = pressedOn;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public void mouseReleased(MouseEvent e) {
|
|
public void mouseReleased(MouseEvent e) {
|
|
// Finish drag operation
|
|
// Finish drag operation
|
|
- if (e.getButton() == MouseEvent.BUTTON1)
|
|
|
|
|
|
+ //if (e.getButton() == MouseEvent.BUTTON1)
|
|
finishDrag();
|
|
finishDrag();
|
|
|
|
+ //else if(e.getButton() == MouseEvent.BUTTON3){
|
|
|
|
+ finishConnectionCreation();
|
|
|
|
+ //}
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -234,8 +244,8 @@ public class VisualisationInteractor implements MouseInputListener, MouseMotionL
|
|
dragged_y = model.getHeight() - panel.getVisualisationRadius();
|
|
dragged_y = model.getHeight() - panel.getVisualisationRadius();
|
|
else
|
|
else
|
|
dragged_y = e.getY();
|
|
dragged_y = e.getY();
|
|
- // repaint the dragged smartDevice
|
|
|
|
- if (dragged != null)
|
|
|
|
|
|
+ // repaint the dragged smartDevice or new connection
|
|
|
|
+ if (dragged != null || connectionFrom != null)
|
|
panel.repaint();
|
|
panel.repaint();
|
|
}
|
|
}
|
|
|
|
|
|
@@ -254,4 +264,48 @@ public class VisualisationInteractor implements MouseInputListener, MouseMotionL
|
|
dragged = null;
|
|
dragged = null;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Finishes the create connection operation and open a PopUp for Link/Connection creation
|
|
|
|
+ */
|
|
|
|
+ private void finishConnectionCreation() {
|
|
|
|
+ /**
|
|
|
|
+ * SmartDevice the connection was
|
|
|
|
+ */
|
|
|
|
+ SmartDevice connectionTo = getSmartDeviceAtPosition(dragged_x, dragged_y);
|
|
|
|
+ if(connectionFrom != null && connectionTo != null && connectionFrom != connectionTo){
|
|
|
|
+ //Create new Connection
|
|
|
|
+ Link l = new SimpleLink("Ethernet: "+connectionFrom.getName()+" to "+connectionTo.getName());
|
|
|
|
+ l.addDevice(connectionFrom);
|
|
|
|
+ l.addDevice(connectionTo);
|
|
|
|
+ Connection c = new SimpleConnection(connectionFrom, connectionTo, l, new SimpleProtocol(connectionFrom, connectionTo));
|
|
|
|
+ connectionTo.addLink(l);
|
|
|
|
+ connectionTo.addConnection(c);
|
|
|
|
+ connectionFrom.addLink(l);
|
|
|
|
+ connectionFrom.addConnection(c);
|
|
|
|
+ connectionFrom = null;
|
|
|
|
+ }else{
|
|
|
|
+ connectionFrom = null;
|
|
|
|
+ }
|
|
|
|
+ panel.repaint();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Returns SmartDevice which is at position (x,y) or within its visualization radius.
|
|
|
|
+ * Returns null, if no SmartDevice is within the range.
|
|
|
|
+ *
|
|
|
|
+ * @param x x-position which should be checked
|
|
|
|
+ * @param y y-position which should be checked
|
|
|
|
+ * @return {@link SmartDevice} at position (x,y) or null if there is no
|
|
|
|
+ */
|
|
|
|
+ private SmartDevice getSmartDeviceAtPosition(int x, int y) {
|
|
|
|
+ //Check is device is inside visualization radius
|
|
|
|
+ for (SmartDevice d : model.getDevices()) {
|
|
|
|
+ if (Math.abs(d.getX() - x) < panel.getVisualisationRadius()
|
|
|
|
+ && Math.abs(d.getY() - y) < panel.getVisualisationRadius()) {
|
|
|
|
+ return d;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
}
|
|
}
|