|
@@ -40,22 +40,23 @@ public class VisualisationInteractor implements MouseInputListener, MouseMotionL
|
|
|
* Panel which is observed
|
|
|
*/
|
|
|
private VisualisationPanel panel;
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* Menu which is shown on right clicks
|
|
|
*/
|
|
|
private JPopupMenu rightClickMenu;
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
- * RightClick MenuItem for SmartDevice creation
|
|
|
+ * RightClick MenuItem for SmartDevice creation**
|
|
|
+ * Finishes the drag operation, if a SmartDevice was dragged, repaint the panel and set dragged
|
|
|
*/
|
|
|
private JMenuItem itemCreate;
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* RightClick MenuItem for SmartDevice deletion
|
|
|
*/
|
|
|
private JMenuItem itemDelete;
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* SmartDevice that is dragged on Screen
|
|
|
*/
|
|
@@ -70,55 +71,65 @@ public class VisualisationInteractor implements MouseInputListener, MouseMotionL
|
|
|
* Current y Position of the dragged device
|
|
|
*/
|
|
|
public int dragged_y;
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* SmartDevice that was clicked
|
|
|
*/
|
|
|
private SmartDevice clicked = null;
|
|
|
|
|
|
/**
|
|
|
- * Creates a new VisualisationInteractor
|
|
|
- *
|
|
|
+ * Creates a new VisualisationInteractor**
|
|
|
+ * Finishes the drag operation, if a SmartDevice was dragged, repaint the panel and set dragged
|
|
|
+ *
|
|
|
* @param model
|
|
|
* @param controller
|
|
|
*/
|
|
|
public VisualisationInteractor(Model model, Controller controller, VisualisationPanel panel) {
|
|
|
+ //Initialize the values
|
|
|
this.model = model;
|
|
|
this.control = controller;
|
|
|
this.panel = panel;
|
|
|
+
|
|
|
this.rightClickMenu = new JPopupMenu();
|
|
|
itemCreate = new JMenuItem("Create SmartDevice");
|
|
|
itemDelete = new JMenuItem("Delete");
|
|
|
+
|
|
|
itemDelete.addActionListener(e -> {
|
|
|
+ //Delete the clicked object
|
|
|
controller.deleteSmartDevice(clicked);
|
|
|
clicked = null;
|
|
|
panel.repaint();
|
|
|
- });
|
|
|
- itemCreate.addActionListener(e -> {
|
|
|
- for (Link l : model.getConnectionNetworks())
|
|
|
- System.out.println("Link: " + l.getName());
|
|
|
- for (SmartDevice d : model.getDevices()) {
|
|
|
- System.out.println("Device: " + d.getName());
|
|
|
- for (Connection c : d.getConnections()) {
|
|
|
- if (c.getSource() == null)
|
|
|
+ });
|
|
|
+
|
|
|
+ itemCreate.addActionListener(e->{
|
|
|
+ //Print Links, Devices and Connections
|
|
|
+ for(Link l:model.getConnectionNetworks())
|
|
|
+ System.out.println("Link: "+l.getName());
|
|
|
+ for(SmartDevice d: model.getDevices()){
|
|
|
+ System.out.println("Device: "+d.getName());
|
|
|
+ for(Connection c: d.getConnections()){
|
|
|
+ if(c.getSource()==null)
|
|
|
System.out.println("Connection: terminated");
|
|
|
else
|
|
|
- System.out.println("Connection: " + c.getSource().getName());
|
|
|
+ System.out.println("Connection: "+c.getSource().getName());
|
|
|
}
|
|
|
}
|
|
|
- for (Connection c : model.getTerminatingConnections()) {
|
|
|
- for (Packet p : c.getTerminationPackages(1000))
|
|
|
+ //Print Terminating Packages
|
|
|
+ for(Connection c: model.getTerminatingConnections()){
|
|
|
+ for(Packet p:c.getTerminationPackages(1000))
|
|
|
System.out.println(p.toString());
|
|
|
}
|
|
|
});
|
|
|
+
|
|
|
rightClickMenu.add(itemCreate);
|
|
|
rightClickMenu.add(itemDelete);
|
|
|
+
|
|
|
this.panel.add(rightClickMenu);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void mouseClicked(MouseEvent e) {
|
|
|
- if (dragged != null) {
|
|
|
+ if(dragged!=null){
|
|
|
finishDrag();
|
|
|
}
|
|
|
/*
|
|
@@ -132,37 +143,36 @@ public class VisualisationInteractor implements MouseInputListener, MouseMotionL
|
|
|
clicked = d;
|
|
|
}
|
|
|
}
|
|
|
- // If Rightclick
|
|
|
- if (e.getButton() == MouseEvent.BUTTON3) {
|
|
|
- // Show the RightClickMenu
|
|
|
- showRightClickMenu(clicked);
|
|
|
+ //If Rightclick
|
|
|
+ if(e.getButton()==MouseEvent.BUTTON3) {
|
|
|
+ //Show the RightClickMenu
|
|
|
+ showRightClickMenu(clicked);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Shows the RightClick Menu on the Visualisation Panel, with Options for
|
|
|
- * the given SmartDevice clickedOn, 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.
|
|
|
- *
|
|
|
- * @param clickedOn
|
|
|
- * Device which was clicked, null if no
|
|
|
+ * Shows the RightClick Menu on the Visualisation Panel, with Options for the given SmartDevice clickedOn,
|
|
|
+ * 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.
|
|
|
+ * @param clickedOn Device which was clicked, null if no
|
|
|
*/
|
|
|
protected void showRightClickMenu(SmartDevice clickedOn) {
|
|
|
/**
|
|
|
* Mouse Position on the VisualisationPanel
|
|
|
*/
|
|
|
Point mousePos = panel.getMousePosition();
|
|
|
- // Just execute if Mouse Position is on the Panel
|
|
|
- if (mousePos != null) {
|
|
|
- if (clickedOn == null) {
|
|
|
+ //Just execute if Mouse Position is on the Panel
|
|
|
+ if(mousePos != null){
|
|
|
+ if(clickedOn == null){
|
|
|
itemCreate.setEnabled(true);
|
|
|
itemDelete.setEnabled(false);
|
|
|
- } else {
|
|
|
+ }
|
|
|
+ else{
|
|
|
itemCreate.setEnabled(false);
|
|
|
itemDelete.setEnabled(true);
|
|
|
}
|
|
|
+ //Show the RightClickMenu
|
|
|
rightClickMenu.show(panel, mousePos.x, mousePos.y);
|
|
|
rightClickMenu.setEnabled(true);
|
|
|
rightClickMenu.setVisible(true);
|
|
@@ -223,20 +233,20 @@ public class VisualisationInteractor implements MouseInputListener, MouseMotionL
|
|
|
dragged_y = model.getHeight() - panel.getVisualisationRadius();
|
|
|
else
|
|
|
dragged_y = e.getY();
|
|
|
- // repaint the drag
|
|
|
+ // repaint the dragged smartDevice
|
|
|
if (dragged != null)
|
|
|
panel.repaint();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void mouseMoved(MouseEvent e) {
|
|
|
+
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
- * Finishes the drag operation, if a SmartDevice was dragged, repaint the
|
|
|
- * panel and set dragged==null
|
|
|
+ * Finishes the drag operation, if a SmartDevice was dragged, repaint the panel and set dragged to null
|
|
|
*/
|
|
|
- public void finishDrag() {
|
|
|
+ public void finishDrag(){
|
|
|
if (dragged != null && (dragged.getX() != dragged_x || dragged.getY() != dragged_y)) {
|
|
|
control.moveSmartDevice(dragged, dragged_x, dragged_y, dragged.getZ());
|
|
|
panel.repaint();
|