|
@@ -63,6 +63,11 @@ public class VisualisationInteractor implements MouseInputListener,
|
|
|
* RightClick MenuItem for SmartDevice deletion
|
|
|
*/
|
|
|
private JMenuItem itemDelete;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * RightClick MenuItem for deletion of multiple selected SmartDevices
|
|
|
+ */
|
|
|
+ private JMenuItem itemDeleteSelected;
|
|
|
|
|
|
/**
|
|
|
* RightClick MenuItem for debug purposes
|
|
@@ -176,7 +181,22 @@ public class VisualisationInteractor implements MouseInputListener,
|
|
|
});
|
|
|
|
|
|
rightClickMenu.add(itemDelete);
|
|
|
-
|
|
|
+
|
|
|
+ // Delete device option
|
|
|
+ itemDeleteSelected = new JMenuItem("Delete Selected");
|
|
|
+
|
|
|
+ itemDeleteSelected.addActionListener(e -> {
|
|
|
+ // Delete the clicked object
|
|
|
+ for(SmartDevice c: selectedDevices)
|
|
|
+ controller.deleteSmartDevice(c);
|
|
|
+ selectedDevices.clear();
|
|
|
+ clicked = null;
|
|
|
+ controller.notifyObservers();
|
|
|
+ mode = NOTHING;
|
|
|
+ });
|
|
|
+ itemDeleteSelected.setEnabled(false);
|
|
|
+ rightClickMenu.add(itemDeleteSelected);
|
|
|
+
|
|
|
/*
|
|
|
* Add PrintDebug option
|
|
|
*/
|
|
@@ -249,6 +269,12 @@ public class VisualisationInteractor implements MouseInputListener,
|
|
|
finishDrag();
|
|
|
case SELECTED:
|
|
|
case NOTHING:
|
|
|
+ // If Rightclick
|
|
|
+ if (e.getButton() == MouseEvent.BUTTON3) {
|
|
|
+ // Show the RightClickMenu
|
|
|
+ showRightClickMenu(clicked);
|
|
|
+ break;
|
|
|
+ }
|
|
|
if(!selectedDevices.isEmpty()&&!controlDown){
|
|
|
selectedDevices.clear();
|
|
|
if (clicked == null) {
|
|
@@ -274,47 +300,10 @@ public class VisualisationInteractor implements MouseInputListener,
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
- // If Rightclick
|
|
|
- if (e.getButton() == MouseEvent.BUTTON3) {
|
|
|
- // Show the RightClickMenu
|
|
|
- showRightClickMenu(clicked);
|
|
|
- }
|
|
|
+
|
|
|
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 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. 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) {
|
|
|
- itemCreate.setText("Create Device");
|
|
|
- itemCreate.setEnabled(true);
|
|
|
- itemDelete.setEnabled(false);
|
|
|
- } else {
|
|
|
- itemCreate.setText("Edit Device");
|
|
|
- itemCreate.setEnabled(true);
|
|
|
- itemDelete.setEnabled(true);
|
|
|
- }
|
|
|
- // Show the RightClickMenu
|
|
|
- rightClickMenu.show(panel, mousePos.x, mousePos.y);
|
|
|
- rightClickMenu.setEnabled(true);
|
|
|
- rightClickMenu.setVisible(true);
|
|
|
- mode = RIGHTCLICK_MENU;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
@Override
|
|
|
public void mousePressed(MouseEvent e) {
|
|
|
// Save mouse position for right Click options
|
|
@@ -383,38 +372,6 @@ public class VisualisationInteractor implements MouseInputListener,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void finishDragSelect() {
|
|
|
- LinkedList<SmartDevice> merged = new LinkedList<SmartDevice>();
|
|
|
- //XOR of selectedDevices and selectedDevices Drag
|
|
|
- merged.addAll(selectedDevices);
|
|
|
- merged.removeAll(selectedDevicesDrag);
|
|
|
- selectedDevicesDrag.removeAll(selectedDevices);
|
|
|
- merged.addAll(selectedDevicesDrag);
|
|
|
- //clear sets
|
|
|
- selectedDevices.clear();
|
|
|
- selectedDevicesDrag.clear();
|
|
|
- selectedDevices = merged;
|
|
|
- if(selectedDevices.isEmpty())
|
|
|
- mode = NOTHING;
|
|
|
- else
|
|
|
- mode = SELECTED;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void mouseEntered(MouseEvent e) {
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void mouseExited(MouseEvent e) {
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void actionPerformed(ActionEvent e) {
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
@Override
|
|
|
public void mouseDragged(MouseEvent e) {
|
|
|
// move dragged object/objecte selection on screen
|
|
@@ -482,11 +439,44 @@ public class VisualisationInteractor implements MouseInputListener,
|
|
|
panel.repaint();
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public void mouseMoved(MouseEvent e) {
|
|
|
-
|
|
|
+ /**
|
|
|
+ * 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. 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) {
|
|
|
+ itemCreate.setText("Create Device");
|
|
|
+ itemCreate.setEnabled(true);
|
|
|
+ itemDelete.setEnabled(false);
|
|
|
+ itemDeleteSelected.setEnabled(false);
|
|
|
+ } else {
|
|
|
+ itemCreate.setText("Edit Device");
|
|
|
+ itemCreate.setEnabled(true);
|
|
|
+ itemDelete.setEnabled(true);
|
|
|
+ if(selectedDevices.contains(clickedOn))
|
|
|
+ itemDeleteSelected.setEnabled(true);
|
|
|
+ else
|
|
|
+ itemDeleteSelected.setEnabled(false);
|
|
|
+ }
|
|
|
+ // Show the RightClickMenu
|
|
|
+ rightClickMenu.show(panel, mousePos.x, mousePos.y);
|
|
|
+ rightClickMenu.setEnabled(true);
|
|
|
+ rightClickMenu.setVisible(true);
|
|
|
+ mode = RIGHTCLICK_MENU;
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* Finishes the drag operation, if a SmartDevice was dragged, repaint the
|
|
|
* panel and set dragged to null
|
|
@@ -510,6 +500,23 @@ public class VisualisationInteractor implements MouseInputListener,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private void finishDragSelect() {
|
|
|
+ LinkedList<SmartDevice> merged = new LinkedList<SmartDevice>();
|
|
|
+ //XOR of selectedDevices and selectedDevices Drag
|
|
|
+ merged.addAll(selectedDevices);
|
|
|
+ merged.removeAll(selectedDevicesDrag);
|
|
|
+ selectedDevicesDrag.removeAll(selectedDevices);
|
|
|
+ merged.addAll(selectedDevicesDrag);
|
|
|
+ //clear sets
|
|
|
+ selectedDevices.clear();
|
|
|
+ selectedDevicesDrag.clear();
|
|
|
+ selectedDevices = merged;
|
|
|
+ if(selectedDevices.isEmpty())
|
|
|
+ mode = NOTHING;
|
|
|
+ else
|
|
|
+ mode = SELECTED;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Finishes the create connection operation and open a PopUp for
|
|
|
* Link/Connection creation
|
|
@@ -599,4 +606,16 @@ public class VisualisationInteractor implements MouseInputListener,
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void mouseMoved(MouseEvent e) {}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void mouseEntered(MouseEvent e) {}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void mouseExited(MouseEvent e) {}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void actionPerformed(ActionEvent e) {}
|
|
|
}
|