|
@@ -2,6 +2,8 @@ package de.tu_darmstadt.tk.SmartHomeNetworkSim.view.popups;
|
|
|
|
|
|
import java.awt.BorderLayout;
|
|
|
import java.awt.Color;
|
|
|
+import java.awt.event.FocusAdapter;
|
|
|
+import java.awt.event.FocusEvent;
|
|
|
import java.util.LinkedList;
|
|
|
|
|
|
import javax.swing.JButton;
|
|
@@ -16,6 +18,7 @@ import javax.swing.SwingUtilities;
|
|
|
|
|
|
import de.tu_darmstadt.tk.SmartHomeNetworkSim.control.Controller;
|
|
|
import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.SmartDevice;
|
|
|
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.devices.FloatSensor;
|
|
|
import de.tu_darmstadt.tk.SmartHomeNetworkSim.view.util.IntegerInputValidator;
|
|
|
|
|
|
import javax.swing.JComboBox;
|
|
@@ -77,6 +80,10 @@ public class SmartDeviceCreationPopUp extends JDialog {
|
|
|
* ComboBox containing the different Device classes
|
|
|
*/
|
|
|
private JComboBox<String> cmbDevice;
|
|
|
+ /**
|
|
|
+ * Bottom TabbedPane for different Sensor Collector settings.
|
|
|
+ */
|
|
|
+ JTabbedPane tbConfigureDevice;
|
|
|
|
|
|
/**
|
|
|
* Allows editing/creation of a smartDevice
|
|
@@ -176,6 +183,7 @@ public class SmartDeviceCreationPopUp extends JDialog {
|
|
|
} else {
|
|
|
newDevice = importedDevice;
|
|
|
lastSmartDeviceIndex = selectedIndex;
|
|
|
+ refreshGUI();
|
|
|
}
|
|
|
} else {
|
|
|
cmbDevice.setSelectedIndex(lastSmartDeviceIndex);
|
|
@@ -205,12 +213,16 @@ public class SmartDeviceCreationPopUp extends JDialog {
|
|
|
}
|
|
|
});
|
|
|
|
|
|
- JTabbedPane tbConfigureDevice = new JTabbedPane(JTabbedPane.TOP);
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Bottom TabbedPane for different Sensor Collector settings.
|
|
|
+ */
|
|
|
+ tbConfigureDevice = new JTabbedPane(JTabbedPane.TOP);
|
|
|
tbConfigureDevice.setBounds(10, 147, 607, 230);
|
|
|
panelGeneral.add(tbConfigureDevice);
|
|
|
|
|
|
- JPanel panel = new JPanel();
|
|
|
- tbConfigureDevice.addTab("Sensor", null, panel, null);
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
@@ -322,6 +334,146 @@ public class SmartDeviceCreationPopUp extends JDialog {
|
|
|
lastSmartDeviceIndex = i;
|
|
|
}
|
|
|
cmbDevice.setSelectedIndex(lastSmartDeviceIndex);
|
|
|
+
|
|
|
+ tbConfigureDevice.removeAll();
|
|
|
+ tbConfigureDevice.setVisible(false);
|
|
|
+ if(newDevice instanceof FloatSensor)
|
|
|
+ initializesSensorConfigurationPanel();
|
|
|
+ if(tbConfigureDevice.getTabCount()>0)
|
|
|
+ tbConfigureDevice.setVisible(true);
|
|
|
+
|
|
|
mutex = false;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Initializes a panel for Float Sensors
|
|
|
+ */
|
|
|
+ private void initializesSensorConfigurationPanel(){
|
|
|
+ if(!(newDevice instanceof FloatSensor))return;
|
|
|
+ FloatSensor sensor = (FloatSensor) newDevice;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Configure FloatSensor Tab
|
|
|
+ */
|
|
|
+ JPanel pnlFloatSensor = new JPanel();
|
|
|
+ tbConfigureDevice.addTab("FloatSensor", null, pnlFloatSensor, null);
|
|
|
+ pnlFloatSensor.setLayout(null);
|
|
|
+
|
|
|
+ JLabel lblInformationname = new JLabel("InformationName:");
|
|
|
+ lblInformationname.setHorizontalAlignment(SwingConstants.RIGHT);
|
|
|
+ lblInformationname.setBounds(10, 10, 200, 20);
|
|
|
+ pnlFloatSensor.add(lblInformationname);
|
|
|
+
|
|
|
+ JTextField tfInfoName = new JTextField();
|
|
|
+ tfInfoName.setBounds(220, 10, 220, 20);
|
|
|
+ tfInfoName.setColumns(10);
|
|
|
+ tfInfoName.setText(sensor.getFSinfoName());
|
|
|
+ tfInfoName.addActionListener(a->{
|
|
|
+ sensor.setFSinfoName(tfInfoName.getText());
|
|
|
+ });
|
|
|
+ tfInfoName.addFocusListener(new FocusAdapter() {
|
|
|
+ @Override
|
|
|
+ public void focusLost(FocusEvent e) {
|
|
|
+ sensor.setFSinfoName(tfInfoName.getText());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ pnlFloatSensor.add(tfInfoName);
|
|
|
+
|
|
|
+ JLabel lblValue = new JLabel("Value:");
|
|
|
+ lblValue.setHorizontalAlignment(SwingConstants.RIGHT);
|
|
|
+ lblValue.setBounds(10, 40, 200, 20);
|
|
|
+ pnlFloatSensor.add(lblValue);
|
|
|
+
|
|
|
+ JTextField tfValue = new JTextField();
|
|
|
+ tfValue.setColumns(10);
|
|
|
+ tfValue.setBounds(220, 40, 220, 20);
|
|
|
+ tfValue.setText(""+sensor.getFSval());
|
|
|
+ tfValue.addFocusListener(new FocusAdapter() {
|
|
|
+ @Override
|
|
|
+ public void focusLost(FocusEvent e) {
|
|
|
+ try{
|
|
|
+ float val = Float.parseFloat(tfValue.getText());
|
|
|
+ tfValue.setBackground(Color.WHITE);
|
|
|
+ sensor.setFSval(val);
|
|
|
+ }catch (Exception ef) {
|
|
|
+ tfValue.setBackground(Color.RED);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ tfValue.addActionListener(a->{
|
|
|
+ try{
|
|
|
+ float val = Float.parseFloat(tfValue.getText());
|
|
|
+ tfValue.setBackground(Color.WHITE);
|
|
|
+ sensor.setFSval(val);
|
|
|
+ }catch (Exception e) {
|
|
|
+ tfValue.setBackground(Color.RED);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ pnlFloatSensor.add(tfValue);
|
|
|
+
|
|
|
+ JLabel lblMinimum = new JLabel("Minimum:");
|
|
|
+ lblMinimum.setHorizontalAlignment(SwingConstants.RIGHT);
|
|
|
+ lblMinimum.setBounds(10, 70, 200, 20);
|
|
|
+ pnlFloatSensor.add(lblMinimum);
|
|
|
+
|
|
|
+ JTextField tfMinimum = new JTextField();
|
|
|
+ tfMinimum.setColumns(10);
|
|
|
+ tfMinimum.setBounds(220, 70, 220, 20);
|
|
|
+ tfMinimum.setText(""+sensor.getFSmin());
|
|
|
+ tfMinimum.addFocusListener(new FocusAdapter() {
|
|
|
+ @Override
|
|
|
+ public void focusLost(FocusEvent e) {
|
|
|
+ try{
|
|
|
+ float val = Float.parseFloat(tfMinimum.getText());
|
|
|
+ tfMinimum.setBackground(Color.WHITE);
|
|
|
+ sensor.setFSmin(val);
|
|
|
+ }catch (Exception ef) {
|
|
|
+ tfMinimum.setBackground(Color.RED);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ tfMinimum.addActionListener(a->{
|
|
|
+ try{
|
|
|
+ float val = Float.parseFloat(tfMinimum.getText());
|
|
|
+ tfMinimum.setBackground(Color.WHITE);
|
|
|
+ sensor.setFSmin(val);
|
|
|
+ }catch (Exception e) {
|
|
|
+ tfMinimum.setBackground(Color.RED);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ pnlFloatSensor.add(tfMinimum);
|
|
|
+
|
|
|
+ JLabel lblMaximum = new JLabel("Maximum:");
|
|
|
+ lblMaximum.setHorizontalAlignment(SwingConstants.RIGHT);
|
|
|
+ lblMaximum.setBounds(10, 100, 200, 20);
|
|
|
+ pnlFloatSensor.add(lblMaximum);
|
|
|
+
|
|
|
+ JTextField tfMaxmimum = new JTextField();
|
|
|
+ tfMaxmimum.setColumns(10);
|
|
|
+ tfMaxmimum.setBounds(220, 100, 220, 20);
|
|
|
+ tfMaxmimum.setText(""+sensor.getFSmax());
|
|
|
+ tfMaxmimum.addFocusListener(new FocusAdapter() {
|
|
|
+ @Override
|
|
|
+ public void focusLost(FocusEvent e) {
|
|
|
+ try{
|
|
|
+ float val = Float.parseFloat(tfMaxmimum.getText());
|
|
|
+ tfMaxmimum.setBackground(Color.WHITE);
|
|
|
+ sensor.setFSmax(val);
|
|
|
+ }catch (Exception er) {
|
|
|
+ tfMaxmimum.setBackground(Color.RED);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ tfMaxmimum.addActionListener(a->{
|
|
|
+ try{
|
|
|
+ float val = Float.parseFloat(tfMaxmimum.getText());
|
|
|
+ tfMaxmimum.setBackground(Color.WHITE);
|
|
|
+ sensor.setFSmax(val);
|
|
|
+ }catch (Exception e) {
|
|
|
+ tfMaxmimum.setBackground(Color.RED);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ pnlFloatSensor.add(tfMaxmimum);
|
|
|
+
|
|
|
+ }
|
|
|
}
|