|
@@ -14,9 +14,11 @@ import javax.swing.JFileChooser;
|
|
|
import javax.swing.JFrame;
|
|
|
import javax.swing.JMenu;
|
|
|
import javax.swing.JMenuItem;
|
|
|
+import javax.swing.JOptionPane;
|
|
|
import javax.tools.JavaCompiler;
|
|
|
import javax.tools.ToolProvider;
|
|
|
|
|
|
+import api.CpsAlgorithm;
|
|
|
import ui.controller.Control;
|
|
|
import ui.model.Model;
|
|
|
|
|
@@ -129,7 +131,8 @@ public class AlgorithmMenu extends JMenu {
|
|
|
}
|
|
|
|
|
|
public void setAlgorithm(File file, String name) {
|
|
|
- boolean missinConsole = false;
|
|
|
+ boolean missingCompiler = false;
|
|
|
+ boolean instantiationError = false;
|
|
|
try {
|
|
|
BufferedReader br = new BufferedReader(new FileReader(file.getPath()));
|
|
|
String line = br.readLine();
|
|
@@ -155,7 +158,7 @@ public class AlgorithmMenu extends JMenu {
|
|
|
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
|
|
|
|
|
|
if (ToolProvider.getSystemJavaCompiler() == null) {
|
|
|
- missinConsole = true;
|
|
|
+ missingCompiler = true;
|
|
|
}
|
|
|
|
|
|
compiler.run(null, null, null, file.getPath());
|
|
@@ -163,6 +166,7 @@ public class AlgorithmMenu extends JMenu {
|
|
|
|
|
|
URLClassLoader classLoader = URLClassLoader.newInstance(new URL[] { root.toURI().toURL() });
|
|
|
|
|
|
+ instantiationError = true;
|
|
|
Class<?> cls;
|
|
|
if (packageName.isEmpty()) {
|
|
|
cls = Class.forName(name, true, classLoader);
|
|
@@ -171,14 +175,23 @@ public class AlgorithmMenu extends JMenu {
|
|
|
}
|
|
|
|
|
|
Object t = cls.newInstance();
|
|
|
-
|
|
|
- controller.setAlgorithm(t);
|
|
|
-
|
|
|
+ if (t instanceof CpsAlgorithm) {
|
|
|
+ controller.setAlgorithm(t);
|
|
|
+ } else {
|
|
|
+ JOptionPane.showMessageDialog(null, "Class does not Implement CpsAlgorithm!", "Error!",
|
|
|
+ JOptionPane.ERROR_MESSAGE);
|
|
|
+ noneItem.doClick();
|
|
|
+ }
|
|
|
} catch (Exception e) {
|
|
|
- if (missinConsole) {
|
|
|
- controller.addTextToConsole("missing Compiiler! Please install JDK");
|
|
|
+ if (missingCompiler) {
|
|
|
+ JOptionPane.showMessageDialog(null, "Missing Compiiler! Please install JDK!", "Error!",
|
|
|
+ JOptionPane.ERROR_MESSAGE);
|
|
|
+ } else if (instantiationError) {
|
|
|
+ JOptionPane.showMessageDialog(null, "Class does not Implement CpsAlgorithm!", "Error!",
|
|
|
+ JOptionPane.ERROR_MESSAGE);
|
|
|
+ noneItem.doClick();
|
|
|
} else {
|
|
|
- controller.addTextToConsole(e.toString());
|
|
|
+ JOptionPane.showMessageDialog(null, e.toString(), "Error!", JOptionPane.ERROR_MESSAGE);
|
|
|
}
|
|
|
}
|
|
|
}
|