|
@@ -11,7 +11,10 @@ import javax.swing.JPopupMenu;
|
|
|
import javax.swing.event.MouseInputListener;
|
|
|
|
|
|
import de.tu_darmstadt.tk.SmartHomeNetworkSim.control.Controller;
|
|
|
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.Connection;
|
|
|
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.Link;
|
|
|
import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.Model;
|
|
|
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.Packet;
|
|
|
import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.SmartDevice;
|
|
|
|
|
|
/**
|
|
@@ -80,6 +83,27 @@ public class VisualisationInteractor implements MouseInputListener, MouseMotionL
|
|
|
this.rightClickMenu = new JPopupMenu();
|
|
|
itemCreate = new JMenuItem("Create SmartDevice");
|
|
|
itemDelete = new JMenuItem("Delete");
|
|
|
+ itemDelete.addActionListener(e -> {
|
|
|
+ controller.deleteSmartDevice(dragged);
|
|
|
+ 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)
|
|
|
+ System.out.println("Connection: terminated");
|
|
|
+ else
|
|
|
+ System.out.println("Connection: "+c.getSource().getName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ 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);
|
|
@@ -87,21 +111,21 @@ public class VisualisationInteractor implements MouseInputListener, MouseMotionL
|
|
|
|
|
|
@Override
|
|
|
public void mouseClicked(MouseEvent e) {
|
|
|
- /**
|
|
|
- * SmartDevice that was clicked
|
|
|
+ /*
|
|
|
+ * FindSmartDevice that was clicked
|
|
|
*/
|
|
|
- SmartDevice clickedOn = null;
|
|
|
+ dragged = null;
|
|
|
// Find the clicked SmartDevice
|
|
|
for (SmartDevice d : model.getDevices()) {
|
|
|
if (Math.abs(d.getX() - e.getX()) < panel.getVisualisationRadius()
|
|
|
&& Math.abs(d.getY() - e.getY()) < panel.getVisualisationRadius()) {
|
|
|
- clickedOn = d;
|
|
|
+ dragged = d;
|
|
|
}
|
|
|
}
|
|
|
//If Rightclick
|
|
|
if(e.getButton()==MouseEvent.BUTTON3) {
|
|
|
//Show the RightClickMenu
|
|
|
- showRightClickMenu(clickedOn);
|
|
|
+ showRightClickMenu(dragged);
|
|
|
}
|
|
|
|
|
|
}
|