Переглянути джерело

Improves the MenuBar: Adds Create, View, Algorithms

Andreas T. Meyer-Berg 5 роки тому
батько
коміт
91a03c2795

+ 3 - 1
README.md

@@ -8,6 +8,8 @@ Gradle will download required libraries and handle the build process
 	$ gradlew build		# Assembles and tests this project
 	
 	$ gradlew jar 		# Creates an executable Jar-file
+
+	$ gradlew javadoc	# Generates Java Doc for the framework
 	
 	$ gradlew test		# Runs the included unit tests
 	
@@ -24,4 +26,4 @@ Gradle will download required libraries and handle the build process
 <!-- comment -->
 
 ## Developed by
-Andreas T. Meyer-Berg (As part of his Bachelor Thesis)
+Andreas T. Meyer-Berg (As part of his Bachelor Thesis)

+ 136 - 30
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/view/MenuBar.java

@@ -1,24 +1,25 @@
 package de.tu_darmstadt.tk.SmartHomeNetworkSim.view;
 
 import java.awt.FlowLayout;
-
-
-
+import java.util.LinkedList;
 
 import javax.swing.JMenu;
 import javax.swing.JMenuBar;
 import javax.swing.JMenuItem;
 
-
 import javax.swing.JOptionPane;
 
 import de.tu_darmstadt.tk.SmartHomeNetworkSim.control.Controller;
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.SmartDevice;
 import de.tu_darmstadt.tk.SmartHomeNetworkSim.view.popups.AboutPopUp;
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.view.popups.ConnectionCreationDialog;
 import de.tu_darmstadt.tk.SmartHomeNetworkSim.view.popups.EditAlgorithmsPopUp;
 import de.tu_darmstadt.tk.SmartHomeNetworkSim.view.popups.EditCollectorsPopUp;
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.view.popups.LinkCreationDialog;
 import de.tu_darmstadt.tk.SmartHomeNetworkSim.view.popups.NetworkTreeWindow;
 import de.tu_darmstadt.tk.SmartHomeNetworkSim.view.popups.SettingsPopUp;
 import de.tu_darmstadt.tk.SmartHomeNetworkSim.view.popups.SimulationConfigurator;
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.view.popups.SmartDeviceCreationPopUp;
 
 /**
  * MenuBar for the MainFrame, which contains the different items like options
@@ -31,73 +32,155 @@ public class MenuBar extends JMenuBar {
 	 * Controller to manipulate the model
 	 */
 	private Controller controller;
-	
+
 	/**
 	 * JMenu for the Simulation
 	 */
 	private JMenu mnSimulation;
-	
+
+	/**
+	 * JMenu for Creation of Devices etc.
+	 */
+	private JMenu mnCreate;
+
 	/**
-	 * JMenu for Editing of Devices, Options etc. 
+	 * JMenu for Editing of Devices, Options etc.
 	 */
 	private JMenu mnEdit;
-	
+
+	/**
+	 * JMenu for managing different views
+	 */
+	private JMenu mnView;
+
+	/**
+	 * JMenu for managing different algorithms
+	 */
+	private JMenu mnAlgorithms;
+
 	/**
 	 * JMenu for help with the program
 	 */
 	private JMenu mnHelp;
-	
+
 	/**
 	 * Serial Version
 	 */
 	private static final long serialVersionUID = 4293499386792032777L;
-	
+
 	/**
 	 * Initialize the Menu Bar, add all the items and add the different actions
-	 * @param controller Controller
+	 * 
+	 * @param controller
+	 *            Controller
 	 */
 	public MenuBar(Controller controller) {
 		this.controller = controller;
-		
+
 		this.setLayout(new FlowLayout(FlowLayout.LEADING));
 
 		initializeSimulationMenu();
 		this.add(mnSimulation);
+		initializeCreateMenu();
+		this.add(mnCreate);
 		initializeEditMenu();
 		this.add(mnEdit);
+		initializeViewMenu();
+		this.add(mnView);
+		initializeAlgorithmMenu();
+		this.add(mnAlgorithms);
 		initializeHelpMenu();
 		this.add(mnHelp);
 	}
-	
+
 	/**
 	 * Initializes the Simulation Menu
 	 */
-	private void initializeSimulationMenu(){
+	private void initializeSimulationMenu() {
 		mnSimulation = new JMenu("Simulation");
 		JMenuItem mntmConfigureSim = new JMenuItem("Configure Sim");
-		mntmConfigureSim.addActionListener(a->{
+		mntmConfigureSim.addActionListener(a -> {
 			SimulationConfigurator sim = new SimulationConfigurator(controller);
 			sim.setLocationRelativeTo(this.getParent());
 			sim.setVisible(true);
 		});
-		mnSimulation.add(mntmConfigureSim);		
+		mnSimulation.add(mntmConfigureSim);
 	}
-	
+
+	/**
+	 * Initialize the creation menu
+	 */
+	private void initializeCreateMenu() {
+		mnCreate = new JMenu("Create");
+
+		// Create device option
+		JMenuItem mntmCreateDevice = new JMenuItem("Create SmartDevice");
+
+		mntmCreateDevice.addActionListener(e -> {
+			SmartDevice newDevice = new SmartDevice();
+			controller.getNetworkController().validateDevicePosition();
+
+			SmartDeviceCreationPopUp popUp = new SmartDeviceCreationPopUp(newDevice, false, controller);
+			popUp.setLocationRelativeTo(this.getParent());
+			popUp.setEnabled(true);
+			popUp.setVisible(true);
+		});
+		mnCreate.add(mntmCreateDevice);
+
+		// Create Link option
+		JMenuItem mntmCreateLink = new JMenuItem("Create Link of all visible Devices");
+		mntmCreateLink.addActionListener(e -> {
+			new LinkCreationDialog(controller.getNetworkController().getVisibleSmartDevices(), controller,
+					this.getParent());
+
+		});
+		mnCreate.add(mntmCreateLink);
+		
+		// Create Link of selected option
+		JMenuItem mntmCreateLinkOfSelected = new JMenuItem("Create Link of all selected Devices");
+		mntmCreateLinkOfSelected.addActionListener(e -> {
+			LinkedList<SmartDevice> devices = controller.getSettingsController().getConfigurationManager().getSelectionModel().selectedDevices;
+			if(!devices.isEmpty())
+				new LinkCreationDialog(devices, controller, this.getParent());
+
+		});
+		mnCreate.add(mntmCreateLinkOfSelected);
+		
+		// Create Connection option
+		JMenuItem mntmCreateConnection = new JMenuItem("Create Connection of all visible Devices");
+		mntmCreateConnection.addActionListener(e -> {
+			new ConnectionCreationDialog(controller.getNetworkController().getVisibleSmartDevices(), controller,
+					this.getParent());
+			});
+		mnCreate.add(mntmCreateConnection);
+		
+		// Create Connection option
+		JMenuItem mntmCreateConnectionOfSelected = new JMenuItem("Create Connection of all selected Devices");
+		mntmCreateConnectionOfSelected.addActionListener(e -> {
+			LinkedList<SmartDevice> devices = controller.getSettingsController().getConfigurationManager().getSelectionModel().selectedDevices;
+			if(!devices.isEmpty())
+				new ConnectionCreationDialog(devices, controller,
+					this.getParent());
+			});
+		mnCreate.add(mntmCreateConnectionOfSelected);
+	}
+
 	/**
 	 * Initializes the Edit Menu
 	 */
 	private void initializeEditMenu() {
 		mnEdit = new JMenu("Edit");
-		
+
 		JMenuItem mntmDeleteModel = new JMenuItem("Delete Network");
 		mntmDeleteModel.addActionListener(a -> {
-			int dialogResult = JOptionPane.showConfirmDialog(this.getParent(), "Do you really want do delete all Devices, Ports, Links & Connections?");
-			if(dialogResult == JOptionPane.YES_OPTION){
-			  controller.getNetworkController().deleteNetworkModel();
+			int dialogResult = JOptionPane.showConfirmDialog(this.getParent(),
+					"Do you really want do delete all Devices, Ports, Links & Connections?");
+			if (dialogResult == JOptionPane.YES_OPTION) {
+				controller.getNetworkController().deleteNetworkModel();
 			}
 		});
 		mnEdit.add(mntmDeleteModel);
-		
+
 		JMenuItem mntmOption = new JMenuItem("Settings");
 		mntmOption.addActionListener(a -> {
 			SettingsPopUp settings = new SettingsPopUp(controller);
@@ -105,27 +188,50 @@ public class MenuBar extends JMenuBar {
 			settings.setVisible(true);
 		});
 		mnEdit.add(mntmOption);
-		
+	}
+
+	/**
+	 * Initializes the View Menu
+	 */
+	private void initializeViewMenu() {
+		mnView = new JMenu("View");
+
 		JMenuItem mntmTreeView = new JMenuItem("Tree View");
 		mntmTreeView.addActionListener(a -> {
 			NetworkTreeWindow net = new NetworkTreeWindow(controller, this.getParent());
 			net.setVisible(true);
 		});
-		mnEdit.add(mntmTreeView);
-		
+		mnView.add(mntmTreeView);
+
+		JMenuItem mntmOption = new JMenuItem("View Settings");
+		mntmOption.addActionListener(a -> {
+			SettingsPopUp settings = new SettingsPopUp(controller);
+			settings.setLocationRelativeTo(this.getParent());
+			settings.setVisible(true);
+		});
+		mnView.add(mntmOption);
+	}
+
+	/**
+	 * Initializes the Algorithm Menu
+	 */
+	private void initializeAlgorithmMenu() {
+		mnAlgorithms = new JMenu("Algorithms");
+
 		JMenuItem mntmManageAlgos = new JMenuItem("Manage Algorithms");
 		mntmManageAlgos.addActionListener(a -> {
 			new EditAlgorithmsPopUp(controller, this.getParent());
 		});
-		mnEdit.add(mntmManageAlgos);
-		
-		JMenuItem mntmManageCollectors = new JMenuItem("Manage Collectors");
+		mnAlgorithms.add(mntmManageAlgos);
+
+		JMenuItem mntmManageCollectors = new JMenuItem("Manage Collectors & PacketSniffers");
+		mntmManageCollectors.setToolTipText("Allows managing of the Packet Collectors and Packet Sniffer");
 		mntmManageCollectors.addActionListener(a -> {
 			new EditCollectorsPopUp(controller, this.getParent());
 		});
-		mnEdit.add(mntmManageCollectors);
+		mnAlgorithms.add(mntmManageCollectors);
 	}
-	
+
 	/**
 	 * Initializes the Help Menu
 	 */

+ 2 - 14
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/view/VisualizationInteractor.java

@@ -1040,20 +1040,8 @@ public class VisualizationInteractor implements MouseInputListener,
 		itemCreateConnection = new JMenuItem("Create Connection");
 		itemCreateConnection.addActionListener(e->{
 			LinkedList<SmartDevice> selectedDevices = new LinkedList<SmartDevice>(controller.getSettingsController().getConfigurationManager().getSelectionModel().selectedDevices);
-			LinkedList<Port> ports = new LinkedList<Port>();
-			for(SmartDevice d: selectedDevices)
-				ports.add(new Port(d, (short) 12));
-			Link link = null;
-			/**
-			 * Find common link -> else null -> create new link
-			 */
-			for(Link l:network.getLinks()){
-				if(l.getDevices().containsAll(selectedDevices)){
-					link = l;
-					break;
-				}
-			}
-			new ConnectionCreationDialog(ports,link, controller, panel);
+			
+			new ConnectionCreationDialog(selectedDevices, controller, panel);
 			if(controller.getSettingsController().getConfigurationManager().getSelectionModel().selectedDevices.isEmpty())
 				mode = NOTHING;
 			else

+ 51 - 2
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/view/popups/ConnectionCreationDialog.java

@@ -2,6 +2,7 @@ package de.tu_darmstadt.tk.SmartHomeNetworkSim.view.popups;
 
 import java.awt.Component;
 import java.util.Collection;
+import java.util.LinkedList;
 
 import javax.swing.JDialog;
 
@@ -9,12 +10,25 @@ 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.Port;
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.SmartDevice;
 
+/**
+ * PopUp for the creation of Connections
+ * 
+ *
+ * @author Andreas T. Meyer-Berg
+ */
 @SuppressWarnings("serial")
 public class ConnectionCreationDialog extends JDialog {
-ConnectionCreationPanel content;
-Component parent;
+	private ConnectionCreationPanel content;
+	private Component parent;
 
+	/**
+	 * Create a Dialog for editing the given Connection
+	 * @param connection Connection to be edited
+	 * @param controller Controller for changing the connection
+	 * @param panel Panel the PopUp should be moved relative to
+	 */
 	public ConnectionCreationDialog(Connection connection, Controller controller, Component panel) {
 		super();
 		content = new ConnectionCreationPanel(connection, controller, this);
@@ -22,13 +36,48 @@ Component parent;
 		initialize();
 	}
 	
+	/**
+	 * Create a Dialog for creating a Connection of the given devices
+	 * @param devices ports which should be connected
+	 * @param link Link which the connection should run on
+	 * @param controller Controller for changing the connection
+	 * @param panel Panel the PopUp should be moved relative to
+	 */
 	public ConnectionCreationDialog(Collection<Port> devices, Link link, Controller controller, Component panel){
 		super();
 		content = new ConnectionCreationPanel(devices, link, controller, this);
 		parent = panel;
 		initialize();
 	}
+	/**
+	 * Initializes and shows a creation dialog for a connection of the given devices
+	 * @param devices Devices, which should be connected
+	 * @param controller Controller for changing the connection
+	 * @param panel Panel the PopUp should be moved relative to
+	 */
+	public ConnectionCreationDialog(Collection<SmartDevice> devices, Controller controller, Component panel){
+		super();
+		LinkedList<Port> ports = new LinkedList<Port>();
+		for(SmartDevice d: devices)
+			ports.add(new Port(d, (short) 12));
+		Link link = null;
+		/**
+		 * Find common link -> else null -> create new link
+		 */
+		for(Link l:controller.getNetworkController().getLinks()){
+			if(l.getDevices().containsAll(devices)){
+				link = l;
+				break;
+			}
+		}
+		content = new ConnectionCreationPanel(ports, link, controller, this);
+		parent = panel;
+		initialize();
+	}
 
+	/**
+	 * Initialize and show the popUp
+	 */
 	private void initialize() {
 		this.setModal(true);
 		this.setContentPane(content);