mirror of
https://github.com/DanilaFe/abacus
synced 2025-01-09 23:58:09 -08:00
add live load and unload
This commit is contained in:
parent
5de9453bec
commit
c03e191c36
@ -9,7 +9,7 @@ import org.nwapw.abacus.parsing.ShuntingYardParser;
|
|||||||
import org.nwapw.abacus.parsing.TreeBuilder;
|
import org.nwapw.abacus.parsing.TreeBuilder;
|
||||||
import org.nwapw.abacus.plugin.ClassFinder;
|
import org.nwapw.abacus.plugin.ClassFinder;
|
||||||
import org.nwapw.abacus.plugin.PluginManager;
|
import org.nwapw.abacus.plugin.PluginManager;
|
||||||
import org.nwapw.abacus.plugin.StandardPlugin;
|
//import org.nwapw.abacus.plugin.StandardPlugin;
|
||||||
import org.nwapw.abacus.tree.NumberReducer;
|
import org.nwapw.abacus.tree.NumberReducer;
|
||||||
import org.nwapw.abacus.tree.TreeNode;
|
import org.nwapw.abacus.tree.TreeNode;
|
||||||
|
|
||||||
@ -67,16 +67,22 @@ public class Abacus {
|
|||||||
|
|
||||||
pluginManager.addListener(lexerTokenizer);
|
pluginManager.addListener(lexerTokenizer);
|
||||||
pluginManager.addListener(shuntingYardParser);
|
pluginManager.addListener(shuntingYardParser);
|
||||||
pluginManager.addInstantiated(new StandardPlugin(pluginManager));
|
//pluginManager.addInstantiated(new StandardPlugin(pluginManager));
|
||||||
|
/*
|
||||||
try {
|
try {
|
||||||
ClassFinder.loadJars("plugins")
|
ClassFinder.loadJars("plugins")
|
||||||
.forEach(plugin -> pluginManager.addClass(plugin));
|
.forEach(plugin -> pluginManager.addClass(plugin));
|
||||||
} catch (IOException | ClassNotFoundException e) {
|
} catch (IOException | ClassNotFoundException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}//*/
|
||||||
pluginManager.load();
|
pluginManager.load();
|
||||||
}
|
}
|
||||||
|
public void loadClass(Class<?> newClass){
|
||||||
|
pluginManager.addClass(newClass);
|
||||||
|
}
|
||||||
|
public void unloadClass(Class<?> newClass){
|
||||||
|
pluginManager.removeClass(newClass);
|
||||||
|
}
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
AbacusApplication.launch(AbacusApplication.class, args);
|
AbacusApplication.launch(AbacusApplication.class, args);
|
||||||
}
|
}
|
||||||
|
@ -8,8 +8,11 @@ import javafx.scene.text.Text;
|
|||||||
import javafx.util.Callback;
|
import javafx.util.Callback;
|
||||||
import org.nwapw.abacus.Abacus;
|
import org.nwapw.abacus.Abacus;
|
||||||
import org.nwapw.abacus.number.NumberInterface;
|
import org.nwapw.abacus.number.NumberInterface;
|
||||||
|
import org.nwapw.abacus.plugin.ClassFinder;
|
||||||
import org.nwapw.abacus.tree.TreeNode;
|
import org.nwapw.abacus.tree.TreeNode;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The controller for the abacus FX UI, responsible
|
* The controller for the abacus FX UI, responsible
|
||||||
@ -42,6 +45,12 @@ public class AbacusController {
|
|||||||
private Button inputButton;
|
private Button inputButton;
|
||||||
@FXML
|
@FXML
|
||||||
private ComboBox<String> numberImplementationBox;
|
private ComboBox<String> numberImplementationBox;
|
||||||
|
@FXML
|
||||||
|
private Button loadButton;
|
||||||
|
@FXML
|
||||||
|
private Button unloadButton;
|
||||||
|
@FXML
|
||||||
|
private TextField loadField;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The list of history entries, created by the users.
|
* The list of history entries, created by the users.
|
||||||
@ -106,5 +115,38 @@ public class AbacusController {
|
|||||||
inputButton.setDisable(false);
|
inputButton.setDisable(false);
|
||||||
inputField.setText("");
|
inputField.setText("");
|
||||||
}
|
}
|
||||||
|
@FXML
|
||||||
|
private void loadClass(){
|
||||||
|
try {
|
||||||
|
for(Class<?> plugin :ClassFinder.loadJars("plugins")){
|
||||||
|
String name = "";
|
||||||
|
//String name = plugin.getName();
|
||||||
|
while(!(name.indexOf('/') ==-1)){
|
||||||
|
name=name.substring(name.indexOf('/')+1);
|
||||||
|
}
|
||||||
|
if(loadField.getText().equals("")||loadField.getText().equals(name)||(loadField.getText()+".class").equals(name)){
|
||||||
|
//abacus.loadClass(plugin);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (IOException | ClassNotFoundException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@FXML
|
||||||
|
private void unloadClass(){
|
||||||
|
try {
|
||||||
|
for(Class<?> plugin :ClassFinder.loadJars("plugins")){
|
||||||
|
String name = plugin.getName();
|
||||||
|
while(!(name.indexOf('/') ==-1)){
|
||||||
|
name=name.substring(name.indexOf('/')+1);
|
||||||
|
}
|
||||||
|
if(loadField.getText().equals("")||loadField.getText().equals(name)||(loadField.getText()+".class").equals(name)){
|
||||||
|
//abacus.unloadClass(plugin);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (IOException | ClassNotFoundException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -140,6 +140,11 @@ public class PluginManager {
|
|||||||
plugins.add(plugin);
|
plugins.add(plugin);
|
||||||
loadedPluginClasses.add(plugin.getClass());
|
loadedPluginClasses.add(plugin.getClass());
|
||||||
}
|
}
|
||||||
|
public void removeInstantiated(Plugin plugin){
|
||||||
|
if (loadedPluginClasses.contains(plugin.getClass())) return;
|
||||||
|
plugins.remove(plugin);
|
||||||
|
loadedPluginClasses.remove(plugin.getClass());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instantiates a class of plugin, and adds it to this
|
* Instantiates a class of plugin, and adds it to this
|
||||||
@ -155,6 +160,14 @@ public class PluginManager {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public void removeClass(Class<?> newClass){
|
||||||
|
if (!Plugin.class.isAssignableFrom(newClass) || newClass == Plugin.class) return;
|
||||||
|
try {
|
||||||
|
removeInstantiated((Plugin) newClass.getConstructor(PluginManager.class).newInstance(this));
|
||||||
|
} catch (InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads all the plugins in the PluginManager.
|
* Loads all the plugins in the PluginManager.
|
||||||
|
@ -46,6 +46,9 @@
|
|||||||
<padding><Insets left="10" right="10" top="10" bottom="10"/></padding>
|
<padding><Insets left="10" right="10" top="10" bottom="10"/></padding>
|
||||||
<Label text="Number Implementation" GridPane.columnIndex="0" GridPane.rowIndex="0"/>
|
<Label text="Number Implementation" GridPane.columnIndex="0" GridPane.rowIndex="0"/>
|
||||||
<ComboBox fx:id="numberImplementationBox" GridPane.columnIndex="1" GridPane.rowIndex="0"/>
|
<ComboBox fx:id="numberImplementationBox" GridPane.columnIndex="1" GridPane.rowIndex="0"/>
|
||||||
|
<Button fx:id="loadButton" text="Load" GridPane.rowIndex="1" GridPane.columnIndex="0" maxWidth = "Infinity" onAction="#loadClass"/>
|
||||||
|
<Button fx:id="unloadButton" text="Unload" GridPane.rowIndex="1" GridPane.columnIndex="1" maxWidth = "Infinity" onAction="#unloadClass"/>
|
||||||
|
<TextField fx:id="loadField" GridPane.rowIndex="1" GridPane.columnIndex="2"/>
|
||||||
</GridPane>
|
</GridPane>
|
||||||
</Tab>
|
</Tab>
|
||||||
</TabPane>
|
</TabPane>
|
||||||
|
Loading…
Reference in New Issue
Block a user