|
@@ -27,6 +27,7 @@ import classes.AbstractCpsObject;
|
|
|
import classes.HolonObject;
|
|
|
import classes.HolonSwitch;
|
|
|
import classes.HolonTransformer;
|
|
|
+import jdk.nashorn.api.scripting.URLReader;
|
|
|
import ui.controller.Control;
|
|
|
import ui.model.Model;
|
|
|
import java.util.ArrayList;
|
|
@@ -46,6 +47,7 @@ import java.beans.PropertyChangeEvent;
|
|
|
import java.beans.PropertyChangeListener;
|
|
|
import java.io.File;
|
|
|
import java.io.IOException;
|
|
|
+import java.io.InputStream;
|
|
|
import java.net.MalformedURLException;
|
|
|
import java.net.URL;
|
|
|
import java.net.URLClassLoader;
|
|
@@ -71,6 +73,9 @@ public class SimulationMenu extends JMenuBar {
|
|
|
private JButton algoFolderButton = new JButton("Algorithm:");
|
|
|
private HashMap<String, File> algosHash = new HashMap<>();
|
|
|
|
|
|
+
|
|
|
+ File root = null;
|
|
|
+
|
|
|
Model model;
|
|
|
Control controller;
|
|
|
|
|
@@ -106,37 +111,18 @@ public class SimulationMenu extends JMenuBar {
|
|
|
algoCombo.removeAllItems();
|
|
|
File[] files = fileChooser.getSelectedFile().listFiles();
|
|
|
for (int i = 0; i < files.length; i++) {
|
|
|
- if ( files[i].toString().endsWith(".java") ) {
|
|
|
+ if (files[i].toString()
|
|
|
+ .endsWith(".java")
|
|
|
+ * || files[i].toString().
|
|
|
+ * endsWith(".class")
|
|
|
+ */) {
|
|
|
String name = files[i].getName();
|
|
|
int tmpB = name.lastIndexOf('.');
|
|
|
name = name.substring(0, tmpB);
|
|
|
algosHash.put(name, files[i]);
|
|
|
algoCombo.addItem(name);
|
|
|
-
|
|
|
- try {
|
|
|
-
|
|
|
-
|
|
|
- File root = new File(fileChooser.getCurrentDirectory().getPath());
|
|
|
-
|
|
|
-
|
|
|
- JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
|
|
|
-
|
|
|
- compiler.run(null, null, null, files[i].getPath());
|
|
|
-
|
|
|
-
|
|
|
- URLClassLoader classLoader = URLClassLoader
|
|
|
- .newInstance(new URL[] { root.toURI().toURL() });
|
|
|
- Class<?> cls = Class.forName("projectPackage.APITest", true, classLoader);
|
|
|
-
|
|
|
- Object t = cls.newInstance();
|
|
|
-
|
|
|
- controller.addTextToConsole(((interfaceTest)t).outPrintTest());
|
|
|
-
|
|
|
- controller.addTextToConsole(classLoader.getClass().getPackage()+"");
|
|
|
- } catch (Exception e) {
|
|
|
-
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
+ root = new File(fileChooser.getCurrentDirectory().getPath());
|
|
|
+ setAlgorithm(files[i]);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -211,4 +197,30 @@ public class SimulationMenu extends JMenuBar {
|
|
|
|
|
|
this.add(menuPanel);
|
|
|
}
|
|
|
+
|
|
|
+ public void setAlgorithm(File file) {
|
|
|
+ try {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
|
|
|
+
|
|
|
+ compiler.run(null, null, null, file.getPath());
|
|
|
+
|
|
|
+
|
|
|
+ controller.addTextToConsole(root.toString());
|
|
|
+ URLClassLoader classLoader = URLClassLoader.newInstance(new URL[] { root.toURI().toURL() });
|
|
|
+ Class<?> cls = Class.forName("projectPackage.APITest", true, classLoader);
|
|
|
+
|
|
|
+ Object t = cls.newInstance();
|
|
|
+
|
|
|
+ controller.addTextToConsole("success");
|
|
|
+
|
|
|
+ controller.setAlgorithm(t);
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|