Ver código fonte

api MenuItem

Kevin Trometer 7 anos atrás
pai
commit
ea7b4e426d

+ 1 - 1
src/exampleAlgorithms/randomSwitchesAlgorithm.java → src/exampleAlgorithms/RandomSwitchesAlgorithm.java

@@ -5,7 +5,7 @@ import ui.controller.Control;
 import ui.model.Model;
 import classes.*;
 
-public class randomSwitchesAlgorithm implements CpsAlgorithm {
+public class RandomSwitchesAlgorithm implements CpsAlgorithm {
 
 	@Override
 	public void runAlgorithm(Model model, Control controller) {

+ 43 - 0
src/exampleAlgorithms/RepairAllEdges.java

@@ -0,0 +1,43 @@
+package exampleAlgorithms;
+
+import api.CpsAlgorithm;
+import ui.controller.Control;
+import ui.model.Model;
+import ui.view.UpperNodeCanvas;
+import classes.*;
+
+public class RepairAllEdges implements CpsAlgorithm {
+
+	@Override
+	public void runAlgorithm(Model model, Control controller) {
+		repairAllEdgesOnMainCanvas(model);
+	}
+
+	/**
+	 * Repairs all Edges on the main Canvas.
+	 * 
+	 * @param model
+	 *            the Model
+	 */
+	private void repairAllEdgesOnMainCanvas(Model model) {
+		for (AbstractCpsObject obj : model.getObjectsOnCanvas()) {
+			if (obj instanceof CpsUpperNode) {
+				repairAllEdgesInUpperNode((CpsUpperNode) obj);
+			}
+			for (CpsEdge e : obj.getConnections()) {
+				e.setState(true);
+			}
+		}
+	}
+
+	private void repairAllEdgesInUpperNode(CpsUpperNode uNode) {
+		for (AbstractCpsObject obj : uNode.getNodes()) {
+			if (obj instanceof CpsUpperNode) {
+				repairAllEdgesInUpperNode((CpsUpperNode) obj);
+			}
+			for (CpsEdge e : obj.getConnections()) {
+				e.setState(true);
+			}
+		}
+	}
+}

+ 36 - 27
src/ui/view/AlgorithmMenu.java

@@ -1,5 +1,7 @@
 package ui.view;
 
+import java.awt.Color;
+import java.awt.Component;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
 import java.io.BufferedReader;
@@ -9,6 +11,7 @@ import java.net.URL;
 import java.net.URLClassLoader;
 import java.util.HashMap;
 
+import javax.swing.Action;
 import javax.swing.JButton;
 import javax.swing.JComboBox;
 import javax.swing.JFileChooser;
@@ -16,28 +19,29 @@ import javax.swing.JFrame;
 import javax.swing.JMenu;
 import javax.swing.JMenuBar;
 import javax.swing.JMenuItem;
-import javax.swing.JPanel;
+import javax.swing.border.LineBorder;
 import javax.tools.JavaCompiler;
 import javax.tools.ToolProvider;
 
+import javafx.scene.control.MenuItem;
+import sun.security.provider.NativePRNG.NonBlocking;
 import ui.controller.Control;
 import ui.model.Model;
 
 /**
- * This Class represents the Menu, where you can edit stuff about the
- * Simulation.
+ * This Class represents the Menu, where you can select the Algorithms.
  * 
  * @author Gruppe14
  */
-public class AlgorithmMenu extends JPanel{
+public class AlgorithmMenu extends JMenu {
 
 	private static final long serialVersionUID = 1L;
 
-	private JComboBox<Object> algoCombo = new JComboBox<>();
-	JButton algoFolderButton = new JButton(Languages.getLanguage()[85]);
+	JMenuItem algoFolderButton = new JMenuItem("Selecte Algorithm Folder");
+	private JMenu mnSelectAlgorithm = new JMenu("Select Algorithm");
 	private HashMap<String, File> algosHash = new HashMap<>();
-	private JPanel menuPanel = new JPanel();
-	
+	private JMenuItem noneItem= new JMenuItem("none");
+
 	// root Directory
 	File root = null;
 
@@ -57,20 +61,8 @@ public class AlgorithmMenu extends JPanel{
 		// Init Stuff
 		this.model = mod;
 		this.controller = cont;
-		
-		algoCombo.addItem("None");
+		this.setText("Algorithm");
 
-		// Algorithm ComboBox Action
-		algoCombo.addActionListener(new ActionListener() {
-			@Override
-			public void actionPerformed(ActionEvent e) {
-				if (algoCombo.getSelectedIndex() != 0) {
-					setAlgorithm(algosHash.get(algoCombo.getSelectedItem()), algoCombo.getSelectedItem() + "");
-				}else{
-					setAlgorithm(null, "non Chosen");
-				}
-			}
-		});
 
 		// algoFolderButton Action
 		algoFolderButton.addActionListener(new ActionListener() {
@@ -87,8 +79,12 @@ public class AlgorithmMenu extends JPanel{
 				fileChooser.setAcceptAllFileFilterUsed(false);
 
 				if (fileChooser.showOpenDialog(test) == JFileChooser.APPROVE_OPTION) {
-					algoCombo.removeAllItems();
-					algoCombo.addItem("non chosen");
+					//empty everything and reset the selected algorithm
+					controller.setAlgorithm(null);
+					mnSelectAlgorithm.removeAll();
+					mnSelectAlgorithm.add(noneItem);
+					noneItem.doClick();
+
 					File[] files = fileChooser.getSelectedFile().listFiles();
 					// Set Root Folder Path
 					root = new File(fileChooser.getCurrentDirectory().getPath());
@@ -103,8 +99,15 @@ public class AlgorithmMenu extends JPanel{
 							int tmpB = name.lastIndexOf('.');
 							name = name.substring(0, tmpB);
 							algosHash.put(name, files[i]);
-							algoCombo.addItem(name);
-
+							JMenuItem tempItem = new JMenuItem(name);
+							tempItem.addActionListener(new ActionListener() {
+								
+								@Override
+								public void actionPerformed(ActionEvent e) {
+									setAlgorithm(algosHash.get(tempItem.getText()), tempItem.getText());
+								}
+							});
+							mnSelectAlgorithm.add(tempItem);
 						}
 					}
 
@@ -115,8 +118,14 @@ public class AlgorithmMenu extends JPanel{
 
 		// Add to Panel
 		this.add(algoFolderButton);
-
-		this.add(algoCombo);
+		this.add(mnSelectAlgorithm);
+		mnSelectAlgorithm.add(noneItem);
+		noneItem.addActionListener(new ActionListener() {
+			@Override
+			public void actionPerformed(ActionEvent e) {
+				controller.setAlgorithm(null);
+			}
+		});
 	}
 
 	public void setAlgorithm(File file, String name) {

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

@@ -834,8 +834,6 @@ public class GUI<E> implements CategoryListener {
 
 		menuBar.add(algorithmMenu);
 
-		menuBar.add(mnAlgorithm);
-
 		menuBar.add(mnHelp);
 
 		mnHelp.add(mntmAboutUs);