|
@@ -1,22 +1,16 @@
|
|
package de.tu_darmstadt.tk.SmartHomeNetworkSim.view;
|
|
package de.tu_darmstadt.tk.SmartHomeNetworkSim.view;
|
|
|
|
|
|
import java.awt.Dimension;
|
|
import java.awt.Dimension;
|
|
|
|
+import java.awt.FlowLayout;
|
|
import java.awt.Toolkit;
|
|
import java.awt.Toolkit;
|
|
import java.awt.event.WindowEvent;
|
|
import java.awt.event.WindowEvent;
|
|
import java.awt.event.WindowStateListener;
|
|
import java.awt.event.WindowStateListener;
|
|
|
|
|
|
import javax.swing.JFrame;
|
|
import javax.swing.JFrame;
|
|
-import javax.swing.JMenuBar;
|
|
|
|
-import javax.swing.JMenuItem;
|
|
|
|
-
|
|
|
|
-import java.awt.BorderLayout;
|
|
|
|
-
|
|
|
|
-import javax.swing.SwingConstants;
|
|
|
|
|
|
|
|
import de.tu_darmstadt.tk.SmartHomeNetworkSim.control.Controller;
|
|
import de.tu_darmstadt.tk.SmartHomeNetworkSim.control.Controller;
|
|
import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.Model;
|
|
import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.Model;
|
|
-import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.util.Utility;
|
|
|
|
-import de.tu_darmstadt.tk.SmartHomeNetworkSim.view.popups.SimulationConfigurator;
|
|
|
|
|
|
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.view.util.Utility;
|
|
|
|
|
|
/**
|
|
/**
|
|
* Main class of the GUI, which combines the UserInterface and visualisation of the simulation.
|
|
* Main class of the GUI, which combines the UserInterface and visualisation of the simulation.
|
|
@@ -25,15 +19,23 @@ import de.tu_darmstadt.tk.SmartHomeNetworkSim.view.popups.SimulationConfigurator
|
|
*/
|
|
*/
|
|
@SuppressWarnings("serial")
|
|
@SuppressWarnings("serial")
|
|
public class MainFrame extends JFrame {
|
|
public class MainFrame extends JFrame {
|
|
-
|
|
|
|
- public final VisualisationPanel panel;
|
|
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Model of the smart home
|
|
* Model of the smart home
|
|
*/
|
|
*/
|
|
private Model model;
|
|
private Model model;
|
|
|
|
+ /**
|
|
|
|
+ * Controller for manipulation of the model
|
|
|
|
+ */
|
|
private Controller control;
|
|
private Controller control;
|
|
-
|
|
|
|
|
|
+ /**
|
|
|
|
+ * MenuBar of the GUI
|
|
|
|
+ */
|
|
|
|
+ private MenuBar menu;
|
|
|
|
+ /**
|
|
|
|
+ * Panel which visualizes the devices, connections and links
|
|
|
|
+ */
|
|
|
|
+ public final VisualisationPanel panel;
|
|
/**
|
|
/**
|
|
* Creates a new Frame for the program, which is the most outer frame of the application
|
|
* Creates a new Frame for the program, which is the most outer frame of the application
|
|
* @param m Model which is represented
|
|
* @param m Model which is represented
|
|
@@ -44,10 +46,10 @@ public class MainFrame extends JFrame {
|
|
this.model = m;
|
|
this.model = m;
|
|
this.control = c;
|
|
this.control = c;
|
|
|
|
|
|
- setTitle("Smart Home Network Simulator");
|
|
|
|
-
|
|
|
|
|
|
+ setTitle("Smart Home Network Simulator");
|
|
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
|
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
|
- getContentPane().setLayout(new BorderLayout(0, 0));
|
|
|
|
|
|
+ this.setIconImage(Utility.loadFile("images/SmartHomeNetworkSim_icon.jpeg"));
|
|
|
|
+ setLayout(new FlowLayout());
|
|
|
|
|
|
//Set initial size of the frame
|
|
//Set initial size of the frame
|
|
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
|
|
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
|
|
@@ -56,44 +58,21 @@ public class MainFrame extends JFrame {
|
|
this.setBounds(width/8, height/8, 6*width/8, 6*height/8);
|
|
this.setBounds(width/8, height/8, 6*width/8, 6*height/8);
|
|
this.setMinimumSize(new Dimension(640, 480));
|
|
this.setMinimumSize(new Dimension(640, 480));
|
|
|
|
|
|
|
|
+ /*
|
|
|
|
+ * Add Visualisation Panel
|
|
|
|
+ */
|
|
|
|
+ //Could be a more complex panel later on (TabbedPanel, ScrollPanel, SplitPanel
|
|
panel = new VisualisationPanel(model, control);
|
|
panel = new VisualisationPanel(model, control);
|
|
- getContentPane().add(panel, BorderLayout.CENTER);
|
|
|
|
|
|
+ this.setContentPane(panel);
|
|
c.addObserver(panel);
|
|
c.addObserver(panel);
|
|
- //Update model Dimensions to visualisation size
|
|
|
|
-
|
|
|
|
- try {
|
|
|
|
- /**
|
|
|
|
- * Icon of the MainFrame UI
|
|
|
|
- */
|
|
|
|
- String path = "images/SmartHomeNetworkSim_icon.jpeg";
|
|
|
|
- //this.setIconImage(ImageIO.read(new File("src/main/resources/images/SmartHomeNetworkSim_icon.jpeg")));
|
|
|
|
- this.setIconImage(Utility.loadFile(path));
|
|
|
|
- } catch (Exception e) {
|
|
|
|
- System.err.println("WARNING: Failed to load Icon image in MainFrame.java");
|
|
|
|
- e.printStackTrace();
|
|
|
|
- }
|
|
|
|
|
|
|
|
- JMenuBar menuBar = new JMenuBar();
|
|
|
|
- super.setJMenuBar(menuBar);
|
|
|
|
- //getContentPane().add(menuBar, BorderLayout.NORTH);
|
|
|
|
/*
|
|
/*
|
|
- JMenuItem mntmOptions = new JMenuItem("Options");
|
|
|
|
- mntmOptions.setHorizontalAlignment(SwingConstants.LEFT);
|
|
|
|
- menuBar.add(mntmOptions);
|
|
|
|
- */
|
|
|
|
- JMenuItem mntmSimulation = new JMenuItem("Simulation");
|
|
|
|
- mntmSimulation.setHorizontalAlignment(SwingConstants.LEFT);
|
|
|
|
- mntmSimulation.addActionListener(a->{
|
|
|
|
- SimulationConfigurator sim = new SimulationConfigurator(m.getSim());
|
|
|
|
- sim.setLocationRelativeTo(this);
|
|
|
|
- sim.setVisible(true);
|
|
|
|
- });
|
|
|
|
- menuBar.add(mntmSimulation);
|
|
|
|
- /*
|
|
|
|
- JMenuItem mntmOption = new JMenuItem("Options");
|
|
|
|
- menuBar.add(mntmOption);
|
|
|
|
- menuBar.setLayout(new FlowLayout(FlowLayout.LEFT));
|
|
|
|
- */
|
|
|
|
|
|
+ * Add Menu Bar
|
|
|
|
+ */
|
|
|
|
+ menu = new MenuBar(model, control);
|
|
|
|
+ super.setJMenuBar(menu);
|
|
|
|
+
|
|
|
|
+ //Show Frame
|
|
this.setVisible(true);
|
|
this.setVisible(true);
|
|
//Set Dimension of the model to the JPanel size
|
|
//Set Dimension of the model to the JPanel size
|
|
panel.delayedInit();
|
|
panel.delayedInit();
|
|
@@ -109,6 +88,8 @@ public class MainFrame extends JFrame {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
+
|
|
|
|
+ // Panel should get Focus, so Clicks on panel would be recognized
|
|
panel.requestFocusInWindow();
|
|
panel.requestFocusInWindow();
|
|
}
|
|
}
|
|
}
|
|
}
|