diff --git a/PlayWall/assets/de/tobias/playpad/assets/view/main/mainMenu.fxml b/PlayWall/assets/de/tobias/playpad/assets/view/main/mainMenu.fxml index 1019034cadcd369e709a0a0091e34f3b7b181c7d..4811fc21c824512215069318915dd99aed3ea491 100644 --- a/PlayWall/assets/de/tobias/playpad/assets/view/main/mainMenu.fxml +++ b/PlayWall/assets/de/tobias/playpad/assets/view/main/mainMenu.fxml @@ -48,7 +48,6 @@ <SeparatorMenuItem mnemonicParsing="false" /> <MenuItem mnemonicParsing="false" onAction="#pluginMenuItemHandler" text="%main.menuitem.plugins" /> <SeparatorMenuItem mnemonicParsing="false" /> - <CheckMenuItem fx:id="quickEditMenuItem" mnemonicParsing="false" onAction="#quickEditMenuHandler" text="Quick Edit" visible="false" /> <MenuItem fx:id="settingsMenuItem" mnemonicParsing="false" onAction="#settingsHandler" text="%main.menuitem.settings"> <accelerator> <KeyCodeCombination alt="UP" code="COMMA" control="UP" meta="UP" shift="UP" shortcut="DOWN" /> diff --git a/PlayWall/src/de/tobias/playpad/PlayPadImpl.java b/PlayWall/src/de/tobias/playpad/PlayPadImpl.java index 5c08b23ea204b8ca13ee35acfb9553c3f59edb8c..ecff8fee390fa91ea62c2ad024ff452164a7553a 100644 --- a/PlayWall/src/de/tobias/playpad/PlayPadImpl.java +++ b/PlayWall/src/de/tobias/playpad/PlayPadImpl.java @@ -54,41 +54,6 @@ public class PlayPadImpl implements PlayPad { 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); @@ -124,16 +89,6 @@ public class PlayPadImpl implements PlayPad { 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; diff --git a/PlayWall/src/de/tobias/playpad/viewcontroller/main/MainMenuBarController.java b/PlayWall/src/de/tobias/playpad/viewcontroller/main/MainMenuBarController.java index 439372156089d4990b4ee6ea9d0dc074950e63da..8ed2b134f07c501b1ba28832f18dad8c4845560c 100644 --- a/PlayWall/src/de/tobias/playpad/viewcontroller/main/MainMenuBarController.java +++ b/PlayWall/src/de/tobias/playpad/viewcontroller/main/MainMenuBarController.java @@ -10,11 +10,7 @@ import java.util.ResourceBundle; import de.tobias.playpad.AppUserInfoStrings; import de.tobias.playpad.PlayPadMain; -import de.tobias.playpad.PlayPadPlugin; import de.tobias.playpad.Strings; -import de.tobias.playpad.action.Action; -import de.tobias.playpad.action.cartaction.CartAction; -import de.tobias.playpad.action.connect.CartActionConnect; import de.tobias.playpad.midi.Midi; import de.tobias.playpad.pad.view.IPadViewController; import de.tobias.playpad.project.Project; @@ -61,16 +57,16 @@ import javafx.stage.Stage; public class MainMenuBarController implements EventHandler<ActionEvent>, Initializable, ProfileListener { @FXML private MenuBar menuBar; - @FXML CheckMenuItem dndModeMenuItem; - @FXML CheckMenuItem alwaysOnTopItem; - @FXML CheckMenuItem fullScreenMenuItem; - @FXML Menu recentOpenMenu; - @FXML MenuItem profileMenu; + @FXML private CheckMenuItem dndModeMenuItem; + @FXML private CheckMenuItem alwaysOnTopItem; + @FXML private CheckMenuItem fullScreenMenuItem; + @FXML private Menu recentOpenMenu; + @FXML private MenuItem profileMenu; - @FXML CheckMenuItem quickEditMenuItem; - @FXML MenuItem settingsMenuItem; + @FXML private CheckMenuItem quickEditMenuItem; + @FXML private MenuItem settingsMenuItem; - @FXML Menu extensionMenu; + @FXML private Menu extensionMenu; // Open Windows private SettingsViewController settingsViewController; @@ -172,23 +168,6 @@ public class MainMenuBarController implements EventHandler<ActionEvent>, Initial }); } - @FXML - private void quickEditMenuHandler(ActionEvent event) { - try { - for (Action action : Profile.currentProfile().getMappings().getActiveMapping().getActionsOfType(CartActionConnect.TYPE)) { - CartAction cartAction = (CartAction) action; - if (cartAction.getCart() < mvc.padViewList.size()) { - cartAction.getPad().getController().getParent().setBusy(quickEditMenuItem.isSelected()); - // IPadViewController controller = mvc.padViewList.get(cartAction.getCart()); - // MapperQuickSettingsView view = new MapperQuickSettingsView((Pane) controller.getParent().getParent()); - // view.showDropOptions(action.getMappers()); - } - } - } catch (Exception e) { - e.printStackTrace(); - } - } - @FXML private void settingsHandler(ActionEvent event) { Midi midi = Midi.getInstance(); @@ -216,7 +195,7 @@ public class MainMenuBarController implements EventHandler<ActionEvent>, Initial } if (change) { - PlayPadPlugin.getImplementation().getSettingsListener().forEach(l -> l.onChange(Profile.currentProfile())); + PlayPadMain.getProgramInstance().getSettingsListener().forEach(l -> l.onChange(Profile.currentProfile())); } settingsViewController = null; @@ -392,4 +371,18 @@ public class MainMenuBarController implements EventHandler<ActionEvent>, Initial profileSettings.lockedProperty().addListener(lockedListener); lockedListener.changed(profileSettings.lockedProperty(), null, profileSettings.isLocked()); } + + // Getter + + public CheckMenuItem getAlwaysOnTopItem() { + return alwaysOnTopItem; + } + + public Menu getExtensionMenu() { + return extensionMenu; + } + + public CheckMenuItem getFullScreenMenuItem() { + return fullScreenMenuItem; + } } diff --git a/PlayWall/src/de/tobias/playpad/viewcontroller/main/MainViewController.java b/PlayWall/src/de/tobias/playpad/viewcontroller/main/MainViewController.java index 8c40bc4cfa21b24883c5d7a41f726b6338146e34..4b4e7031c9dc08d2f3adfd9fd96751405f640808 100644 --- a/PlayWall/src/de/tobias/playpad/viewcontroller/main/MainViewController.java +++ b/PlayWall/src/de/tobias/playpad/viewcontroller/main/MainViewController.java @@ -67,6 +67,7 @@ import javafx.stage.Modality; import javafx.stage.Screen; import javafx.stage.Stage; +// TODO Extract Color Adjust methodes public class MainViewController extends ViewController implements IMainViewController, NotificationHandler, ProfileListener { private static final String CURRENT_PAGE_BUTTON = "current-page-button"; @@ -157,7 +158,7 @@ public class MainViewController extends ViewController implements IMainViewContr public void init() { padGridPane.getStyleClass().add("pad-grid"); - menuBarController.extensionMenu.setVisible(false); + menuBarController.getExtensionMenu().setVisible(false); liveLabel.setVisible(false); liveLabel.getStyleClass().add("live-label"); @@ -170,7 +171,7 @@ public class MainViewController extends ViewController implements IMainViewContr getStage().fullScreenProperty().addListener((a, b, c) -> { - menuBarController.fullScreenMenuItem.setSelected(c); + menuBarController.getFullScreenMenuItem().setSelected(c); }); // Lautstärke Veränderung @@ -654,7 +655,7 @@ public class MainViewController extends ViewController implements IMainViewContr } // WINDOW Settings - menuBarController.alwaysOnTopItem.setSelected(profilSettings.isWindowAlwaysOnTop()); + menuBarController.getAlwaysOnTopItem().setSelected(profilSettings.isWindowAlwaysOnTop()); getStage().setAlwaysOnTop(profilSettings.isWindowAlwaysOnTop()); setTitle(); @@ -683,9 +684,9 @@ public class MainViewController extends ViewController implements IMainViewContr * @since 2.0.0 */ public void addMenuItem(MenuItem item) { - menuBarController.extensionMenu.getItems().add(item); - if (!menuBarController.extensionMenu.isVisible()) { - menuBarController.extensionMenu.setVisible(true); + menuBarController.getExtensionMenu().getItems().add(item); + if (!menuBarController.getExtensionMenu().isVisible()) { + menuBarController.getExtensionMenu().setVisible(true); } } diff --git a/PlayWall/src/de/tobias/playpad/viewcontroller/option/GeneralTabViewController.java b/PlayWall/src/de/tobias/playpad/viewcontroller/option/GeneralTabViewController.java index dedc6b40dec0b564ee47058c1c5783cd093e11ee..4bb3bedb665346bac197cd878f182a515083b053 100644 --- a/PlayWall/src/de/tobias/playpad/viewcontroller/option/GeneralTabViewController.java +++ b/PlayWall/src/de/tobias/playpad/viewcontroller/option/GeneralTabViewController.java @@ -67,9 +67,9 @@ public class GeneralTabViewController extends SettingsTabViewController { private boolean changeSettings; - public GeneralTabViewController(Screen screen, ViewController parentController, boolean activePlayer) { + public GeneralTabViewController(Screen currentScreen, ViewController parentController, boolean activePlayer) { super("generalTab", "de/tobias/playpad/assets/view/option/", PlayPadMain.getUiResourceBundle()); - this.mainWindowScreen = screen; + this.mainWindowScreen = currentScreen; this.parentController = parentController; if (activePlayer) { diff --git a/PlayWall/src/de/tobias/playpad/viewcontroller/option/SettingsViewController.java b/PlayWall/src/de/tobias/playpad/viewcontroller/option/SettingsViewController.java index 30ac7e9f14e9a08636f53c3743a3313c6a3bf3d8..8dc5d9b1b85b7e8a3a1f60e77ac049717285483f 100644 --- a/PlayWall/src/de/tobias/playpad/viewcontroller/option/SettingsViewController.java +++ b/PlayWall/src/de/tobias/playpad/viewcontroller/option/SettingsViewController.java @@ -35,18 +35,18 @@ public class SettingsViewController extends ViewController implements ISettingsV protected List<SettingsTabViewController> tabs = new ArrayList<>(); - public SettingsViewController(Midi midiHandler, Screen screen, Window owner, Project project) { + public SettingsViewController(Midi midiHandler, Screen currentScreen, Window owner, Project project) { super("settingsView", "de/tobias/playpad/assets/view/option/", null, PlayPadMain.getUiResourceBundle()); - boolean activePlayer = project.getPlayedPlayers() > 0; + boolean activePlayer = project.hasPlayedPlayers(); - addTab(new GeneralTabViewController(screen, this, activePlayer)); + addTab(new GeneralTabViewController(currentScreen, this, activePlayer)); addTab(new MappingTabViewController()); addTab(new MidiTabViewController()); addTab(new LayoutTabViewController()); addTab(new PlayerTabViewController()); - // Content Types + // Custom Tabs - Content Types for (String type : PadContentRegistry.getTypes()) { try { SettingsTabViewController controller = PadContentRegistry.getPadContentConnect(type).getSettingsTabViewController(activePlayer); @@ -58,21 +58,12 @@ public class SettingsViewController extends ViewController implements ISettingsV } } - // Listener - PlayPadMain.getProgramInstance().getSettingsViewListener().forEach(l -> - { - try { - l.onInit(this); - } catch (Exception e) { - e.printStackTrace(); - } - }); addTab(new UpdateTabViewController()); getStage().initOwner(owner); // Show Current Settings - showCurrentSettings(); + loadTabs(); } @Override @@ -82,21 +73,19 @@ public class SettingsViewController extends ViewController implements ISettingsV // KeyCode addCloseKeyShortcut(() -> finishButton.fire()); + // Look Button Listener lockedButton.setGraphic(new FontIcon(FontAwesomeType.LOCK)); lockedButton.setOnAction(e -> { boolean isLocked = lockedButton.isSelected(); - // Model profileSettings.setLocked(isLocked); - - // SettingsUI - tabPane.setDisable(isLocked); + setLookEnable(isLocked); }); + // Übernimmt die aktuellen Einstellungen des Look Button if (profileSettings.isLocked()) { - // SettingsUI lockedButton.setSelected(true); - tabPane.setDisable(true); + setLookEnable(true); } finishButton.defaultButtonProperty().bind(finishButton.focusedProperty()); @@ -113,37 +102,20 @@ public class SettingsViewController extends ViewController implements ISettingsV Profile.currentProfile().currentLayout().applyCss(getStage()); } - // Copy Of Settings - public boolean closeRequest() { - boolean valid = true; - for (SettingsTabViewController controller : tabs) { - if (controller.validSettings() == false) { - valid = false; - } - } - - if (valid) { // Einstellungen sind Valide - // Listener - PlayPadMain.getProgramInstance().getSettingsViewListener().forEach(l -> l.onClose(this)); - - saveChanges(); - getStage().close(); - updateData(); - return true; - } else { - return false; - } - } - - // Settings aus AppSettings - private void showCurrentSettings() { + /** + * Zeigt die aktuellen Einstellungen für die Tabs an. + */ + private void loadTabs() { Profile profile = Profile.currentProfile(); for (SettingsTabViewController controller : tabs) { controller.loadSettings(profile); } } - private void saveChanges() { + /** + * Speichert die Einstellungen der Tabs. + */ + private void saveTabs() { Profile profile = Profile.currentProfile(); for (SettingsTabViewController controller : tabs) { controller.saveSettings(profile); @@ -157,33 +129,42 @@ public class SettingsViewController extends ViewController implements ISettingsV } } - public boolean needUpdate() { - boolean change = false; - for (SettingsTabViewController controller : tabs) { - if (controller.needReload()) { - change = true; - } - } - return change; + public boolean closeRequest() { + return onFinish(); } + // Button Listener @FXML private void finishButtonHandler(ActionEvent event) { - boolean valid = true; + onFinish(); + getStage().close(); + } + + /** + * Speichert alle Informationen. + * + * @return <code>true</code>Alle Einstellungen sind Valid. + */ + private boolean onFinish() { for (SettingsTabViewController controller : tabs) { if (controller.validSettings() == false) { - valid = false; + return false; } } - if (valid) { // Einstellungen sind Valide - // Listener - PlayPadMain.getProgramInstance().getSettingsViewListener().forEach(l -> l.onClose(this)); + saveTabs(); + updateData(); // Reload MainViewController Settings // TODO Rewrite + return true; + } - saveChanges(); - getStage().close(); - updateData(); - } + /** + * Aktiviert/Deaktiviert den Look Button. + * + * @param isLocked + * isLooked + */ + private void setLookEnable(boolean isLocked) { + tabPane.setDisable(isLocked); } public void addTab(SettingsTabViewController controller) { 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 0b2a9356190a28f5bad1edf01dff25aac071c33d..8a8c69521c07984f3713b192bb7664c7d72c80f4 100644 --- a/PlayWall/src/de/tobias/playpad/viewcontroller/option/pad/PadSettingsViewController.java +++ b/PlayWall/src/de/tobias/playpad/viewcontroller/option/pad/PadSettingsViewController.java @@ -44,8 +44,7 @@ public class PadSettingsViewController extends ViewController implements IPadSet if (pad.getContent() != null) { try { // Get Pad Type specific tab - PadContentConnect padContentConnect = PadContentRegistry - .getPadContentConnect(pad.getContent().getType()); + PadContentConnect padContentConnect = PadContentRegistry.getPadContentConnect(pad.getContent().getType()); PadSettingsTabViewController contentTab = padContentConnect.getSettingsViewController(pad); if (contentTab != null) addTab(contentTab); @@ -54,15 +53,6 @@ public class PadSettingsViewController extends ViewController implements IPadSet } } - // Listener - PlayPadMain.getProgramInstance().getPadSettingsViewListener().forEach(l -> { - try { - l.onInit(this); - } catch (Exception e) { - e.printStackTrace(); - } - }); - getStage().initOwner(owner); // Show Current Settings @@ -72,11 +62,9 @@ public class PadSettingsViewController extends ViewController implements IPadSet private void setTitle(Pad pad) { if (pad.getStatus() != PadStatus.EMPTY) { - getStage().setTitle( - Localization.getString(Strings.UI_Window_PadSettings_Title, pad.getIndexReadable(), pad.getName())); + getStage().setTitle(Localization.getString(Strings.UI_Window_PadSettings_Title, pad.getIndexReadable(), pad.getName())); } else { - getStage().setTitle( - Localization.getString(Strings.UI_Window_PadSettings_Title_Empty, pad.getIndexReadable())); + getStage().setTitle(Localization.getString(Strings.UI_Window_PadSettings_Title_Empty, pad.getIndexReadable())); } } @@ -116,25 +104,23 @@ public class PadSettingsViewController extends ViewController implements IPadSet @Override public boolean closeRequest() { - saveChanges(); - - // Listener - PlayPadMain.getProgramInstance().getPadSettingsViewListener().forEach(l -> l.onClose(this)); + onFinish(); return true; } - private void saveChanges() { - for (PadSettingsTabViewController controller : tabs) { - controller.saveSettings(pad); - } - } - @FXML private void finishButtonHandler(ActionEvent event) { - saveChanges(); - // Listener - PlayPadMain.getProgramInstance().getPadSettingsViewListener().forEach(l -> l.onClose(this)); - getStage().close(); + onFinish(); } + /** + * Diese Methode wird aufgerufen, wenn das Fenster geschlossen wird (Per X oder Finish Button). Hier geschehen alle Aktionen zum + * manuellen Speichern. + */ + private void onFinish() { + // Speichern der einzelen Tabs + for (PadSettingsTabViewController controller : tabs) { + controller.saveSettings(pad); + } + } } diff --git a/PlayWallCore/src/de/tobias/playpad/PlayPad.java b/PlayWallCore/src/de/tobias/playpad/PlayPad.java index 569250e2b75b942fa6afac1b86c1959c961e1db2..877bd5d97fc07a4e84b89911fa0c063e8663033c 100644 --- a/PlayWallCore/src/de/tobias/playpad/PlayPad.java +++ b/PlayWallCore/src/de/tobias/playpad/PlayPad.java @@ -7,11 +7,8 @@ import java.util.Optional; import de.tobias.playpad.plugin.PadListener; import de.tobias.playpad.plugin.SettingsListener; import de.tobias.playpad.plugin.WindowListener; -import de.tobias.playpad.viewcontroller.IPadSettingsViewController; -import de.tobias.playpad.viewcontroller.ISettingsViewController; import de.tobias.playpad.viewcontroller.main.IMainViewController; import javafx.scene.image.Image; -import net.xeoh.plugins.base.PluginManager; /** * Hauptfunktionen für Listener und zur Programmsteuerung für Plugins. @@ -24,7 +21,7 @@ import net.xeoh.plugins.base.PluginManager; public interface PlayPad { /** - * Fügt einen Listener für das Hauptfenster hinzu + * Fügt einen Listener für das Hauptfenster hinzu. * * @param listener * @@ -33,102 +30,73 @@ public interface PlayPad { public void addMainViewListener(WindowListener<IMainViewController> listener); /** - * Entfernt ein registrierten Listener des Hauptfensters + * Fügt einen Settings Listener hinzu. * * @param listener * * @since 2.0.0 */ - @Deprecated - public void removeMainViewListener(WindowListener<IMainViewController> listener); + public void addSettingsListener(SettingsListener listener); /** - * Fügt einen Listener zum Settings Fenster hinzu + * Entfernt einen Settings Listener. * * @param listener * * @since 2.0.0 */ - @Deprecated - public void addSettingsViewListener(WindowListener<ISettingsViewController> listener); + public void removeSettingsListener(SettingsListener listener); /** - * Entfernt einen Listener des Settings Fensters + * Gibt alle SettingListener zurück. * - * @param listener - * - * @since 2.0.0 + * @return Settingslistener */ - @Deprecated - public void removeSettingsViewListener(WindowListener<ISettingsViewController> listener); - - @Deprecated - public List<WindowListener<ISettingsViewController>> getSettingsViewListener(); + public List<SettingsListener> getSettingsListener(); /** - * Fügt einen Listener zum PadSettings Fenster hinzu + * Fügt ein PadListener zum System hinzu. Der Listener gilt für alle Pads. * * @param listener - * - * @since 2.0.0 + * Listener + * @since 5.0.0 */ - @Deprecated - public void addPadSettingsViewListener(WindowListener<IPadSettingsViewController> listener); + public void addPadListener(PadListener listener); /** - * Entfernt einen Listener vom PadSettings Fenster + * Entfernt ein Pad Listener. * * @param listener - * - * @since 2.0.0 + * Listener */ - @Deprecated - public void removePadSettingsViewListener(WindowListener<IPadSettingsViewController> listener); - - @Deprecated - public List<WindowListener<IPadSettingsViewController>> getPadSettingsViewListener(); + public void removePadListener(PadListener listener); /** - * Fügt einen Settings Listener hinzu + * Gibt alle PadListener zurück. * - * @param listener + * @return PadListener * - * @since 2.0.0 + * @see 5.0.0 */ - public void addSettingsListener(SettingsListener listener); + public List<PadListener> getPadListener(); /** - * Entfernt einen Settings Listener + * Gibt eine Refernz auf das Hauptfenster zurück. * - * @param listener - * - * @since 2.0.0 + * @return Main ViewController */ - public void removeSettingsListener(SettingsListener listener); - - public List<SettingsListener> getSettingsListener(); - - public void addPadListener(PadListener listener); - - public void removePadListener(PadListener listener); - - public List<PadListener> getPadListener(); - public IMainViewController getMainViewController(); - @Deprecated - public PluginManager getPluginManager(); - - @Deprecated - public String[] getProjectFileTypes(); - /** - * Gibt das Programmicon zurück. + * Gibt das Programm Icon zurück. * * @return Programmicon */ public Optional<Image> getIcon(); + /** + * Beendet PlayWall. + */ public void shutdown(); /** diff --git a/PlayWallCore/src/de/tobias/playpad/plugin/PadListener.java b/PlayWallCore/src/de/tobias/playpad/plugin/PadListener.java index 0d6349a2196269b18434cb77256ea9c3cf82c94e..26ba636bfc86ef54d0eea5717acb960b7e7c9733 100644 --- a/PlayWallCore/src/de/tobias/playpad/plugin/PadListener.java +++ b/PlayWallCore/src/de/tobias/playpad/plugin/PadListener.java @@ -2,10 +2,30 @@ package de.tobias.playpad.plugin; import de.tobias.playpad.pad.Pad; +/** + * Listener für ein Pad. + * + * @author tobias + * + * @see Pad + * + */ public interface PadListener { - public default void onPlay(Pad pad) {} + /** + * Wird aufgerufen, sobald ein Pad wiedergegeben wird. + * + * @param pad + * Pad + */ + public void onPlay(Pad pad); - public default void onStop(Pad pad) {} + /** + * Wird aufgerufen, sobald ein Pad gestoppt wird. + * + * @param pad + * Pad + */ + public void onStop(Pad pad); } \ No newline at end of file diff --git a/PlayWallCore/src/de/tobias/playpad/project/Project.java b/PlayWallCore/src/de/tobias/playpad/project/Project.java index 299a0bdd744f165c3808b45dbd0a7565ba83978c..8cda094d15b3871873d614c6bdf02063ad134d2b 100644 --- a/PlayWallCore/src/de/tobias/playpad/project/Project.java +++ b/PlayWallCore/src/de/tobias/playpad/project/Project.java @@ -196,6 +196,10 @@ public class Project { return count; } + public boolean hasPlayedPlayers() { + return getPlayedPlayers() > 0; + } + // Exceptions public void addException(Pad pad, Path path, Exception exception) { if (!Platform.isFxApplicationThread()) { diff --git a/PlayWallCore/src/de/tobias/playpad/project/ProjectReference.java b/PlayWallCore/src/de/tobias/playpad/project/ProjectReference.java index 1ca57c656c16b62848b4a779e3d2bbbde3d0eeb1..8dd9ff1d3887837e9c386ec7689cca326dffc27b 100644 --- a/PlayWallCore/src/de/tobias/playpad/project/ProjectReference.java +++ b/PlayWallCore/src/de/tobias/playpad/project/ProjectReference.java @@ -13,12 +13,10 @@ import org.dom4j.Document; import org.dom4j.DocumentException; import org.dom4j.DocumentHelper; import org.dom4j.Element; -import org.dom4j.io.OutputFormat; -import org.dom4j.io.SAXReader; -import org.dom4j.io.XMLWriter; import de.tobias.playpad.Displayable; import de.tobias.playpad.settings.ProfileReference; +import de.tobias.playpad.xml.XMLHandler; import de.tobias.utils.application.App; import de.tobias.utils.application.ApplicationUtils; import de.tobias.utils.application.container.PathType; @@ -27,31 +25,7 @@ import javafx.beans.property.StringProperty; public class ProjectReference implements Displayable { - private static List<ProjectReference> projects = new ArrayList<ProjectReference>() { - - private static final long serialVersionUID = 1L; - - public boolean contains(Object o) { - if (o instanceof String) { - for (ProjectReference reference : this) { - if (reference.getName().equals(o)) { - return true; - } else if (reference.toString().equals(o)) { - return true; - } - } - } else if (o instanceof ProjectReference) { - for (ProjectReference reference : this) { - if (reference.getName() == o) { - return true; - } else if (reference.getName() == ((ProjectReference) o).getName()) { - return true; - } - } - } - return super.contains(o); - }; - }; + private static List<ProjectReference> projects = new ProjectReferenceList(); private static boolean loadedProjectOverview = false; /** @@ -144,14 +118,18 @@ public class ProjectReference implements Displayable { ProjectReference newProjectReference = new ProjectReference(UUID.randomUUID(), name, currentProject.getProfileReference()); addProject(newProjectReference); - Path oldPath = ApplicationUtils.getApplication().getPath(PathType.DOCUMENTS, currentProject.getName()); - Path newPath = ApplicationUtils.getApplication().getPath(PathType.DOCUMENTS, newProjectReference.getName()); - Files.copy(oldPath, newPath, StandardCopyOption.COPY_ATTRIBUTES); + duplicateFiles(currentProject, newProjectReference); saveProjects(); return newProjectReference; } + private static void duplicateFiles(ProjectReference currentProject, ProjectReference newProjectReference) throws IOException { + Path oldPath = ApplicationUtils.getApplication().getPath(PathType.DOCUMENTS, currentProject.getName()); + Path newPath = ApplicationUtils.getApplication().getPath(PathType.DOCUMENTS, newProjectReference.getName()); + Files.copy(oldPath, newPath, StandardCopyOption.COPY_ATTRIBUTES); + } + public static List<ProjectReference> getProjects() { if (!loadedProjectOverview) try { @@ -162,59 +140,28 @@ public class ProjectReference implements Displayable { return projects; } - private static final String UUID_ATTR = "uuid"; - private static final String NAME_ATTR = "name"; - private static final String PROFILE_ATTR = "profile"; + // Load and Save + private static final String FILE_NAME = "Projects.xml"; + private static final String PROJECT_ELEMENT = "Project"; + private static final String ROOT_ELEMENT = "Settings"; public static void loadProjects() throws DocumentException, IOException { - projects.clear(); - - Path path = ApplicationUtils.getApplication().getPath(PathType.CONFIGURATION, "Projects.xml"); + Path path = ApplicationUtils.getApplication().getPath(PathType.CONFIGURATION, FILE_NAME); + XMLHandler<ProjectReference> loader = new XMLHandler<>(path); + projects = loader.loadElements(PROJECT_ELEMENT, new ProjectReferenceSerializer()); - if (Files.exists(path)) { - SAXReader reader = new SAXReader(); - Document document = reader.read(Files.newInputStream(path)); - Element root = document.getRootElement(); - - for (Object object : root.elements("Project")) { - Element element = (Element) object; - - UUID uuid = UUID.fromString(element.attributeValue(UUID_ATTR)); - String name = element.attributeValue(NAME_ATTR); - UUID profile = UUID.fromString(element.attributeValue(PROFILE_ATTR)); - - ProfileReference profileRef = ProfileReference.getReference(profile); - ProjectReference ref = new ProjectReference(uuid, name, profileRef); - - Path projectPath = ApplicationUtils.getApplication().getPath(PathType.DOCUMENTS, ref.getFileName()); - if (Files.exists(projectPath)) { - ref.setLastMofied(Files.getLastModifiedTime(projectPath).toMillis()); - ref.setSize(Files.size(projectPath)); - } - - projects.add(ref); - } - - loadedProjectOverview = true; - } + loadedProjectOverview = true; } public static void saveProjects() throws UnsupportedEncodingException, IOException { Document document = DocumentHelper.createDocument(); - Element root = document.addElement("Settings"); - - for (ProjectReference project : projects) { - Element projectElement = root.addElement("Project"); - projectElement.addAttribute(UUID_ATTR, project.uuid.toString()); - projectElement.addAttribute(NAME_ATTR, project.name); - projectElement.addAttribute(PROFILE_ATTR, project.profileReference.getUuid().toString()); - } + Element root = document.addElement(ROOT_ELEMENT); - Path path = ApplicationUtils.getApplication().getPath(PathType.CONFIGURATION, "Projects.xml"); + XMLHandler<ProjectReference> handler = new XMLHandler<>(root); + handler.saveElements(PROJECT_ELEMENT, projects, new ProjectReferenceSerializer()); - XMLWriter writer = new XMLWriter(Files.newOutputStream(path), OutputFormat.createPrettyPrint()); - writer.write(document); - writer.close(); + Path path = ApplicationUtils.getApplication().getPath(PathType.CONFIGURATION, FILE_NAME); + XMLHandler.save(path, document); } public static List<ProjectReference> getProjectsSorted() { diff --git a/PlayWallCore/src/de/tobias/playpad/project/ProjectReferenceList.java b/PlayWallCore/src/de/tobias/playpad/project/ProjectReferenceList.java new file mode 100644 index 0000000000000000000000000000000000000000..a9d7ea8412887f1f5173b1a3416018271e59a29b --- /dev/null +++ b/PlayWallCore/src/de/tobias/playpad/project/ProjectReferenceList.java @@ -0,0 +1,37 @@ +package de.tobias.playpad.project; + +import de.tobias.utils.list.UniqList; + +/** + * Liste, wo nur ProjektRefernzen gespeichert werden, deren Namen Unique ist. + * + * @author tobias + * + * @since 5.0.1 + * @see ProjectReference + */ +final class ProjectReferenceList extends UniqList<ProjectReference> { + + private static final long serialVersionUID = 1L; + + public boolean contains(Object o) { + if (o instanceof String) { + for (ProjectReference reference : this) { + if (reference.getName().equals(o)) { + return true; + } else if (reference.toString().equals(o)) { + return true; + } + } + } else if (o instanceof ProjectReference) { + for (ProjectReference reference : this) { + if (reference.getName() == o) { + return true; + } else if (reference.getName().equals(((ProjectReference) o).getName())) { // TODO Check + return true; + } + } + } + return super.contains(o); + } +} \ No newline at end of file diff --git a/PlayWallCore/src/de/tobias/playpad/project/ProjectReferenceSerializer.java b/PlayWallCore/src/de/tobias/playpad/project/ProjectReferenceSerializer.java new file mode 100644 index 0000000000000000000000000000000000000000..009b68e7171f8ed1ef6bdd1442070abf48a6fe3f --- /dev/null +++ b/PlayWallCore/src/de/tobias/playpad/project/ProjectReferenceSerializer.java @@ -0,0 +1,49 @@ +package de.tobias.playpad.project; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.UUID; + +import org.dom4j.Element; + +import de.tobias.playpad.settings.ProfileReference; +import de.tobias.playpad.xml.XMLDeserializer; +import de.tobias.playpad.xml.XMLSerializer; +import de.tobias.utils.application.ApplicationUtils; +import de.tobias.utils.application.container.PathType; + +public class ProjectReferenceSerializer implements XMLDeserializer<ProjectReference>, XMLSerializer<ProjectReference> { + + private static final String UUID_ATTR = "uuid"; + private static final String NAME_ATTR = "name"; + private static final String PROFILE_ATTR = "profile"; + + @Override + public ProjectReference loadElement(Element element) { + UUID uuid = UUID.fromString(element.attributeValue(UUID_ATTR)); + String name = element.attributeValue(NAME_ATTR); + UUID profile = UUID.fromString(element.attributeValue(PROFILE_ATTR)); + + ProfileReference profileRef = ProfileReference.getReference(profile); + ProjectReference ref = new ProjectReference(uuid, name, profileRef); + + Path projectPath = ApplicationUtils.getApplication().getPath(PathType.DOCUMENTS, ref.getFileName()); + if (Files.exists(projectPath)) { + try { + ref.setLastMofied(Files.getLastModifiedTime(projectPath).toMillis()); + ref.setSize(Files.size(projectPath)); + } catch (IOException e) { + e.printStackTrace(); + } + } + return ref; + } + + @Override + public void saveElement(Element newElement, ProjectReference data) { + newElement.addAttribute(UUID_ATTR, data.getUuid().toString()); + newElement.addAttribute(NAME_ATTR, data.getName()); + newElement.addAttribute(PROFILE_ATTR, data.getProfileReference().getUuid().toString()); + } +} diff --git a/PlayWallCore/src/de/tobias/playpad/settings/ProfileReference.java b/PlayWallCore/src/de/tobias/playpad/settings/ProfileReference.java index 103c9f9b0eda1250c26bd0818f074559424159e1..9eaf5a154233d099d757f234a5f65142504568e2 100644 --- a/PlayWallCore/src/de/tobias/playpad/settings/ProfileReference.java +++ b/PlayWallCore/src/de/tobias/playpad/settings/ProfileReference.java @@ -9,79 +9,102 @@ import java.util.List; import java.util.UUID; import org.dom4j.Document; +import org.dom4j.DocumentException; import org.dom4j.DocumentHelper; import org.dom4j.Element; -import org.dom4j.io.OutputFormat; -import org.dom4j.io.SAXReader; -import org.dom4j.io.XMLWriter; import de.tobias.playpad.Displayable; +import de.tobias.playpad.xml.XMLHandler; import de.tobias.utils.application.ApplicationUtils; import de.tobias.utils.application.container.PathType; -import de.tobias.utils.list.UniqList; import de.tobias.utils.util.FileUtils; -import de.tobias.utils.util.FileUtils.FileAction; +import de.tobias.utils.util.FileUtils.FileActionAdapter; import javafx.beans.property.SimpleStringProperty; import javafx.beans.property.StringProperty; +/** + * Container für Profile Referenzen + * + * @author tobias + * + * @see Profile + * @since 5.0.0 + */ public class ProfileReference implements Displayable { private static final String DEFAULT_PROFILE_NAME = "Default"; - private static List<ProfileReference> profiles = new UniqList<ProfileReference>() { - - private static final long serialVersionUID = 1L; - - public boolean contains(Object o) { - if (o instanceof String) { - for (ProfileReference reference : this) { - if (reference.getName().equals(o)) { - return true; - } else if (reference.toString().equals(o)) { - return true; - } - } - } else if (o instanceof ProfileReference) { - for (ProfileReference reference : this) { - if (reference.getName() == o) { - return true; - } else if (reference.getName() == ((ProfileReference) o).getName()) { - return true; - } - } - } - return super.contains(o); - }; - }; - private final UUID uuid; private String name; + /** + * Erstellt eine neue Referenz mit einer Random UUID. + * + * @param name + * Name + */ public ProfileReference(String name) { this.name = name; this.uuid = UUID.randomUUID(); updateDisplayProperty(); } + /** + * Erstellt eine neue Referenz mit Namen und UUID. + * + * @param uuid + * UUID + * @param name + * Name + */ public ProfileReference(UUID uuid, String name) { this.uuid = uuid; this.name = name; updateDisplayProperty(); } + /** + * Gibt den Namen zurück + * + * @return Name + */ public String getName() { return name; } + /** + * Gibt die UUID zurück + * + * @return uudi + */ public UUID getUuid() { return uuid; } + /** + * Setzt einen neuen Namen. + * + * @param name + * Neuer Name + */ public void setName(String name) { this.name = name; updateDisplayProperty(); } + // Verwaltungsmethoden für Profile Referenzen // TODO Extract in Extra Class + + /** + * Liste mit allen Referenzen + */ + private static List<ProfileReference> profiles = new ProfileReferenceList(); + + /** + * Sucht eine Referenz zu einer UUID raus. + * + * @param profile + * @return + */ public static ProfileReference getReference(UUID profile) { for (ProfileReference ref : profiles) { if (ref.uuid.equals(profile)) { @@ -91,6 +114,11 @@ public class ProfileReference implements Displayable { return null; } + /** + * Listet alle verfügbaren Profil Refernzen auf. + * + * @return Liste von Referenzen (Name, UUID) + */ public static List<ProfileReference> getProfiles() { return profiles; } @@ -103,6 +131,7 @@ public class ProfileReference implements Displayable { * @return * @throws UnsupportedEncodingException * @throws IOException + * IO Fehler */ public static Profile newProfile(String name) throws UnsupportedEncodingException, IOException { ProfileReference ref = new ProfileReference(UUID.randomUUID(), name); @@ -114,9 +143,17 @@ public class ProfileReference implements Displayable { return profile; } + /** + * Fügt ein Profile hinzu und erstellt den Ordner auf der Festplatte. + * + * @param ref + * Referenz zu diesem Profile (Name, UUID) + */ public static void addProfile(ProfileReference ref) { + // MODEL profiles.add(ref); + // DRIVE Path path = ApplicationUtils.getApplication().getPath(PathType.CONFIGURATION, ref.getFileName()); if (Files.notExists(path)) { try { @@ -128,19 +165,19 @@ public class ProfileReference implements Displayable { } /** - * Duplicate one profile on drive. To use the new profile, it must be load manually. - * + * Dupliziert eine Profile. Dabei werden die Dateien auf der Festplatte auch dupliziert. * * @param src - * Name of the original Profile + * Name des Orginalprofiles * @param des - * Name of the new Profile + * Name des neuen Profiles * @throws IOException + * IO Fehler */ public static void duplicate(ProfileReference src, ProfileReference des) throws IOException { if (!des.equals(src)) { FileUtils.loopThroughDirectory(ApplicationUtils.getApplication().getPath(PathType.CONFIGURATION, src.getFileName()), - new FileAction() { + new FileActionAdapter() { @Override public void onFile(Path file) throws IOException { @@ -151,18 +188,25 @@ public class ProfileReference implements Displayable { } Files.copy(file, desPath, StandardCopyOption.REPLACE_EXISTING); } - - @Override - public void onDirectory(Path file) throws IOException {} }); profiles.add(des); } } + /** + * Entfernt eine ProfileReferenz und das Profile. + * + * @param ref + * Profile Referenz + * @throws IOException + * IO Fehler + */ public static void removeProfile(ProfileReference ref) throws IOException { + // Model profiles.remove(ref); + // DRIVE Path root = ApplicationUtils.getApplication().getPath(PathType.CONFIGURATION, ref.getFileName()); if (Files.exists(root)) { Files.walk(root).forEach(path -> @@ -178,58 +222,74 @@ public class ProfileReference implements Displayable { } } + // Load and Save + + private static final String FILE_NAME = "Profiles.xml"; private static final String ROOT_ELEMENT = "Settings"; private static final String PROFILE_ELEMENT = "Profile"; - private static final String UUID_ATTR = "uuid"; - private static final String NAME_ATTR = "name"; - public static void loadProfiles() throws Exception { + /** + * Lädt alle Profile Referenzen. + * + * @throws IOException + * IO Fehler + * @throws DocumentException + * XML Fehler + */ + public static void loadProfiles() throws IOException, DocumentException { profiles.clear(); - Path path = ApplicationUtils.getApplication().getPath(PathType.CONFIGURATION, "Profiles.xml"); + Path path = ApplicationUtils.getApplication().getPath(PathType.CONFIGURATION, FILE_NAME); if (Files.exists(path)) { - SAXReader reader = new SAXReader(); - Document document = reader.read(Files.newInputStream(path)); - Element root = document.getRootElement(); - for (Object object : root.elements(PROFILE_ELEMENT)) { - Element element = (Element) object; - - UUID uuid = UUID.fromString(element.attributeValue(UUID_ATTR)); - String name = element.attributeValue(NAME_ATTR); - - ProfileReference ref = new ProfileReference(uuid, name); - profiles.add(ref); - } + // Load data from xml + XMLHandler<ProfileReference> handler = new XMLHandler<>(path); + profiles = handler.loadElements(PROFILE_ELEMENT, new ProfileReferenceSerializer()); + System.out.println(profiles); } + // Add Default Element if list is empty if (profiles.isEmpty()) { Profile profile = newProfile(DEFAULT_PROFILE_NAME); profile.save(); } } + /** + * Speichert alle Profile Referenzen in eine Datei. + * + * @throws UnsupportedEncodingException + * XML Fehler + * @throws IOException + * IO Fehler + */ public static void saveProfiles() throws UnsupportedEncodingException, IOException { Document document = DocumentHelper.createDocument(); Element root = document.addElement(ROOT_ELEMENT); - for (ProfileReference ref : profiles) { - Element element = root.addElement(PROFILE_ELEMENT); - - element.addAttribute(UUID_ATTR, ref.uuid.toString()); - element.addAttribute(NAME_ATTR, ref.name); - } + // Save data to xml + XMLHandler<ProfileReference> handler = new XMLHandler<>(root); + handler.saveElements(PROFILE_ELEMENT, profiles, new ProfileReferenceSerializer()); - Path path = ApplicationUtils.getApplication().getPath(PathType.CONFIGURATION, "Profiles.xml"); - XMLWriter writer = new XMLWriter(Files.newOutputStream(path), OutputFormat.createPrettyPrint()); - writer.write(document); - writer.close(); + Path path = ApplicationUtils.getApplication().getPath(PathType.CONFIGURATION, FILE_NAME); + XMLHandler.save(path, document); } + /** + * Gibt einen Pfad für einen Dateinamen in diesem Profile zurück. + * + * @param name + * @return + */ public Path getCustomFilePath(String name) { return ApplicationUtils.getApplication().getPath(PathType.CONFIGURATION, getFileName(), name); } + /** + * Gibt den internen (File-) Namen des Profiles zurück. + * + * @return Ordnernamen + */ public String getFileName() { return uuid.toString(); } @@ -239,6 +299,7 @@ public class ProfileReference implements Displayable { return name; } + // Displayable private StringProperty displayProperty = new SimpleStringProperty(toString()); @Override diff --git a/PlayWallCore/src/de/tobias/playpad/settings/ProfileReferenceList.java b/PlayWallCore/src/de/tobias/playpad/settings/ProfileReferenceList.java new file mode 100644 index 0000000000000000000000000000000000000000..01bf7b7d7a68a3253c946e964ebfa14800796f31 --- /dev/null +++ b/PlayWallCore/src/de/tobias/playpad/settings/ProfileReferenceList.java @@ -0,0 +1,37 @@ +package de.tobias.playpad.settings; + +import de.tobias.utils.list.UniqList; + +/** + * Liste, wo nur ProfileRefernzen gespeichert werden, deren Namen Unique ist. + * + * @author tobias + * + * @since 5.0.1 + * @see ProfileReference + */ +final class ProfileReferenceList extends UniqList<ProfileReference> { + + private static final long serialVersionUID = 1L; + + public boolean contains(Object o) { + if (o instanceof String) { + for (ProfileReference reference : this) { + if (reference.getName().equals(o)) { + return true; + } else if (reference.toString().equals(o)) { + return true; + } + } + } else if (o instanceof ProfileReference) { + for (ProfileReference reference : this) { + if (reference.getName() == o) { + return true; + } else if (reference.getName() == ((ProfileReference) o).getName()) { + return true; + } + } + } + return super.contains(o); + } +} \ No newline at end of file diff --git a/PlayWallCore/src/de/tobias/playpad/settings/ProfileReferenceSerializer.java b/PlayWallCore/src/de/tobias/playpad/settings/ProfileReferenceSerializer.java new file mode 100644 index 0000000000000000000000000000000000000000..3a281ef16c223a94c255b4d18591bcaf7423c2bd --- /dev/null +++ b/PlayWallCore/src/de/tobias/playpad/settings/ProfileReferenceSerializer.java @@ -0,0 +1,38 @@ +package de.tobias.playpad.settings; + +import java.util.UUID; + +import org.dom4j.Element; + +import de.tobias.playpad.xml.XMLDeserializer; +import de.tobias.playpad.xml.XMLSerializer; + +/** + * Util zum arbeiten mit XML und ProfileReference + * + * @author tobias + * + * @since 5.0.1 + * @see ProfileReference + */ +public class ProfileReferenceSerializer implements XMLSerializer<ProfileReference>, XMLDeserializer<ProfileReference> { + + private static final String UUID_ATTR = "uuid"; + private static final String NAME_ATTR = "name"; + + @Override + public ProfileReference loadElement(Element element) { + UUID uuid = UUID.fromString(element.attributeValue(UUID_ATTR)); + String name = element.attributeValue(NAME_ATTR); + + ProfileReference ref = new ProfileReference(uuid, name); + return ref; + } + + @Override + public void saveElement(Element newElement, ProfileReference data) { + newElement.addAttribute(UUID_ATTR, data.getUuid().toString()); + newElement.addAttribute(NAME_ATTR, data.getName()); + } + +} diff --git a/PlayWallCore/src/de/tobias/playpad/viewcontroller/ISettingsViewController.java b/PlayWallCore/src/de/tobias/playpad/viewcontroller/ISettingsViewController.java index 5b7373d51483b85de5fd7341ff83d33ad312bca3..173055b25647b514d39da9f6005ea04a3959a80b 100644 --- a/PlayWallCore/src/de/tobias/playpad/viewcontroller/ISettingsViewController.java +++ b/PlayWallCore/src/de/tobias/playpad/viewcontroller/ISettingsViewController.java @@ -1,7 +1,20 @@ package de.tobias.playpad.viewcontroller; +/** + * Schnittstelle um die ProfileSettingsView zu ändern. + * + * @author tobias + * + * @since 5.0.0 + */ public interface ISettingsViewController { + /** + * Fügt en Tab hinzu. + * + * @param videoSettingsTabViewController + * tab + */ public void addTab(SettingsTabViewController videoSettingsTabViewController); } diff --git a/PlayWallCore/src/de/tobias/playpad/viewcontroller/SettingsTabViewController.java b/PlayWallCore/src/de/tobias/playpad/viewcontroller/SettingsTabViewController.java index 6a64bfc43502ca3065d135f54d4e6eb706730c22..fba59413967875b1b17a348a546158b8016ceda5 100644 --- a/PlayWallCore/src/de/tobias/playpad/viewcontroller/SettingsTabViewController.java +++ b/PlayWallCore/src/de/tobias/playpad/viewcontroller/SettingsTabViewController.java @@ -7,21 +7,77 @@ import de.tobias.playpad.settings.Profile; import de.tobias.playpad.viewcontroller.main.IMainViewController; import de.tobias.utils.ui.ContentViewController; +/** + * Abstract Tab für SettingsViewController. + * + * @author tobias + * + * @since 5.0.0 + * + */ public abstract class SettingsTabViewController extends ContentViewController { + /** + * Erstellt einen neuen Tab. + * + * @param name + * Name der FXML + * @param path + * Pfad zu FXML (ohne Dateiname) + * @param localization + * ResourceBundle oder null + */ public SettingsTabViewController(String name, String path, ResourceBundle localization) { super(name, path, localization); } + /** + * Lädt alle Einstellungen vom Model in die GUI. + * + * @param profile + * Aktuelles Profile + */ public abstract void loadSettings(Profile profile); + /** + * Speichert alle Änderungen in das Model. + * + * @param profile + * Aktuelles Profile + */ public abstract void saveSettings(Profile profile); + /** + * Gibt <code>true</code> zurück, wenn im Hauptprogramm etwas neu geladen werden muss. Der eigentliche Reload wird in + * {@link #reload(Profile, Project, IMainViewController)} ausgeführt. + * + * @return <code>true</code> Benötigt Reload + */ public abstract boolean needReload(); + /** + * Lädt gestimmte Einstellungen für die GUI neu. + * + * @param profile + * Aktuelles Profile + * @param project + * Aktuelles Projekt + * @param controller + * Main View Controller + */ public void reload(Profile profile, Project project, IMainViewController controller) {} + /** + * Prüft ob die eingetragen Einstellungen erlaubt sind. Bei falschen Eingaben können die Einstellungen nicht geschlossen werden. + * + * @return <code>true</code> Einstellungen erlaubt. <code>false</code> Einstellungen fehlerhaft. + */ public abstract boolean validSettings(); + /** + * Gibt den Namen für den Tab zurück. + * + * @return + */ public abstract String name(); } diff --git a/PlayWallCore/src/de/tobias/playpad/xml/XMLDeserializer.java b/PlayWallCore/src/de/tobias/playpad/xml/XMLDeserializer.java new file mode 100644 index 0000000000000000000000000000000000000000..b458b2bbbbbe92ee5f73321857d5574db09fb816 --- /dev/null +++ b/PlayWallCore/src/de/tobias/playpad/xml/XMLDeserializer.java @@ -0,0 +1,23 @@ +package de.tobias.playpad.xml; + +import org.dom4j.Element; + +/** + * Schnittstelle um ein Object auf einem XML Tree zu deserialisieren. + * + * @author tobias + * + * @param <T> + * Typ der Daten + */ +public interface XMLDeserializer<T> { + + /** + * Lädt ein Object auf XML Daten. + * + * @param element + * @return + */ + public T loadElement(Element element); + +} diff --git a/PlayWallCore/src/de/tobias/playpad/xml/XMLHandler.java b/PlayWallCore/src/de/tobias/playpad/xml/XMLHandler.java new file mode 100644 index 0000000000000000000000000000000000000000..cd847e4f6e4171c4be882911d794c50e85b9a44c --- /dev/null +++ b/PlayWallCore/src/de/tobias/playpad/xml/XMLHandler.java @@ -0,0 +1,120 @@ +package de.tobias.playpad.xml; + +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.List; + +import org.dom4j.Document; +import org.dom4j.DocumentException; +import org.dom4j.Element; +import org.dom4j.io.OutputFormat; +import org.dom4j.io.SAXReader; +import org.dom4j.io.XMLWriter; + +/** + * Util Methods zum Laden von XML Files. + * + * @author tobias + * + * @since 5.0.1 + */ +public class XMLHandler<T> { + + private Element rootElement; + + /** + * Lädt ein XML Dokument und speichert sich den RootNode. + * + * @param path + * Path zu XML Datei + * @throws DocumentException + * Fehler in der XML Datei + * @throws IOException + * IO Fehler (Bsp. Datei nicht vorhanden) + */ + public XMLHandler(Path path) throws DocumentException, IOException { + if (Files.exists(path)) { + SAXReader reader = new SAXReader(); + Document document = reader.read(Files.newInputStream(path)); + rootElement = document.getRootElement(); + } else { + throw new FileNotFoundException(path.toString()); + } + } + + /** + * Erstellt einen neuen Handler mit einem RootElement. + * + * @param rootElement + * RootElement + */ + public XMLHandler(Element rootElement) { + this.rootElement = rootElement; + } + + /** + * Lädt ein Datenrecord auf einem Array von Daten + * + * @param listElementTag + * Datentype + * @param deserializer + * Deserializer + * @return Liste von Daten + */ + public List<T> loadElements(String listElementTag, XMLDeserializer<T> deserializer) { + List<T> list = new ArrayList<>(); + + for (Object object : rootElement.elements(listElementTag)) { + if (object instanceof Element) { + Element element = (Element) object; + T data = deserializer.loadElement(element); + list.add(data); + } + } + + return list; + } + + /** + * Speichert eine Liste von Objekten mittels Serializer. + * + * @param listElementTag + * Name der XML Element + * @param list + * Liste der Daten + * @param serializer + * Serializer + */ + public void saveElements(String listElementTag, List<T> list, XMLSerializer<T> serializer) { + for (T data : list) { + Element element = rootElement.addElement(listElementTag); + serializer.saveElement(element, data); + } + } + + /** + * Speichert eine XML in einem Path. + * + * @param path + * Path der Datei + * @param document + * XML Document + * @throws UnsupportedEncodingException + * Falsches Encoding + * @throws IOException + * IO Fehler (Bsp. File nicht vorhanden) + */ + public static void save(Path path, Document document) throws UnsupportedEncodingException, IOException { + if (Files.exists(path)) { + XMLWriter writer = new XMLWriter(Files.newOutputStream(path), OutputFormat.createPrettyPrint()); + writer.write(document); + writer.close(); + } else { + throw new FileNotFoundException(path.toString()); + } + } +} diff --git a/PlayWallCore/src/de/tobias/playpad/xml/XMLSerializer.java b/PlayWallCore/src/de/tobias/playpad/xml/XMLSerializer.java new file mode 100644 index 0000000000000000000000000000000000000000..824741866bf6a72c89126febc81415cecb63869a --- /dev/null +++ b/PlayWallCore/src/de/tobias/playpad/xml/XMLSerializer.java @@ -0,0 +1,26 @@ +package de.tobias.playpad.xml; + +import org.dom4j.Element; + +/** + * Schnittstelle um ein Object in eine XML Struktur zu überführen. + * + * @author tobias + * + * @param <T> + * Typ der Daten + */ +public interface XMLSerializer<T> { + + /** + * Überführt ein Object in eine XML Struktur. Dafür wird bereits ein XML Object angelegt, zu dem Attribute und Sub Elemente hinzugefügt + * werden können. + * + * @param newElement + * XML Object + * @param data + * Daten + */ + public void saveElement(Element newElement, T data); + +}