Andreas T. Meyer-Berg пре 5 година
родитељ
комит
7b009daaac

+ 18 - 0
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/view/VisualizationInteractor.java

@@ -663,6 +663,24 @@ public class VisualizationInteractor implements MouseInputListener,
 		if(e.getKeyCode()==KeyEvent.VK_ESCAPE){
 			deselectAllDevics();
 		}
+		if(e.getKeyCode()==KeyEvent.VK_F2){
+			/** mouse position */
+			Point p = panel.getMousePosition();
+			if(p!=null){
+				/** Device at mouse */
+				SmartDevice d = getSmartDeviceAtPosition((int)p.getX(), (int)p.getY());
+				if(d!=null){
+					/**
+					 * PopUp for editing the given device
+					 */
+					SmartDeviceCreationPopUp popUp = new SmartDeviceCreationPopUp(d, true,controller);
+					popUp.setLocationRelativeTo(panel);
+					popUp.setEnabled(true);
+					popUp.setVisible(true);
+					popUp.setNameFocus();
+				}
+			}
+		}
 	}
 
 	@Override

+ 12 - 1
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/view/popups/SmartDeviceCreationPopUp.java

@@ -12,6 +12,7 @@ import javax.swing.JPanel;
 import javax.swing.JTabbedPane;
 import javax.swing.JTextField;
 import javax.swing.SwingConstants;
+import javax.swing.SwingUtilities;
 
 import de.tu_darmstadt.tk.SmartHomeNetworkSim.control.Controller;
 import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.SmartDevice;
@@ -238,7 +239,17 @@ public class SmartDeviceCreationPopUp extends JDialog {
 		tabbedPane.setSelectedIndex(0);
 		refreshGUI();
 	}
-
+	/**
+	 * Sets focus to the name text field
+	 */
+	public void setNameFocus(){
+		tfName.setFocusable(true);
+		SwingUtilities.invokeLater(new Runnable() {
+		      public void run() {
+		        tfName.requestFocusInWindow();
+		      }
+		    });
+	}
 	/**
 	 * Validate the input Fields, and add the new SmartDevice to the model and
 	 * panel