|
@@ -1,11 +1,17 @@
|
|
|
package de.tu_darmstadt.tk.SmartHomeNetworkSim.view;
|
|
|
|
|
|
import java.awt.Dimension;
|
|
|
+import java.awt.Window;
|
|
|
+import java.awt.event.ActionEvent;
|
|
|
+import java.awt.event.ActionListener;
|
|
|
+import java.util.Collection;
|
|
|
import java.util.LinkedList;
|
|
|
|
|
|
import javax.swing.JFrame;
|
|
|
|
|
|
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.control.Controller;
|
|
|
import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.Link;
|
|
|
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.Model;
|
|
|
import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.SmartDevice;
|
|
|
import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.simpleImplementation.SimpleLink;
|
|
|
|
|
@@ -23,11 +29,40 @@ public class LinkCreationPanel extends JScrollPane{
|
|
|
|
|
|
JPanel content;
|
|
|
private JTextField tfName;
|
|
|
- public LinkCreationPanel() {
|
|
|
+
|
|
|
+ private Window frame;
|
|
|
+
|
|
|
+ private Link newLink;
|
|
|
+ private SmartDevice[] devices;
|
|
|
+ private boolean edit;
|
|
|
+
|
|
|
+ private Controller controller;
|
|
|
+ public LinkCreationPanel(Link link, Controller controller) {
|
|
|
+ this.controller = controller;
|
|
|
+ newLink = link;
|
|
|
+ devices = (SmartDevice[]) link.getDevices().toArray();
|
|
|
+ edit = true;
|
|
|
+ initializePanel();
|
|
|
+ }
|
|
|
+
|
|
|
+ public LinkCreationPanel(Collection<SmartDevice> devices, Controller controller) {
|
|
|
+ this.controller = controller;
|
|
|
+ newLink = new SimpleLink("LinkName");
|
|
|
+ this.devices = new SmartDevice[devices.size()];
|
|
|
+ int i=0;
|
|
|
+ for(SmartDevice d: devices){
|
|
|
+ newLink.addDevice(d);
|
|
|
+ this.devices[i++] = d;
|
|
|
+ }
|
|
|
+ edit = false;
|
|
|
+ initializePanel();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void initializePanel() {
|
|
|
setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
|
|
|
- this.setPreferredSize(new Dimension(600, 400));
|
|
|
+ this.setPreferredSize(new Dimension(600, 170 + devices.length*20));
|
|
|
content = new JPanel();
|
|
|
- content.setPreferredSize(new Dimension(600,1000));
|
|
|
+ content.setPreferredSize(new Dimension(600, 150 + devices.length*20));
|
|
|
this.setViewportView(content);
|
|
|
content.setLayout(null);
|
|
|
|
|
@@ -41,10 +76,17 @@ public class LinkCreationPanel extends JScrollPane{
|
|
|
content.add(lblName);
|
|
|
|
|
|
tfName = new JTextField();
|
|
|
- tfName.setText("LinkName");
|
|
|
+ tfName.setText(newLink.getName());
|
|
|
tfName.setBounds(162, 39, 116, 22);
|
|
|
content.add(tfName);
|
|
|
tfName.setColumns(10);
|
|
|
+ tfName.addActionListener(new ActionListener() {
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void actionPerformed(ActionEvent e) {
|
|
|
+ newLink.setName(tfName.getText());
|
|
|
+ }
|
|
|
+ });
|
|
|
|
|
|
JLabel lblLinkType = new JLabel("Type:");
|
|
|
lblLinkType.setHorizontalAlignment(SwingConstants.RIGHT);
|
|
@@ -53,20 +95,68 @@ public class LinkCreationPanel extends JScrollPane{
|
|
|
|
|
|
JComboBox<String> cmbLinkType = new JComboBox<String>();
|
|
|
cmbLinkType.addItem("SimpleLink");
|
|
|
- cmbLinkType.addItem("ZigbeeNetwork");
|
|
|
+ cmbLinkType.addItem("testZigbee");
|
|
|
cmbLinkType.setBounds(162, 68, 116, 22);
|
|
|
content.add(cmbLinkType);
|
|
|
-
|
|
|
- content.setPreferredSize(new Dimension(500,1000));
|
|
|
+ cmbLinkType.addActionListener(new ActionListener() {
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void actionPerformed(ActionEvent e) {
|
|
|
+ System.out.println("WARNING: No further Link Types implemented");
|
|
|
+ }
|
|
|
+ });
|
|
|
|
|
|
JButton btnImportLink = new JButton("Import Link Type");
|
|
|
btnImportLink.setBounds(290, 67, 144, 25);
|
|
|
content.add(btnImportLink);
|
|
|
+ btnImportLink.addActionListener(a->System.out.println("WARNING: No import yet"));
|
|
|
|
|
|
JButton btnCreate = new JButton("Verify and Create");
|
|
|
btnCreate.setBounds(121, 103, 206, 25);
|
|
|
content.add(btnCreate);
|
|
|
+ btnCreate.addActionListener(new ActionListener() {
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void actionPerformed(ActionEvent e) {
|
|
|
+ if(!edit){
|
|
|
+ controller.addLink(newLink);
|
|
|
+ }
|
|
|
+ content.setVisible(false);
|
|
|
+ setVisible(false);
|
|
|
+ if(frame != null){
|
|
|
+ frame.setVisible(false);
|
|
|
+ frame.dispose();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
|
|
|
+ int currentHeight = 150;
|
|
|
+ for(int i = 0; i<devices.length;i++){
|
|
|
+ int pos = i;
|
|
|
+ JLabel lblDevice = new JLabel(devices[i].getName()+":");
|
|
|
+ lblDevice.setHorizontalAlignment(SwingConstants.RIGHT);
|
|
|
+ lblDevice.setBounds(10, currentHeight, 230, 18);
|
|
|
+ content.add(lblDevice);
|
|
|
+
|
|
|
+ JComboBox<String> cmbDev = new JComboBox<String>();
|
|
|
+ cmbDev.addItem("Connected");
|
|
|
+ cmbDev.addItem("Disconnected");
|
|
|
+ cmbDev.setBounds(250, currentHeight, 240, 18);
|
|
|
+ content.add(cmbDev);
|
|
|
+ cmbDev.addActionListener(new ActionListener() {
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void actionPerformed(ActionEvent e) {
|
|
|
+ if(cmbDev.getSelectedIndex()==0 && !newLink.getDevices().contains(devices[pos])){
|
|
|
+ newLink.addDevice(devices[pos]);
|
|
|
+ }else if(cmbDev.getSelectedIndex()==1&&newLink.getDevices().contains(devices[pos])){
|
|
|
+ newLink.removeDevice(devices[pos]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ currentHeight += 20;
|
|
|
+ }
|
|
|
+
|
|
|
JLabel lblDeviceA = new JLabel("DeviceA:");
|
|
|
lblDeviceA.setHorizontalAlignment(SwingConstants.RIGHT);
|
|
|
lblDeviceA.setBounds(12, 141, 138, 16);
|
|
@@ -82,26 +172,23 @@ public class LinkCreationPanel extends JScrollPane{
|
|
|
lblDeviceC.setBounds(12, 199, 138, 16);
|
|
|
content.add(lblDeviceC);
|
|
|
|
|
|
- JComboBox<String> comboBox = new JComboBox<String>();
|
|
|
- comboBox.addItem("Router");
|
|
|
- comboBox.addItem("Client");
|
|
|
- comboBox.addItem("not participating");
|
|
|
- comboBox.setBounds(162, 138, 165, 22);
|
|
|
- content.add(comboBox);
|
|
|
+ JComboBox<String> cmbDev1 = new JComboBox<String>();
|
|
|
+ cmbDev1.addItem("Connected");
|
|
|
+ cmbDev1.addItem("Disconnected");
|
|
|
+ cmbDev1.setBounds(162, 138, 165, 22);
|
|
|
+ content.add(cmbDev1);
|
|
|
|
|
|
- JComboBox<String> comboBox_1 = new JComboBox<String>();
|
|
|
- comboBox_1.addItem("Router");
|
|
|
- comboBox_1.addItem("Client");
|
|
|
- comboBox_1.addItem("not participating");
|
|
|
- comboBox_1.setBounds(162, 167, 165, 22);
|
|
|
- content.add(comboBox_1);
|
|
|
+ JComboBox<String> cmbDev2 = new JComboBox<String>();
|
|
|
+ cmbDev1.addItem("Connected");
|
|
|
+ cmbDev1.addItem("Disconnected");
|
|
|
+ cmbDev2.setBounds(162, 167, 165, 22);
|
|
|
+ content.add(cmbDev2);
|
|
|
|
|
|
- JComboBox<String> comboBox_2 = new JComboBox<String>();
|
|
|
- comboBox_2.addItem("Router");
|
|
|
- comboBox_2.addItem("Client");
|
|
|
- comboBox_2.addItem("not participating");
|
|
|
- comboBox_2.setBounds(162, 196, 165, 22);
|
|
|
- content.add(comboBox_2);
|
|
|
+ JComboBox<String> cmbDev3 = new JComboBox<String>();
|
|
|
+ cmbDev1.addItem("Connected");
|
|
|
+ cmbDev1.addItem("Disconnected");
|
|
|
+ cmbDev3.setBounds(162, 196, 165, 22);
|
|
|
+ content.add(cmbDev3);*/
|
|
|
}
|
|
|
|
|
|
|
|
@@ -111,16 +198,25 @@ public class LinkCreationPanel extends JScrollPane{
|
|
|
private static void testGUI() {
|
|
|
JFrame frame = new JFrame("LinkCreation Panel");
|
|
|
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
|
|
- SmartDevice test = new SmartDevice("TestDevice");
|
|
|
+
|
|
|
+ LinkCreationPanel panel;
|
|
|
+
|
|
|
LinkedList<SmartDevice> devicesOfLink = new LinkedList<SmartDevice>();
|
|
|
- devicesOfLink.add(test);
|
|
|
+ for(int i = 0; i<5; i++)
|
|
|
+ devicesOfLink.add(new SmartDevice("Device" + i));
|
|
|
+ panel = new LinkCreationPanel(devicesOfLink, new Controller(new Model()));
|
|
|
+
|
|
|
Link testNet = new SimpleLink("Test Network");
|
|
|
- testNet.addDevice(test);
|
|
|
- LinkCreationPanel panel = new LinkCreationPanel();
|
|
|
+ for(int i = 0; i<5; i++)
|
|
|
+ testNet.addDevice(new SmartDevice("Device" + i));
|
|
|
+ panel = new LinkCreationPanel(testNet);
|
|
|
+ */
|
|
|
+ panel.setFrame(frame);
|
|
|
frame.setContentPane(panel);
|
|
|
frame.pack();
|
|
|
frame.setVisible(true);
|
|
|
}
|
|
|
+
|
|
|
|
|
|
|
|
|
public static void main(String[] args) {
|
|
@@ -130,4 +226,18 @@ public class LinkCreationPanel extends JScrollPane{
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ * @return the frame
|
|
|
+ */
|
|
|
+ public Window getFrame() {
|
|
|
+ return frame;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * @param frame the frame to set
|
|
|
+ */
|
|
|
+ public void setFrame(Window frame) {
|
|
|
+ this.frame = frame;
|
|
|
+ }
|
|
|
}
|