瀏覽代碼

algo auswahl im simmenü

Kevin Trometer 7 年之前
父節點
當前提交
81a27ad4a7
共有 5 個文件被更改,包括 109 次插入97 次删除
  1. 14 1
      src/ui/controller/ConsoleController.java
  2. 10 0
      src/ui/controller/Control.java
  3. 19 1
      src/ui/view/Console.java
  4. 0 62
      src/ui/view/GUI.java
  5. 66 33
      src/ui/view/SimulationMenu.java

+ 14 - 1
src/ui/controller/ConsoleController.java

@@ -2,6 +2,9 @@ package ui.controller;
 
 import java.awt.Color;
 
+import javax.swing.text.BadLocationException;
+import javax.swing.text.StyleConstants;
+
 import ui.model.Model;
 import ui.view.Console;
 
@@ -14,7 +17,7 @@ public class ConsoleController {
 	}
 
 	/**
-	 * Getter for selected CpsObject
+	 * Print Text on the console
 	 *
 	 * @param text
 	 *            String the Text
@@ -34,6 +37,16 @@ public class ConsoleController {
 	public void addTextToConsole(String text, Color color, int p, boolean bold, boolean italic, boolean nl) {
 		MODEL.getConsole().addText(text, color, p, bold, italic, nl);
 	}
+	
+	/**
+	 * Print Text on the console in black and font size 12
+	 *
+	 * @param text
+	 *            String the Text
+	 */
+	public void addTextToConsole(String text) {
+		MODEL.getConsole().addText(text);
+	}
 
 	/**
 	 * Clears the console

+ 10 - 0
src/ui/controller/Control.java

@@ -313,6 +313,16 @@ public class Control {
 	public void addTextToConsole(String text, Color color, int p, boolean bold, boolean italic, boolean nl) {
 		consoleController.addTextToConsole(text, color, p, bold, italic, nl);
 	}
+	
+	/**
+	 * Print Text on the console in black and font size 12
+	 *
+	 * @param text
+	 *            String the Text
+	 */
+	public void addTextToConsole(String text) {
+		consoleController.addTextToConsole(text);
+	}
 
 	/**
 	 * Clears the console

+ 19 - 1
src/ui/view/Console.java

@@ -41,7 +41,7 @@ public class Console extends JScrollPane {
 	}
 
 	/**
-	 * Getter for selected CpsObject
+	 * Print Text on the console
 	 *
 	 * @param text
 	 *            String the Text
@@ -72,6 +72,24 @@ public class Console extends JScrollPane {
 		} catch (BadLocationException e) {
 		}
 	}
+	
+	/**
+	 * Print Text on the console in black and font size 12
+	 *
+	 * @param text
+	 *            String the Text
+	 */
+	public void addText(String text) {
+		StyleConstants.setForeground(style, Color.BLACK);
+		StyleConstants.setFontSize(style, 12);
+		StyleConstants.setBold(style, false);
+		StyleConstants.setItalic(style, false);
+
+		try {
+			doc.insertString(doc.getLength(), text+"\n", style);
+		} catch (BadLocationException e) {
+		}
+	}
 
 	/**
 	 * Clears the console

+ 0 - 62
src/ui/view/GUI.java

@@ -202,9 +202,6 @@ public class GUI<E> implements CategoryListener {
 	private final JLabel lblImageSize = new JLabel("Image Size");
 	// Time Stuff
 	private TimePanel timePanel;
-	private final JMenu mnAlgorithm = new JMenu("Algorithm");
-	private final JCheckBoxMenuItem chckbxmntmUseAlgorithm = new JCheckBoxMenuItem("Use Algorithm");
-	private final JComboBox comboBoxAlgo = new JComboBox();
 	// Coord for all Cells with text
 	private int yTHIS;
 	private int xTHIS;
@@ -219,10 +216,6 @@ public class GUI<E> implements CategoryListener {
 	private final JMenuItem mntmFindReplace = new JMenuItem("Find/ Replace");
 	private final JMenuItem mntmEditShowedInformation = new JMenuItem("Edit showed Information");
 	private final JMenuItem mntmResetCategory = new JMenuItem("Reset Categories");
-	private final JMenuItem mntmSetFolder = new JMenuItem("Set Folder");
-	private final JMenu mnSimulationSpeed = new JMenu("Simulation Speed");
-	private final JTextField simulationSpeedField = new JTextField();
-	private final JButton btnApply = new JButton("Apply");
 
 	/**
 	 * Create the application.
@@ -245,7 +238,6 @@ public class GUI<E> implements CategoryListener {
 	 */
 	@SuppressWarnings({ "serial", "unchecked" })
 	private void initialize() {
-		simulationSpeedField.setColumns(10);
 		frmCyberPhysical = new JFrame();
 		frmCyberPhysical.setTitle("Cyber Physical Systems Model");
 		frmCyberPhysical.setBounds(100, 100, 1000, 800);
@@ -483,10 +475,6 @@ public class GUI<E> implements CategoryListener {
 		mnNewMenu_2.add(mntmEditEdges);
 
 		mnNewMenu_2.add(mntmResetCategory);
-
-		mnNewMenu_2.add(mnSimulationSpeed);
-
-		mnSimulationSpeed.add(simulationSpeedField);
 		mntmResetCategory.addActionListener(new ActionListener() {
 
 			@Override
@@ -540,12 +528,6 @@ public class GUI<E> implements CategoryListener {
 
 		mnHelp.add(aboutUs);
 
-		menuBar.add(mnAlgorithm);
-
-		mnAlgorithm.add(mntmSetFolder);
-
-		mnAlgorithm.add(chckbxmntmUseAlgorithm);
-
 		canvas.setBackground(Color.WHITE);
 		canvas.setPreferredSize(new Dimension(1000, 1000));
 
@@ -1430,34 +1412,6 @@ public class GUI<E> implements CategoryListener {
 
 		});
 
-		mntmSetFolder.addActionListener(new java.awt.event.ActionListener() {
-
-			@Override
-			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) {
-					comboBoxAlgo.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")) {
-							comboBoxAlgo.addItem(files[i]);
-						}
-					}
-				}
-			}
-
-		});
-
 		timePanel = new TimePanel(model, controller);
 		timePanel.setBorder(null);
 		((JSlider) (timePanel.getComponent(1))).addChangeListener(new ChangeListener() {
@@ -1504,22 +1458,6 @@ public class GUI<E> implements CategoryListener {
 		tableHolonElementScrollPane.setBorder(null);
 
 		frmCyberPhysical.getContentPane().add(timePanel, BorderLayout.SOUTH);
-
-		simulationSpeedField.setText(Integer.toString(model.getTimerSpeed()));
-		btnApply.addActionListener(new ActionListener() {
-			public void actionPerformed(ActionEvent e) {
-				int speed = Integer.parseInt(simulationSpeedField.getText());
-				controller.setTimerSpeed(speed);
-				mnSimulationSpeed.setPopupMenuVisible(false);
-			}
-		});
-
-		mnSimulationSpeed.add(btnApply);
-		menuBar.add(comboBoxAlgo);
-
-		Dimension height = comboBoxAlgo.getPreferredSize();
-		comboBoxAlgo.setPreferredSize(new Dimension(200, (int) height.getHeight()));
-		comboBoxAlgo.setMaximumSize(comboBoxAlgo.getPreferredSize());
 	}
 
 	/*

+ 66 - 33
src/ui/view/SimulationMenu.java

@@ -1,6 +1,9 @@
 package ui.view;
 
+import javax.swing.JButton;
 import javax.swing.JComboBox;
+import javax.swing.JFileChooser;
+import javax.swing.JFrame;
 import javax.swing.JLabel;
 import javax.swing.JMenuBar;
 import javax.swing.JPanel;
@@ -20,8 +23,11 @@ import java.awt.Color;
 import java.awt.Dimension;
 import java.awt.GridBagConstraints;
 import java.awt.Insets;
+import java.awt.event.ActionListener;
 import java.beans.PropertyChangeEvent;
 import java.beans.PropertyChangeListener;
+import java.io.File;
+import java.awt.FlowLayout;
 
 public class SimulationMenu extends JMenuBar {
 	/**
@@ -29,61 +35,66 @@ public class SimulationMenu extends JMenuBar {
 	 */
 	private static final long serialVersionUID = 1L;
 
-	// Components
-	private JPanel simMenuPanel = new JPanel();
+	private JPanel menuPanel = new JPanel();
 	private JRadioButton simButton = new JRadioButton("Simulate");
 	private JLabel simSpeedLabel = new JLabel("Simulation Speed:");
 	private JTextField simSpeedText = new JTextField("1000");
 	private JLabel algoLabel = new JLabel("Algorithm:");
 	private JComboBox algoCombo;
-	private ArrayList<String> algos = new ArrayList<>();
+	private JButton algoFolderButton = new JButton("Set Algorithm Folder");
 
 	Model model;
 	Control controller;
-	
+
 	public SimulationMenu(Model mod, Control cont) {
 		super();
 		// Init Stuff
 		this.model = mod;
 		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
-			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() {
-			
+
 			@Override
 			public void propertyChange(PropertyChangeEvent evt) {
 				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();
 		gbc_simButton.anchor = GridBagConstraints.NORTHWEST;
 		gbc_simButton.insets = new Insets(0, 0, 0, 5);
@@ -96,6 +107,20 @@ public class SimulationMenu extends JMenuBar {
 		gbc_simSpeedLabel.gridx = 1;
 		gbc_simSpeedLabel.gridy = 0;
 		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();
 		gbc_simSpeedText.anchor = GridBagConstraints.WEST;
 		gbc_simSpeedText.insets = new Insets(0, 0, 0, 5);
@@ -109,12 +134,20 @@ public class SimulationMenu extends JMenuBar {
 		gbc_algoLabel.gridy = 0;
 		menuPanel.add(algoLabel, gbc_algoLabel);
 
-		algoCombo = new JComboBox<Object>(algos.toArray());
+		algoCombo = new JComboBox<>();
 		GridBagConstraints gbc_algoCombo = new GridBagConstraints();
 		gbc_algoCombo.anchor = GridBagConstraints.WEST;
+		gbc_algoCombo.insets = new Insets(0, 0, 0, 5);
 		gbc_algoCombo.gridx = 4;
 		gbc_algoCombo.gridy = 0;
 		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);
 	}
 }