|
@@ -75,19 +75,25 @@ public class GUI implements CategoryListener {
|
|
private final JScrollPane scrollPane_1 = new JScrollPane();
|
|
private final JScrollPane scrollPane_1 = new JScrollPane();
|
|
private final JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
|
|
private final JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
|
|
private final JScrollPane scrollPane_2 = new JScrollPane();
|
|
private final JScrollPane scrollPane_2 = new JScrollPane();
|
|
|
|
+
|
|
private final MyCanvas canvas = new MyCanvas();
|
|
private final MyCanvas canvas = new MyCanvas();
|
|
|
|
+
|
|
private final JTree tree = new JTree();
|
|
private final JTree tree = new JTree();
|
|
private final JEditorPane dtrpnHereWillBe = new JEditorPane();
|
|
private final JEditorPane dtrpnHereWillBe = new JEditorPane();
|
|
private final JSplitPane splitPane_2 = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
|
|
private final JSplitPane splitPane_2 = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
|
|
|
|
+
|
|
private JTable table;
|
|
private JTable table;
|
|
- private final JTable table_2 = new JTable();
|
|
|
|
- private Model model;
|
|
|
|
|
|
+ private JTable table_2 = new JTable();
|
|
|
|
+ private final Model model;
|
|
private final Control controller;
|
|
private final Control controller;
|
|
|
|
|
|
private final JPanel panel = new JPanel();
|
|
private final JPanel panel = new JPanel();
|
|
private final JTextField textField = new JTextField();
|
|
private final JTextField textField = new JTextField();
|
|
private final JComboBox comboBox = new JComboBox();
|
|
private final JComboBox comboBox = new JComboBox();
|
|
|
|
+
|
|
|
|
+ // Buttons
|
|
private final JButton btnAdd = new JButton("Add");
|
|
private final JButton btnAdd = new JButton("Add");
|
|
|
|
+ private final JButton btnDel = new JButton("Del");
|
|
|
|
|
|
private final JToolBar toolBar = new JToolBar();
|
|
private final JToolBar toolBar = new JToolBar();
|
|
|
|
|
|
@@ -97,7 +103,7 @@ public class GUI implements CategoryListener {
|
|
public GUI(Control control) {
|
|
public GUI(Control control) {
|
|
this.controller = control;
|
|
this.controller = control;
|
|
this.model = control.getModel();
|
|
this.model = control.getModel();
|
|
- model.addCatListener(this);
|
|
|
|
|
|
+ control.initListener(this);
|
|
initialize();
|
|
initialize();
|
|
}
|
|
}
|
|
|
|
|
|
@@ -183,15 +189,58 @@ public class GUI implements CategoryListener {
|
|
panel.add(toolBar);
|
|
panel.add(toolBar);
|
|
toolBar.add(comboBox);
|
|
toolBar.add(comboBox);
|
|
comboBox.setModel(new DefaultComboBoxModel(new String[] { "Category", "Object", "Transformer", "Switch" }));
|
|
comboBox.setModel(new DefaultComboBoxModel(new String[] { "Category", "Object", "Transformer", "Switch" }));
|
|
|
|
+
|
|
|
|
+ // Add Button
|
|
btnAdd.addActionListener(new ActionListener() {
|
|
btnAdd.addActionListener(new ActionListener() {
|
|
public void actionPerformed(ActionEvent arg0) {
|
|
public void actionPerformed(ActionEvent arg0) {
|
|
- if (comboBox.getSelectedItem().toString() == "Category") {
|
|
|
|
|
|
+
|
|
|
|
+ Category selectedNode;
|
|
|
|
+ Object nodeInfo = tree.getLastSelectedPathComponent();
|
|
|
|
+ String selected = comboBox.getSelectedItem().toString();
|
|
|
|
+ String text = textField.getText();
|
|
|
|
+
|
|
|
|
+ if (selected.equals("Category") && !text.isEmpty()) {
|
|
controller.addNewCategory(textField.getText());
|
|
controller.addNewCategory(textField.getText());
|
|
- } else if (comboBox.getSelectedItem().toString() == "Object") {
|
|
|
|
|
|
+
|
|
|
|
+ } else if (text.isEmpty() || nodeInfo.toString().isEmpty()) {
|
|
|
|
+ // throw EmptyField or NoSelectedNode Exception
|
|
|
|
+
|
|
|
|
+ } else if (selected.equals("Object")) {
|
|
|
|
+ selectedNode = controller.searchCategory(nodeInfo.toString());
|
|
|
|
+ controller.addNewObject(selectedNode, textField.getText());
|
|
|
|
+
|
|
|
|
+ } else if (selected.equals("Transformer")) {
|
|
|
|
+ selectedNode = controller.searchCategory(nodeInfo.toString());
|
|
|
|
+ controller.addNewTransformer(selectedNode, textField.getText());
|
|
|
|
+
|
|
|
|
+ } else {
|
|
|
|
+ selectedNode = controller.searchCategory(nodeInfo.toString());
|
|
|
|
+ controller.addNewSwitch(selectedNode, textField.getText());
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
+
|
|
}
|
|
}
|
|
});
|
|
});
|
|
toolBar.add(btnAdd);
|
|
toolBar.add(btnAdd);
|
|
|
|
+
|
|
|
|
+ // Del Button
|
|
|
|
+ btnDel.addActionListener(new ActionListener() {
|
|
|
|
+ public void actionPerformed(ActionEvent arg0) {
|
|
|
|
+
|
|
|
|
+ Category selectedNode;
|
|
|
|
+ Object nodeInfo = tree.getLastSelectedPathComponent();
|
|
|
|
+ String selected = comboBox.getSelectedItem().toString();
|
|
|
|
+
|
|
|
|
+ if(nodeInfo.toString().isEmpty()){
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ toolBar.add(btnDel);
|
|
|
|
+
|
|
|
|
+
|
|
panel.add(textField);
|
|
panel.add(textField);
|
|
frmCyberPhysical.getContentPane().add(splitPane);
|
|
frmCyberPhysical.getContentPane().add(splitPane);
|
|
|
|
|
|
@@ -213,26 +262,19 @@ public class GUI implements CategoryListener {
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- public void onChange(ArrayList<Category> cats) {
|
|
|
|
- DefaultTreeModel model = (DefaultTreeModel) tree.getModel();
|
|
|
|
- refreshCategories(cats);
|
|
|
|
- textField.setText("Test");
|
|
|
|
- model.reload();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
/**
|
|
/**
|
|
* reloads the Categories from Model
|
|
* reloads the Categories from Model
|
|
*/
|
|
*/
|
|
- public void refreshCategories(final ArrayList<Category> cats) {
|
|
|
|
|
|
+ public void updateCategories(final ArrayList<Category> categories) {
|
|
tree.setModel(new DefaultTreeModel(new DefaultMutableTreeNode("Categories") {
|
|
tree.setModel(new DefaultTreeModel(new DefaultMutableTreeNode("Categories") {
|
|
{
|
|
{
|
|
DefaultMutableTreeNode node_1;
|
|
DefaultMutableTreeNode node_1;
|
|
- for (Category c : cats) {
|
|
|
|
|
|
+ for (Category c : categories) {
|
|
node_1 = new DefaultMutableTreeNode(c.getName());
|
|
node_1 = new DefaultMutableTreeNode(c.getName());
|
|
|
|
|
|
// kann eventuell umgeändert werden
|
|
// kann eventuell umgeändert werden
|
|
- for (CpsObject hol : c.getObjects()) {
|
|
|
|
- node_1.add(new DefaultMutableTreeNode(hol.getObjName()));
|
|
|
|
|
|
+ for (CpsObject obj : c.getObjects()) {
|
|
|
|
+ node_1.add(new DefaultMutableTreeNode(obj.getObjName()));
|
|
}
|
|
}
|
|
add(node_1);
|
|
add(node_1);
|
|
}
|
|
}
|
|
@@ -241,6 +283,20 @@ public class GUI implements CategoryListener {
|
|
}));
|
|
}));
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ *
|
|
|
|
+ */
|
|
|
|
+ public void onChange(ArrayList<Category> categories) {
|
|
|
|
+ DefaultTreeModel model = (DefaultTreeModel) tree.getModel();
|
|
|
|
+ updateCategories(categories);
|
|
|
|
+ textField.setText("");
|
|
|
|
+ model.reload();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ *
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
public JFrame getFrmCyberPhysical() {
|
|
public JFrame getFrmCyberPhysical() {
|
|
return frmCyberPhysical;
|
|
return frmCyberPhysical;
|
|
}
|
|
}
|