SettingsPopUp.java 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. package de.tu_darmstadt.tk.SmartHomeNetworkSim.view.popups;
  2. import java.awt.BorderLayout;
  3. import java.awt.Rectangle;
  4. import java.awt.event.WindowAdapter;
  5. import java.util.Observable;
  6. import java.util.Observer;
  7. import javax.swing.JCheckBox;
  8. import javax.swing.JFrame;
  9. import javax.swing.JLabel;
  10. import javax.swing.JPanel;
  11. import javax.swing.JSlider;
  12. import javax.swing.JTabbedPane;
  13. import javax.swing.SwingConstants;
  14. import de.tu_darmstadt.tk.SmartHomeNetworkSim.control.SettingsController;
  15. import de.tu_darmstadt.tk.SmartHomeNetworkSim.control.Controller;
  16. import de.tu_darmstadt.tk.SmartHomeNetworkSim.view.util.Utility;
  17. /**
  18. * PopUp to display and edit the settings
  19. *
  20. * @author Andreas T. Meyer-Berg
  21. */
  22. public class SettingsPopUp extends JFrame implements Observer {
  23. /**
  24. * Main Controller
  25. */
  26. private Controller controller;
  27. /**
  28. * Settings controller
  29. */
  30. private SettingsController config;
  31. /**
  32. * Reference to this
  33. */
  34. private SettingsPopUp that;
  35. /**
  36. * Creates a SettingsPopUp
  37. *
  38. * @param controller
  39. * controller which should manipulate the model
  40. */
  41. public SettingsPopUp(Controller controller) {
  42. setBounds(new Rectangle(0, 0, 470, 360));
  43. this.controller = controller;
  44. this.config = this.controller.getSettingsController();
  45. this.that = this;
  46. setTitle("Settings");
  47. setIconImage(Utility.loadFile("/images/settings.png"));
  48. JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
  49. getContentPane().add(tabbedPane, BorderLayout.CENTER);
  50. /****************************************************************************
  51. * Visualization Radius Settings
  52. ****************************************************************************/
  53. JPanel pVisualisation = new JPanel();
  54. tabbedPane.addTab("Visualization", null, pVisualisation, null);
  55. pVisualisation.setLayout(null);
  56. JLabel lblVisualisationSize = new JLabel("Visualization Radius:");
  57. lblVisualisationSize.setBounds(10, 10, 150, 20);
  58. lblVisualisationSize.setHorizontalAlignment(SwingConstants.RIGHT);
  59. lblVisualisationSize
  60. .setToolTipText("<html>Radius of the SmartDevice Visualization, which is half of the Device width.</html>");
  61. pVisualisation.add(lblVisualisationSize);
  62. JLabel lblradiusInPixels = new JLabel("(Radius in pixels:)");
  63. lblradiusInPixels.setHorizontalAlignment(SwingConstants.RIGHT);
  64. lblradiusInPixels.setBounds(10, 30, 150, 20);
  65. pVisualisation.add(lblradiusInPixels);
  66. sliderRadius = new JSlider();
  67. sliderRadius.setPaintLabels(true);
  68. sliderRadius.setPaintTicks(true);
  69. sliderRadius.setMajorTickSpacing(18);
  70. sliderRadius.setMaximum(110);
  71. sliderRadius.setMinimum(2);
  72. sliderRadius.setBounds(160, 10, 280, 50);
  73. pVisualisation.add(sliderRadius);
  74. sliderRadius.addChangeListener(a -> {
  75. config.setDeviceVisualizationRadius(sliderRadius.getValue());
  76. controller.notifyObservers();
  77. });
  78. JLabel lblLinkSize = new JLabel("Link dimension:");
  79. lblLinkSize.setBounds(10, 60, 150, 20);
  80. lblLinkSize
  81. .setToolTipText("<html>Dimenions of the Link visualization around SmartDevices.</html>");
  82. lblLinkSize.setHorizontalAlignment(SwingConstants.RIGHT);
  83. pVisualisation.add(lblLinkSize);
  84. JLabel lblDimInPixels = new JLabel("(Dimension in pixels:)");
  85. lblDimInPixels.setHorizontalAlignment(SwingConstants.RIGHT);
  86. lblDimInPixels.setBounds(10, 80, 150, 20);
  87. pVisualisation.add(lblDimInPixels);
  88. sliderLinkRadius = new JSlider();
  89. sliderLinkRadius.setPaintLabels(true);
  90. sliderLinkRadius.setPaintTicks(true);
  91. sliderLinkRadius.setMajorTickSpacing(18);
  92. sliderLinkRadius.setMaximum(110);
  93. sliderLinkRadius.setMinimum(2);
  94. sliderLinkRadius.setBounds(160, 70, 280, 50);
  95. pVisualisation.add(sliderLinkRadius);
  96. sliderLinkRadius.addChangeListener(a -> {
  97. config.setLinkRadius(sliderLinkRadius.getValue());
  98. controller.notifyObservers();
  99. });
  100. chckbxTerminatedConnections = new JCheckBox(
  101. "Show terminated connections");
  102. chckbxTerminatedConnections.setBounds(0, 150, 240, 25);
  103. chckbxTerminatedConnections.addActionListener(a -> config
  104. .setShowTerminatedConnections(chckbxTerminatedConnections
  105. .isSelected()));
  106. chckbxTerminatedConnections
  107. .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>");
  108. pVisualisation.add(chckbxTerminatedConnections);
  109. chckbxConnections = new JCheckBox("Show connections");
  110. chckbxConnections.setBounds(240, 150, 200, 25);
  111. chckbxConnections.addActionListener(a -> config
  112. .setShowConnections(chckbxConnections.isSelected()));
  113. chckbxConnections
  114. .setToolTipText("True if connections (Services/Connections) should be shown on the Visualization Panel.");
  115. pVisualisation.add(chckbxConnections);
  116. chckbxLinks = new JCheckBox("Show links");
  117. chckbxLinks.setBounds(240, 180, 200, 25);
  118. chckbxLinks.addActionListener(a -> config.setShowLinks(chckbxLinks
  119. .isSelected()));
  120. chckbxLinks
  121. .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>");
  122. pVisualisation.add(chckbxLinks);
  123. chckbxLinkToolTips = new JCheckBox("Show link ToolTips");
  124. chckbxLinkToolTips.setBounds(240, 210, 200, 25);
  125. chckbxLinkToolTips.addActionListener(a -> config
  126. .setShowLinkToolTips(chckbxLinkToolTips.isSelected()));
  127. chckbxLinkToolTips
  128. .setToolTipText("True if the link name should be shown on, when the mouse hovers over the link");
  129. pVisualisation.add(chckbxLinkToolTips);
  130. chckbxLinkNames = new JCheckBox("Show Link names as a list");
  131. chckbxLinkNames.setBounds(240, 240, 200, 25);
  132. chckbxLinkNames.addActionListener(a -> config
  133. .setShowLinkNameList(chckbxLinkNames.isSelected()));
  134. chckbxLinkNames
  135. .setToolTipText("True if the link names should be shown in a list in the visualization panel");
  136. pVisualisation.add(chckbxLinkNames);
  137. chckbxSmartdevices = new JCheckBox("Show SmartDevices");
  138. chckbxSmartdevices.setBounds(0, 180, 240, 25);
  139. chckbxSmartdevices.addActionListener(a -> config
  140. .setShowSmartDevices(chckbxSmartdevices.isSelected()));
  141. chckbxSmartdevices
  142. .setToolTipText("True if SmartDevices should be shown (Circles on the VisualizationPanel)");
  143. pVisualisation.add(chckbxSmartdevices);
  144. chckbxDeviceNames = new JCheckBox("Show SmartDevice names");
  145. chckbxDeviceNames.setBounds(0, 210, 240, 25);
  146. chckbxDeviceNames.addActionListener(a -> config
  147. .setShowSmartDeviceNames(chckbxDeviceNames.isSelected()));
  148. chckbxDeviceNames
  149. .setToolTipText("True if SmartDevice names should be shown");
  150. pVisualisation.add(chckbxDeviceNames);
  151. chckbxDebugMode = new JCheckBox("Show debug information");
  152. chckbxDebugMode.setBounds(0, 240, 240, 25);
  153. chckbxDebugMode.addActionListener(a -> config
  154. .setDebugModus(chckbxDebugMode.isSelected()));
  155. chckbxDebugMode
  156. .setToolTipText("True if debug information should be shown");
  157. pVisualisation.add(chckbxDebugMode);
  158. /****************************************************************************
  159. * Show Further tabs for: Imports, Simulation, Graphics e.g.
  160. ****************************************************************************/
  161. /**
  162. * Unused Tabs for further settings
  163. **
  164. * JPanel pImports = new JPanel(); tabbedPane.addTab("Imports", null,
  165. * pImports, null);
  166. *
  167. * JPanel pSimulation = new JPanel(); tabbedPane.addTab("Simulation",
  168. * null, pSimulation, null);
  169. */
  170. update(null, null);
  171. this.addWindowListener(new WindowAdapter() {
  172. public void windowClosing(java.awt.event.WindowEvent e) {
  173. controller.removeObserver(that);
  174. }
  175. });
  176. controller.addObserver(this);
  177. }
  178. /**
  179. *
  180. */
  181. private static final long serialVersionUID = -7638231800254589350L;
  182. private JCheckBox chckbxDeviceNames;
  183. private JSlider sliderRadius;
  184. private JSlider sliderLinkRadius;
  185. private JCheckBox chckbxTerminatedConnections;
  186. private JCheckBox chckbxConnections;
  187. private JCheckBox chckbxLinks;
  188. private JCheckBox chckbxLinkToolTips;
  189. private JCheckBox chckbxLinkNames;
  190. private JCheckBox chckbxSmartdevices;
  191. private JCheckBox chckbxDebugMode;
  192. @Override
  193. public void update(Observable o, Object arg) {
  194. /**
  195. * Update all sliders and checkboxes to the current values in the
  196. * SettingsController
  197. */
  198. sliderRadius.setValue(config.getDeviceVisualizationRadius());
  199. sliderLinkRadius.setValue(config.getLinkRadius());
  200. chckbxTerminatedConnections.setSelected(config
  201. .isShowTerminatedConnections());
  202. chckbxConnections.setSelected(config.isShowConnections());
  203. chckbxLinks.setSelected(config.isShowLinks());
  204. chckbxLinkToolTips.setSelected(config.isShowLinkToolTips());
  205. chckbxSmartdevices.setSelected(config.isShowSmartDevices());
  206. chckbxDeviceNames.setSelected(config.isShowSmartDeviceNames());
  207. chckbxLinkNames.setSelected(config.isShowLinkNameList());
  208. chckbxDebugMode.setSelected(config.isDebugModus());
  209. }
  210. }