From e716034ecc6a5ae2833c8ee6d33568ad73e26466 Mon Sep 17 00:00:00 2001 From: tobias <tobias.ullerich@icloud.com> Date: Fri, 5 Aug 2016 17:14:30 +0200 Subject: [PATCH] Continue on main view --- .../playpad/assets/lang/ui_de.properties | 1 + .../de/tobias/playpad/assets/style/touch.css | 13 + .../assets/view/main/touch/header.fxml | 82 +--- .../de/tobias/playpad/components/Layout.xml | 2 +- .../desktop/DesktopMainLayoutConnect.java | 9 +- .../DesktopMenuToolbarViewController.java | 361 +++++++++++++++++- .../layout/touch/TouchMainLayoutConnect.java | 8 +- .../touch/TouchMenuToolbarViewController.java | 62 ++- .../playpad/layout/touch/TouchPadView.java | 2 +- .../layout/touch/TouchPadViewController.java | 10 +- .../main/BasicMenuToolbarViewController.java | 331 +--------------- .../main/MainViewControllerV2.java | 12 +- .../registry/DefaultComponentRegistry.java | 39 ++ .../main/MenuToolbarViewController.java | 4 + .../awakeplugin/impl/AwakePluginImpl.java | 22 +- 15 files changed, 509 insertions(+), 449 deletions(-) diff --git a/PlayWall/assets/de/tobias/playpad/assets/lang/ui_de.properties b/PlayWall/assets/de/tobias/playpad/assets/lang/ui_de.properties index f241aa5b..cd795228 100644 --- a/PlayWall/assets/de/tobias/playpad/assets/lang/ui_de.properties +++ b/PlayWall/assets/de/tobias/playpad/assets/lang/ui_de.properties @@ -22,6 +22,7 @@ main.menuitem.website=Webseite besuchen... main.menuitem.senderror=Fehler senden... main.menuitem.fullScreen=Vollbild main.menuitem.layout=Layout +main.menuitem.close=Touch Modus schlie�en main.label.live=Live diff --git a/PlayWall/assets/de/tobias/playpad/assets/style/touch.css b/PlayWall/assets/de/tobias/playpad/assets/style/touch.css index 4db18b4f..8b0042dd 100644 --- a/PlayWall/assets/de/tobias/playpad/assets/style/touch.css +++ b/PlayWall/assets/de/tobias/playpad/assets/style/touch.css @@ -9,4 +9,17 @@ .button { -fx-font-size : 20px; +} + +.slider .track { + -fx-pref-height:20; +} + +.slider:vertical .track { + -fx-pref-width:20; +} + +.slider .thumb { + -fx-pref-height: 30; + -fx-pref-width: 30; } \ No newline at end of file diff --git a/PlayWall/assets/de/tobias/playpad/assets/view/main/touch/header.fxml b/PlayWall/assets/de/tobias/playpad/assets/view/main/touch/header.fxml index a9ea5cfc..f9a87997 100644 --- a/PlayWall/assets/de/tobias/playpad/assets/view/main/touch/header.fxml +++ b/PlayWall/assets/de/tobias/playpad/assets/view/main/touch/header.fxml @@ -8,79 +8,6 @@ <HBox xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1"> <children> -<MenuBar fx:id="menuBar" maxHeight="1.7976931348623157E308"> - <menus> - <Menu mnemonicParsing="false" text="%main.menu.file"> - <items> - <MenuItem mnemonicParsing="false" onAction="#newDocumentHandler" text="%main.menuitem.new"> - <accelerator> - <KeyCodeCombination alt="UP" code="N" control="UP" meta="UP" shift="UP" shortcut="DOWN" /> - </accelerator> - </MenuItem> - <Menu fx:id="recentOpenMenu" mnemonicParsing="false" text="%main.menuitem.recentFiles" /> - <MenuItem mnemonicParsing="false" onAction="#openDocumentHandler" text="%main.menuitem.project"> - <accelerator> - <KeyCodeCombination alt="UP" code="O" control="UP" meta="UP" shift="UP" shortcut="DOWN" /> - </accelerator> - </MenuItem> - <MenuItem fx:id="saveMenuItem" mnemonicParsing="false" onAction="#saveMenuHandler" text="%main.menuitem.save"> - <accelerator> - <KeyCodeCombination alt="UP" code="S" control="UP" meta="UP" shift="UP" shortcut="DOWN" /> - </accelerator> - </MenuItem> - <SeparatorMenuItem mnemonicParsing="false" /> - <MenuItem fx:id="profileMenu" mnemonicParsing="false" onAction="#profileMenuHandler" text="%main.menuitem.profile" /> - <SeparatorMenuItem mnemonicParsing="false" /> - <MenuItem mnemonicParsing="false" onAction="#printMenuHandler" text="%main.menuitem.print"> - <accelerator> - <KeyCodeCombination alt="UP" code="P" control="UP" meta="UP" shift="UP" shortcut="DOWN" /> - </accelerator> - </MenuItem> - </items> - </Menu> - <Menu mnemonicParsing="false" text="%main.menu.option"> - <items> - <CheckMenuItem fx:id="dndModeMenuItem" mnemonicParsing="false" onAction="#dndModeHandler" text="%main.menuitem.dnd"> - <accelerator> - <KeyCodeCombination alt="UP" code="M" control="UP" meta="UP" shift="UP" shortcut="DOWN" /> - </accelerator> - </CheckMenuItem> - <MenuItem fx:id="errorMenu" mnemonicParsing="false" onAction="#errorMenuHandler" text="%main.menuitem.errors"> - <accelerator> - <KeyCodeCombination alt="UP" code="E" control="UP" meta="UP" shift="UP" shortcut="DOWN" /> - </accelerator> - </MenuItem> - <SeparatorMenuItem mnemonicParsing="false" /> - <MenuItem mnemonicParsing="false" onAction="#pluginMenuItemHandler" text="%main.menuitem.plugins" /> - <SeparatorMenuItem mnemonicParsing="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" /> - </accelerator> - </MenuItem> - </items> - </Menu> - <Menu mnemonicParsing="false" text="%main.menu.view"> - <items> - <Menu fx:id="layoutMenu" mnemonicParsing="false" text="%main.menuitem.layout" /> - <CheckMenuItem fx:id="alwaysOnTopItem" mnemonicParsing="false" onAction="#alwaysOnTopItemHandler" text="%main.menuitem.onTop" /> - <CheckMenuItem fx:id="fullScreenMenuItem" mnemonicParsing="false" onAction="#fullScreenMenuItemHandler" text="%main.menuitem.fullScreen"> - <accelerator> - <KeyCodeCombination alt="UP" code="F" control="UP" meta="UP" shift="DOWN" shortcut="DOWN" /> - </accelerator> - </CheckMenuItem> - </items> - </Menu> - <Menu fx:id="extensionMenu" mnemonicParsing="false" text="%main.menu.extension" /> - <Menu mnemonicParsing="false" text="%main.menu.info"> - <items> - <MenuItem mnemonicParsing="false" onAction="#aboutMenuHandler" text="%main.menuitem.about" /> - <MenuItem mnemonicParsing="false" onAction="#visiteWebsiteMenuHandler" text="%main.menuitem.website" /> - <MenuItem mnemonicParsing="false" onAction="#sendErrorMenuItem" text="%main.menuitem.senderror" /> - </items> - </Menu> - </menus> -</MenuBar> <ToolBar fx:id="toolbar" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" HBox.hgrow="ALWAYS" VBox.vgrow="ALWAYS"> <items> <HBox fx:id="toolbarHBox" alignment="CENTER_LEFT" maxWidth="1.7976931348623157E308" prefHeight="28.0" prefWidth="586.0" spacing="14.0"> @@ -94,12 +21,19 @@ <Font size="24.0" /> </font> </Label> - <Slider fx:id="volumeSlider" focusTraversable="false" max="1.0" /> + <Slider fx:id="volumeSlider" focusTraversable="false" max="1.0" prefWidth="200.0" /> <Label fx:id="volumeUpLabel"> <font> <Font size="24.0" /> </font> </Label> + <MenuButton focusTraversable="false" mnemonicParsing="false" text="..."> + <items> + <CheckMenuItem fx:id="fullScreenMenuItem" mnemonicParsing="false" onAction="#fullScreenMenuItemHandler" text="%main.menuitem.fullScreen" /> + <CheckMenuItem fx:id="alwaysOnTopItem" mnemonicParsing="false" onAction="#alwaysOnTopItemHandler" text="%main.menuitem.onTop" /> + <MenuItem fx:id="closeMenuItem" mnemonicParsing="false" onAction="#closeMenuItemHandler" text="%main.menuitem.close" /> + </items> + </MenuButton> </children> </HBox> </children> diff --git a/PlayWall/src/de/tobias/playpad/components/Layout.xml b/PlayWall/src/de/tobias/playpad/components/Layout.xml index 8829c910..a828ab59 100644 --- a/PlayWall/src/de/tobias/playpad/components/Layout.xml +++ b/PlayWall/src/de/tobias/playpad/components/Layout.xml @@ -1,4 +1,4 @@ <Actions> - <Component id="Desktop">de.tobias.playpad.layout.desktop.DesktopMainLayoutConnect</Component> + <Component id="Desktop" default="true">de.tobias.playpad.layout.desktop.DesktopMainLayoutConnect</Component> <Component id="Touch">de.tobias.playpad.layout.touch.TouchMainLayoutConnect</Component> </Actions> \ No newline at end of file diff --git a/PlayWall/src/de/tobias/playpad/layout/desktop/DesktopMainLayoutConnect.java b/PlayWall/src/de/tobias/playpad/layout/desktop/DesktopMainLayoutConnect.java index e0c9e2b6..9ef7c735 100644 --- a/PlayWall/src/de/tobias/playpad/layout/desktop/DesktopMainLayoutConnect.java +++ b/PlayWall/src/de/tobias/playpad/layout/desktop/DesktopMainLayoutConnect.java @@ -7,6 +7,8 @@ import de.tobias.playpad.viewcontroller.main.MenuToolbarViewController; public class DesktopMainLayoutConnect implements MainLayoutConnect { + private DesktopMenuToolbarViewController desktopMenuToolbarViewController; + @Override public String getType() { return "Desktop"; @@ -19,14 +21,17 @@ public class DesktopMainLayoutConnect implements MainLayoutConnect { @Override public MenuToolbarViewController createMenuToolbar(IMainViewController mainViewRef) { - return new DesktopMenuToolbarViewController(mainViewRef); + if (desktopMenuToolbarViewController == null) { + desktopMenuToolbarViewController = new DesktopMenuToolbarViewController(mainViewRef); + } + return desktopMenuToolbarViewController; } @Override public IPadViewV2 createPadView() { return new DesktopPadView(); } - + @Override public String getStylesheet() { return null; diff --git a/PlayWall/src/de/tobias/playpad/layout/desktop/DesktopMenuToolbarViewController.java b/PlayWall/src/de/tobias/playpad/layout/desktop/DesktopMenuToolbarViewController.java index d053ee37..60ea0fef 100644 --- a/PlayWall/src/de/tobias/playpad/layout/desktop/DesktopMenuToolbarViewController.java +++ b/PlayWall/src/de/tobias/playpad/layout/desktop/DesktopMenuToolbarViewController.java @@ -1,29 +1,84 @@ package de.tobias.playpad.layout.desktop; +import java.awt.Desktop; +import java.io.IOException; +import java.net.URI; +import java.net.URISyntaxException; +import java.util.Optional; + +import de.tobias.playpad.AppUserInfoStrings; 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.view.IPadViewV2; import de.tobias.playpad.project.Project; import de.tobias.playpad.project.ProjectNotFoundException; import de.tobias.playpad.project.ProjectReference; +import de.tobias.playpad.registry.NoSuchComponentException; +import de.tobias.playpad.registry.Registry; import de.tobias.playpad.settings.Profile; import de.tobias.playpad.settings.ProfileNotFoundException; import de.tobias.playpad.settings.ProfileSettings; +import de.tobias.playpad.view.main.MainLayoutConnect; import de.tobias.playpad.view.main.MenuType; +import de.tobias.playpad.viewcontroller.SettingsTabViewController; import de.tobias.playpad.viewcontroller.dialog.ImportDialog; +import de.tobias.playpad.viewcontroller.dialog.NewProjectDialog; +import de.tobias.playpad.viewcontroller.dialog.PluginViewController; +import de.tobias.playpad.viewcontroller.dialog.PrintDialog; +import de.tobias.playpad.viewcontroller.dialog.ProfileViewController; +import de.tobias.playpad.viewcontroller.dialog.ProjectManagerDialog; import de.tobias.playpad.viewcontroller.main.BasicMenuToolbarViewController; import de.tobias.playpad.viewcontroller.main.IMainViewController; +import de.tobias.playpad.viewcontroller.option.SettingsViewController; +import de.tobias.playpad.viewcontroller.pad.PadDragListener; +import de.tobias.utils.application.ApplicationInfo; +import de.tobias.utils.application.ApplicationUtils; +import de.tobias.utils.application.container.PathType; +import de.tobias.utils.ui.Alertable; import de.tobias.utils.util.Localization; +import de.tobias.utils.util.Worker; +import de.tobias.utils.util.net.FileUpload; +import javafx.application.Platform; import javafx.event.ActionEvent; import javafx.event.EventHandler; +import javafx.fxml.FXML; import javafx.scene.Node; +import javafx.scene.control.Alert; +import javafx.scene.control.Alert.AlertType; import javafx.scene.control.Button; +import javafx.scene.control.CheckMenuItem; +import javafx.scene.control.Menu; +import javafx.scene.control.MenuBar; import javafx.scene.control.MenuItem; +import javafx.scene.control.RadioMenuItem; import javafx.scene.control.Slider; +import javafx.scene.control.ToggleGroup; import javafx.scene.image.Image; +import javafx.scene.input.KeyCombination; +import javafx.stage.Modality; +import javafx.stage.Stage; public class DesktopMenuToolbarViewController extends BasicMenuToolbarViewController implements EventHandler<ActionEvent> { + // meuBar + @FXML protected MenuBar menuBar; + + @FXML protected MenuItem saveMenuItem; + @FXML protected MenuItem profileMenu; + + @FXML protected MenuItem errorMenu; + @FXML protected MenuItem settingsMenuItem; + @FXML protected CheckMenuItem dndModeMenuItem; + @FXML protected CheckMenuItem fullScreenMenuItem; + @FXML protected CheckMenuItem alwaysOnTopItem; + @FXML protected Menu layoutMenu; + + @FXML protected Menu extensionMenu; + private IMainViewController mainViewController; + private SettingsViewController settingsViewController; public DesktopMenuToolbarViewController(IMainViewController controller) { super("header", "de/tobias/playpad/assets/view/main/desktop/", PlayPadMain.getUiResourceBundle(), controller); @@ -31,6 +86,51 @@ public class DesktopMenuToolbarViewController extends BasicMenuToolbarViewContro toolbarHBox.prefWidthProperty().bind(toolbar.widthProperty().subtract(25)); toolbarHBox.prefHeightProperty().bind(toolbar.minHeightProperty()); + + initLayoutMenu(); + } + + private void initLayoutMenu() { + ProfileSettings profileSettings = Profile.currentProfile().getProfileSettings(); + Registry<MainLayoutConnect> mainLayouts = PlayPadPlugin.getRegistryCollection().getMainLayouts(); + ToggleGroup group = new ToggleGroup(); + + int index = 1; // Für Tastenkombination + for (String layoutType : mainLayouts.getTypes()) { + try { + MainLayoutConnect connect = mainLayouts.getComponent(layoutType); + + RadioMenuItem item = new RadioMenuItem(connect.name()); + item.setUserData(connect); + group.getToggles().add(item); + + // Key Combi + if (index < 10) { + item.setAccelerator(KeyCombination.keyCombination("Shortcut+" + index)); + } + + if (connect.getType().equals(profileSettings.getMainLayoutType())) { + item.setSelected(true); + } + + layoutMenu.getItems().add(item); + } catch (NoSuchComponentException e) { + e.printStackTrace(); + } + index++; + } + + group.selectedToggleProperty().addListener((a, b, c) -> + { + if (c instanceof RadioMenuItem) { + RadioMenuItem menuItem = (RadioMenuItem) c; + if (menuItem.getUserData() instanceof MainLayoutConnect) { + MainLayoutConnect connect = (MainLayoutConnect) menuItem.getUserData(); + mainViewController.setMainLayout(connect); + Profile.currentProfile().getProfileSettings().setMainLayoutType(connect.getType()); + } + } + }); } @Override @@ -52,6 +152,16 @@ public class DesktopMenuToolbarViewController extends BasicMenuToolbarViewContro public void setLocked(boolean looked) { dndModeMenuItem.setDisable(looked); } + + @Override + public void setAlwaysOnTopActive(boolean alwaysOnTopActive) { + alwaysOnTopItem.setSelected(alwaysOnTopActive); + } + + @Override + public void setFullScreenActive(boolean fullScreenActive) { + fullScreenMenuItem.setSelected(fullScreenActive); + } @Override public void addToolbarIcon(Image icon) { @@ -62,12 +172,12 @@ public class DesktopMenuToolbarViewController extends BasicMenuToolbarViewContro public void removeToolbarIcon(Image icon) { // TODO Implement } - + @Override public void addToolbarItem(Node node) { iconHbox.getChildren().add(node); } - + @Override public void removeToolbarItem(Node node) { iconHbox.getChildren().remove(node); @@ -77,7 +187,7 @@ public class DesktopMenuToolbarViewController extends BasicMenuToolbarViewContro public void addMenuItem(MenuItem item, MenuType type) { if (type == MenuType.EXTENSION) { extensionMenu.getItems().add(item); - } else if (type == MenuType.SETTINGS) { + } else if (type == MenuType.SETTINGS) { // TODO Implement } } @@ -86,7 +196,7 @@ public class DesktopMenuToolbarViewController extends BasicMenuToolbarViewContro public void removeMenuItem(MenuItem item) { if (extensionMenu.getItems().contains(item)) extensionMenu.getItems().remove(item); - + // TODO Implement } @@ -102,16 +212,255 @@ public class DesktopMenuToolbarViewController extends BasicMenuToolbarViewContro @Override public void deinit() { - super.deinit(); toolbarHBox.prefWidthProperty().unbind(); toolbarHBox.prefHeightProperty().unbind(); } - + @Override public Slider getVolumeSlider() { return volumeSlider; } + // EventHandler + // Basic Event Handler + @FXML + void newDocumentHandler(ActionEvent event) { + doAction(() -> + { + NewProjectDialog dialog = new NewProjectDialog(mainViewController.getStage()); + dialog.getStage().showAndWait(); + + Project project = dialog.getProject(); + if (project != null) { + PlayPadMain.getProgramInstance().openProject(project); + } + }); + } + + @FXML + void openDocumentHandler(ActionEvent event) { + doAction(() -> + { + Stage stage = mainViewController.getStage(); + Project currentProject = PlayPadMain.getProgramInstance().getCurrentProject(); + + ProjectManagerDialog view = new ProjectManagerDialog(stage, currentProject); + Optional<ProjectReference> result = view.showAndWait(); + + if (result.isPresent()) { + ProjectReference ref = result.get(); + + try { + Project project = Project.load(result.get(), true, ImportDialog.getInstance(stage)); + PlayPadMain.getProgramInstance().openProject(project); + + createRecentDocumentMenuItems(); + } catch (ProfileNotFoundException e) { + e.printStackTrace(); + + // Error Message + String errorMessage = Localization.getString(Strings.Error_Profile_NotFound, ref.getProfileReference(), + e.getLocalizedMessage()); + mainViewController.showError(errorMessage); + + // Neues Profile wählen + Profile profile = ImportDialog.getInstance(stage).getUnkownProfile(); + ref.setProfileReference(profile.getRef()); + } catch (ProjectNotFoundException e) { + e.printStackTrace(); + mainViewController.showError(Localization.getString(Strings.Error_Project_NotFound, ref, e.getLocalizedMessage())); + } catch (Exception e) { + e.printStackTrace(); + mainViewController.showError(Localization.getString(Strings.Error_Project_Open, ref, e.getLocalizedMessage())); + } + } + }); + } + + @FXML + void saveMenuHandler(ActionEvent event) { + Project currentProject = PlayPadMain.getProgramInstance().getCurrentProject(); + + try { + currentProject.save(); + mainViewController.notify(Localization.getString(Strings.Standard_File_Save), PlayPadMain.displayTimeMillis); + } catch (IOException e) { + mainViewController.showError(Localization.getString(Strings.Error_Project_Save)); + e.printStackTrace(); + } + } + + @FXML + void profileMenuHandler(ActionEvent event) { + doAction(() -> + { + Project currentProject = PlayPadMain.getProgramInstance().getCurrentProject(); + + ProfileViewController controller = new ProfileViewController(mainViewController.getStage(), currentProject); + controller.getStage().showAndWait(); + mainViewController.setTitle(); + }); + } + + @FXML + void printMenuHandler(ActionEvent event) { + Project currentProject = PlayPadMain.getProgramInstance().getCurrentProject(); + PrintDialog dialog = new PrintDialog(currentProject, mainViewController.getStage()); + dialog.getStage().show(); + } + + @FXML + void dndModeHandler(ActionEvent event) { + if (dndModeMenuItem.isSelected()) { + ProfileSettings settings = Profile.currentProfile().getProfileSettings(); + Project currentProject = PlayPadMain.getProgramInstance().getCurrentProject(); + + if (settings.isLiveMode() && settings.isLiveModeDrag() && currentProject.getPlayedPlayers() > 0) { + mainViewController.showLiveInfo(); + } else { + PadDragListener.setDndMode(true); + for (IPadViewV2 view : mainViewController.getPadViews()) { + view.enableDragAndDropDesignMode(true); + } + } + } else { + PadDragListener.setDndMode(false); + for (IPadViewV2 view : mainViewController.getPadViews()) { + view.enableDragAndDropDesignMode(false); + } + } + + } + + @FXML + void errorMenuHandler(ActionEvent event) { + // TODO Implement + } + + @FXML + void pluginMenuItemHandler(ActionEvent event) { + doAction(() -> + { + PluginViewController controller = new PluginViewController(mainViewController.getStage()); + controller.getStage().showAndWait(); + }); + } + + @FXML + void settingsHandler(ActionEvent event) { + Midi midi = Midi.getInstance(); + Project currentProject = PlayPadMain.getProgramInstance().getCurrentProject(); + + ProfileSettings settings = Profile.currentProfile().getProfileSettings(); + + if (settings.isLiveMode() && settings.isLiveModeSettings() && currentProject.getPlayedPlayers() > 0) { + mainViewController.showLiveInfo(); + return; + } + + if (settingsViewController == null) { + Stage mainStage = mainViewController.getStage(); + + settingsViewController = new SettingsViewController(midi, mainViewController.getScreen(), mainStage, currentProject, () -> + { + midi.setListener(mainViewController.getMidiHandler()); + + boolean change = false; + for (SettingsTabViewController controller : settingsViewController.getTabs()) { + if (controller.needReload()) { + change = true; + controller.reload(Profile.currentProfile(), currentProject, mainViewController); + } + } + + if (change) { + PlayPadMain.getProgramInstance().getSettingsListener().forEach(l -> l.onChange(Profile.currentProfile())); + } + + settingsViewController = null; + mainStage.toFront(); + }); + + settingsViewController.getStage().show(); + } else if (settingsViewController.getStage().isShowing()) { + settingsViewController.getStage().toFront(); + } + + } + + @FXML + void alwaysOnTopItemHandler(ActionEvent event) { + boolean selected = alwaysOnTopItem.isSelected(); + + mainViewController.getStage().setAlwaysOnTop(selected); + Profile.currentProfile().getProfileSettings().setWindowAlwaysOnTop(selected); + } + + @FXML + void fullScreenMenuItemHandler(ActionEvent event) { + mainViewController.getStage().setFullScreen(fullScreenMenuItem.isSelected()); + } + + @FXML + void aboutMenuHandler(ActionEvent event) { + ApplicationInfo info = ApplicationUtils.getApplication().getInfo(); + String message = Localization.getString(Strings.UI_Dialog_Info_Content, info.getVersion(), info.getBuild(), info.getAuthor()); + if (mainViewController instanceof Alertable) { + ((Alertable) mainViewController).showInfoMessage(message, Localization.getString(Strings.UI_Dialog_Info_Header, info.getName()), + PlayPadMain.stageIcon.orElse(null)); + } + } + + @FXML + void visiteWebsiteMenuHandler(ActionEvent event) { + String website = ApplicationUtils.getApplication().getInfo().getUserInfo().getString(AppUserInfoStrings.WEBSITE); + try { + Desktop.getDesktop().browse(new URI(website)); + } catch (IOException | URISyntaxException e) { + e.printStackTrace(); + } + } + + @FXML + void sendErrorMenuItem(ActionEvent event) { + Alert alert = new Alert(AlertType.INFORMATION); + alert.initOwner(mainViewController.getStage()); + alert.initModality(Modality.WINDOW_MODAL); + Stage dialog = (Stage) alert.getDialogPane().getScene().getWindow(); + PlayPadMain.stageIcon.ifPresent(dialog.getIcons()::add); + alert.setContentText(Localization.getString(Strings.UI_Dialog_Feedback_Content)); + alert.show(); + + Worker.runLater(() -> + { + try { + String response = FileUpload.fileUpload( + ApplicationUtils.getApplication().getInfo().getUserInfo().getString(AppUserInfoStrings.ERROR_URL), + ApplicationUtils.getApplication().getPath(PathType.LOG, "err.log").toFile()); + Platform.runLater(() -> alert.setContentText(response)); + } catch (IOException e) { + e.printStackTrace(); + } + }); + } + + private final int LAST_DOCUMENT_LIMIT = 3; + + public void createRecentDocumentMenuItems() { + recentOpenMenu.getItems().clear(); + + Project currentProject = PlayPadMain.getProgramInstance().getCurrentProject(); + String project = currentProject.getRef().getName(); + + ProjectReference.getProjectsSorted().stream().filter(item -> !item.getName().equals(project)).limit(LAST_DOCUMENT_LIMIT).forEach(item -> + { + MenuItem menuItem = new MenuItem(item.toString()); + menuItem.setUserData(item); + menuItem.setOnAction(this); + recentOpenMenu.getItems().add(menuItem); + }); + } + @Override public void handle(ActionEvent event) { if (event.getSource() instanceof Button) { diff --git a/PlayWall/src/de/tobias/playpad/layout/touch/TouchMainLayoutConnect.java b/PlayWall/src/de/tobias/playpad/layout/touch/TouchMainLayoutConnect.java index 0dac72d7..5616af4a 100644 --- a/PlayWall/src/de/tobias/playpad/layout/touch/TouchMainLayoutConnect.java +++ b/PlayWall/src/de/tobias/playpad/layout/touch/TouchMainLayoutConnect.java @@ -7,6 +7,8 @@ import de.tobias.playpad.viewcontroller.main.MenuToolbarViewController; public class TouchMainLayoutConnect implements MainLayoutConnect { + private TouchMenuToolbarViewController touchMainLayoutConnect; + @Override public String getType() { return "Touch"; @@ -19,7 +21,11 @@ public class TouchMainLayoutConnect implements MainLayoutConnect { @Override public MenuToolbarViewController createMenuToolbar(IMainViewController mainViewRef) { - return new TouchMenuToolbarViewController(mainViewRef); + if (touchMainLayoutConnect == null) { + touchMainLayoutConnect = new TouchMenuToolbarViewController(mainViewRef); + } + + return touchMainLayoutConnect; } @Override diff --git a/PlayWall/src/de/tobias/playpad/layout/touch/TouchMenuToolbarViewController.java b/PlayWall/src/de/tobias/playpad/layout/touch/TouchMenuToolbarViewController.java index b2519237..1b2b41b2 100644 --- a/PlayWall/src/de/tobias/playpad/layout/touch/TouchMenuToolbarViewController.java +++ b/PlayWall/src/de/tobias/playpad/layout/touch/TouchMenuToolbarViewController.java @@ -1,6 +1,7 @@ package de.tobias.playpad.layout.touch; import de.tobias.playpad.PlayPadMain; +import de.tobias.playpad.PlayPadPlugin; import de.tobias.playpad.Strings; import de.tobias.playpad.project.Project; import de.tobias.playpad.project.ProjectNotFoundException; @@ -8,22 +9,29 @@ import de.tobias.playpad.project.ProjectReference; import de.tobias.playpad.settings.Profile; import de.tobias.playpad.settings.ProfileNotFoundException; import de.tobias.playpad.settings.ProfileSettings; +import de.tobias.playpad.view.main.MainLayoutConnect; import de.tobias.playpad.view.main.MenuType; import de.tobias.playpad.viewcontroller.dialog.ImportDialog; import de.tobias.playpad.viewcontroller.main.BasicMenuToolbarViewController; import de.tobias.playpad.viewcontroller.main.IMainViewController; import de.tobias.utils.util.Localization; import javafx.event.ActionEvent; +import javafx.fxml.FXML; import javafx.scene.Node; import javafx.scene.control.Button; +import javafx.scene.control.CheckMenuItem; import javafx.scene.control.MenuItem; import javafx.scene.control.Slider; import javafx.scene.image.Image; public class TouchMenuToolbarViewController extends BasicMenuToolbarViewController { + @FXML protected CheckMenuItem fullScreenMenuItem; + @FXML protected CheckMenuItem alwaysOnTopItem; + @FXML protected MenuItem closeMenuItem; + private IMainViewController mainViewController; - + public TouchMenuToolbarViewController(IMainViewController mainViewController) { super("header", "de/tobias/playpad/assets/view/main/touch/", PlayPadMain.getUiResourceBundle(), mainViewController); this.mainViewController = mainViewController; @@ -52,6 +60,16 @@ public class TouchMenuToolbarViewController extends BasicMenuToolbarViewControll } + @Override + public void setAlwaysOnTopActive(boolean alwaysOnTopActive) { + alwaysOnTopItem.setSelected(alwaysOnTopActive); + } + + @Override + public void setFullScreenActive(boolean fullScreenActive) { + fullScreenMenuItem.setSelected(fullScreenActive); + } + @Override public void addToolbarIcon(Image icon) { // TODO Implement @@ -73,35 +91,23 @@ public class TouchMenuToolbarViewController extends BasicMenuToolbarViewControll } @Override - public void addMenuItem(MenuItem item, MenuType type) { - if (type == MenuType.EXTENSION) { - extensionMenu.getItems().add(item); - } else if (type == MenuType.SETTINGS) { - // TODO Implement - } - } + public void addMenuItem(MenuItem item, MenuType type) {} @Override - public void removeMenuItem(MenuItem item) { - if (extensionMenu.getItems().contains(item)) - extensionMenu.getItems().remove(item); - - // TODO Implement - } + public void removeMenuItem(MenuItem item) {} @Override public boolean isAlwaysOnTopActive() { - return alwaysOnTopItem.isSelected(); + return false; // TODO } @Override public boolean isFullscreenActive() { - return fullScreenMenuItem.isSelected(); + return false; // TODO } @Override public void deinit() { - super.deinit(); toolbarHBox.prefWidthProperty().unbind(); toolbarHBox.prefHeightProperty().unbind(); } @@ -111,6 +117,28 @@ public class TouchMenuToolbarViewController extends BasicMenuToolbarViewControll return volumeSlider; } + // Event Handler + @FXML + void alwaysOnTopItemHandler(ActionEvent event) { + boolean selected = alwaysOnTopItem.isSelected(); + + mainViewController.getStage().setAlwaysOnTop(selected); + Profile.currentProfile().getProfileSettings().setWindowAlwaysOnTop(selected); + } + + @FXML + void fullScreenMenuItemHandler(ActionEvent event) { + mainViewController.getStage().setFullScreen(fullScreenMenuItem.isSelected()); + } + + @FXML + void closeMenuItemHandler(ActionEvent event) { + MainLayoutConnect defaultLayout = PlayPadPlugin.getRegistryCollection().getMainLayouts().getDefault(); + + Profile.currentProfile().getProfileSettings().setMainLayoutType(defaultLayout.getType()); + mainViewController.setMainLayout(defaultLayout); + } + @Override public void handle(ActionEvent event) { if (event.getSource() instanceof Button) { diff --git a/PlayWall/src/de/tobias/playpad/layout/touch/TouchPadView.java b/PlayWall/src/de/tobias/playpad/layout/touch/TouchPadView.java index 849b15cc..68581c2c 100644 --- a/PlayWall/src/de/tobias/playpad/layout/touch/TouchPadView.java +++ b/PlayWall/src/de/tobias/playpad/layout/touch/TouchPadView.java @@ -86,8 +86,8 @@ public class TouchPadView implements IPadViewV2 { root.getChildren().addAll(infoBox, preview, playBar); superRoot.getChildren().addAll(root); - superRoot.setOnTouchPressed(controller); superRoot.setOnMouseClicked(controller); + playBar.setOnMouseClicked(controller); } @Override diff --git a/PlayWall/src/de/tobias/playpad/layout/touch/TouchPadViewController.java b/PlayWall/src/de/tobias/playpad/layout/touch/TouchPadViewController.java index 0a4c14f7..347a5e90 100644 --- a/PlayWall/src/de/tobias/playpad/layout/touch/TouchPadViewController.java +++ b/PlayWall/src/de/tobias/playpad/layout/touch/TouchPadViewController.java @@ -37,7 +37,6 @@ import javafx.event.EventHandler; import javafx.scene.Node; import javafx.scene.input.MouseButton; import javafx.scene.input.MouseEvent; -import javafx.scene.input.TouchEvent; import javafx.stage.FileChooser; import javafx.stage.FileChooser.ExtensionFilter; import javafx.stage.Stage; @@ -154,14 +153,7 @@ public class TouchPadViewController implements IPadViewControllerV2, EventHandle @Override public void handle(Event event) { - if (event instanceof TouchEvent) { - TouchEvent touchEvent = (TouchEvent) event; - if (event.getEventType() == TouchEvent.TOUCH_PRESSED) { - if (touchEvent.getTouchCount() == 1 || touchEvent.getTouchCount() == 2) { - handleAction(touchEvent.getTouchCount() == 1, event); - } - } - } else if (event instanceof MouseEvent) { + if (event instanceof MouseEvent) { if (event.getEventType() == MouseEvent.MOUSE_CLICKED) { MouseEvent mouseEvent = (MouseEvent) event; if (mouseEvent.getButton() == MouseButton.PRIMARY || mouseEvent.getButton() == MouseButton.SECONDARY) { diff --git a/PlayWall/src/de/tobias/playpad/viewcontroller/main/BasicMenuToolbarViewController.java b/PlayWall/src/de/tobias/playpad/viewcontroller/main/BasicMenuToolbarViewController.java index 5dc4751a..9e8af0b1 100644 --- a/PlayWall/src/de/tobias/playpad/viewcontroller/main/BasicMenuToolbarViewController.java +++ b/PlayWall/src/de/tobias/playpad/viewcontroller/main/BasicMenuToolbarViewController.java @@ -1,90 +1,36 @@ package de.tobias.playpad.viewcontroller.main; -import java.awt.Desktop; -import java.io.IOException; -import java.net.URI; -import java.net.URISyntaxException; -import java.util.Optional; 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.midi.Midi; -import de.tobias.playpad.pad.view.IPadViewV2; import de.tobias.playpad.project.Project; -import de.tobias.playpad.project.ProjectNotFoundException; -import de.tobias.playpad.project.ProjectReference; -import de.tobias.playpad.registry.NoSuchComponentException; -import de.tobias.playpad.registry.Registry; import de.tobias.playpad.settings.Profile; -import de.tobias.playpad.settings.ProfileNotFoundException; -import de.tobias.playpad.settings.ProfileSettings; -import de.tobias.playpad.view.main.MainLayoutConnect; -import de.tobias.playpad.viewcontroller.SettingsTabViewController; -import de.tobias.playpad.viewcontroller.dialog.ImportDialog; -import de.tobias.playpad.viewcontroller.dialog.NewProjectDialog; -import de.tobias.playpad.viewcontroller.dialog.PluginViewController; -import de.tobias.playpad.viewcontroller.dialog.PrintDialog; -import de.tobias.playpad.viewcontroller.dialog.ProfileViewController; -import de.tobias.playpad.viewcontroller.dialog.ProjectManagerDialog; -import de.tobias.playpad.viewcontroller.option.SettingsViewController; -import de.tobias.playpad.viewcontroller.pad.PadDragListener; -import de.tobias.utils.application.ApplicationInfo; -import de.tobias.utils.application.ApplicationUtils; -import de.tobias.utils.application.container.PathType; -import de.tobias.utils.ui.Alertable; import de.tobias.utils.ui.icon.FontAwesomeType; import de.tobias.utils.ui.icon.FontIcon; -import de.tobias.utils.util.Localization; -import de.tobias.utils.util.Worker; -import de.tobias.utils.util.net.FileUpload; -import javafx.application.Platform; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.fxml.FXML; -import javafx.scene.control.Alert; -import javafx.scene.control.Alert.AlertType; -import javafx.scene.control.CheckMenuItem; import javafx.scene.control.Label; import javafx.scene.control.Menu; -import javafx.scene.control.MenuBar; -import javafx.scene.control.MenuItem; -import javafx.scene.control.RadioMenuItem; import javafx.scene.control.Slider; -import javafx.scene.control.ToggleGroup; import javafx.scene.control.ToolBar; -import javafx.scene.input.KeyCombination; import javafx.scene.layout.HBox; -import javafx.stage.Modality; -import javafx.stage.Stage; public abstract class BasicMenuToolbarViewController extends MenuToolbarViewController implements EventHandler<ActionEvent> { // Menu @FXML protected Label volumeUpLabel; @FXML protected HBox iconHbox; - @FXML protected MenuItem errorMenu; + @FXML protected HBox pageHBox; - @FXML protected MenuItem saveMenuItem; @FXML protected HBox toolbarHBox; - @FXML protected CheckMenuItem fullScreenMenuItem; - @FXML protected MenuItem settingsMenuItem; - @FXML protected MenuBar menuBar; @FXML protected ToolBar toolbar; @FXML protected Menu recentOpenMenu; @FXML protected Slider volumeSlider; - @FXML protected Menu extensionMenu; - @FXML protected MenuItem profileMenu; @FXML protected Label volumeDownLabel; - @FXML protected CheckMenuItem dndModeMenuItem; - @FXML protected CheckMenuItem alwaysOnTopItem; - @FXML protected Menu layoutMenu; // window references private IMainViewController mainViewController; - private SettingsViewController settingsViewController; public BasicMenuToolbarViewController(String name, String path, ResourceBundle localization, IMainViewController mainViewController) { super(name, path, localization); @@ -101,281 +47,6 @@ public abstract class BasicMenuToolbarViewController extends MenuToolbarViewCont volumeSlider.setValue(volumeSlider.getValue() - ev.getDeltaY() * 0.001); volumeSlider.setValue(volumeSlider.getValue() + ev.getDeltaX() * 0.001); }); - - ProfileSettings profileSettings = Profile.currentProfile().getProfileSettings(); - Registry<MainLayoutConnect> mainLayouts = PlayPadPlugin.getRegistryCollection().getMainLayouts(); - ToggleGroup group = new ToggleGroup(); - - int index = 1; // Für Tastenkombination - for (String layoutType : mainLayouts.getTypes()) { - try { - MainLayoutConnect connect = mainLayouts.getComponent(layoutType); - - RadioMenuItem item = new RadioMenuItem(connect.name()); - group.getToggles().add(item); - item.setOnAction((e) -> - { - mainViewController.setMainLayout(connect); - Profile.currentProfile().getProfileSettings().setMainLayoutType(connect.getType()); - }); - - // Key Combi - if (index < 10) { - item.setAccelerator(KeyCombination.keyCombination("Shortcut+" + index)); - } - - if (connect.getType().equals(profileSettings.getMainLayoutType())) { - item.setSelected(true); - } - - layoutMenu.getItems().add(item); - } catch (NoSuchComponentException e) { - e.printStackTrace(); - } - index++; - } - } - - @Override - public void deinit() {} - - // Basic Event Handler - @FXML - void newDocumentHandler(ActionEvent event) { - doAction(() -> - { - NewProjectDialog dialog = new NewProjectDialog(mainViewController.getStage()); - dialog.getStage().showAndWait(); - - Project project = dialog.getProject(); - if (project != null) { - PlayPadMain.getProgramInstance().openProject(project); - } - }); - } - - @FXML - void openDocumentHandler(ActionEvent event) { - doAction(() -> - { - Stage stage = mainViewController.getStage(); - Project currentProject = PlayPadMain.getProgramInstance().getCurrentProject(); - - ProjectManagerDialog view = new ProjectManagerDialog(stage, currentProject); - Optional<ProjectReference> result = view.showAndWait(); - - if (result.isPresent()) { - ProjectReference ref = result.get(); - - try { - Project project = Project.load(result.get(), true, ImportDialog.getInstance(stage)); - PlayPadMain.getProgramInstance().openProject(project); - - createRecentDocumentMenuItems(); - } catch (ProfileNotFoundException e) { - e.printStackTrace(); - - // Error Message - String errorMessage = Localization.getString(Strings.Error_Profile_NotFound, ref.getProfileReference(), - e.getLocalizedMessage()); - mainViewController.showError(errorMessage); - - // Neues Profile wählen - Profile profile = ImportDialog.getInstance(stage).getUnkownProfile(); - ref.setProfileReference(profile.getRef()); - } catch (ProjectNotFoundException e) { - e.printStackTrace(); - mainViewController.showError(Localization.getString(Strings.Error_Project_NotFound, ref, e.getLocalizedMessage())); - } catch (Exception e) { - e.printStackTrace(); - mainViewController.showError(Localization.getString(Strings.Error_Project_Open, ref, e.getLocalizedMessage())); - } - } - }); - } - - @FXML - void saveMenuHandler(ActionEvent event) { - Project currentProject = PlayPadMain.getProgramInstance().getCurrentProject(); - - try { - currentProject.save(); - mainViewController.notify(Localization.getString(Strings.Standard_File_Save), PlayPadMain.displayTimeMillis); - } catch (IOException e) { - mainViewController.showError(Localization.getString(Strings.Error_Project_Save)); - e.printStackTrace(); - } - } - - @FXML - void profileMenuHandler(ActionEvent event) { - doAction(() -> - { - Project currentProject = PlayPadMain.getProgramInstance().getCurrentProject(); - - ProfileViewController controller = new ProfileViewController(mainViewController.getStage(), currentProject); - controller.getStage().showAndWait(); - mainViewController.setTitle(); - }); - } - - @FXML - void printMenuHandler(ActionEvent event) { - Project currentProject = PlayPadMain.getProgramInstance().getCurrentProject(); - PrintDialog dialog = new PrintDialog(currentProject, mainViewController.getStage()); - dialog.getStage().show(); - } - - @FXML - void dndModeHandler(ActionEvent event) { - if (dndModeMenuItem.isSelected()) { - ProfileSettings settings = Profile.currentProfile().getProfileSettings(); - Project currentProject = PlayPadMain.getProgramInstance().getCurrentProject(); - - if (settings.isLiveMode() && settings.isLiveModeDrag() && currentProject.getPlayedPlayers() > 0) { - mainViewController.showLiveInfo(); - } else { - PadDragListener.setDndMode(true); - for (IPadViewV2 view : mainViewController.getPadViews()) { - view.enableDragAndDropDesignMode(true); - } - } - } else { - PadDragListener.setDndMode(false); - for (IPadViewV2 view : mainViewController.getPadViews()) { - view.enableDragAndDropDesignMode(false); - } - } - - } - - @FXML - void errorMenuHandler(ActionEvent event) { - // TODO Implement - } - - @FXML - void pluginMenuItemHandler(ActionEvent event) { - doAction(() -> - { - PluginViewController controller = new PluginViewController(mainViewController.getStage()); - controller.getStage().showAndWait(); - }); - } - - @FXML - void settingsHandler(ActionEvent event) { - Midi midi = Midi.getInstance(); - Project currentProject = PlayPadMain.getProgramInstance().getCurrentProject(); - - ProfileSettings settings = Profile.currentProfile().getProfileSettings(); - - if (settings.isLiveMode() && settings.isLiveModeSettings() && currentProject.getPlayedPlayers() > 0) { - mainViewController.showLiveInfo(); - return; - } - - if (settingsViewController == null) { - Stage mainStage = mainViewController.getStage(); - - settingsViewController = new SettingsViewController(midi, mainViewController.getScreen(), mainStage, currentProject, () -> - { - midi.setListener(mainViewController.getMidiHandler()); - - boolean change = false; - for (SettingsTabViewController controller : settingsViewController.getTabs()) { - if (controller.needReload()) { - change = true; - controller.reload(Profile.currentProfile(), currentProject, mainViewController); - } - } - - if (change) { - PlayPadMain.getProgramInstance().getSettingsListener().forEach(l -> l.onChange(Profile.currentProfile())); - } - - settingsViewController = null; - mainStage.toFront(); - }); - - settingsViewController.getStage().show(); - } else if (settingsViewController.getStage().isShowing()) { - settingsViewController.getStage().toFront(); - } - - } - - @FXML - void alwaysOnTopItemHandler(ActionEvent event) { - boolean selected = alwaysOnTopItem.isSelected(); - - mainViewController.getStage().setAlwaysOnTop(selected); - Profile.currentProfile().getProfileSettings().setWindowAlwaysOnTop(selected); - } - - @FXML - void fullScreenMenuItemHandler(ActionEvent event) { - mainViewController.getStage().setFullScreen(fullScreenMenuItem.isSelected()); - } - - @FXML - void aboutMenuHandler(ActionEvent event) { - ApplicationInfo info = ApplicationUtils.getApplication().getInfo(); - String message = Localization.getString(Strings.UI_Dialog_Info_Content, info.getVersion(), info.getBuild(), info.getAuthor()); - if (mainViewController instanceof Alertable) { - ((Alertable) mainViewController).showInfoMessage(message, Localization.getString(Strings.UI_Dialog_Info_Header, info.getName()), - PlayPadMain.stageIcon.orElse(null)); - } - } - - @FXML - void visiteWebsiteMenuHandler(ActionEvent event) { - String website = ApplicationUtils.getApplication().getInfo().getUserInfo().getString(AppUserInfoStrings.WEBSITE); - try { - Desktop.getDesktop().browse(new URI(website)); - } catch (IOException | URISyntaxException e) { - e.printStackTrace(); - } - } - - @FXML - void sendErrorMenuItem(ActionEvent event) { - Alert alert = new Alert(AlertType.INFORMATION); - alert.initOwner(mainViewController.getStage()); - alert.initModality(Modality.WINDOW_MODAL); - Stage dialog = (Stage) alert.getDialogPane().getScene().getWindow(); - PlayPadMain.stageIcon.ifPresent(dialog.getIcons()::add); - alert.setContentText(Localization.getString(Strings.UI_Dialog_Feedback_Content)); - alert.show(); - - Worker.runLater(() -> - { - try { - String response = FileUpload.fileUpload( - ApplicationUtils.getApplication().getInfo().getUserInfo().getString(AppUserInfoStrings.ERROR_URL), - ApplicationUtils.getApplication().getPath(PathType.LOG, "err.log").toFile()); - Platform.runLater(() -> alert.setContentText(response)); - } catch (IOException e) { - e.printStackTrace(); - } - }); - } - - private final int LAST_DOCUMENT_LIMIT = 3; - - public void createRecentDocumentMenuItems() { - recentOpenMenu.getItems().clear(); - - Project currentProject = PlayPadMain.getProgramInstance().getCurrentProject(); - String project = currentProject.getRef().getName(); - - ProjectReference.getProjectsSorted().stream().filter(item -> !item.getName().equals(project)).limit(LAST_DOCUMENT_LIMIT).forEach(item -> - { - MenuItem menuItem = new MenuItem(item.toString()); - menuItem.setUserData(item); - menuItem.setOnAction(this); - recentOpenMenu.getItems().add(menuItem); - }); } // Utils diff --git a/PlayWall/src/de/tobias/playpad/viewcontroller/main/MainViewControllerV2.java b/PlayWall/src/de/tobias/playpad/viewcontroller/main/MainViewControllerV2.java index 3d2f5ace..a41373ad 100644 --- a/PlayWall/src/de/tobias/playpad/viewcontroller/main/MainViewControllerV2.java +++ b/PlayWall/src/de/tobias/playpad/viewcontroller/main/MainViewControllerV2.java @@ -194,8 +194,16 @@ public class MainViewControllerV2 extends ViewController implements IMainViewCon removePadsFromView(); headerBox.getChildren().clear(); - menuToolbarViewController = mainLayout.createMenuToolbar(this); - headerBox.getChildren().add(menuToolbarViewController.getParent()); + MenuToolbarViewController newMenuToolbarViewController = mainLayout.createMenuToolbar(this); + headerBox.getChildren().add(newMenuToolbarViewController.getParent()); + + // Kopiert alte Einstellungen + if (menuToolbarViewController != null) { + newMenuToolbarViewController.setAlwaysOnTopActive(this.menuToolbarViewController.isAlwaysOnTopActive()); + newMenuToolbarViewController.setFullScreenActive(this.menuToolbarViewController.isFullscreenActive()); + } + + this.menuToolbarViewController = newMenuToolbarViewController; createPadViews(); showPage(currentPageShowing); diff --git a/PlayWallCore/src/de/tobias/playpad/registry/DefaultComponentRegistry.java b/PlayWallCore/src/de/tobias/playpad/registry/DefaultComponentRegistry.java index 90aeb3e8..f085a261 100644 --- a/PlayWallCore/src/de/tobias/playpad/registry/DefaultComponentRegistry.java +++ b/PlayWallCore/src/de/tobias/playpad/registry/DefaultComponentRegistry.java @@ -1,5 +1,13 @@ package de.tobias.playpad.registry; +import java.io.IOException; +import java.net.URL; + +import org.dom4j.Document; +import org.dom4j.DocumentException; +import org.dom4j.Element; +import org.dom4j.io.SAXReader; + public class DefaultComponentRegistry<C> extends ComponentRegistry<C> implements DefaultRegistry<C> { private C defaultValue; @@ -37,4 +45,35 @@ public class DefaultComponentRegistry<C> extends ComponentRegistry<C> implements setDefault(getComponent(id)); } + @Override + public void loadComponentsFromFile(URL url, ClassLoader loader) + throws IOException, DocumentException, ClassNotFoundException, InstantiationException, IllegalAccessException { + if (url == null) { + throw new IOException("URL not found: " + url); + } + SAXReader reader = new SAXReader(); + Document document = reader.read(url); + + Element rootElement = document.getRootElement(); + for (Object obj : rootElement.elements("Component")) { + if (obj instanceof Element) { + Element element = (Element) obj; + String type = element.attributeValue("id"); + + // Find the class of the type + @SuppressWarnings("unchecked") Class<C> clazz = (Class<C>) loader.loadClass(element.getStringValue()); + C component = clazz.newInstance(); + + registerComponent(component, type); + + if (element.attributeValue("default") != null) { + String defaultValue = element.attributeValue("default"); + if (defaultValue.equals("true")) { + setDefault(component); + } + } + } + } + } + } diff --git a/PlayWallCore/src/de/tobias/playpad/viewcontroller/main/MenuToolbarViewController.java b/PlayWallCore/src/de/tobias/playpad/viewcontroller/main/MenuToolbarViewController.java index 1bd8bf92..72863a94 100644 --- a/PlayWallCore/src/de/tobias/playpad/viewcontroller/main/MenuToolbarViewController.java +++ b/PlayWallCore/src/de/tobias/playpad/viewcontroller/main/MenuToolbarViewController.java @@ -144,4 +144,8 @@ public abstract class MenuToolbarViewController extends ContentViewController { public abstract void deinit(); public abstract Slider getVolumeSlider(); + + public abstract void setAlwaysOnTopActive(boolean alwaysOnTopActive); + + public abstract void setFullScreenActive(boolean fullScreenActive); } diff --git a/PlayWallPlugins/awakeplugin/de/tobias/playpad/awakeplugin/impl/AwakePluginImpl.java b/PlayWallPlugins/awakeplugin/de/tobias/playpad/awakeplugin/impl/AwakePluginImpl.java index 292b838d..91bd1d0a 100644 --- a/PlayWallPlugins/awakeplugin/de/tobias/playpad/awakeplugin/impl/AwakePluginImpl.java +++ b/PlayWallPlugins/awakeplugin/de/tobias/playpad/awakeplugin/impl/AwakePluginImpl.java @@ -143,12 +143,22 @@ public class AwakePluginImpl implements AwakePlugin, WindowListener<IMainViewCon @Override public void onInit(IMainViewController t) { - activeMenu = new CheckMenuItem(); - activeMenu.setOnAction(this); - activeMenu.setText(bundle.getString("menutitle")); - activeMenu.setSelected(settings.active); - t.getMenuToolbarController().addMenuItem(activeMenu, MenuType.EXTENSION); - + t.performLayoutDependendAction(() -> + { + activeMenu = new CheckMenuItem(); + activeMenu.setOnAction(this); + activeMenu.setText(bundle.getString("menutitle")); + activeMenu.setSelected(settings.active); + t.getMenuToolbarController().addMenuItem(activeMenu, MenuType.EXTENSION); + + if (iconLabel != null) { + if (settings.active) { + t.getMenuToolbarController().addToolbarItem(iconLabel); + } else { + t.getMenuToolbarController().removeToolbarItem(iconLabel); + } + } + }); iconLabel = new Label(); iconLabel.setGraphic(new FontIcon(FontAwesomeType.MOON_ALT)); } -- GitLab