Explorar o código

Allow EditAlgoPanel scrolling, fixes button text sizes

Andreas T. Meyer-Berg %!s(int64=5) %!d(string=hai) anos
pai
achega
2cc25f362d

+ 1 - 1
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/core/simpleImplementation/SimpleManipulation.java

@@ -42,7 +42,7 @@ public class SimpleManipulation implements NetworkManipulationAlgorithm {
 			controller.getNetworkController().moveSmartDevice(move,(int)(move.getX()+Math.random()*10-5), (int)(move.getY()+Math.random()*10-5), move.getZ());
 			controller.getNetworkController().validateDevicePosition();
 		}
-			/**
+		/**
 		 * Refresh Panel
 		 */
 		controller.notifyObservers();

+ 26 - 9
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/view/popups/EditAlgorithmsPopUp.java

@@ -5,6 +5,8 @@ import javax.swing.JList;
 
 
 import javax.swing.JOptionPane;
+import javax.swing.JScrollPane;
+import javax.swing.ListSelectionModel;
 
 import de.tu_darmstadt.tk.SmartHomeNetworkSim.control.Controller;
 import de.tu_darmstadt.tk.SmartHomeNetworkSim.control.SimulationController;
@@ -43,6 +45,11 @@ public class EditAlgorithmsPopUp extends JDialog {
 	 */
 	private JList<String> list;
 	
+	/**
+	 * Scroll Pane for scrolling in the Algorithm list
+	 */
+	private JScrollPane scrollPanelList;
+	
 	/**
 	 * Mutex, to disable listeners on update
 	 */
@@ -70,7 +77,7 @@ public class EditAlgorithmsPopUp extends JDialog {
 
 		JButton btnImportAlgorithm = new JButton("Import Algorithm");
 		btnImportAlgorithm.setToolTipText("Import new algorithm, which will be executed after each time step.");
-		btnImportAlgorithm.setBounds(222, 129, 148, 25);
+		btnImportAlgorithm.setBounds(220, 130, 160, 25);
 		getContentPane().add(btnImportAlgorithm);
 		btnImportAlgorithm.addActionListener(a->{
 			if(mutex)
@@ -112,7 +119,7 @@ public class EditAlgorithmsPopUp extends JDialog {
 		
 		JButton btnRemoveSelected = new JButton("Remove Selected");
 		btnRemoveSelected.setToolTipText("Remove the selected algorithm");
-		btnRemoveSelected.setBounds(222, 161, 148, 25);
+		btnRemoveSelected.setBounds(220, 160, 160, 25);
 		getContentPane().add(btnRemoveSelected);
 		btnRemoveSelected.addActionListener(a->{
 			if(mutex)
@@ -135,12 +142,12 @@ public class EditAlgorithmsPopUp extends JDialog {
 
 		JLabel lblMoveSelected = new JLabel("Move selected:");
 		lblMoveSelected.setToolTipText("Algorithms will be executed from top to bottom after each simulation step");
-		lblMoveSelected.setBounds(221, 13, 149, 16);
+		lblMoveSelected.setBounds(222, 10, 160, 20);
 		getContentPane().add(lblMoveSelected);
 		
 		JButton btnUp = new JButton("Up");
-		btnUp.setToolTipText("Move the selected algorithm up. (Executed earlier)");
-		btnUp.setBounds(222, 42, 64, 25);
+		btnUp.setToolTipText("Move the selected algorithm up. Will be executed earlier.");
+		btnUp.setBounds(220, 50, 75, 25);
 		btnUp.addActionListener(a->{
 			if(mutex)
 				return;
@@ -181,9 +188,15 @@ public class EditAlgorithmsPopUp extends JDialog {
 			list.setSelectedIndex(index+1);
 			updateThis(null);
 		});
-		btnDown.setBounds(306, 42, 64, 25);
+		btnDown.setBounds(310, 50, 75, 25);
 		getContentPane().add(btnDown);
+		
+		scrollPanelList = new JScrollPane();
+		scrollPanelList.setBounds(0, 0, 205, 375);
+		getContentPane().add(scrollPanelList);
+		
 		updateThis(null);
+		this.setResizable(false);
 		this.setLocationRelativeTo(parent);
 		this.setEnabled(true);
 		this.setVisible(true);
@@ -209,12 +222,16 @@ public class EditAlgorithmsPopUp extends JDialog {
 		 */
 		JList<String> newList = new JList<String>(algoNames);
 		newList.setToolTipText("List of all currently active ManipulationAlgorithms.");
-		newList.setBounds(10, 10, 200, 380);
+		newList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
+		
+		int pos = scrollPanelList.getVerticalScrollBar().getValue();
+
 		if(list!=null){
-			getContentPane().remove(list);
+			scrollPanelList.remove(list);
 			newList.setSelectedIndex(list.getSelectedIndex());		
 		}
-		getContentPane().add(newList);
+		scrollPanelList.setViewportView(newList);
+		scrollPanelList.getVerticalScrollBar().setValue(pos);
 		list = newList;
 		
 		this.repaint();