|
@@ -2,6 +2,9 @@ package de.tu_darmstadt.tk.SmartHomeNetworkSim.view.popups;
|
|
|
|
|
|
import java.awt.BorderLayout;
|
|
|
import java.awt.Rectangle;
|
|
|
+import java.awt.event.WindowAdapter;
|
|
|
+import java.util.Observable;
|
|
|
+import java.util.Observer;
|
|
|
|
|
|
import javax.swing.JCheckBox;
|
|
|
import javax.swing.JFrame;
|
|
@@ -20,7 +23,7 @@ import de.tu_darmstadt.tk.SmartHomeNetworkSim.view.util.Utility;
|
|
|
*
|
|
|
* @author Andreas T. Meyer-Berg
|
|
|
*/
|
|
|
-public class SettingsPopUp extends JFrame {
|
|
|
+public class SettingsPopUp extends JFrame implements Observer {
|
|
|
|
|
|
/**
|
|
|
* Main Controller
|
|
@@ -31,6 +34,11 @@ public class SettingsPopUp extends JFrame {
|
|
|
*/
|
|
|
private SettingsController config;
|
|
|
|
|
|
+ /**
|
|
|
+ * Reference to this
|
|
|
+ */
|
|
|
+ private SettingsPopUp that;
|
|
|
+
|
|
|
/**
|
|
|
* Creates a SettingsPopUp
|
|
|
*
|
|
@@ -41,6 +49,7 @@ public class SettingsPopUp extends JFrame {
|
|
|
setBounds(new Rectangle(0, 0, 450, 300));
|
|
|
this.controller = controller;
|
|
|
this.config = this.controller.getSettingsController();
|
|
|
+ this.that = this;
|
|
|
|
|
|
setTitle("Settings");
|
|
|
setIconImage(Utility.loadFile("/images/settings.png"));
|
|
@@ -66,13 +75,12 @@ public class SettingsPopUp extends JFrame {
|
|
|
lblradiusInPixels.setBounds(12, 43, 118, 16);
|
|
|
pVisualisation.add(lblradiusInPixels);
|
|
|
|
|
|
- JSlider sliderRadius = new JSlider();
|
|
|
+ sliderRadius = new JSlider();
|
|
|
sliderRadius.setPaintLabels(true);
|
|
|
sliderRadius.setPaintTicks(true);
|
|
|
sliderRadius.setMajorTickSpacing(18);
|
|
|
sliderRadius.setMaximum(110);
|
|
|
sliderRadius.setMinimum(2);
|
|
|
- sliderRadius.setValue(config.getDeviceVisualizationRadius());
|
|
|
sliderRadius.setBounds(135, 13, 280, 45);
|
|
|
pVisualisation.add(sliderRadius);
|
|
|
sliderRadius.addChangeListener(a -> {
|
|
@@ -80,14 +88,9 @@ public class SettingsPopUp extends JFrame {
|
|
|
controller.notifyObservers();
|
|
|
});
|
|
|
|
|
|
- /****************************************************************************
|
|
|
- * Show Terminated Connections Settings
|
|
|
- ****************************************************************************/
|
|
|
- JCheckBox chckbxTerminatedConnections = new JCheckBox(
|
|
|
+ chckbxTerminatedConnections = new JCheckBox(
|
|
|
"Show terminated connections");
|
|
|
chckbxTerminatedConnections.setBounds(8, 67, 197, 25);
|
|
|
- chckbxTerminatedConnections.setSelected(config
|
|
|
- .isShowTerminatedConnections());
|
|
|
chckbxTerminatedConnections.addActionListener(a -> config
|
|
|
.setShowTerminatedConnections(chckbxTerminatedConnections
|
|
|
.isSelected()));
|
|
@@ -95,60 +98,40 @@ public class SettingsPopUp extends JFrame {
|
|
|
.setToolTipText("<html>True if connections to devices, which were removed from the connection,<br> should be shown until the terminating packages of this device were sent.</html>");
|
|
|
pVisualisation.add(chckbxTerminatedConnections);
|
|
|
|
|
|
- /****************************************************************************
|
|
|
- * Show Connections Settings
|
|
|
- ****************************************************************************/
|
|
|
- JCheckBox chckbxConnections = new JCheckBox("Show connections");
|
|
|
+ chckbxConnections = new JCheckBox("Show connections");
|
|
|
chckbxConnections.setBounds(237, 67, 182, 25);
|
|
|
- chckbxConnections.setSelected(config.isShowConnections());
|
|
|
chckbxConnections.addActionListener(a -> config
|
|
|
.setShowConnections(chckbxConnections.isSelected()));
|
|
|
chckbxConnections
|
|
|
.setToolTipText("True if connections (Services/Connections) should be shown on the Visualization Panel.");
|
|
|
pVisualisation.add(chckbxConnections);
|
|
|
|
|
|
- /****************************************************************************
|
|
|
- * Show Links Settings
|
|
|
- ****************************************************************************/
|
|
|
- JCheckBox chckbxLinks = new JCheckBox("Show links");
|
|
|
+ chckbxLinks = new JCheckBox("Show links");
|
|
|
chckbxLinks.setBounds(237, 97, 178, 25);
|
|
|
- chckbxLinks.setSelected(config.isShowLinks());
|
|
|
chckbxLinks.addActionListener(a -> config.setShowLinks(chckbxLinks
|
|
|
.isSelected()));
|
|
|
chckbxLinks
|
|
|
.setToolTipText("<html>True if Links (Mediums of physical connection for devices like Wifi, Ethernet, Zigbee),<br> should be visualized (As part of the Circle around the Devices)</html>");
|
|
|
pVisualisation.add(chckbxLinks);
|
|
|
|
|
|
- /****************************************************************************
|
|
|
- * Show Link Tool Tips Settings
|
|
|
- ****************************************************************************/
|
|
|
- JCheckBox chckbxLinkToolTips = new JCheckBox("Show link ToolTips");
|
|
|
+ chckbxLinkToolTips = new JCheckBox("Show link ToolTips");
|
|
|
chckbxLinkToolTips.setBounds(237, 127, 178, 25);
|
|
|
- chckbxLinkToolTips.setSelected(config.isShowLinkToolTips());
|
|
|
chckbxLinkToolTips.addActionListener(a -> config
|
|
|
.setShowLinkToolTips(chckbxLinkToolTips.isSelected()));
|
|
|
chckbxLinkToolTips
|
|
|
.setToolTipText("True if the link name should be shown on, when the mouse hovers over the link");
|
|
|
pVisualisation.add(chckbxLinkToolTips);
|
|
|
|
|
|
- /****************************************************************************
|
|
|
- * Show SmartDevices Settings
|
|
|
- ****************************************************************************/
|
|
|
- JCheckBox chckbxSmartdevices = new JCheckBox("Show SmartDevices");
|
|
|
+ chckbxSmartdevices = new JCheckBox("Show SmartDevices");
|
|
|
chckbxSmartdevices.setBounds(8, 97, 197, 25);
|
|
|
- chckbxSmartdevices.setSelected(config.isShowSmartDevices());
|
|
|
chckbxSmartdevices.addActionListener(a -> config
|
|
|
.setShowSmartDevices(chckbxSmartdevices.isSelected()));
|
|
|
chckbxSmartdevices
|
|
|
.setToolTipText("True if SmartDevices should be shown (Circles on the VisualizationPanel)");
|
|
|
pVisualisation.add(chckbxSmartdevices);
|
|
|
|
|
|
- /****************************************************************************
|
|
|
- * Show SmartDevice Names Settings
|
|
|
- ****************************************************************************/
|
|
|
- JCheckBox chckbxDeviceNames = new JCheckBox("Show SmartDevice names");
|
|
|
+ chckbxDeviceNames = new JCheckBox("Show SmartDevice names");
|
|
|
chckbxDeviceNames.setBounds(8, 127, 197, 25);
|
|
|
- chckbxDeviceNames.setSelected(config.isShowSmartDeviceNames());
|
|
|
chckbxDeviceNames.addActionListener(a -> config
|
|
|
.setShowSmartDeviceNames(chckbxDeviceNames.isSelected()));
|
|
|
chckbxDeviceNames
|
|
@@ -167,10 +150,40 @@ public class SettingsPopUp extends JFrame {
|
|
|
* JPanel pSimulation = new JPanel(); tabbedPane.addTab("Simulation",
|
|
|
* null, pSimulation, null);
|
|
|
*/
|
|
|
+ update(null, null);
|
|
|
+ this.addWindowListener(new WindowAdapter() {
|
|
|
+ public void windowClosing(java.awt.event.WindowEvent e) {
|
|
|
+ controller.removeObserver(that);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ controller.addObserver(this);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
*
|
|
|
*/
|
|
|
private static final long serialVersionUID = -7638231800254589350L;
|
|
|
+ private JCheckBox chckbxDeviceNames;
|
|
|
+ private JSlider sliderRadius;
|
|
|
+ private JCheckBox chckbxTerminatedConnections;
|
|
|
+ private JCheckBox chckbxConnections;
|
|
|
+ private JCheckBox chckbxLinks;
|
|
|
+ private JCheckBox chckbxLinkToolTips;
|
|
|
+ private JCheckBox chckbxSmartdevices;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void update(Observable o, Object arg) {
|
|
|
+ /**
|
|
|
+ * Update all sliders and checkboxes to the current values in the
|
|
|
+ * SettingsController
|
|
|
+ */
|
|
|
+ sliderRadius.setValue(config.getDeviceVisualizationRadius());
|
|
|
+ chckbxTerminatedConnections.setSelected(config
|
|
|
+ .isShowTerminatedConnections());
|
|
|
+ chckbxConnections.setSelected(config.isShowConnections());
|
|
|
+ chckbxLinks.setSelected(config.isShowLinks());
|
|
|
+ chckbxLinkToolTips.setSelected(config.isShowLinkToolTips());
|
|
|
+ chckbxSmartdevices.setSelected(config.isShowSmartDevices());
|
|
|
+ chckbxDeviceNames.setSelected(config.isShowSmartDeviceNames());
|
|
|
+ }
|
|
|
}
|