|
@@ -1,6 +1,7 @@
|
|
package ui.view;
|
|
package ui.view;
|
|
|
|
|
|
import java.awt.EventQueue;
|
|
import java.awt.EventQueue;
|
|
|
|
+import java.io.File;
|
|
|
|
|
|
import javax.swing.JFrame;
|
|
import javax.swing.JFrame;
|
|
import javax.swing.JMenuBar;
|
|
import javax.swing.JMenuBar;
|
|
@@ -9,14 +10,20 @@ import javax.swing.JMenuItem;
|
|
import javax.swing.UIManager;
|
|
import javax.swing.UIManager;
|
|
import javax.swing.UnsupportedLookAndFeelException;
|
|
import javax.swing.UnsupportedLookAndFeelException;
|
|
import javax.swing.JTree;
|
|
import javax.swing.JTree;
|
|
|
|
+
|
|
import javax.swing.BoxLayout;
|
|
import javax.swing.BoxLayout;
|
|
import javax.swing.JSplitPane;
|
|
import javax.swing.JSplitPane;
|
|
import javax.swing.JScrollPane;
|
|
import javax.swing.JScrollPane;
|
|
import javax.swing.JTabbedPane;
|
|
import javax.swing.JTabbedPane;
|
|
import javax.swing.JTable;
|
|
import javax.swing.JTable;
|
|
import javax.swing.tree.DefaultTreeModel;
|
|
import javax.swing.tree.DefaultTreeModel;
|
|
|
|
+
|
|
|
|
+
|
|
import javax.swing.tree.DefaultMutableTreeNode;
|
|
import javax.swing.tree.DefaultMutableTreeNode;
|
|
import javax.swing.JEditorPane;
|
|
import javax.swing.JEditorPane;
|
|
|
|
+import javax.swing.JFileChooser;
|
|
|
|
+import javax.swing.table.DefaultTableModel;
|
|
|
|
+import java.awt.Color;
|
|
|
|
|
|
public class GUI {
|
|
public class GUI {
|
|
|
|
|
|
@@ -28,7 +35,7 @@ public class GUI {
|
|
private final JMenu mnNewMenu_3 = new JMenu("View");
|
|
private final JMenu mnNewMenu_3 = new JMenu("View");
|
|
private final JMenu mnHelp = new JMenu("Help");
|
|
private final JMenu mnHelp = new JMenu("Help");
|
|
private final JMenuItem mntmOpen = new JMenuItem("Open");
|
|
private final JMenuItem mntmOpen = new JMenuItem("Open");
|
|
- private final JMenuItem mntmNew = new JMenuItem("New");
|
|
|
|
|
|
+ private JMenuItem mntmNew = new JMenuItem("New");
|
|
private final JMenuItem mntmSave = new JMenuItem("Save");
|
|
private final JMenuItem mntmSave = new JMenuItem("Save");
|
|
private final JSplitPane splitPane = new JSplitPane();
|
|
private final JSplitPane splitPane = new JSplitPane();
|
|
private final JSplitPane splitPane_1 = new JSplitPane();
|
|
private final JSplitPane splitPane_1 = new JSplitPane();
|
|
@@ -38,12 +45,18 @@ public class GUI {
|
|
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_Producer = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
|
|
|
|
+ private final JSplitPane splitPane_Consumer = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
|
|
|
|
+ private JTable table;
|
|
|
|
+ private final JTable table_2 = new JTable();
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Launch the application.
|
|
* Launch the application.
|
|
*/
|
|
*/
|
|
public static void main(String[] args) {
|
|
public static void main(String[] args) {
|
|
|
|
|
|
|
|
+ //*Design
|
|
try {
|
|
try {
|
|
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
|
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
|
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException
|
|
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException
|
|
@@ -74,9 +87,10 @@ public class GUI {
|
|
/**
|
|
/**
|
|
* Initialize the contents of the frame.
|
|
* Initialize the contents of the frame.
|
|
*/
|
|
*/
|
|
|
|
+ @SuppressWarnings("serial")
|
|
private void initialize() {
|
|
private void initialize() {
|
|
frame = new JFrame();
|
|
frame = new JFrame();
|
|
- frame.setBounds(100, 100, 805, 486);
|
|
|
|
|
|
+ frame.setBounds(100, 100, 863, 467);
|
|
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
|
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
|
|
|
|
|
frame.setJMenuBar(menuBar);
|
|
frame.setJMenuBar(menuBar);
|
|
@@ -101,27 +115,20 @@ public class GUI {
|
|
frame.getContentPane().add(splitPane);
|
|
frame.getContentPane().add(splitPane);
|
|
|
|
|
|
//Table
|
|
//Table
|
|
- String[] columnNames = {"Producer",
|
|
|
|
|
|
+ String[] columnNames = {"Consumer",
|
|
"Units",
|
|
"Units",
|
|
"Number"};
|
|
"Number"};
|
|
|
|
|
|
Object[][] data = {
|
|
Object[][] data = {
|
|
- {"TV", "20",
|
|
|
|
- "1"},
|
|
|
|
- {"PC", "30",
|
|
|
|
- "2"},
|
|
|
|
- {"Fridge", "40",
|
|
|
|
- "1"}
|
|
|
|
|
|
+ {"TV", "20", "1"},
|
|
|
|
+ {"PC", "30", "2"},
|
|
|
|
+ {"Fridge", "40","1"}
|
|
};
|
|
};
|
|
- JTable table = new JTable(data, columnNames);
|
|
|
|
- table.setCellSelectionEnabled(true);
|
|
|
|
- table.setColumnSelectionAllowed(true);
|
|
|
|
|
|
|
|
splitPane.setRightComponent(splitPane_1);
|
|
splitPane.setRightComponent(splitPane_1);
|
|
splitPane.setDividerLocation(200);
|
|
splitPane.setDividerLocation(200);
|
|
-
|
|
|
|
- splitPane_1.setRightComponent(new JScrollPane(table));
|
|
|
|
- splitPane_1.setDividerLocation(400);
|
|
|
|
|
|
+ splitPane_1.setDividerLocation(500);
|
|
|
|
+ canvas.setBackground(Color.WHITE);
|
|
|
|
|
|
tabbedPane.addTab("Modeling", null, canvas, null);
|
|
tabbedPane.addTab("Modeling", null, canvas, null);
|
|
tabbedPane.addTab("Simulation", null, scrollPane_2, null);
|
|
tabbedPane.addTab("Simulation", null, scrollPane_2, null);
|
|
@@ -131,7 +138,39 @@ public class GUI {
|
|
|
|
|
|
splitPane_1.setLeftComponent(tabbedPane);
|
|
splitPane_1.setLeftComponent(tabbedPane);
|
|
|
|
|
|
|
|
+ splitPane_1.setRightComponent(splitPane_2);
|
|
|
|
+ table = new JTable(data, columnNames);
|
|
|
|
+ splitPane_2.setLeftComponent(splitPane_Producer);
|
|
|
|
+ splitPane_2.setDividerLocation(200);
|
|
|
|
+ splitPane_2.setRightComponent(splitPane_Consumer);
|
|
|
|
+
|
|
|
|
+ splitPane_Producer.setLeftComponent(new JScrollPane(table));
|
|
|
|
+ splitPane_Consumer.setLeftComponent(new JScrollPane(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", "Name", "Number"
|
|
|
|
+ }
|
|
|
|
+ ));
|
|
|
|
+ table_2.getColumnModel().getColumn(0).setPreferredWidth(103);
|
|
|
|
+ table_2.getColumnModel().getColumn(1).setPreferredWidth(107);
|
|
|
|
+ table_2.getColumnModel().getColumn(2).setPreferredWidth(125);
|
|
|
|
+ table.setFillsViewportHeight(true);
|
|
|
|
+ table.setModel(new DefaultTableModel(
|
|
|
|
+ data,
|
|
|
|
+ columnNames
|
|
|
|
+ ));
|
|
|
|
+ table.setCellSelectionEnabled(true);
|
|
|
|
+ table.setColumnSelectionAllowed(true);
|
|
|
|
+
|
|
splitPane.setLeftComponent(scrollPane_1);
|
|
splitPane.setLeftComponent(scrollPane_1);
|
|
|
|
+ tree.setEditable(true);
|
|
tree.setModel(new DefaultTreeModel(
|
|
tree.setModel(new DefaultTreeModel(
|
|
new DefaultMutableTreeNode("Components") {
|
|
new DefaultMutableTreeNode("Components") {
|
|
{
|
|
{
|
|
@@ -157,5 +196,21 @@ public class GUI {
|
|
));
|
|
));
|
|
|
|
|
|
scrollPane_1.setViewportView(tree);
|
|
scrollPane_1.setViewportView(tree);
|
|
|
|
+
|
|
|
|
+ mntmOpen.addActionListener(new java.awt.event.ActionListener() {
|
|
|
|
+ @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());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+
|
|
}
|
|
}
|
|
}
|
|
}
|