|
@@ -13,6 +13,7 @@ import java.util.LinkedList;
|
|
|
import javax.swing.JMenu;
|
|
|
import javax.swing.JMenuItem;
|
|
|
import javax.swing.JPopupMenu;
|
|
|
+import javax.swing.SwingUtilities;
|
|
|
import javax.swing.event.MouseInputListener;
|
|
|
|
|
|
import de.tu_darmstadt.tk.SmartHomeNetworkSim.control.SettingsController;
|
|
@@ -26,6 +27,7 @@ import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.Packet;
|
|
|
import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.PacketCollector;
|
|
|
import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.Port;
|
|
|
import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.SmartDevice;
|
|
|
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.configuration.SelectionModel;
|
|
|
import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.simpleImplementation.SimpleLink;
|
|
|
import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.simpleImplementation.SimpleProtocol;
|
|
|
import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.util.Pair;
|
|
@@ -207,7 +209,7 @@ public class VisualizationInteractor implements MouseInputListener,
|
|
|
* PacketCapture Controller, for capturing packets
|
|
|
*/
|
|
|
private PacketCaptureController captureController;
|
|
|
-
|
|
|
+ SelectionModel selectionModel;
|
|
|
/**
|
|
|
* Creates a new VisualisationInteractor
|
|
|
*
|
|
@@ -225,7 +227,7 @@ public class VisualizationInteractor implements MouseInputListener,
|
|
|
this.network = controller.getNetworkController();
|
|
|
this.toolTip = new LinkToolTip();
|
|
|
this.captureController = controller.getSimulationController().getPacketCaptureController();
|
|
|
-
|
|
|
+ this.selectionModel = controller.getSettingsController().getConfigurationManager().getSelectionModel();
|
|
|
initializeRightClickMenu();
|
|
|
}
|
|
|
|
|
@@ -237,9 +239,9 @@ public class VisualizationInteractor implements MouseInputListener,
|
|
|
*/
|
|
|
clicked = getSmartDeviceAtPosition(e.getX(), e.getY());
|
|
|
|
|
|
- controller.getSettingsController().getConfigurationManager().getSelectionModel().clickedConnection.clear();
|
|
|
+ selectionModel.clickedConnection.clear();
|
|
|
if(clicked == null)
|
|
|
- controller.getSettingsController().getConfigurationManager().getSelectionModel().clickedConnection = getConnectionsAtPosition(e.getX(), e.getY());
|
|
|
+ selectionModel.clickedConnection = getConnectionsAtPosition(e.getX(), e.getY());
|
|
|
|
|
|
|
|
|
switch (mode) {
|
|
@@ -252,30 +254,30 @@ public class VisualizationInteractor implements MouseInputListener,
|
|
|
case SELECTED:
|
|
|
case NOTHING:
|
|
|
// If Rightclick
|
|
|
- if (e.getButton() == MouseEvent.BUTTON3) {
|
|
|
+ if (SwingUtilities.isRightMouseButton(e)) {
|
|
|
// Show the RightClickMenu
|
|
|
Link linkAtPosition = getLinkVisualizationAtPosition(e.getX(), e.getY());
|
|
|
showRightClickMenu(clicked, linkAtPosition);
|
|
|
break;
|
|
|
}
|
|
|
- if(!controller.getSettingsController().getConfigurationManager().getSelectionModel().selectedDevices.isEmpty()&&!controlDown){
|
|
|
- controller.getSettingsController().getConfigurationManager().getSelectionModel().selectedDevices.clear();
|
|
|
+ if(!selectionModel.selectedDevices.isEmpty()&&!controlDown){
|
|
|
+ selectionModel.selectedDevices.clear();
|
|
|
if (clicked == null) {
|
|
|
panel.repaint();
|
|
|
}
|
|
|
}
|
|
|
if(clicked!=null){
|
|
|
if(!controlDown)
|
|
|
- controller.getSettingsController().getConfigurationManager().getSelectionModel().selectedDevices.add(clicked);
|
|
|
- else if(controller.getSettingsController().getConfigurationManager().getSelectionModel().selectedDevices.remove(clicked)&&!draggedDeviceWasSelected){
|
|
|
- controller.getSettingsController().getConfigurationManager().getSelectionModel().selectedDevices.add(clicked);
|
|
|
+ selectionModel.selectedDevices.add(clicked);
|
|
|
+ else if(selectionModel.selectedDevices.remove(clicked)&&!draggedDeviceWasSelected){
|
|
|
+ selectionModel.selectedDevices.add(clicked);
|
|
|
}
|
|
|
mode = SELECTED;
|
|
|
panel.repaint();
|
|
|
}else{
|
|
|
if(!controlDown)
|
|
|
mode = NOTHING;
|
|
|
- else if(!controller.getSettingsController().getConfigurationManager().getSelectionModel().selectedDevices.isEmpty())
|
|
|
+ else if(!selectionModel.selectedDevices.isEmpty())
|
|
|
mode = SELECTED;
|
|
|
|
|
|
panel.repaint();
|
|
@@ -305,22 +307,22 @@ public class VisualizationInteractor implements MouseInputListener,
|
|
|
dragged_x_start = e.getX();
|
|
|
dragged_y_start = e.getY();
|
|
|
mode = DRAG_SELECT;
|
|
|
- if(!controlDown)
|
|
|
- controller.getSettingsController().getConfigurationManager().getSelectionModel().selectedDevices.clear();
|
|
|
+ if(!controlDown && !SwingUtilities.isRightMouseButton(e))
|
|
|
+ selectionModel.selectedDevices.clear();
|
|
|
break;
|
|
|
} else if (e.getButton() == MouseEvent.BUTTON1){// && connectionFrom == null) {
|
|
|
// Recognize possible drag operation
|
|
|
- draggedDeviceWasSelected = controller.getSettingsController().getConfigurationManager().getSelectionModel().selectedDevices.contains(pressedOn);
|
|
|
+ draggedDeviceWasSelected = selectionModel.selectedDevices.contains(pressedOn);
|
|
|
if(!draggedDeviceWasSelected){
|
|
|
if(!controlDown)
|
|
|
- controller.getSettingsController().getConfigurationManager().getSelectionModel().selectedDevices.clear();
|
|
|
- controller.getSettingsController().getConfigurationManager().getSelectionModel().selectedDevices.add(pressedOn);
|
|
|
+ selectionModel.selectedDevices.clear();
|
|
|
+ selectionModel.selectedDevices.add(pressedOn);
|
|
|
}
|
|
|
dragged = pressedOn;
|
|
|
dragged_x = pressedOn.getX();
|
|
|
dragged_y = pressedOn.getY();
|
|
|
mode = SELECTED_DRAG;
|
|
|
- } else if (e.getButton() == MouseEvent.BUTTON3){// && dragged == null) {
|
|
|
+ } else if (SwingUtilities.isRightMouseButton(e)){// && dragged == null) {
|
|
|
connectionFrom = pressedOn;
|
|
|
mode = DRAG_CONNECTION;
|
|
|
}
|
|
@@ -383,11 +385,11 @@ public class VisualizationInteractor implements MouseInputListener,
|
|
|
int max_x = Math.max(dragged_x, dragged_x_start);
|
|
|
int max_y = Math.max(dragged_y, dragged_y_start);
|
|
|
//Remove unselected
|
|
|
- controller.getSettingsController().getConfigurationManager().getSelectionModel().selectedDevicesDrag.removeIf(s->(s.getX()<min_x||s.getX()>max_x||s.getY()<min_y||s.getY()>max_y));
|
|
|
+ selectionModel.selectedDevicesDrag.removeIf(s->(s.getX()<min_x||s.getX()>max_x||s.getY()<min_y||s.getY()>max_y));
|
|
|
//Add selected devices
|
|
|
for(SmartDevice sel:network.getVisibleSmartDevices()){
|
|
|
- if(sel.getX()>=min_x&&sel.getX()<=max_x&&sel.getY()>=min_y&&sel.getY()<=max_y&&!controller.getSettingsController().getConfigurationManager().getSelectionModel().selectedDevicesDrag.contains(sel)){
|
|
|
- controller.getSettingsController().getConfigurationManager().getSelectionModel().selectedDevicesDrag.add(sel);
|
|
|
+ if(sel.getX()>=min_x&&sel.getX()<=max_x&&sel.getY()>=min_y&&sel.getY()<=max_y&&!selectionModel.selectedDevicesDrag.contains(sel)){
|
|
|
+ selectionModel.selectedDevicesDrag.add(sel);
|
|
|
}
|
|
|
}
|
|
|
break;
|
|
@@ -399,7 +401,7 @@ public class VisualizationInteractor implements MouseInputListener,
|
|
|
int x_offset = dragged_x - dragged.getX();
|
|
|
int y_offset = dragged_y - dragged.getY();
|
|
|
//Validate for all moved devices, that they are within the model, if not change offset
|
|
|
- for(SmartDevice d:controller.getSettingsController().getConfigurationManager().getSelectionModel().selectedDevices){
|
|
|
+ for(SmartDevice d:selectionModel.selectedDevices){
|
|
|
if (d.getX() + x_offset <= config.getDeviceVisualizationRadius())
|
|
|
x_offset = config.getDeviceVisualizationRadius()-d.getX();
|
|
|
else if (d.getX() + x_offset >= config.getWidth() - config.getDeviceVisualizationRadius())
|
|
@@ -433,11 +435,11 @@ public class VisualizationInteractor implements MouseInputListener,
|
|
|
&& (dragged.getX() != dragged_x || dragged.getY() != dragged_y)) {
|
|
|
int x_offset = dragged_x-dragged.getX();
|
|
|
int y_offset = dragged_y-dragged.getY();
|
|
|
- for(SmartDevice d: controller.getSettingsController().getConfigurationManager().getSelectionModel().selectedDevices)
|
|
|
+ for(SmartDevice d: selectionModel.selectedDevices)
|
|
|
network.moveSmartDevice(d, d.getX()+x_offset, d.getY()+y_offset, d.getZ());
|
|
|
}
|
|
|
dragged = null;
|
|
|
- if(controller.getSettingsController().getConfigurationManager().getSelectionModel().selectedDevices.isEmpty())
|
|
|
+ if(selectionModel.selectedDevices.isEmpty())
|
|
|
mode = NOTHING;
|
|
|
else
|
|
|
mode = SELECTED;
|
|
@@ -449,15 +451,15 @@ public class VisualizationInteractor implements MouseInputListener,
|
|
|
private void finishDragSelect() {
|
|
|
LinkedList<SmartDevice> merged = new LinkedList<SmartDevice>();
|
|
|
//XOR of controller.getControllerConfiguration().getConfigurationManager().getSelectionModel().selectedDevices and controller.getControllerConfiguration().getConfigurationManager().getSelectionModel().selectedDevices Drag
|
|
|
- merged.addAll(controller.getSettingsController().getConfigurationManager().getSelectionModel().selectedDevices);
|
|
|
- merged.removeAll(controller.getSettingsController().getConfigurationManager().getSelectionModel().selectedDevicesDrag);
|
|
|
- controller.getSettingsController().getConfigurationManager().getSelectionModel().selectedDevicesDrag.removeAll(controller.getSettingsController().getConfigurationManager().getSelectionModel().selectedDevices);
|
|
|
- merged.addAll(controller.getSettingsController().getConfigurationManager().getSelectionModel().selectedDevicesDrag);
|
|
|
+ merged.addAll(selectionModel.selectedDevices);
|
|
|
+ merged.removeAll(selectionModel.selectedDevicesDrag);
|
|
|
+ selectionModel.selectedDevicesDrag.removeAll(selectionModel.selectedDevices);
|
|
|
+ merged.addAll(selectionModel.selectedDevicesDrag);
|
|
|
//clear sets
|
|
|
- controller.getSettingsController().getConfigurationManager().getSelectionModel().selectedDevices.clear();
|
|
|
- controller.getSettingsController().getConfigurationManager().getSelectionModel().selectedDevicesDrag.clear();
|
|
|
- controller.getSettingsController().getConfigurationManager().getSelectionModel().selectedDevices = merged;
|
|
|
- if(controller.getSettingsController().getConfigurationManager().getSelectionModel().selectedDevices.isEmpty())
|
|
|
+ selectionModel.selectedDevices.clear();
|
|
|
+ selectionModel.selectedDevicesDrag.clear();
|
|
|
+ selectionModel.selectedDevices = merged;
|
|
|
+ if(selectionModel.selectedDevices.isEmpty())
|
|
|
mode = NOTHING;
|
|
|
else
|
|
|
mode = SELECTED;
|
|
@@ -520,7 +522,7 @@ public class VisualizationInteractor implements MouseInputListener,
|
|
|
|
|
|
}
|
|
|
connectionFrom = null;
|
|
|
- if(controller.getSettingsController().getConfigurationManager().getSelectionModel().selectedDevices.isEmpty())
|
|
|
+ if(selectionModel.selectedDevices.isEmpty())
|
|
|
mode = NOTHING;
|
|
|
else
|
|
|
mode = SELECTED;
|
|
@@ -806,7 +808,10 @@ public class VisualizationInteractor implements MouseInputListener,
|
|
|
LinkedList<Link> captureLinks = new LinkedList<Link>();
|
|
|
if(clickedLink == null){
|
|
|
itemCreateLink.setText("Create Link");
|
|
|
- itemCreateLink.setEnabled(false);
|
|
|
+ if(selectionModel.selectedDevices.isEmpty())
|
|
|
+ itemCreateLink.setEnabled(false);
|
|
|
+ else
|
|
|
+ itemCreateLink.setEnabled(true);
|
|
|
}else{
|
|
|
itemCreateLink.setText("Edit Link");
|
|
|
itemCreateLink.setEnabled(true);
|
|
@@ -817,7 +822,7 @@ public class VisualizationInteractor implements MouseInputListener,
|
|
|
itemCreate.setEnabled(true);
|
|
|
itemDelete.setEnabled(false);
|
|
|
itemDeleteSelected.setEnabled(false);
|
|
|
- if(controller.getSettingsController().getConfigurationManager().getSelectionModel().clickedConnection.size()>0){
|
|
|
+ if(selectionModel.clickedConnection.size()>0){
|
|
|
/**
|
|
|
* Update Connections which can be edited
|
|
|
*/
|
|
@@ -825,7 +830,7 @@ public class VisualizationInteractor implements MouseInputListener,
|
|
|
|
|
|
//List to prevent duplicate connection entries
|
|
|
LinkedList<Connection> editableConnections = new LinkedList<Connection>();
|
|
|
- for(Pair<Connection, Pair<Port,Port>> p:controller.getSettingsController().getConfigurationManager().getSelectionModel().clickedConnection){
|
|
|
+ for(Pair<Connection, Pair<Port,Port>> p:selectionModel.clickedConnection){
|
|
|
//Don't add the same connection multiple times
|
|
|
if(editableConnections.contains(p.getLeft())|| p == null || p.getLeft() == null)continue;
|
|
|
editableConnections.add(p.getLeft());
|
|
@@ -850,7 +855,11 @@ public class VisualizationInteractor implements MouseInputListener,
|
|
|
rightClickMenu.remove(itemEditConnection);
|
|
|
rightClickMenu.add(itemCreateConnection,editCreateConnectionIndex);
|
|
|
}
|
|
|
- itemCreateConnection.setEnabled(false);
|
|
|
+ if(selectionModel.selectedDevices.isEmpty()){
|
|
|
+ itemCreateConnection.setEnabled(false);
|
|
|
+ }else{
|
|
|
+ itemCreateConnection.setEnabled(true);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
//Item capture
|
|
@@ -905,7 +914,7 @@ public class VisualizationInteractor implements MouseInputListener,
|
|
|
}
|
|
|
itemCreateLink.setText("Create Link");
|
|
|
itemCapture.removeAll();
|
|
|
- if(controller.getSettingsController().getConfigurationManager().getSelectionModel().selectedDevices.contains(clickedOn)){
|
|
|
+ if(selectionModel.selectedDevices.contains(clickedOn)){
|
|
|
itemDeleteSelected.setEnabled(true);
|
|
|
itemCreateLink.setEnabled(true);
|
|
|
itemCreateConnection.setEnabled(true);
|
|
@@ -924,13 +933,13 @@ public class VisualizationInteractor implements MouseInputListener,
|
|
|
if(collector.getDevices().contains(clickedOn)){
|
|
|
captureDeviceText += "stop capturing all";
|
|
|
itemCaptureDevice.addActionListener(a->{
|
|
|
- for(SmartDevice d: controller.getSettingsController().getConfigurationManager().getSelectionModel().selectedDevices)
|
|
|
+ for(SmartDevice d: selectionModel.selectedDevices)
|
|
|
captureController.removeDeviceFromCollector(collector, d);
|
|
|
});
|
|
|
}else{
|
|
|
captureDeviceText += "start capturing all";
|
|
|
itemCaptureDevice.addActionListener(a->{
|
|
|
- for(SmartDevice d: controller.getSettingsController().getConfigurationManager().getSelectionModel().selectedDevices)
|
|
|
+ for(SmartDevice d: selectionModel.selectedDevices)
|
|
|
captureController.addDeviceToCollector(collector, d);
|
|
|
});
|
|
|
}
|
|
@@ -941,7 +950,7 @@ public class VisualizationInteractor implements MouseInputListener,
|
|
|
JMenuItem newCapture = new JMenuItem("Create new PacketCapturer");
|
|
|
newCapture.addActionListener(a->{
|
|
|
PacketCollector c = new PacketCollector();
|
|
|
- for(SmartDevice d: controller.getSettingsController().getConfigurationManager().getSelectionModel().selectedDevices)
|
|
|
+ for(SmartDevice d: selectionModel.selectedDevices)
|
|
|
c.addDevice(d);
|
|
|
EditPacketSniffer popUp = new EditPacketSniffer(controller, panel, c, false);
|
|
|
popUp.setVisible(true);
|
|
@@ -1029,9 +1038,9 @@ public class VisualizationInteractor implements MouseInputListener,
|
|
|
if(clickedLink!=null){
|
|
|
new LinkCreationDialog(clickedLink, controller, panel);
|
|
|
}else{
|
|
|
- new LinkCreationDialog(controller.getSettingsController().getConfigurationManager().getSelectionModel().selectedDevices, controller, panel);
|
|
|
+ new LinkCreationDialog(selectionModel.selectedDevices, controller, panel);
|
|
|
}
|
|
|
- if(controller.getSettingsController().getConfigurationManager().getSelectionModel().selectedDevices.isEmpty())
|
|
|
+ if(selectionModel.selectedDevices.isEmpty())
|
|
|
mode = NOTHING;
|
|
|
else
|
|
|
mode = SELECTED;
|
|
@@ -1042,10 +1051,10 @@ public class VisualizationInteractor implements MouseInputListener,
|
|
|
// Create Connection
|
|
|
itemCreateConnection = new JMenuItem("Create Connection");
|
|
|
itemCreateConnection.addActionListener(e->{
|
|
|
- LinkedList<SmartDevice> selectedDevices = new LinkedList<SmartDevice>(controller.getSettingsController().getConfigurationManager().getSelectionModel().selectedDevices);
|
|
|
+ LinkedList<SmartDevice> selectedDevices = new LinkedList<SmartDevice>(selectionModel.selectedDevices);
|
|
|
|
|
|
new ConnectionCreationDialog(selectedDevices, controller, panel);
|
|
|
- if(controller.getSettingsController().getConfigurationManager().getSelectionModel().selectedDevices.isEmpty())
|
|
|
+ if(selectionModel.selectedDevices.isEmpty())
|
|
|
mode = NOTHING;
|
|
|
else
|
|
|
mode = SELECTED;
|
|
@@ -1080,9 +1089,9 @@ public class VisualizationInteractor implements MouseInputListener,
|
|
|
|
|
|
itemDeleteSelected.addActionListener(e -> {
|
|
|
// Delete the clicked object
|
|
|
- for(SmartDevice c: controller.getSettingsController().getConfigurationManager().getSelectionModel().selectedDevices)
|
|
|
+ for(SmartDevice c: selectionModel.selectedDevices)
|
|
|
network.deleteSmartDevice(c);
|
|
|
- controller.getSettingsController().getConfigurationManager().getSelectionModel().selectedDevices.clear();
|
|
|
+ selectionModel.selectedDevices.clear();
|
|
|
clicked = null;
|
|
|
controller.notifyObservers();
|
|
|
mode = NOTHING;
|
|
@@ -1150,7 +1159,7 @@ public class VisualizationInteractor implements MouseInputListener,
|
|
|
System.out.println(p.getTextualRepresentation());
|
|
|
});
|
|
|
network.getConnections().removeAll(terminated);
|
|
|
- if(controller.getSettingsController().getConfigurationManager().getSelectionModel().selectedDevices.isEmpty())
|
|
|
+ if(selectionModel.selectedDevices.isEmpty())
|
|
|
mode = NOTHING;
|
|
|
else
|
|
|
mode = SELECTED;
|