Browse Source

algo name fix for windows

Jessey Widhalm 7 years ago
parent
commit
cb6d9674a6
1 changed files with 12 additions and 5 deletions
  1. 12 5
      src/ui/view/SimulationMenu.java

+ 12 - 5
src/ui/view/SimulationMenu.java

@@ -51,7 +51,7 @@ public class SimulationMenu extends JMenuBar {
 	private JComboBox algoCombo = new JComboBox<>();
 	private JButton algoFolderButton = new JButton("Algorithm:");
 	private HashMap<String, File> algosHash = new HashMap<>();
-	
+
 	Model model;
 	Control controller;
 
@@ -81,9 +81,16 @@ public class SimulationMenu extends JMenuBar {
 					for (int i = 0; i < files.length; i++) {
 						if (files[i].toString().endsWith(".java") || files[i].toString().endsWith(".class")) {
 							String name = files[i].toString();
-							int tmpA = name.lastIndexOf('/');
+							int tmpS = name.lastIndexOf('/');
+							int tmpBS = name.lastIndexOf('\\');
+							int tmpA;
+							if (tmpS > tmpBS) {
+								tmpA = tmpS;
+							} else {
+								tmpA = tmpBS;
+							}
 							int tmpB = name.lastIndexOf('.');
-							name = name.substring(tmpA+1, tmpB);
+							name = name.substring(tmpA + 1, tmpB);
 							algosHash.put(name, files[i]);
 							algoCombo.addItem(name);
 						}
@@ -155,8 +162,8 @@ public class SimulationMenu extends JMenuBar {
 		gbc_algoCombo.gridy = 0;
 		menuPanel.add(algoCombo, gbc_algoCombo);
 		algoCombo.addItem("choose folder");
-		
-		//Add Panel to SimulationMenu
+
+		// Add Panel to SimulationMenu
 		this.add(menuPanel);
 	}
 }