Browse Source

First GUI version

Andreas T. Meyer-Berg 4 years ago
parent
commit
953a11cf06

+ 64 - 0
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/view/popups/PortDistributionConfigurationPopUp.java

@@ -0,0 +1,64 @@
+package de.tu_darmstadt.tk.SmartHomeNetworkSim.view.popups;
+
+import javax.swing.JFrame;
+import javax.swing.JPanel;
+
+import java.awt.BorderLayout;
+import java.util.Observable;
+import java.util.Observer;
+
+import javax.swing.JComboBox;
+import javax.swing.JLabel;
+import javax.swing.JButton;
+import javax.swing.JSplitPane;
+import javax.swing.border.EmptyBorder;
+
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.Port;
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.ProbabilityDistributionHandler;
+
+public class PortDistributionConfigurationPopUp extends JFrame implements Observer{
+	
+	private Port port;
+	
+	private JSplitPane splitPane;
+	
+	public PortDistributionConfigurationPopUp(Port port) {
+		this.port = port;
+		this.setSize(300, 500);
+		splitPane = new JSplitPane();
+		splitPane.setOrientation(JSplitPane.VERTICAL_SPLIT);
+		splitPane.setBorder(new EmptyBorder(0, 0, 0, 0));
+		getContentPane().add(splitPane, BorderLayout.CENTER);
+		
+		JPanel panel = new JPanel();
+		splitPane.setLeftComponent(panel);
+		panel.setLayout(null);
+		
+		JLabel lblDescription = new JLabel("Distribution Type:");
+		lblDescription.setBounds(10, 10, 120, 20);
+		panel.add(lblDescription);
+		
+		JComboBox comboBox = new JComboBox();
+		comboBox.setBounds(120, 10, 190, 20);
+		panel.add(comboBox);
+		
+		JButton btnImport = new JButton("Import");
+		btnImport.setBounds(320, 10, 100, 20);
+		panel.add(btnImport);
+
+		splitPane.setDividerLocation(40);
+		
+		update(null,null);
+	}
+
+	@Override
+	public void update(Observable o, Object arg) {
+		if(port == null)return;
+		ProbabilityDistributionHandler handler = port.getTriggerHandler();
+		
+		if(handler!=null)
+			splitPane.setRightComponent(handler.getConfigurationPanel());
+		else
+			splitPane.setRightComponent(null);
+	}
+}

+ 31 - 9
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/view/popups/PortEditorPanel.java

@@ -177,15 +177,21 @@ public class PortEditorPanel extends JPanel
         tfTriggerInterval = new JTextField();
         tfTriggerInterval.setBounds(160, 100, 130, 20);
         editPanel.add(tfTriggerInterval);
-        tfTriggerInterval.setColumns(10);
-        tfTriggerInterval.addFocusListener(this);
-        tfTriggerInterval.addActionListener(this);
-        tfTriggerInterval.addMouseListener(this);
+        //tfTriggerInterval.setColumns(10);
+        //tfTriggerInterval.addFocusListener(this);
+        //tfTriggerInterval.addActionListener(this);
+        //tfTriggerInterval.addMouseListener(this);
         tfTriggerInterval.setToolTipText(toolTipTrigger);
+        tfTriggerInterval.setEnabled(false);
         
-        JLabel lblTriggerIntervalUnit = new JLabel("ms");
-        lblTriggerIntervalUnit.setBounds(3000, 100, 50, 20);
-        editPanel.add(lblTriggerIntervalUnit);
+        JButton btnEditTriggerInterval = new JButton("Edit Distribution");
+        btnEditTriggerInterval.setBounds(300, 100, 150, 20);
+        btnEditTriggerInterval.addActionListener(l->openEditDistribution());
+        editPanel.add(btnEditTriggerInterval);
+        
+        //JLabel lblTriggerIntervalUnit = new JLabel("ms");
+        //lblTriggerIntervalUnit.setBounds(300, 100, 50, 20);
+        //editPanel.add(lblTriggerIntervalUnit);
         
         
         String toolTipResponse = "<html>Time in milliseconds which this port needs to calculate<br>"
@@ -271,7 +277,21 @@ public class PortEditorPanel extends JPanel
         	updateLabel(toEdit.getPorts().get(list.getSelectedIndex()));
     }
      
-    //Listens to the list
+    private void openEditDistribution() {
+    	if(list.getSelectedIndex() < 0 || list.getSelectedIndex() >= toEdit.getPorts().size())return;
+		/**
+		 * Port, which is being edited at the moment 
+		 */
+		Port toChange = toEdit.getPorts().get(list.getSelectedIndex());
+		
+		PortDistributionConfigurationPopUp popUp = new PortDistributionConfigurationPopUp(toChange);
+		popUp.setEnabled(true);
+		popUp.setVisible(true);
+		popUp.setLocationRelativeTo(this);
+		popUp.setFocusable(true);
+	}
+
+	//Listens to the list
     @SuppressWarnings("unchecked")
 	public void valueChanged(ListSelectionEvent e) {
     	if(!(e.getSource() instanceof JList<?>)||!(((JList<?>)e.getSource()).getSelectedValue() instanceof Port))return;
@@ -291,7 +311,7 @@ public class PortEditorPanel extends JPanel
     	tfLastTrigger.setBackground(Color.WHITE);
     	tfResponseTime.setText(""+port.getResponseTime());
     	tfResponseTime.setBackground(Color.WHITE);
-    	tfTriggerInterval.setText(""+port.getTriggerInterval());
+    	tfTriggerInterval.setText(""+port.getTriggerInterval()+" ms");
     	tfTriggerInterval.setBackground(Color.WHITE);
     	tfJitter.setText(""+port.getJitter());
     	tfJitter.setBackground(Color.WHITE);
@@ -375,6 +395,7 @@ public class PortEditorPanel extends JPanel
 			toChange.setStatus((short) cmbStatus.getSelectedIndex());
 		
 		//Edit trigger Interval
+		/**
 		if(tfTriggerInterval.getText()!=""+toChange.getTriggerInterval()){
 			try {
 				//TODO: Advanced Triggers
@@ -391,6 +412,7 @@ public class PortEditorPanel extends JPanel
 		}else{
 			tfTriggerInterval.setBackground(Color.WHITE);
 		}
+		*/
 		
 		//Edit Response time
 		if(tfResponseTime.getText()!=""+toChange.getResponseTime()){