diff --git a/PlayWall/src/de/tobias/playpad/PlayPadImpl.java b/PlayWall/src/de/tobias/playpad/PlayPadImpl.java new file mode 100644 index 0000000000000000000000000000000000000000..5c08b23ea204b8ca13ee35acfb9553c3f59edb8c --- /dev/null +++ b/PlayWall/src/de/tobias/playpad/PlayPadImpl.java @@ -0,0 +1,211 @@ +package de.tobias.playpad; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.PrintWriter; +import java.net.URI; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Optional; +import java.util.Set; + +import de.tobias.playpad.plugin.PadListener; +import de.tobias.playpad.plugin.SettingsListener; +import de.tobias.playpad.plugin.WindowListener; +import de.tobias.playpad.project.Project; +import de.tobias.playpad.viewcontroller.IPadSettingsViewController; +import de.tobias.playpad.viewcontroller.ISettingsViewController; +import de.tobias.playpad.viewcontroller.main.IMainViewController; +import de.tobias.playpad.viewcontroller.main.MainViewController; +import de.tobias.utils.application.ApplicationUtils; +import de.tobias.utils.application.container.PathType; +import de.tobias.utils.util.Worker; +import javafx.scene.image.Image; +import net.xeoh.plugins.base.PluginManager; +import net.xeoh.plugins.base.impl.PluginManagerFactory; + +public class PlayPadImpl implements PlayPad { + + private static final String PLUGIN_INFO_TXT = "pluginInfo.txt"; + + protected List<WindowListener<IMainViewController>> mainViewListeners = new ArrayList<>(); + protected List<WindowListener<ISettingsViewController>> settingsViewListeners = new ArrayList<>(); + protected List<WindowListener<IPadSettingsViewController>> padSettingsViewListeners = new ArrayList<>(); + protected List<SettingsListener> settingsListeners = new ArrayList<>(); + protected List<PadListener> padListeners = new ArrayList<>(); + + private PluginManager pluginManager; + private Set<Path> deletedPlugins; + + private MainViewController mainViewController; + + public PlayPadImpl() { + pluginManager = PluginManagerFactory.createPluginManager(); + deletedPlugins = new HashSet<>(); + } + + @Override + public void addMainViewListener(WindowListener<IMainViewController> listener) { + mainViewListeners.add(listener); + } + + @Override + public void removeMainViewListener(WindowListener<IMainViewController> listener) { + mainViewListeners.remove(listener); + } + + @Override + public void addSettingsViewListener(WindowListener<ISettingsViewController> listener) { + settingsViewListeners.add(listener); + } + + @Override + public void removeSettingsViewListener(WindowListener<ISettingsViewController> listener) { + settingsViewListeners.remove(listener); + } + + @Override + public List<WindowListener<ISettingsViewController>> getSettingsViewListener() { + return settingsViewListeners; + } + + @Override + public void addPadSettingsViewListener(WindowListener<IPadSettingsViewController> listener) { + padSettingsViewListeners.add(listener); + } + + @Override + public void removePadSettingsViewListener(WindowListener<IPadSettingsViewController> listener) { + padSettingsViewListeners.remove(listener); + } + + @Override + public List<WindowListener<IPadSettingsViewController>> getPadSettingsViewListener() { + return padSettingsViewListeners; + } + + @Override + public void addSettingsListener(SettingsListener listener) { + settingsListeners.add(listener); + } + + @Override + public void removeSettingsListener(SettingsListener listener) { + settingsListeners.remove(listener); + } + + @Override + public List<SettingsListener> getSettingsListener() { + return settingsListeners; + } + + @Override + public void addPadListener(PadListener listener) { + padListeners.add(listener); + } + + @Override + public void removePadListener(PadListener listener) { + padListeners.remove(listener); + } + + @Override + public List<PadListener> getPadListener() { + return padListeners; + } + + @Override + public IMainViewController getMainViewController() { + return mainViewController; + } + + @Override + public PluginManager getPluginManager() { + return pluginManager; + } + + @Override + public String[] getProjectFileTypes() { + return new String[] { PlayPadMain.projectType }; + } + + @Override + public Optional<Image> getIcon() { + return PlayPadMain.stageIcon; + } + + /** + * Fügt ein Plugin hinzu, sich zu löschen. + * + * @param path + * Pfad zu einem Plugin + */ + public void addDeletedPlugin(Path path) { + deletedPlugins.add(path); + } + + /** + * Gibt alle Plugins zurück, die gelöscht werden sollen. + * + * @return Plugins + */ + public Set<Path> getDeletedPlugins() { + return deletedPlugins; + } + + void deletePlugins() throws IOException { + Path pluginInfoPath = ApplicationUtils.getApplication().getPath(PathType.LIBRARY, PLUGIN_INFO_TXT); + + // Delete Plugin + if (Files.exists(pluginInfoPath)) { + BufferedReader reader = new BufferedReader(new InputStreamReader(Files.newInputStream(pluginInfoPath))); + String line; + while ((line = reader.readLine()) != null) { + Path plugin = Paths.get(line); + Files.deleteIfExists(plugin); + } + reader.close(); + Files.delete(pluginInfoPath); + } + + } + + @Override + public void shutdown() { + // Delete Plugins Info Textfile --> Löschen dann beim Start. + Path pluginInfoPath = ApplicationUtils.getApplication().getPath(PathType.LIBRARY, PLUGIN_INFO_TXT); + try { + if (Files.notExists(pluginInfoPath)) { + Files.createDirectories(pluginInfoPath.getParent()); + Files.createFile(pluginInfoPath); + } + PrintWriter deleteWriter = new PrintWriter(Files.newOutputStream(pluginInfoPath)); + for (Path path : getDeletedPlugins()) { + deleteWriter.println(path.toString()); + } + deleteWriter.close(); + } catch (IOException e) { + e.printStackTrace(); + } + + pluginManager.shutdown(); + Worker.shutdown(); + } + + public void loadPlugin(URI uri) { + pluginManager.addPluginsFrom(uri); + } + + public void openProject(Project project) { + if (mainViewController == null) { + mainViewController = new MainViewController(project, mainViewListeners); + } else { + mainViewController.setProject(project); + } + } +} diff --git a/PlayWall/src/de/tobias/playpad/PlayPadMain.java b/PlayWall/src/de/tobias/playpad/PlayPadMain.java index 901fd7248db60153a925bfdcd49e2006080ae858..429036da604cb52fa0ee4bd78e8b444d56e28368 100644 --- a/PlayWall/src/de/tobias/playpad/PlayPadMain.java +++ b/PlayWall/src/de/tobias/playpad/PlayPadMain.java @@ -1,20 +1,12 @@ package de.tobias.playpad; -import java.io.BufferedReader; import java.io.IOException; -import java.io.InputStreamReader; -import java.io.PrintWriter; import java.net.MalformedURLException; -import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; import java.util.Locale; import java.util.Optional; import java.util.ResourceBundle; -import java.util.Set; import java.util.UUID; import de.tobias.playpad.action.ActionRegistery; @@ -42,9 +34,6 @@ import de.tobias.playpad.pad.content.AudioContentConnect; import de.tobias.playpad.pad.drag.MoveDragMode; import de.tobias.playpad.pad.drag.PadDragModeRegistery; import de.tobias.playpad.pad.drag.ReplaceDragMode; -import de.tobias.playpad.plugin.PadListener; -import de.tobias.playpad.plugin.SettingsListener; -import de.tobias.playpad.plugin.WindowListener; import de.tobias.playpad.project.Project; import de.tobias.playpad.project.ProjectReference; import de.tobias.playpad.settings.Profile; @@ -54,16 +43,11 @@ import de.tobias.playpad.tigger.TriggerRegistry; import de.tobias.playpad.trigger.CartTriggerItemConnect; import de.tobias.playpad.trigger.VolumeTriggerItemConnect; import de.tobias.playpad.update.PlayPadUpdater; -import de.tobias.playpad.update.Updatable; import de.tobias.playpad.update.UpdateRegistery; import de.tobias.playpad.update.Updates; import de.tobias.playpad.view.MapperOverviewViewController; -import de.tobias.playpad.viewcontroller.IPadSettingsViewController; -import de.tobias.playpad.viewcontroller.ISettingsViewController; import de.tobias.playpad.viewcontroller.LaunchDialog; import de.tobias.playpad.viewcontroller.dialog.ChangelogDialog; -import de.tobias.playpad.viewcontroller.main.IMainViewController; -import de.tobias.playpad.viewcontroller.main.MainViewController; import de.tobias.utils.application.App; import de.tobias.utils.application.ApplicationUtils; import de.tobias.utils.application.container.PathType; @@ -81,8 +65,6 @@ import javafx.scene.control.Alert.AlertType; import javafx.scene.control.ButtonType; import javafx.scene.image.Image; import javafx.stage.Stage; -import net.xeoh.plugins.base.PluginManager; -import net.xeoh.plugins.base.impl.PluginManagerFactory; /* * TODOS @@ -109,9 +91,8 @@ import net.xeoh.plugins.base.impl.PluginManagerFactory; // FEATURE lnk für Windows mit Dateiparameter // FEATURE Backups irgendwann löschen -public class PlayPadMain extends Application implements LocalizationDelegate, PlayPad, ProfileListener { +public class PlayPadMain extends Application implements LocalizationDelegate, ProfileListener { - private static final String PLUGIN_INFO_TXT = "pluginInfo.txt"; private static final String iconPath = "icon_small.png"; public static Optional<Image> stageIcon = Optional.empty(); @@ -122,24 +103,16 @@ public class PlayPadMain extends Application implements LocalizationDelegate, Pl public static final String midiPresetType = "*.pre"; private static ResourceBundle uiResourceBundle; - private static MainViewController mainViewController; + private static PlayPadImpl impl; private static PlayPadUpdater updater; - private static Set<Path> deletedPlugins = new HashSet<>(); - - public static void addDeletedPlugin(Path path) { - deletedPlugins.add(path); - } - - /* - * - */ public static ResourceBundle getUiResourceBundle() { return uiResourceBundle; } public static void main(String[] args) throws Exception { + // Verhindert einen Bug unter Windows 10 mit comboboxen if (OS.getType() == OSType.Windows) { System.setProperty("glass.accessible.force", "false"); } @@ -153,21 +126,18 @@ public class PlayPadMain extends Application implements LocalizationDelegate, Pl app.start(args); } - private static PluginManager pluginManager; - @Override public void init() throws Exception { - PlayPadPlugin.setImplementation(this); + impl = new PlayPadImpl(); + PlayPadPlugin.setImplementation(impl); // Localization setupLocalization(); // Console if (!ApplicationUtils.getApplication().isDebug()) { - System.setOut( - ConsoleUtils.streamToFile(ApplicationUtils.getApplication().getPath(PathType.LOG, "out.log"))); - System.setErr( - ConsoleUtils.streamToFile(ApplicationUtils.getApplication().getPath(PathType.LOG, "err.log"))); + System.setOut(ConsoleUtils.streamToFile(ApplicationUtils.getApplication().getPath(PathType.LOG, "out.log"))); + System.setErr(ConsoleUtils.streamToFile(ApplicationUtils.getApplication().getPath(PathType.LOG, "err.log"))); } } @@ -177,8 +147,7 @@ public class PlayPadMain extends Application implements LocalizationDelegate, Pl try { Image stageIcon = new Image(iconPath); PlayPadMain.stageIcon = Optional.of(stageIcon); - } catch (Exception e) { - } + } catch (Exception e) {} /* * Setup @@ -213,10 +182,9 @@ public class PlayPadMain extends Application implements LocalizationDelegate, Pl if (getParameters().getRaw().size() > 0) { try { UUID uuid = UUID.fromString(getParameters().getNamed().get("project")); - launchProject(Project.load(ProjectReference.getProject(uuid), true, null)); + impl.openProject(Project.load(ProjectReference.getProject(uuid), true, null)); return; - } catch (IllegalArgumentException | NullPointerException e) { - } catch (Exception e) { + } catch (IllegalArgumentException | NullPointerException e) {} catch (Exception e) { e.printStackTrace(); } } @@ -234,27 +202,13 @@ public class PlayPadMain extends Application implements LocalizationDelegate, Pl e.printStackTrace(); // Speichern Fehler } + // Shutdown components + // TODO use AutoCloseable TinyAudioHandler.shutdown(); ClipAudioHandler.shutdown(); - pluginManager.shutdown(); - - Path pluginInfoPath = ApplicationUtils.getApplication().getPath(PathType.LIBRARY, PLUGIN_INFO_TXT); - try { - if (Files.notExists(pluginInfoPath)) { - Files.createDirectories(pluginInfoPath.getParent()); - Files.createFile(pluginInfoPath); - } - PrintWriter deleteWriter = new PrintWriter(Files.newOutputStream(pluginInfoPath)); - for (Path path : deletedPlugins) { - deleteWriter.println(path.toString()); - } - deleteWriter.close(); - } catch (IOException e) { - e.printStackTrace(); - } + impl.shutdown(); - Worker.shutdown(); Platform.exit(); System.exit(0); } @@ -300,26 +254,11 @@ public class PlayPadMain extends Application implements LocalizationDelegate, Pl } private void setupPlugins(Path pluginPath) throws IOException, MalformedURLException { - /* - * Plugins - */ - Path pluginInfoPath = ApplicationUtils.getApplication().getPath(PathType.LIBRARY, PLUGIN_INFO_TXT); - - // Delete Plugin - if (Files.exists(pluginInfoPath)) { - BufferedReader reader = new BufferedReader(new InputStreamReader(Files.newInputStream(pluginInfoPath))); - String line; - while ((line = reader.readLine()) != null) { - Path plugin = Paths.get(line); - Files.deleteIfExists(plugin); - } - reader.close(); - Files.delete(pluginInfoPath); - } - + // Delete old plugins + impl.deletePlugins(); + // Load Plugins - pluginManager = PluginManagerFactory.createPluginManager(); - pluginManager.addPluginsFrom(pluginPath.toUri()); + impl.loadPlugin(pluginPath.toUri()); } private void setupLocalization() { @@ -329,10 +268,6 @@ public class PlayPadMain extends Application implements LocalizationDelegate, Pl uiResourceBundle = Localization.loadBundle("de/tobias/playpad/assets/lang/ui", getClass().getClassLoader()); } - public static void launchProject(Project project) { - mainViewController = new MainViewController(project, mainViewListeners, pluginManager); - } - /** * Handle Auto Update on profile reload */ @@ -373,107 +308,15 @@ public class PlayPadMain extends Application implements LocalizationDelegate, Pl return Locale.getDefault(); } - /* - * Plugins + /** + * Gibt die Implementierung des Peers für Plugins zurück. + * + * @return Schnittstelle + * + * @see PlayPad */ - protected static List<WindowListener<IMainViewController>> mainViewListeners = new ArrayList<>(); - protected static List<WindowListener<ISettingsViewController>> settingsViewListeners = new ArrayList<>(); - protected static List<WindowListener<IPadSettingsViewController>> padSettingsViewListeners = new ArrayList<>(); - protected static List<SettingsListener> settingsListeners = new ArrayList<>(); - protected static List<PadListener> padListeners = new ArrayList<>(); - - @Override - public void addMainViewListener(WindowListener<IMainViewController> listener) { - mainViewListeners.add(listener); - } - - @Override - public void removeMainViewListener(WindowListener<IMainViewController> listener) { - mainViewListeners.remove(listener); - } - - @Override - public void addSettingsViewListener(WindowListener<ISettingsViewController> listener) { - settingsViewListeners.add(listener); - } - - @Override - public void removeSettingsViewListener(WindowListener<ISettingsViewController> listener) { - settingsViewListeners.remove(listener); - } - - @Override - public List<WindowListener<ISettingsViewController>> getSettingsViewListener() { - return settingsViewListeners; - } - - @Override - public void addPadSettingsViewListener(WindowListener<IPadSettingsViewController> listener) { - padSettingsViewListeners.add(listener); - } - - @Override - public void removePadSettingsViewListener(WindowListener<IPadSettingsViewController> listener) { - padSettingsViewListeners.remove(listener); - } - - @Override - public List<WindowListener<IPadSettingsViewController>> getPadSettingsViewListener() { - return padSettingsViewListeners; - } - - @Override - public void addSettingsListener(SettingsListener listener) { - settingsListeners.add(listener); - } - - @Override - public void removeSettingsListener(SettingsListener listener) { - settingsListeners.remove(listener); - } - - @Override - public List<SettingsListener> getSettingsListener() { - return settingsListeners; - } - - @Override - public void addPadListener(PadListener listener) { - padListeners.add(listener); - } - - @Override - public void removePadListener(PadListener listener) { - padListeners.remove(listener); - } - - @Override - public List<PadListener> getPadListener() { - return padListeners; - } - - @Override - public IMainViewController getMainViewController() { - return mainViewController; - } - - @Override - public PluginManager getPluginManager() { - return pluginManager; - } - - @Override - public String[] getProjectFileTypes() { - return new String[] { projectType }; - } - - @Override - public Optional<Image> getIcon() { - return stageIcon; - } - - public static Updatable getUpdater() { - return updater; + public static PlayPadImpl getProgramInstance() { + return impl; } -} +} \ No newline at end of file diff --git a/PlayWall/src/de/tobias/playpad/audio/ClipAudioHandlerConnect.java b/PlayWall/src/de/tobias/playpad/audio/ClipAudioHandlerConnect.java index b0428e4db1774e8be59177263e9308bd682ca5a6..e78e6895cc3a546dba104369f15f6e4ae96e80ee 100644 --- a/PlayWall/src/de/tobias/playpad/audio/ClipAudioHandlerConnect.java +++ b/PlayWall/src/de/tobias/playpad/audio/ClipAudioHandlerConnect.java @@ -4,7 +4,7 @@ import de.tobias.playpad.pad.conntent.PadContent; import de.tobias.playpad.viewcontroller.AudioTypeViewController; import de.tobias.playpad.viewcontroller.audio.ClipSettingsViewController; -public class ClipAudioHandlerConnect extends AudioHandlerConnect { +public class ClipAudioHandlerConnect extends AudioHandlerConnect implements AutoCloseable { @Override public AudioHandler createAudioHandler(PadContent content) { @@ -15,5 +15,10 @@ public class ClipAudioHandlerConnect extends AudioHandlerConnect { public AudioTypeViewController getAudioViewController() { return new ClipSettingsViewController(); } + + @Override + public void close() throws Exception { + TinyAudioHandler.shutdown(); + } } diff --git a/PlayWall/src/de/tobias/playpad/audio/TinyAudioHandlerConnect.java b/PlayWall/src/de/tobias/playpad/audio/TinyAudioHandlerConnect.java index 3c97f5f9288fd6981970433cdd61503952aac39d..c8e8904c0b953c3dfa3e99f7e162bbe5ca7cf6c4 100644 --- a/PlayWall/src/de/tobias/playpad/audio/TinyAudioHandlerConnect.java +++ b/PlayWall/src/de/tobias/playpad/audio/TinyAudioHandlerConnect.java @@ -4,7 +4,7 @@ import de.tobias.playpad.pad.conntent.PadContent; import de.tobias.playpad.viewcontroller.AudioTypeViewController; import de.tobias.playpad.viewcontroller.audio.TinySoundSettingsViewController; -public class TinyAudioHandlerConnect extends AudioHandlerConnect { +public class TinyAudioHandlerConnect extends AudioHandlerConnect implements AutoCloseable { @Override public AudioHandler createAudioHandler(PadContent content) { @@ -16,4 +16,8 @@ public class TinyAudioHandlerConnect extends AudioHandlerConnect { return new TinySoundSettingsViewController(); } + @Override + public void close() throws Exception { + TinyAudioHandler.shutdown(); + } } diff --git a/PlayWall/src/de/tobias/playpad/viewcontroller/LaunchDialog.java b/PlayWall/src/de/tobias/playpad/viewcontroller/LaunchDialog.java index 44603daf3a3668368ecaf440a4241b5741041df3..01c05dae5588ab4fef6c904cc9ce8dae12a0abae 100644 --- a/PlayWall/src/de/tobias/playpad/viewcontroller/LaunchDialog.java +++ b/PlayWall/src/de/tobias/playpad/viewcontroller/LaunchDialog.java @@ -1,5 +1,7 @@ package de.tobias.playpad.viewcontroller; +import static de.tobias.utils.util.Localization.getString; + import java.io.File; import java.io.IOException; import java.nio.file.Path; @@ -7,6 +9,7 @@ import java.nio.file.Path; import org.dom4j.DocumentException; import de.tobias.playpad.PlayPadMain; +import de.tobias.playpad.PlayPadPlugin; import de.tobias.playpad.Strings; import de.tobias.playpad.project.ProfileChooseable; import de.tobias.playpad.project.Project; @@ -22,8 +25,6 @@ import de.tobias.playpad.viewcontroller.dialog.ProfileChooseDialog; import de.tobias.utils.application.App; import de.tobias.utils.application.ApplicationUtils; import de.tobias.utils.ui.ViewController; -import static de.tobias.utils.util.Localization.getString; -import de.tobias.utils.util.Worker; import javafx.event.ActionEvent; import javafx.fxml.FXML; import javafx.scene.control.Alert; @@ -107,10 +108,7 @@ public class LaunchDialog extends ViewController implements ProfileChooseable { stage.setTitle(getString(Strings.UI_Dialog_Launch_Title)); PlayPadMain.stageIcon.ifPresent(stage.getIcons()::add); - stage.setOnCloseRequest(e -> - { - Worker.shutdown(); - }); + PlayPadPlugin.getImplementation().shutdown(); stage.setResizable(false); stage.setWidth(650); @@ -124,7 +122,7 @@ public class LaunchDialog extends ViewController implements ProfileChooseable { Project project = dialog.getProject(); if (project != null) { - PlayPadMain.launchProject(project); + PlayPadMain.getProgramInstance().openProject(project); getStage().close(); } } @@ -197,7 +195,7 @@ public class LaunchDialog extends ViewController implements ProfileChooseable { private void launchProject(ProjectReference ref) { try { Project project = Project.load(ref, true, this); - PlayPadMain.launchProject(project); + PlayPadMain.getProgramInstance().openProject(project); getStage().close(); } catch (ProfileNotFoundException e) { e.printStackTrace(); diff --git a/PlayWall/src/de/tobias/playpad/viewcontroller/cell/PluginCell.java b/PlayWall/src/de/tobias/playpad/viewcontroller/cell/PluginCell.java index fda52d6daca20e823028dc8d1e551d6be4312ba3..6deea2a19ee6d00415ee5d33d791fb75f90439ec 100644 --- a/PlayWall/src/de/tobias/playpad/viewcontroller/cell/PluginCell.java +++ b/PlayWall/src/de/tobias/playpad/viewcontroller/cell/PluginCell.java @@ -19,7 +19,6 @@ import javafx.geometry.Pos; import javafx.scene.control.CheckBox; import javafx.scene.control.ListCell; import javafx.scene.layout.HBox; -import net.xeoh.plugins.base.PluginManager; public class PluginCell extends ListCell<Plugin> implements ChangeListener<Boolean> { @@ -27,11 +26,7 @@ public class PluginCell extends ListCell<Plugin> implements ChangeListener<Boole private HBox buttons; private CheckBox checkBox; - private PluginManager manager; - - public PluginCell(PluginManager manager) { - this.manager = manager; - + public PluginCell() { checkBox = new CheckBox(); checkBox.selectedProperty().addListener(this); @@ -66,24 +61,28 @@ public class PluginCell extends ListCell<Plugin> implements ChangeListener<Boole downloadPlugin(plugin, path); // Dependencies - List<Plugin> dependencies = findDependencies(); - dependencies.forEach(p -> - { - Path decPath = app.getPath(PathType.LIBRARY, p.getFileName()); - downloadPlugin(p, decPath); - - // Add Plugin to classpath - manager.addPluginsFrom(decPath.toUri()); - }); + loadDependencies(app); // Add Plugin to classpath - manager.addPluginsFrom(path.toUri()); + PlayPadMain.getProgramInstance().loadPlugin(path.toUri()); } else { // Deaktivieren - PlayPadMain.addDeletedPlugin(path); + PlayPadMain.getProgramInstance().addDeletedPlugin(path); } } + private void loadDependencies(App app) { + List<Plugin> dependencies = findDependencies(); + dependencies.forEach(p -> + { + Path decPath = app.getPath(PathType.LIBRARY, p.getFileName()); + downloadPlugin(p, decPath); + + // Add Plugin to classpath + PlayPadMain.getProgramInstance().loadPlugin(decPath.toUri()); + }); + } + private List<Plugin> findDependencies() { List<Plugin> plugins = new ArrayList<>(); for (String dependencyName : plugin.getDependencies()) { diff --git a/PlayWall/src/de/tobias/playpad/viewcontroller/dialog/PluginViewController.java b/PlayWall/src/de/tobias/playpad/viewcontroller/dialog/PluginViewController.java index e17181198ecc6cb89af94ecf38776dd34ebe033b..dbe7f9aefae577b2c99d0e62bc95747d84c760df 100644 --- a/PlayWall/src/de/tobias/playpad/viewcontroller/dialog/PluginViewController.java +++ b/PlayWall/src/de/tobias/playpad/viewcontroller/dialog/PluginViewController.java @@ -27,18 +27,14 @@ import javafx.scene.control.ListView; import javafx.stage.Modality; import javafx.stage.Stage; import javafx.stage.Window; -import net.xeoh.plugins.base.PluginManager; public class PluginViewController extends ViewController { @FXML private ListView<Plugin> pluginListView; @FXML private Button finishButton; - private PluginManager manager; - - public PluginViewController(PluginManager manager, Window owner) { + public PluginViewController(Window owner) { super("pluginView", "de/tobias/playpad/assets/dialog/", null, PlayPadMain.getUiResourceBundle()); - this.manager = manager; getStage().initOwner(owner); getStage().initModality(Modality.WINDOW_MODAL); @@ -77,7 +73,7 @@ public class PluginViewController extends ViewController { @Override public void init() { - pluginListView.setCellFactory(list -> new PluginCell(manager)); + pluginListView.setCellFactory(list -> new PluginCell()); pluginListView.setPlaceholder(new Label(Localization.getString(Strings.UI_Placeholder_Plugins))); addCloseKeyShortcut(() -> getStage().close()); diff --git a/PlayWall/src/de/tobias/playpad/viewcontroller/main/MainMenuBarController.java b/PlayWall/src/de/tobias/playpad/viewcontroller/main/MainMenuBarController.java index 56f9b0b0b54e9cdabf4a110c36081ba669343344..439372156089d4990b4ee6ea9d0dc074950e63da 100644 --- a/PlayWall/src/de/tobias/playpad/viewcontroller/main/MainMenuBarController.java +++ b/PlayWall/src/de/tobias/playpad/viewcontroller/main/MainMenuBarController.java @@ -57,7 +57,6 @@ import javafx.scene.control.MenuBar; import javafx.scene.control.MenuItem; import javafx.stage.Modality; import javafx.stage.Stage; -import net.xeoh.plugins.base.PluginManager; public class MainMenuBarController implements EventHandler<ActionEvent>, Initializable, ProfileListener { @@ -75,7 +74,6 @@ public class MainMenuBarController implements EventHandler<ActionEvent>, Initial // Open Windows private SettingsViewController settingsViewController; - private PluginManager manager; private MainViewController mvc; private ChangeListener<Boolean> lockedListener; @@ -319,7 +317,7 @@ public class MainMenuBarController implements EventHandler<ActionEvent>, Initial private void pluginMenuItemHandler(ActionEvent e) { doAction(() -> { - PluginViewController controller = new PluginViewController(manager, mvc.getStage()); + PluginViewController controller = new PluginViewController(mvc.getStage()); controller.getStage().showAndWait(); mvc.showPage(mvc.getPage()); }); @@ -381,10 +379,6 @@ public class MainMenuBarController implements EventHandler<ActionEvent>, Initial }); } - public void setPluginManager(PluginManager manager) { - this.manager = manager; - } - public void setMainViewController(MainViewController mvc) { this.mvc = mvc; } diff --git a/PlayWall/src/de/tobias/playpad/viewcontroller/main/MainViewController.java b/PlayWall/src/de/tobias/playpad/viewcontroller/main/MainViewController.java index 37cc0546e765443ec89abc4fb2d1fa3eddb7ac76..8c40bc4cfa21b24883c5d7a41f726b6338146e34 100644 --- a/PlayWall/src/de/tobias/playpad/viewcontroller/main/MainViewController.java +++ b/PlayWall/src/de/tobias/playpad/viewcontroller/main/MainViewController.java @@ -66,7 +66,6 @@ import javafx.scene.shape.Line; import javafx.stage.Modality; import javafx.stage.Screen; import javafx.stage.Stage; -import net.xeoh.plugins.base.PluginManager; public class MainViewController extends ViewController implements IMainViewController, NotificationHandler, ProfileListener { @@ -99,13 +98,12 @@ public class MainViewController extends ViewController implements IMainViewContr // Style private Color gridColor; - public MainViewController(Project project, List<WindowListener<IMainViewController>> listener, PluginManager manager) { + public MainViewController(Project project, List<WindowListener<IMainViewController>> listener) { super("mainView", "de/tobias/playpad/assets/view/main/", null, PlayPadMain.getUiResourceBundle()); // Include FXML Setup toolbarController.setMainViewController(this); menuBarController.setMainViewController(this); - menuBarController.setPluginManager(manager); padGridPane.setGridLinesVisible(true); diff --git a/PlayWall/src/de/tobias/playpad/viewcontroller/option/SettingsViewController.java b/PlayWall/src/de/tobias/playpad/viewcontroller/option/SettingsViewController.java index 9e9aff7afe1d9708e5331201322811650bd11fd6..30ac7e9f14e9a08636f53c3743a3313c6a3bf3d8 100644 --- a/PlayWall/src/de/tobias/playpad/viewcontroller/option/SettingsViewController.java +++ b/PlayWall/src/de/tobias/playpad/viewcontroller/option/SettingsViewController.java @@ -4,7 +4,6 @@ import java.util.ArrayList; import java.util.List; import de.tobias.playpad.PlayPadMain; -import de.tobias.playpad.PlayPadPlugin; import de.tobias.playpad.Strings; import de.tobias.playpad.midi.Midi; import de.tobias.playpad.pad.conntent.PadContentRegistry; @@ -60,7 +59,7 @@ public class SettingsViewController extends ViewController implements ISettingsV } // Listener - PlayPadPlugin.getImplementation().getSettingsViewListener().forEach(l -> + PlayPadMain.getProgramInstance().getSettingsViewListener().forEach(l -> { try { l.onInit(this); @@ -125,7 +124,7 @@ public class SettingsViewController extends ViewController implements ISettingsV if (valid) { // Einstellungen sind Valide // Listener - PlayPadPlugin.getImplementation().getSettingsViewListener().forEach(l -> l.onClose(this)); + PlayPadMain.getProgramInstance().getSettingsViewListener().forEach(l -> l.onClose(this)); saveChanges(); getStage().close(); @@ -179,7 +178,7 @@ public class SettingsViewController extends ViewController implements ISettingsV if (valid) { // Einstellungen sind Valide // Listener - PlayPadPlugin.getImplementation().getSettingsViewListener().forEach(l -> l.onClose(this)); + PlayPadMain.getProgramInstance().getSettingsViewListener().forEach(l -> l.onClose(this)); saveChanges(); getStage().close(); diff --git a/PlayWall/src/de/tobias/playpad/viewcontroller/option/pad/PadSettingsViewController.java b/PlayWall/src/de/tobias/playpad/viewcontroller/option/pad/PadSettingsViewController.java index 7053289e657bced4098fc4dae07841a964bb1004..0b2a9356190a28f5bad1edf01dff25aac071c33d 100644 --- a/PlayWall/src/de/tobias/playpad/viewcontroller/option/pad/PadSettingsViewController.java +++ b/PlayWall/src/de/tobias/playpad/viewcontroller/option/pad/PadSettingsViewController.java @@ -4,7 +4,6 @@ import java.util.ArrayList; import java.util.List; import de.tobias.playpad.PlayPadMain; -import de.tobias.playpad.PlayPadPlugin; import de.tobias.playpad.Strings; import de.tobias.playpad.pad.Pad; import de.tobias.playpad.pad.PadStatus; @@ -56,7 +55,7 @@ public class PadSettingsViewController extends ViewController implements IPadSet } // Listener - PlayPadPlugin.getImplementation().getPadSettingsViewListener().forEach(l -> { + PlayPadMain.getProgramInstance().getPadSettingsViewListener().forEach(l -> { try { l.onInit(this); } catch (Exception e) { @@ -120,7 +119,7 @@ public class PadSettingsViewController extends ViewController implements IPadSet saveChanges(); // Listener - PlayPadPlugin.getImplementation().getPadSettingsViewListener().forEach(l -> l.onClose(this)); + PlayPadMain.getProgramInstance().getPadSettingsViewListener().forEach(l -> l.onClose(this)); return true; } @@ -134,7 +133,7 @@ public class PadSettingsViewController extends ViewController implements IPadSet private void finishButtonHandler(ActionEvent event) { saveChanges(); // Listener - PlayPadPlugin.getImplementation().getPadSettingsViewListener().forEach(l -> l.onClose(this)); + PlayPadMain.getProgramInstance().getPadSettingsViewListener().forEach(l -> l.onClose(this)); getStage().close(); } diff --git a/PlayWallCore/src/de/tobias/playpad/PlayPad.java b/PlayWallCore/src/de/tobias/playpad/PlayPad.java index 293a1a6c15149310eafa1032c1b1fe35d043a1eb..569250e2b75b942fa6afac1b86c1959c961e1db2 100644 --- a/PlayWallCore/src/de/tobias/playpad/PlayPad.java +++ b/PlayWallCore/src/de/tobias/playpad/PlayPad.java @@ -1,5 +1,6 @@ package de.tobias.playpad; +import java.net.URI; import java.util.List; import java.util.Optional; @@ -115,15 +116,26 @@ public interface PlayPad { public IMainViewController getMainViewController(); + @Deprecated public PluginManager getPluginManager(); @Deprecated public String[] getProjectFileTypes(); - + /** * Gibt das Programmicon zurück. * * @return Programmicon */ public Optional<Image> getIcon(); + + public void shutdown(); + + /** + * Lädt ein Plugin sofort ins System. + * + * @param uri + * Quelle des Plugin + */ + public void loadPlugin(URI uri); } diff --git a/PlayWallPlugins/awakeplugin/de/tobias/playpad/awakeplugin/impl/AwakePluginImpl.java b/PlayWallPlugins/awakeplugin/de/tobias/playpad/awakeplugin/impl/AwakePluginImpl.java index 322a160eaa4e3e66f21386a6ec4164bc9545957a..42b536e0ec16ed773b68a36db6a505652ed05dab 100644 --- a/PlayWallPlugins/awakeplugin/de/tobias/playpad/awakeplugin/impl/AwakePluginImpl.java +++ b/PlayWallPlugins/awakeplugin/de/tobias/playpad/awakeplugin/impl/AwakePluginImpl.java @@ -32,7 +32,6 @@ import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.scene.control.CheckMenuItem; import javafx.scene.control.Label; -import net.xeoh.plugins.base.PluginManager; import net.xeoh.plugins.base.annotations.PluginImplementation; import net.xeoh.plugins.base.annotations.events.PluginLoaded; import net.xeoh.plugins.base.annotations.events.Shutdown; @@ -58,8 +57,7 @@ public class AwakePluginImpl implements AwakePlugin, WindowListener<IMainViewCon if (OS.getType() == OSType.Windows) { try { loadJNA(); - PluginManager manager = PlayPadPlugin.getImplementation().getPluginManager(); - manager.addPluginsFrom(ApplicationUtils.getApplication().getPath(PathType.LIBRARY, "jna").toUri()); + PlayPadPlugin.getImplementation().loadPlugin(ApplicationUtils.getApplication().getPath(PathType.LIBRARY, "jna").toUri()); } catch (IOException e) { e.printStackTrace(); }