|
@@ -1,6 +1,9 @@
|
|
package ui.view;
|
|
package ui.view;
|
|
|
|
|
|
|
|
+import javax.swing.JButton;
|
|
import javax.swing.JComboBox;
|
|
import javax.swing.JComboBox;
|
|
|
|
+import javax.swing.JFileChooser;
|
|
|
|
+import javax.swing.JFrame;
|
|
import javax.swing.JLabel;
|
|
import javax.swing.JLabel;
|
|
import javax.swing.JMenuBar;
|
|
import javax.swing.JMenuBar;
|
|
import javax.swing.JPanel;
|
|
import javax.swing.JPanel;
|
|
@@ -20,8 +23,11 @@ import java.awt.Color;
|
|
import java.awt.Dimension;
|
|
import java.awt.Dimension;
|
|
import java.awt.GridBagConstraints;
|
|
import java.awt.GridBagConstraints;
|
|
import java.awt.Insets;
|
|
import java.awt.Insets;
|
|
|
|
+import java.awt.event.ActionListener;
|
|
import java.beans.PropertyChangeEvent;
|
|
import java.beans.PropertyChangeEvent;
|
|
import java.beans.PropertyChangeListener;
|
|
import java.beans.PropertyChangeListener;
|
|
|
|
+import java.io.File;
|
|
|
|
+import java.awt.FlowLayout;
|
|
|
|
|
|
public class SimulationMenu extends JMenuBar {
|
|
public class SimulationMenu extends JMenuBar {
|
|
/**
|
|
/**
|
|
@@ -29,61 +35,66 @@ public class SimulationMenu extends JMenuBar {
|
|
*/
|
|
*/
|
|
private static final long serialVersionUID = 1L;
|
|
private static final long serialVersionUID = 1L;
|
|
|
|
|
|
- // Components
|
|
|
|
- private JPanel simMenuPanel = new JPanel();
|
|
|
|
|
|
+ private JPanel menuPanel = new JPanel();
|
|
private JRadioButton simButton = new JRadioButton("Simulate");
|
|
private JRadioButton simButton = new JRadioButton("Simulate");
|
|
private JLabel simSpeedLabel = new JLabel("Simulation Speed:");
|
|
private JLabel simSpeedLabel = new JLabel("Simulation Speed:");
|
|
private JTextField simSpeedText = new JTextField("1000");
|
|
private JTextField simSpeedText = new JTextField("1000");
|
|
private JLabel algoLabel = new JLabel("Algorithm:");
|
|
private JLabel algoLabel = new JLabel("Algorithm:");
|
|
private JComboBox algoCombo;
|
|
private JComboBox algoCombo;
|
|
- private ArrayList<String> algos = new ArrayList<>();
|
|
|
|
|
|
+ private JButton algoFolderButton = new JButton("Set Algorithm Folder");
|
|
|
|
|
|
Model model;
|
|
Model model;
|
|
Control controller;
|
|
Control controller;
|
|
-
|
|
|
|
|
|
+
|
|
public SimulationMenu(Model mod, Control cont) {
|
|
public SimulationMenu(Model mod, Control cont) {
|
|
super();
|
|
super();
|
|
// Init Stuff
|
|
// Init Stuff
|
|
this.model = mod;
|
|
this.model = mod;
|
|
this.controller = cont;
|
|
this.controller = cont;
|
|
-
|
|
|
|
- //AlgoCombobox Items
|
|
|
|
- algos.add("algorithm1");
|
|
|
|
- algos.add("algorithm2");
|
|
|
|
- algos.add("algorithm3");
|
|
|
|
-
|
|
|
|
- //timerSpeed
|
|
|
|
- simSpeedText.setMaximumSize(new Dimension(300, 300));
|
|
|
|
- simSpeedText.addCaretListener(new CaretListener() {
|
|
|
|
|
|
+
|
|
|
|
+ // algoFolderButton Action
|
|
|
|
+ algoFolderButton.addActionListener(new ActionListener() {
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
- public void caretUpdate(CaretEvent e) {
|
|
|
|
- try {
|
|
|
|
- controller.setTimerSpeed(Integer.parseInt(simSpeedText.getText()));
|
|
|
|
- } catch (Exception e2) {
|
|
|
|
- // TODO: handle exception
|
|
|
|
|
|
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
|
|
|
|
+ menuSetFolderActionPerformed(evt);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void menuSetFolderActionPerformed(java.awt.event.ActionEvent evt) {
|
|
|
|
+ JFileChooser fileChooser = new JFileChooser();
|
|
|
|
+ JFrame test = new JFrame();
|
|
|
|
+ fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
|
|
|
|
+ fileChooser.setAcceptAllFileFilterUsed(false);
|
|
|
|
+
|
|
|
|
+ if (fileChooser.showOpenDialog(test) == JFileChooser.APPROVE_OPTION) {
|
|
|
|
+ algoCombo.removeAllItems();
|
|
|
|
+ File[] files = fileChooser.getSelectedFile().listFiles();
|
|
|
|
+ for (int i = 0; i < files.length; i++) {
|
|
|
|
+ if (files[i].toString().endsWith(".java") || files[i].toString().endsWith(".class")) {
|
|
|
|
+ algoCombo.addItem(files[i]);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
-
|
|
|
|
}
|
|
}
|
|
|
|
+
|
|
});
|
|
});
|
|
-
|
|
|
|
- //isSimulation
|
|
|
|
|
|
+
|
|
|
|
+ // Add to Panel
|
|
|
|
+ GridBagLayout gbl_menuPanel = new GridBagLayout();
|
|
|
|
+ gbl_menuPanel.columnWidths = new int[] { 79, 105, 34, 60, 31, 151, 0 };
|
|
|
|
+ gbl_menuPanel.rowHeights = new int[] { 25, 0 };
|
|
|
|
+ gbl_menuPanel.columnWeights = new double[] { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE };
|
|
|
|
+ gbl_menuPanel.rowWeights = new double[] { 0.0, Double.MIN_VALUE };
|
|
|
|
+ menuPanel.setLayout(gbl_menuPanel);
|
|
|
|
+
|
|
|
|
+ // isSimulation
|
|
simButton.addPropertyChangeListener(new PropertyChangeListener() {
|
|
simButton.addPropertyChangeListener(new PropertyChangeListener() {
|
|
-
|
|
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public void propertyChange(PropertyChangeEvent evt) {
|
|
public void propertyChange(PropertyChangeEvent evt) {
|
|
controller.setIsSimulation(simButton.isSelected());
|
|
controller.setIsSimulation(simButton.isSelected());
|
|
}
|
|
}
|
|
});
|
|
});
|
|
-
|
|
|
|
- // Add to Panel
|
|
|
|
- JPanel menuPanel = new JPanel();
|
|
|
|
- GridBagLayout gbl_t = new GridBagLayout();
|
|
|
|
- gbl_t.columnWidths = new int[] { 79, 109, 46, 64, 31, 0 };
|
|
|
|
- gbl_t.rowHeights = new int[] { 25, 0 };
|
|
|
|
- gbl_t.columnWeights = new double[] { 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE };
|
|
|
|
- gbl_t.rowWeights = new double[] { 0.0, Double.MIN_VALUE };
|
|
|
|
- menuPanel.setLayout(gbl_t);
|
|
|
|
-
|
|
|
|
GridBagConstraints gbc_simButton = new GridBagConstraints();
|
|
GridBagConstraints gbc_simButton = new GridBagConstraints();
|
|
gbc_simButton.anchor = GridBagConstraints.NORTHWEST;
|
|
gbc_simButton.anchor = GridBagConstraints.NORTHWEST;
|
|
gbc_simButton.insets = new Insets(0, 0, 0, 5);
|
|
gbc_simButton.insets = new Insets(0, 0, 0, 5);
|
|
@@ -96,6 +107,20 @@ public class SimulationMenu extends JMenuBar {
|
|
gbc_simSpeedLabel.gridx = 1;
|
|
gbc_simSpeedLabel.gridx = 1;
|
|
gbc_simSpeedLabel.gridy = 0;
|
|
gbc_simSpeedLabel.gridy = 0;
|
|
menuPanel.add(simSpeedLabel, gbc_simSpeedLabel);
|
|
menuPanel.add(simSpeedLabel, gbc_simSpeedLabel);
|
|
|
|
+
|
|
|
|
+ // timerSpeed
|
|
|
|
+ simSpeedText.setMaximumSize(new Dimension(300, 300));
|
|
|
|
+ simSpeedText.addCaretListener(new CaretListener() {
|
|
|
|
+ @Override
|
|
|
|
+ public void caretUpdate(CaretEvent e) {
|
|
|
|
+ try {
|
|
|
|
+ controller.setTimerSpeed(Integer.parseInt(simSpeedText.getText()));
|
|
|
|
+ } catch (Exception e2) {
|
|
|
|
+ // TODO: handle exception
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ });
|
|
GridBagConstraints gbc_simSpeedText = new GridBagConstraints();
|
|
GridBagConstraints gbc_simSpeedText = new GridBagConstraints();
|
|
gbc_simSpeedText.anchor = GridBagConstraints.WEST;
|
|
gbc_simSpeedText.anchor = GridBagConstraints.WEST;
|
|
gbc_simSpeedText.insets = new Insets(0, 0, 0, 5);
|
|
gbc_simSpeedText.insets = new Insets(0, 0, 0, 5);
|
|
@@ -109,12 +134,20 @@ public class SimulationMenu extends JMenuBar {
|
|
gbc_algoLabel.gridy = 0;
|
|
gbc_algoLabel.gridy = 0;
|
|
menuPanel.add(algoLabel, gbc_algoLabel);
|
|
menuPanel.add(algoLabel, gbc_algoLabel);
|
|
|
|
|
|
- algoCombo = new JComboBox<Object>(algos.toArray());
|
|
|
|
|
|
+ algoCombo = new JComboBox<>();
|
|
GridBagConstraints gbc_algoCombo = new GridBagConstraints();
|
|
GridBagConstraints gbc_algoCombo = new GridBagConstraints();
|
|
gbc_algoCombo.anchor = GridBagConstraints.WEST;
|
|
gbc_algoCombo.anchor = GridBagConstraints.WEST;
|
|
|
|
+ gbc_algoCombo.insets = new Insets(0, 0, 0, 5);
|
|
gbc_algoCombo.gridx = 4;
|
|
gbc_algoCombo.gridx = 4;
|
|
gbc_algoCombo.gridy = 0;
|
|
gbc_algoCombo.gridy = 0;
|
|
menuPanel.add(algoCombo, gbc_algoCombo);
|
|
menuPanel.add(algoCombo, gbc_algoCombo);
|
|
|
|
+ GridBagConstraints gbc_algoFolderButton = new GridBagConstraints();
|
|
|
|
+ gbc_algoFolderButton.anchor = GridBagConstraints.NORTHWEST;
|
|
|
|
+ gbc_algoFolderButton.gridx = 5;
|
|
|
|
+ gbc_algoFolderButton.gridy = 0;
|
|
|
|
+ menuPanel.add(algoFolderButton, gbc_algoFolderButton);
|
|
|
|
+
|
|
|
|
+ //Add Panel to SimulationMenu
|
|
this.add(menuPanel);
|
|
this.add(menuPanel);
|
|
}
|
|
}
|
|
}
|
|
}
|