|
@@ -18,10 +18,6 @@ import javax.swing.JTabbedPane;
|
|
|
import javax.swing.JTable;
|
|
|
import javax.swing.tree.DefaultTreeModel;
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
import ui.controller.Control;
|
|
|
import ui.model.*;
|
|
|
|
|
@@ -65,7 +61,6 @@ public class GUI implements CategoryListener {
|
|
|
|
|
|
private JFrame frmCyberPhysical;
|
|
|
|
|
|
-
|
|
|
private final JMenuBar menuBar = new JMenuBar();
|
|
|
private final JMenu mnNewMenu = new JMenu("File");
|
|
|
private final JMenu mnNewMenu_1 = new JMenu("Edit");
|
|
@@ -73,7 +68,7 @@ public class GUI implements CategoryListener {
|
|
|
private final JMenu mnNewMenu_3 = new JMenu("View");
|
|
|
private final JMenu mnHelp = new JMenu("Help");
|
|
|
private final JMenuItem mntmOpen = new JMenuItem("Open");
|
|
|
- private JMenuItem mntmNew = new JMenuItem("New");
|
|
|
+ private final JMenuItem mntmNew = new JMenuItem("New");
|
|
|
private final JMenuItem mntmSave = new JMenuItem("Save");
|
|
|
private final JSplitPane splitPane = new JSplitPane();
|
|
|
private final JSplitPane splitPane_1 = new JSplitPane();
|
|
@@ -87,25 +82,20 @@ public class GUI implements CategoryListener {
|
|
|
private JTable table;
|
|
|
private final JTable table_2 = new JTable();
|
|
|
private Model model;
|
|
|
- private final Control control;
|
|
|
- public Control getControl() {
|
|
|
- return control;
|
|
|
- }
|
|
|
+ private final Control controller;
|
|
|
|
|
|
private final JPanel panel = new JPanel();
|
|
|
private final JTextField textField = new JTextField();
|
|
|
private final JComboBox comboBox = new JComboBox();
|
|
|
private final JButton btnAdd = new JButton("Add");
|
|
|
|
|
|
-
|
|
|
private final JToolBar toolBar = new JToolBar();
|
|
|
-
|
|
|
|
|
|
/**
|
|
|
* Create the application.
|
|
|
*/
|
|
|
public GUI(Control control) {
|
|
|
- this.control = control;
|
|
|
+ this.controller = control;
|
|
|
this.model = control.getModel();
|
|
|
model.addCatListener(this);
|
|
|
initialize();
|
|
@@ -121,155 +111,136 @@ public class GUI implements CategoryListener {
|
|
|
frmCyberPhysical.setTitle("Cyber Physical Systems Model");
|
|
|
frmCyberPhysical.setBounds(100, 100, 891, 467);
|
|
|
frmCyberPhysical.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
|
|
-
|
|
|
+
|
|
|
frmCyberPhysical.setJMenuBar(menuBar);
|
|
|
-
|
|
|
+
|
|
|
menuBar.add(mnNewMenu);
|
|
|
-
|
|
|
+
|
|
|
mnNewMenu.add(mntmNew);
|
|
|
-
|
|
|
+
|
|
|
mnNewMenu.add(mntmOpen);
|
|
|
-
|
|
|
+
|
|
|
mnNewMenu.add(mntmSave);
|
|
|
-
|
|
|
+
|
|
|
menuBar.add(mnNewMenu_1);
|
|
|
-
|
|
|
+
|
|
|
menuBar.add(mnNewMenu_2);
|
|
|
-
|
|
|
+
|
|
|
menuBar.add(mnNewMenu_3);
|
|
|
-
|
|
|
+
|
|
|
menuBar.add(mnHelp);
|
|
|
-
|
|
|
- //Table
|
|
|
- String[] columnNames = {"Consumer",
|
|
|
- "Units",
|
|
|
- "Number"};
|
|
|
-
|
|
|
- Object[][] data = {
|
|
|
- {"TV", "20", "1"},
|
|
|
- {"PC", "30", "2"},
|
|
|
- {"Fridge", "40","1"}
|
|
|
- };
|
|
|
-
|
|
|
+
|
|
|
+ // Table
|
|
|
+ String[] columnNames = { "Consumer", "Units", "Number" };
|
|
|
+
|
|
|
+ Object[][] data = { { "TV", "20", "1" }, { "PC", "30", "2" }, { "Fridge", "40", "1" } };
|
|
|
+
|
|
|
splitPane.setRightComponent(splitPane_1);
|
|
|
splitPane.setDividerLocation(200);
|
|
|
splitPane_1.setDividerLocation(500);
|
|
|
canvas.setBackground(Color.WHITE);
|
|
|
-
|
|
|
+
|
|
|
tabbedPane.addTab("Modeling", null, canvas, null);
|
|
|
tabbedPane.addTab("Simulation", null, scrollPane_2, null);
|
|
|
dtrpnHereWillBe.setText("Here will be the Simulation");
|
|
|
-
|
|
|
+
|
|
|
scrollPane_2.setViewportView(dtrpnHereWillBe);
|
|
|
-
|
|
|
+
|
|
|
splitPane_1.setLeftComponent(tabbedPane);
|
|
|
-
|
|
|
+
|
|
|
JScrollPane scrollPane = new JScrollPane();
|
|
|
splitPane_1.setRightComponent(splitPane_2);
|
|
|
splitPane_2.setLeftComponent(scrollPane);
|
|
|
table = new JTable(data, columnNames);
|
|
|
scrollPane.setViewportView(table);
|
|
|
-
|
|
|
+
|
|
|
table.setFillsViewportHeight(true);
|
|
|
- table.setModel(new DefaultTableModel(
|
|
|
- data,
|
|
|
- columnNames
|
|
|
- ));
|
|
|
+ table.setModel(new DefaultTableModel(data, columnNames));
|
|
|
table.setCellSelectionEnabled(true);
|
|
|
table.setColumnSelectionAllowed(true);
|
|
|
JScrollPane scrollPane_3 = new JScrollPane();
|
|
|
splitPane_2.setRightComponent(scrollPane_3);
|
|
|
scrollPane_3.setViewportView(table_2);
|
|
|
-
|
|
|
+
|
|
|
table_2.setFillsViewportHeight(true);
|
|
|
- table_2.setModel(new DefaultTableModel(
|
|
|
- new Object[][] {
|
|
|
- {"Solar", "23", "10"},
|
|
|
- {"Generator", "24", "1"},
|
|
|
- {"Something Else", "25", "3"},
|
|
|
- },
|
|
|
- new String[] {
|
|
|
- "Producer", "Units", "Number"
|
|
|
- }
|
|
|
- ));
|
|
|
+ table_2.setModel(new DefaultTableModel(new Object[][] { { "Solar", "23", "10" }, { "Generator", "24", "1" },
|
|
|
+ { "Something Else", "25", "3" }, }, new String[] { "Producer", "Units", "Number" }));
|
|
|
table_2.getColumnModel().getColumn(0).setPreferredWidth(103);
|
|
|
table_2.getColumnModel().getColumn(1).setPreferredWidth(107);
|
|
|
table_2.getColumnModel().getColumn(2).setPreferredWidth(125);
|
|
|
frmCyberPhysical.getContentPane().setLayout(new BorderLayout(0, 0));
|
|
|
splitPane_2.setDividerLocation(200);
|
|
|
-
|
|
|
+
|
|
|
splitPane.setLeftComponent(scrollPane_1);
|
|
|
tree.setEditable(true);
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
scrollPane_1.setViewportView(tree);
|
|
|
-
|
|
|
+
|
|
|
scrollPane_1.setColumnHeaderView(panel);
|
|
|
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
|
|
|
toolBar.setFloatable(false);
|
|
|
-
|
|
|
+
|
|
|
panel.add(toolBar);
|
|
|
toolBar.add(comboBox);
|
|
|
- comboBox.setModel(new DefaultComboBoxModel(new String[] {"Category", "Object"}));
|
|
|
+ comboBox.setModel(new DefaultComboBoxModel(new String[] { "Category", "Object", "Transformer", "Switch" }));
|
|
|
btnAdd.addActionListener(new ActionListener() {
|
|
|
public void actionPerformed(ActionEvent arg0) {
|
|
|
- if(comboBox.getSelectedItem().toString() == "Category"){
|
|
|
- control.addCategory(textField.getText());
|
|
|
- }
|
|
|
- else if(comboBox.getSelectedItem().toString()== "Object"){
|
|
|
+ if (comboBox.getSelectedItem().toString() == "Category") {
|
|
|
+ controller.addNewCategory(textField.getText());
|
|
|
+ } else if (comboBox.getSelectedItem().toString() == "Object") {
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
toolBar.add(btnAdd);
|
|
|
panel.add(textField);
|
|
|
frmCyberPhysical.getContentPane().add(splitPane);
|
|
|
-
|
|
|
+
|
|
|
mntmOpen.addActionListener(new java.awt.event.ActionListener() {
|
|
|
- @Override
|
|
|
- public void actionPerformed(java.awt.event.ActionEvent evt) {
|
|
|
- menuFileExitActionPerformed(evt);
|
|
|
- }
|
|
|
+ @Override
|
|
|
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
|
|
|
+ menuFileExitActionPerformed(evt);
|
|
|
+ }
|
|
|
+
|
|
|
private void menuFileExitActionPerformed(java.awt.event.ActionEvent evt) {
|
|
|
JFileChooser fileChooser = new JFileChooser();
|
|
|
JFrame test = new JFrame();
|
|
|
if (fileChooser.showOpenDialog(test) == JFileChooser.APPROVE_OPTION) {
|
|
|
- File file = fileChooser.getSelectedFile();
|
|
|
- System.out.println("File Path is: "+file.toString());
|
|
|
+ File file = fileChooser.getSelectedFile();
|
|
|
+ System.out.println("File Path is: " + file.toString());
|
|
|
}
|
|
|
}
|
|
|
- });
|
|
|
-
|
|
|
+ });
|
|
|
+
|
|
|
}
|
|
|
-
|
|
|
- public void onChange(ArrayList<Category> cats){
|
|
|
+
|
|
|
+ public void onChange(ArrayList<Category> cats) {
|
|
|
DefaultTreeModel model = (DefaultTreeModel) tree.getModel();
|
|
|
refreshCategories(cats);
|
|
|
textField.setText("Test");
|
|
|
model.reload();
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
* reloads the Categories from Model
|
|
|
*/
|
|
|
- public void refreshCategories(final ArrayList<Category> cats){
|
|
|
- tree.setModel(new DefaultTreeModel(
|
|
|
- new DefaultMutableTreeNode("Categories") {
|
|
|
- {
|
|
|
- DefaultMutableTreeNode node_1;
|
|
|
- for (Category c : cats) {
|
|
|
- node_1 = new DefaultMutableTreeNode(c.getName());
|
|
|
-
|
|
|
- //kann eventuell umgeändert werden
|
|
|
- for (CpsObject hol : c.getObjects()) {
|
|
|
- node_1.add(new DefaultMutableTreeNode(hol.getObjName()));
|
|
|
- }
|
|
|
- add(node_1);
|
|
|
- }
|
|
|
-
|
|
|
+ public void refreshCategories(final ArrayList<Category> cats) {
|
|
|
+ tree.setModel(new DefaultTreeModel(new DefaultMutableTreeNode("Categories") {
|
|
|
+ {
|
|
|
+ DefaultMutableTreeNode node_1;
|
|
|
+ for (Category c : cats) {
|
|
|
+ node_1 = new DefaultMutableTreeNode(c.getName());
|
|
|
+
|
|
|
+ // kann eventuell umgeändert werden
|
|
|
+ for (CpsObject hol : c.getObjects()) {
|
|
|
+ node_1.add(new DefaultMutableTreeNode(hol.getObjName()));
|
|
|
}
|
|
|
+ add(node_1);
|
|
|
}
|
|
|
- ));
|
|
|
+
|
|
|
+ }
|
|
|
+ }));
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public JFrame getFrmCyberPhysical() {
|
|
|
return frmCyberPhysical;
|
|
|
}
|