From e11a0f3fc858ae9487cf29e609129160c2fab108 Mon Sep 17 00:00:00 2001 From: tobias <tobias.ullerich@icloud.com> Date: Mon, 1 Aug 2016 21:32:56 +0200 Subject: [PATCH] Continue working on main view --- .../playpad/assets/view/main/mainViewV2.fxml | 6 +- .../src/de/tobias/playpad/PlayPadImpl.java | 8 +- .../playpad/RegistryCollectionImpl.java | 8 +- .../design/classic/ClassicCartDesign.java | 10 +- .../design/classic/ClassicGlobalDesign.java | 10 +- .../design/modern/ModernCartDesign.java | 12 +- .../design/modern/ModernDesignAnimator.java | 22 +- .../design/modern/ModernGlobalDesign.java | 8 +- .../BasicMenuToolbarViewController.java | 299 +++++++++++++++++- .../DesktopMenuToolbarViewController.java | 57 +++- .../layout/desktop/DesktopPadView.java | 54 +++- .../desktop/DesktopPadViewController.java | 125 +++++++- .../layout/touch/TouchMainLayoutConnect.java | 2 +- .../touch/TouchMenuToolbarViewController.java | 14 +- .../playpad/layout/touch/TouchPadView.java | 6 + .../layout/touch/TouchPadViewController.java | 15 + .../pad/listener/PadContentListener.java | 43 +-- .../pad/listener/PadPositionListener.java | 14 +- .../pad/listener/PadStatusListener.java | 12 +- .../main/MainMenuBarController.java | 2 +- .../main/MainViewController.java | 15 +- .../main/MainViewControllerV2.java | 262 ++++++++++++++- .../option/GeneralTabViewController.java | 2 +- .../option/SettingsViewController.java | 11 +- .../viewcontroller/pad/PadDragListener.java | 77 +++-- .../viewcontroller/pad/PadViewController.java | 3 +- .../de/tobias/playpad/RegistryCollection.java | 4 +- .../de/tobias/playpad/design/CartDesign.java | 6 +- .../tobias/playpad/design/GlobalDesign.java | 6 +- .../playpad/pad/PadContentRegistry.java | 43 +++ .../pad/listener/IPadPositionListener.java | 15 + .../playpad/pad/view/IPadContentView.java | 1 + .../tobias/playpad/pad/view/IPadViewV2.java | 8 + .../viewcontroller/IPadViewControllerV2.java | 6 + .../main/IMainViewController.java | 19 +- .../main/MenuToolbarViewController.java | 2 +- 36 files changed, 1035 insertions(+), 172 deletions(-) create mode 100644 PlayWallCore/src/de/tobias/playpad/pad/PadContentRegistry.java create mode 100644 PlayWallCore/src/de/tobias/playpad/pad/listener/IPadPositionListener.java diff --git a/PlayWall/assets/de/tobias/playpad/assets/view/main/mainViewV2.fxml b/PlayWall/assets/de/tobias/playpad/assets/view/main/mainViewV2.fxml index 8a15c3d2..37c5902f 100644 --- a/PlayWall/assets/de/tobias/playpad/assets/view/main/mainViewV2.fxml +++ b/PlayWall/assets/de/tobias/playpad/assets/view/main/mainViewV2.fxml @@ -11,8 +11,12 @@ <VBox layoutX="-0.7071067690849304" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0"> <children> <VBox fx:id="headerBox" /> - <GridPane fx:id="padGridPane" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" VBox.vgrow="ALWAYS"> + <AnchorPane fx:id="gridContainer" VBox.vgrow="ALWAYS"> + <children> + <GridPane fx:id="padGridPane" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" VBox.vgrow="ALWAYS"> </GridPane> + </children> + </AnchorPane> </children> </VBox> </children> diff --git a/PlayWall/src/de/tobias/playpad/PlayPadImpl.java b/PlayWall/src/de/tobias/playpad/PlayPadImpl.java index 2c81c369..dc87787f 100644 --- a/PlayWall/src/de/tobias/playpad/PlayPadImpl.java +++ b/PlayWall/src/de/tobias/playpad/PlayPadImpl.java @@ -43,7 +43,8 @@ public class PlayPadImpl implements PlayPad { private Set<Path> deletedPlugins; private MainViewControllerV2 mainViewController; - + private Project currentProject; + public PlayPadImpl() { pluginManager = PluginManagerFactory.createPluginManager(); deletedPlugins = new HashSet<>(); @@ -160,6 +161,11 @@ public class PlayPadImpl implements PlayPad { if (mainViewController == null) { mainViewController = new MainViewControllerV2(mainViewListeners); } + currentProject = project; mainViewController.openProject(project); } + + public Project getCurrentProject() { + return currentProject; + } } diff --git a/PlayWall/src/de/tobias/playpad/RegistryCollectionImpl.java b/PlayWall/src/de/tobias/playpad/RegistryCollectionImpl.java index dc057fd7..adbf6095 100644 --- a/PlayWall/src/de/tobias/playpad/RegistryCollectionImpl.java +++ b/PlayWall/src/de/tobias/playpad/RegistryCollectionImpl.java @@ -4,7 +4,7 @@ import de.tobias.playpad.action.ActionConnect; import de.tobias.playpad.action.mapper.MapperConnect; import de.tobias.playpad.audio.AudioRegistry; import de.tobias.playpad.design.DesignConnect; -import de.tobias.playpad.pad.conntent.PadContentConnect; +import de.tobias.playpad.pad.PadContentRegistry; import de.tobias.playpad.pad.drag.PadDragMode; import de.tobias.playpad.registry.ComponentRegistry; import de.tobias.playpad.registry.DefaultComponentRegistry; @@ -19,7 +19,7 @@ public class RegistryCollectionImpl implements RegistryCollection { private Registry<PadDragMode> dragModeRegistry; private DefaultRegistry<DesignConnect> layoutRegistry; private Registry<MapperConnect> mapperRegistry; - private Registry<PadContentConnect> padContentRegistry; + private PadContentRegistry padContentRegistry; private Registry<TriggerItemConnect> triggerItemRegistry; public RegistryCollectionImpl() { @@ -28,7 +28,7 @@ public class RegistryCollectionImpl implements RegistryCollection { dragModeRegistry = new ComponentRegistry<>("DragMode"); layoutRegistry = new DefaultComponentRegistry<>("Layout"); mapperRegistry = new ComponentRegistry<>("Mapper"); - padContentRegistry = new ComponentRegistry<>("PadContent"); + padContentRegistry = new PadContentRegistry("PadContent"); triggerItemRegistry = new ComponentRegistry<>("Trigger"); } @@ -76,7 +76,7 @@ public class RegistryCollectionImpl implements RegistryCollection { * @see de.tobias.playpad.RegistryCollection#getPadContentRegistry() */ @Override - public Registry<PadContentConnect> getPadContents() { + public PadContentRegistry getPadContents() { return padContentRegistry; } diff --git a/PlayWall/src/de/tobias/playpad/design/classic/ClassicCartDesign.java b/PlayWall/src/de/tobias/playpad/design/classic/ClassicCartDesign.java index 687da681..b0acae1a 100644 --- a/PlayWall/src/de/tobias/playpad/design/classic/ClassicCartDesign.java +++ b/PlayWall/src/de/tobias/playpad/design/classic/ClassicCartDesign.java @@ -13,11 +13,11 @@ import org.dom4j.io.XMLWriter; import de.tobias.playpad.PseudoClasses; import de.tobias.playpad.design.CartDesign; -import de.tobias.playpad.design.GlobalDesign; import de.tobias.playpad.design.Design; -import de.tobias.playpad.pad.view.IPadViewController; +import de.tobias.playpad.design.GlobalDesign; +import de.tobias.playpad.pad.view.IPadViewV2; +import de.tobias.playpad.pad.viewcontroller.IPadViewControllerV2; import de.tobias.playpad.settings.Warning; -import de.tobias.playpad.viewcontroller.IPadView; import de.tobias.utils.util.ColorXMLUtils; import javafx.application.Platform; import javafx.scene.paint.Color; @@ -210,8 +210,8 @@ public class ClassicCartDesign extends Design implements CartDesign { } @Override - public void handleWarning(IPadViewController controller, Warning warning, GlobalDesign layout) { - final IPadView view = controller.getParent(); + public void handleWarning(IPadViewControllerV2 controller, Warning warning, GlobalDesign layout) { + final IPadViewV2 view = controller.getView(); try { while (true) { diff --git a/PlayWall/src/de/tobias/playpad/design/classic/ClassicGlobalDesign.java b/PlayWall/src/de/tobias/playpad/design/classic/ClassicGlobalDesign.java index c1be114b..5fdea5f9 100644 --- a/PlayWall/src/de/tobias/playpad/design/classic/ClassicGlobalDesign.java +++ b/PlayWall/src/de/tobias/playpad/design/classic/ClassicGlobalDesign.java @@ -8,13 +8,13 @@ import org.dom4j.Element; import de.tobias.playpad.PseudoClasses; import de.tobias.playpad.design.CartDesign; -import de.tobias.playpad.design.GlobalDesign; import de.tobias.playpad.design.Design; +import de.tobias.playpad.design.GlobalDesign; import de.tobias.playpad.pad.Pad; -import de.tobias.playpad.pad.view.IPadViewController; +import de.tobias.playpad.pad.view.IPadViewV2; +import de.tobias.playpad.pad.viewcontroller.IPadViewControllerV2; import de.tobias.playpad.project.Project; import de.tobias.playpad.settings.Warning; -import de.tobias.playpad.viewcontroller.IPadView; import de.tobias.playpad.viewcontroller.main.IMainViewController; import de.tobias.utils.application.ApplicationUtils; import de.tobias.utils.application.container.PathType; @@ -345,8 +345,8 @@ public class ClassicGlobalDesign extends Design implements GlobalDesign { } @Override - public void handleWarning(IPadViewController controller, Warning warning) { - final IPadView view = controller.getParent(); + public void handleWarning(IPadViewControllerV2 controller, Warning warning) { + final IPadViewV2 view = controller.getView(); try { while (true) { diff --git a/PlayWall/src/de/tobias/playpad/design/modern/ModernCartDesign.java b/PlayWall/src/de/tobias/playpad/design/modern/ModernCartDesign.java index 89d4b6e9..bc5d49f3 100644 --- a/PlayWall/src/de/tobias/playpad/design/modern/ModernCartDesign.java +++ b/PlayWall/src/de/tobias/playpad/design/modern/ModernCartDesign.java @@ -4,13 +4,13 @@ import org.dom4j.Element; import de.tobias.playpad.PseudoClasses; import de.tobias.playpad.design.CartDesign; -import de.tobias.playpad.design.FadeableColor; -import de.tobias.playpad.design.GlobalDesign; import de.tobias.playpad.design.Design; import de.tobias.playpad.design.DesignColorAssociator; +import de.tobias.playpad.design.FadeableColor; +import de.tobias.playpad.design.GlobalDesign; import de.tobias.playpad.pad.Pad; import de.tobias.playpad.pad.conntent.play.Durationable; -import de.tobias.playpad.pad.view.IPadViewController; +import de.tobias.playpad.pad.viewcontroller.IPadViewControllerV2; import de.tobias.playpad.settings.Warning; import javafx.scene.paint.Color; import javafx.util.Duration; @@ -75,7 +75,7 @@ public class ModernCartDesign extends Design implements CartDesign, DesignColorA // Warn Handler -> Animation oder Blinken @Override - public void handleWarning(IPadViewController controller, Warning warning, GlobalDesign layout) { + public void handleWarning(IPadViewControllerV2 controller, Warning warning, GlobalDesign layout) { if (layout instanceof ModernGlobalDesign && ((ModernGlobalDesign) layout).isWarnAnimation()) { warnAnimation(controller, warning); } else { @@ -84,11 +84,11 @@ public class ModernCartDesign extends Design implements CartDesign, DesignColorA } @Override - public void stopWarning(IPadViewController controller) { + public void stopWarning(IPadViewControllerV2 controller) { ModernDesignAnimator.stopAnimation(controller); } - private void warnAnimation(IPadViewController controller, Warning warning) { + private void warnAnimation(IPadViewControllerV2 controller, Warning warning) { FadeableColor stopColor = new FadeableColor(this.backgroundColor.getColorHi(), this.backgroundColor.getColorLow()); FadeableColor playColor = new FadeableColor(this.playColor.getColorHi(), this.playColor.getColorLow()); diff --git a/PlayWall/src/de/tobias/playpad/design/modern/ModernDesignAnimator.java b/PlayWall/src/de/tobias/playpad/design/modern/ModernDesignAnimator.java index 60d6384d..95afa80a 100644 --- a/PlayWall/src/de/tobias/playpad/design/modern/ModernDesignAnimator.java +++ b/PlayWall/src/de/tobias/playpad/design/modern/ModernDesignAnimator.java @@ -4,8 +4,8 @@ import java.util.HashMap; import de.tobias.playpad.PseudoClasses; import de.tobias.playpad.design.FadeableColor; -import de.tobias.playpad.pad.view.IPadViewController; -import de.tobias.playpad.viewcontroller.IPadView; +import de.tobias.playpad.pad.view.IPadViewV2; +import de.tobias.playpad.pad.viewcontroller.IPadViewControllerV2; import javafx.animation.KeyFrame; import javafx.animation.KeyValue; import javafx.animation.Timeline; @@ -23,7 +23,7 @@ public class ModernDesignAnimator { private static HashMap<Integer, Timeline> timelines = new HashMap<>(); - public static void animateFade(IPadViewController padViewController, FadeableColor startColor, FadeableColor endColor, Duration duration) { + public static void animateFade(IPadViewControllerV2 padViewController, FadeableColor startColor, FadeableColor endColor, Duration duration) { int index = padViewController.getPad().getIndex(); if (timelines.containsKey(index)) { @@ -34,7 +34,7 @@ public class ModernDesignAnimator { @Override public void changed(ObservableValue<? extends FadeableColor> observable, FadeableColor oldValue, FadeableColor newValue) { - padViewController.getParent().setStyle("-fx-background-color: " + newValue.toString() + ";"); + padViewController.getView().setStyle("-fx-background-color: " + newValue.toString() + ";"); } }; @@ -48,7 +48,7 @@ public class ModernDesignAnimator { timeline.setOnFinished(event -> { backgroundColor.removeListener(fadeListener); - padViewController.getParent().setStyle(""); + padViewController.getView().setStyle(""); timelines.remove(index); }); @@ -57,7 +57,7 @@ public class ModernDesignAnimator { } - public static void animateWarn(IPadViewController padViewController, FadeableColor startColor, FadeableColor endColor, Duration duration) { + public static void animateWarn(IPadViewControllerV2 padViewController, FadeableColor startColor, FadeableColor endColor, Duration duration) { int index = padViewController.getPad().getIndex(); if (timelines.containsKey(index)) { @@ -68,7 +68,7 @@ public class ModernDesignAnimator { @Override public void changed(ObservableValue<? extends FadeableColor> observable, FadeableColor oldValue, FadeableColor newValue) { - padViewController.getParent().setStyle("-fx-background-color: " + newValue.toString() + ";"); + padViewController.getView().setStyle("-fx-background-color: " + newValue.toString() + ";"); } }; @@ -87,7 +87,7 @@ public class ModernDesignAnimator { timeline.setOnFinished(event -> { backgroundColor.removeListener(fadeListener); - padViewController.getParent().setStyle(""); + padViewController.getView().setStyle(""); timelines.remove(index); }); @@ -95,7 +95,7 @@ public class ModernDesignAnimator { timelines.put(index, timeline); } - public static void stopAnimation(IPadViewController controller) { + public static void stopAnimation(IPadViewControllerV2 controller) { int index = controller.getPad().getIndex(); if (timelines.containsKey(index)) { @@ -103,8 +103,8 @@ public class ModernDesignAnimator { } } - public static void warnFlash(IPadViewController controller) { - final IPadView view = controller.getParent(); + public static void warnFlash(IPadViewControllerV2 controller) { + final IPadViewV2 view = controller.getView(); try { while (true) { Platform.runLater(() -> diff --git a/PlayWall/src/de/tobias/playpad/design/modern/ModernGlobalDesign.java b/PlayWall/src/de/tobias/playpad/design/modern/ModernGlobalDesign.java index 9e83d98b..0316c2b8 100644 --- a/PlayWall/src/de/tobias/playpad/design/modern/ModernGlobalDesign.java +++ b/PlayWall/src/de/tobias/playpad/design/modern/ModernGlobalDesign.java @@ -14,7 +14,7 @@ import de.tobias.playpad.design.FadeableColor; import de.tobias.playpad.design.GlobalDesign; import de.tobias.playpad.pad.Pad; import de.tobias.playpad.pad.conntent.play.Durationable; -import de.tobias.playpad.pad.view.IPadViewController; +import de.tobias.playpad.pad.viewcontroller.IPadViewControllerV2; import de.tobias.playpad.project.Project; import de.tobias.playpad.settings.Profile; import de.tobias.playpad.settings.Warning; @@ -274,7 +274,7 @@ public class ModernGlobalDesign extends Design implements GlobalDesign, DesignCo // Warn Handler -> Animation oder Blinken @Override - public void handleWarning(IPadViewController controller, Warning warning) { + public void handleWarning(IPadViewControllerV2 controller, Warning warning) { if (isWarnAnimation) { warnAnimation(controller, warning); } else { @@ -283,11 +283,11 @@ public class ModernGlobalDesign extends Design implements GlobalDesign, DesignCo } @Override - public void stopWarning(IPadViewController controller) { + public void stopWarning(IPadViewControllerV2 controller) { ModernDesignAnimator.stopAnimation(controller); } - private void warnAnimation(IPadViewController controller, Warning warning) { + private void warnAnimation(IPadViewControllerV2 controller, Warning warning) { FadeableColor stopColor = new FadeableColor(this.backgroundColor.getColorHi(), this.backgroundColor.getColorLow()); FadeableColor playColor = new FadeableColor(this.playColor.getColorHi(), this.playColor.getColorLow()); diff --git a/PlayWall/src/de/tobias/playpad/layout/desktop/BasicMenuToolbarViewController.java b/PlayWall/src/de/tobias/playpad/layout/desktop/BasicMenuToolbarViewController.java index 51a5804d..428eb640 100644 --- a/PlayWall/src/de/tobias/playpad/layout/desktop/BasicMenuToolbarViewController.java +++ b/PlayWall/src/de/tobias/playpad/layout/desktop/BasicMenuToolbarViewController.java @@ -1,10 +1,52 @@ 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 java.util.ResourceBundle; +import de.tobias.playpad.AppUserInfoStrings; +import de.tobias.playpad.PlayPadMain; +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.settings.Profile; +import de.tobias.playpad.settings.ProfileListener; +import de.tobias.playpad.settings.ProfileNotFoundException; +import de.tobias.playpad.settings.ProfileSettings; +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.IMainViewController; import de.tobias.playpad.viewcontroller.main.MenuToolbarViewController; +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.beans.value.ChangeListener; +import javafx.beans.value.ObservableValue; 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; @@ -13,9 +55,12 @@ import javafx.scene.control.MenuItem; import javafx.scene.control.Slider; import javafx.scene.control.ToolBar; import javafx.scene.layout.HBox; +import javafx.stage.Modality; +import javafx.stage.Stage; -public abstract class BasicMenuToolbarViewController extends MenuToolbarViewController { +public abstract class BasicMenuToolbarViewController extends MenuToolbarViewController implements ProfileListener, EventHandler<ActionEvent> { + // Menu @FXML protected Label volumeUpLabel; @FXML protected HBox iconHbox; @FXML protected MenuItem errorMenu; @@ -34,81 +79,307 @@ public abstract class BasicMenuToolbarViewController extends MenuToolbarViewCont @FXML protected CheckMenuItem dndModeMenuItem; @FXML protected CheckMenuItem alwaysOnTopItem; - public BasicMenuToolbarViewController(String name, String path, ResourceBundle localization) { + // Toolbar + private Label lockedLabel; + + private ChangeListener<Boolean> lockedListener; + + // window references + private IMainViewController mainViewController; + private SettingsViewController settingsViewController; + + public BasicMenuToolbarViewController(String name, String path, ResourceBundle localization, IMainViewController mainViewController) { super(name, path, localization); + this.mainViewController = mainViewController; + + ProfileSettings profileSettings = Profile.currentProfile().getProfileSettings(); + Profile.registerListener(this); // Update, wenn sich das Profil ändert (remove Listener & add Listener) + + // Listener + lockedListener = new ChangeListener<Boolean>() { + + @Override + public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) { + dndModeMenuItem.setDisable(newValue); + } + }; + profileSettings.lockedProperty().addListener(lockedListener); + lockedListener.changed(profileSettings.lockedProperty(), null, profileSettings.isLocked()); + + // Info Icons + lockedLabel = new Label(); + lockedLabel.setGraphic(new FontIcon(FontAwesomeType.LOCK)); + lockedListener.changed(profileSettings.lockedProperty(), null, profileSettings.isLocked()); + + // Icons Volume + volumeDownLabel.setGraphic(new FontIcon("volume-item", FontAwesomeType.VOLUME_DOWN)); + volumeUpLabel.setGraphic(new FontIcon("volume-item", FontAwesomeType.VOLUME_UP)); + + volumeSlider.setOnScroll(ev -> + { + volumeSlider.setValue(volumeSlider.getValue() - ev.getDeltaY() * 0.001); + volumeSlider.setValue(volumeSlider.getValue() + ev.getDeltaX() * 0.001); + }); + } - toolbarHBox.prefWidthProperty().bind(toolbar.widthProperty().subtract(25)); - toolbarHBox.prefHeightProperty().bind(toolbar.minHeightProperty()); + // Profile Listener + @Override + public void reloadSettings(Profile oldProfile, Profile currentProfile) { + if (oldProfile != null) { + oldProfile.getProfileSettings().lockedProperty().removeListener(lockedListener); + } + ProfileSettings profileSettings = currentProfile.getProfileSettings(); + profileSettings.lockedProperty().addListener(lockedListener); + lockedListener.changed(profileSettings.lockedProperty(), null, profileSettings.isLocked()); } + // 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 + protected void doAction(Runnable run) { + Project project = PlayPadMain.getProgramInstance().getCurrentProject(); + if (project.getPlayedPlayers() > 0 && Profile.currentProfile().getProfileSettings().isLiveMode()) { + mainViewController.showLiveInfo(); + } else { + run.run(); + } } } diff --git a/PlayWall/src/de/tobias/playpad/layout/desktop/DesktopMenuToolbarViewController.java b/PlayWall/src/de/tobias/playpad/layout/desktop/DesktopMenuToolbarViewController.java index 6a04c32f..20026f81 100644 --- a/PlayWall/src/de/tobias/playpad/layout/desktop/DesktopMenuToolbarViewController.java +++ b/PlayWall/src/de/tobias/playpad/layout/desktop/DesktopMenuToolbarViewController.java @@ -1,10 +1,17 @@ package de.tobias.playpad.layout.desktop; import de.tobias.playpad.PlayPadMain; +import de.tobias.playpad.Strings; +import de.tobias.playpad.project.Project; +import de.tobias.playpad.project.ProjectNotFoundException; +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.MenuType; +import de.tobias.playpad.viewcontroller.dialog.ImportDialog; import de.tobias.playpad.viewcontroller.main.IMainViewController; +import de.tobias.utils.util.Localization; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.scene.control.Button; @@ -16,18 +23,21 @@ public class DesktopMenuToolbarViewController extends BasicMenuToolbarViewContro private IMainViewController mainViewController; public DesktopMenuToolbarViewController(IMainViewController controller) { - super("header", "de/tobias/playpad/assets/view/main/desktop/", PlayPadMain.getUiResourceBundle()); + super("header", "de/tobias/playpad/assets/view/main/desktop/", PlayPadMain.getUiResourceBundle(), controller); this.mainViewController = controller; + + toolbarHBox.prefWidthProperty().bind(toolbar.widthProperty().subtract(25)); + toolbarHBox.prefHeightProperty().bind(toolbar.minHeightProperty()); } @Override - public void initPages() { + public void initPageButtons() { pageHBox.getChildren().clear(); ProfileSettings settings = Profile.currentProfile().getProfileSettings(); for (int i = 0; i < settings.getPageCount(); i++) { - Button button = new Button("Seite: " + (i + 1)); + Button button = new Button(Localization.getString(Strings.UI_Window_Main_PageButton, (i + 1))); button.setUserData(i); button.setOnAction(this); pageHBox.getChildren().add(button); @@ -36,42 +46,44 @@ public class DesktopMenuToolbarViewController extends BasicMenuToolbarViewContro @Override public void setLocked(boolean looked) { - + // TODO Implement } @Override public void addToolbarIcon(Image icon) { - + // TODO Implement } @Override public void removeToolbarIcon(Image icon) { - + // TODO Implement } @Override public void addMenuItem(MenuItem item, MenuType type) { - + // TODO Implement } @Override public void removeMenuItem(MenuItem item) { - + // TODO Implement } @Override public boolean isAlwaysOnTopActive() { + // TODO Imeplement return false; } @Override public boolean isFullscreenActive() { + //TODO Implement return false; } @Override public void deinit() { - + // TODO Implement } @Override @@ -80,6 +92,33 @@ public class DesktopMenuToolbarViewController extends BasicMenuToolbarViewContro Button button = (Button) event.getSource(); int page = (int) button.getUserData(); mainViewController.showPage(page); + } else if (event.getSource() instanceof MenuItem) { + // Zuletzt verwendete Projects + doAction(() -> + { + // TODO Rewrite mit openProject von BasicMenuToolbarViewController + MenuItem item = (MenuItem) event.getSource(); + ProjectReference ref = (ProjectReference) item.getUserData(); + try { + // Speichern das alte Project in mvc.setProject(Project) + Project project = Project.load(ref, true, ImportDialog.getInstance(mainViewController.getStage())); + PlayPadMain.getProgramInstance().openProject(project); + } catch (ProfileNotFoundException e) { + e.printStackTrace(); + mainViewController.showError( + Localization.getString(Strings.Error_Profile_NotFound, ref.getProfileReference(), e.getLocalizedMessage())); + + // Neues Profile wählen + Profile profile = ImportDialog.getInstance(mainViewController.getStage()).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())); + } + }); } } } diff --git a/PlayWall/src/de/tobias/playpad/layout/desktop/DesktopPadView.java b/PlayWall/src/de/tobias/playpad/layout/desktop/DesktopPadView.java index f8f7471a..16ab7c5d 100644 --- a/PlayWall/src/de/tobias/playpad/layout/desktop/DesktopPadView.java +++ b/PlayWall/src/de/tobias/playpad/layout/desktop/DesktopPadView.java @@ -1,6 +1,7 @@ package de.tobias.playpad.layout.desktop; import de.tobias.playpad.PlayPadPlugin; +import de.tobias.playpad.PseudoClasses; import de.tobias.playpad.pad.Pad; import de.tobias.playpad.pad.conntent.PadContent; import de.tobias.playpad.pad.conntent.PadContentConnect; @@ -123,7 +124,6 @@ public class DesktopPadView implements IPadViewV2 { @Override public void setContentView(Pad pad) { if (previewContent != null) { - previewContent.unconnect(); // TODO previewContent.deinit(); } @@ -165,7 +165,7 @@ public class DesktopPadView implements IPadViewV2 { @Override public void enableDragAndDropDesignMode(boolean enable) { - + pseudoClassState(PseudoClasses.DRAG_CLASS, enable); } @Override @@ -187,14 +187,30 @@ public class DesktopPadView implements IPadViewV2 { } @Override - public void pseudoClassState(PseudoClass playCalss, boolean b) { - // TODO Auto-generated method stub + public void pseudoClassState(PseudoClass pseudoClass, boolean active) { + superRoot.pseudoClassStateChanged(pseudoClass, active); + indexLabel.pseudoClassStateChanged(pseudoClass, active); + timeLabel.pseudoClassStateChanged(pseudoClass, active); + loopLabel.getGraphic().pseudoClassStateChanged(pseudoClass, active); + triggerLabel.getGraphic().pseudoClassStateChanged(pseudoClass, active); + errorLabel.getGraphic().pseudoClassStateChanged(pseudoClass, active); + + if (preview != null) { + preview.getChildren().forEach(i -> i.pseudoClassStateChanged(pseudoClass, active)); + } + + playBar.pseudoClassStateChanged(pseudoClass, active); + playButton.getGraphic().pseudoClassStateChanged(pseudoClass, active); + pauseButton.getGraphic().pseudoClassStateChanged(pseudoClass, active); + stopButton.getGraphic().pseudoClassStateChanged(pseudoClass, active); + newButton.getGraphic().pseudoClassStateChanged(pseudoClass, active); + settingsButton.getGraphic().pseudoClassStateChanged(pseudoClass, active); } @Override public void setStyle(String string) { - // TODO Auto-generated method stub + superRoot.setStyle(string); } @@ -235,6 +251,14 @@ public class DesktopPadView implements IPadViewV2 { triggerLabel.setVisible(hasTriggerItems); } + public void setTime(String time) { + if (time == null) { + timeLabel.setText(""); + } else { + timeLabel.setText(time); + } + } + @Override public void addDefaultButton(Pad pad) { if (pad != null) { @@ -330,4 +354,24 @@ public class DesktopPadView implements IPadViewV2 { buttonBox.getStyleClass().add("pad-button-box"); root.getStyleClass().add("pad-root"); } + + public void clearIndex() { + indexLabel.setText(""); + } + + public void clearTime() { + timeLabel.setText(""); + } + + public void clearPreviewContent() { + if (previewContent != null) { + previewContent.deinit(); + } + setContentView(null); + } + + @Override + public void setPlaybarVisible(boolean visible) { + playBar.setVisible(visible); + } } diff --git a/PlayWall/src/de/tobias/playpad/layout/desktop/DesktopPadViewController.java b/PlayWall/src/de/tobias/playpad/layout/desktop/DesktopPadViewController.java index b1c80edd..03fa9b1c 100644 --- a/PlayWall/src/de/tobias/playpad/layout/desktop/DesktopPadViewController.java +++ b/PlayWall/src/de/tobias/playpad/layout/desktop/DesktopPadViewController.java @@ -1,7 +1,11 @@ package de.tobias.playpad.layout.desktop; +import de.tobias.playpad.PlayPadPlugin; import de.tobias.playpad.pad.Pad; import de.tobias.playpad.pad.PadStatus; +import de.tobias.playpad.pad.TimeMode; +import de.tobias.playpad.pad.conntent.play.Durationable; +import de.tobias.playpad.pad.listener.IPadPositionListener; import de.tobias.playpad.pad.listener.PadContentListener; import de.tobias.playpad.pad.listener.PadDurationListener; import de.tobias.playpad.pad.listener.PadLockedListener; @@ -11,13 +15,21 @@ import de.tobias.playpad.pad.view.IPadViewV2; import de.tobias.playpad.pad.viewcontroller.IPadViewControllerV2; import de.tobias.playpad.settings.Profile; import de.tobias.playpad.settings.ProfileSettings; +import de.tobias.playpad.viewcontroller.main.IMainViewController; import de.tobias.playpad.viewcontroller.option.pad.PadSettingsViewController; import de.tobias.playpad.viewcontroller.pad.PadDragListener; +import javafx.beans.value.ChangeListener; import javafx.event.ActionEvent; import javafx.event.EventHandler; +import javafx.stage.Stage; +import javafx.util.Duration; public class DesktopPadViewController implements IPadViewControllerV2, EventHandler<ActionEvent> { + protected static final String CURRENT_PAGE_BUTTON = "current-page-button"; + + private static final String DURATION_FORMAT = "%d:%02d"; + private DesktopPadView padView; private Pad pad; @@ -25,7 +37,7 @@ public class DesktopPadViewController implements IPadViewControllerV2, EventHand private PadStatusListener padStatusListener; private PadContentListener padContentListener; private PadDurationListener padDurationListener; - private PadPositionListener padPositionListener; + private IPadPositionListener padPositionListener; private PadDragListener padDragListener; private transient PadSettingsViewController padSettingsViewController; @@ -84,16 +96,41 @@ public class DesktopPadViewController implements IPadViewControllerV2, EventHand } catch (Exception e) { e.printStackTrace(); } + padView.applyStyleClasses(); padView.setContentView(pad); } @Override public void removePad() { - if (padView != null && pad != null) + if (padView != null && pad != null) { + + padView.clearIndex(); + padView.clearPreviewContent(); + padView.clearTime(); + + padView.setTriggerLabelActive(false); + + padView.loopLabelVisibleProperty().unbind(); + + pad.contentProperty().removeListener(padContentListener); + pad.statusProperty().removeListener(padStatusListener); + + if (pad.getContent() instanceof Durationable) { + Durationable durationable = (Durationable) pad.getContent(); + durationable.durationProperty().removeListener(padDurationListener); + durationable.positionProperty().removeListener(padPositionListener); + } + pad.setController(null); + padDragListener = null; + + // GUI Cleaning + padPositionListener.stopWaning(); padView.removeStyleClasses(); + } - pad = null; + this.padDragListener = null; + this.pad = null; } @Override @@ -130,16 +167,83 @@ public class DesktopPadViewController implements IPadViewControllerV2, EventHand } private void onNew(ActionEvent event) { - + // TODO Implement } private void onSettings() { + ProfileSettings settings = Profile.currentProfile().getProfileSettings(); + IMainViewController mvc = PlayPadPlugin.getImplementation().getMainViewController(); + + if (mvc != null) { + if (pad.getProject() != null) { + if (settings.isLiveMode() && settings.isLiveModeSettings() && pad.getProject().getPlayedPlayers() > 0) { + mvc.showLiveInfo(); + return; + } + } + Stage owner = mvc.getStage(); + if (padSettingsViewController == null) { + padSettingsViewController = new PadSettingsViewController(pad, owner); + padSettingsViewController.getStage().setOnHiding(ev -> + { + if (padView != null && pad != null) + padView.setTriggerLabelActive(pad.hasTriggerItems()); + }); + } + padSettingsViewController.getStage().show(); + } } @Override public void updateTimeLabel() { + if (pad.getContent() != null && pad.getStatus() != PadStatus.EMPTY && pad.getStatus() != PadStatus.ERROR) { + if (pad.getContent() instanceof Durationable) { + Durationable durationable = (Durationable) pad.getContent(); + + Duration duration = durationable.getDuration(); + Duration position = durationable.getPosition(); + + if (duration != null) { + // Nur Gesamtzeit anzeigen + if (pad.getStatus() == PadStatus.READY || position == null) { + String time = durationToString(duration); + padView.setTime(time); + padView.getPlayBar().setProgress(0); + } else { + // Play/Gesamtzeit anzeigen + TimeMode timeMode = pad.getTimeMode(); + + if (timeMode == TimeMode.REST) { + Duration leftTime = duration.subtract(position); + + padView.setTime("- " + durationToString(leftTime)); + } else if (timeMode == TimeMode.PLAYED) { + padView.setTime(durationToString(position)); + } else if (timeMode == TimeMode.BOTH) { + String time = durationToString(position); + String totalTime = durationToString(duration); + + padView.setTime(time + "/" + totalTime); + } + } + } + return; + } + } + padView.getPlayBar().setProgress(0); + padView.setTime(null); + } + public String durationToString(Duration value) { + if (value != null) { + int secounds = (int) ((value.toMillis() / 1000) % 60); + int minutes = (int) ((value.toMillis() / (1000 * 60)) % 60); + String time = String.format(DURATION_FORMAT, minutes, secounds); + return time; + } else { + return null; + } } @Override @@ -194,4 +298,17 @@ public class DesktopPadViewController implements IPadViewControllerV2, EventHand } } + @Override + public IPadPositionListener getPadPositionListener() { + return padPositionListener; + } + + @Override + public ChangeListener<Duration> getPadDurationListener() { + return padDurationListener; + } + + public PadDragListener getPadDragListener() { + return padDragListener; + } } diff --git a/PlayWall/src/de/tobias/playpad/layout/touch/TouchMainLayoutConnect.java b/PlayWall/src/de/tobias/playpad/layout/touch/TouchMainLayoutConnect.java index 9a32c2c4..7a4351cf 100644 --- a/PlayWall/src/de/tobias/playpad/layout/touch/TouchMainLayoutConnect.java +++ b/PlayWall/src/de/tobias/playpad/layout/touch/TouchMainLayoutConnect.java @@ -19,7 +19,7 @@ public class TouchMainLayoutConnect implements MainLayoutConnect { @Override public MenuToolbarViewController createMenuToolbar(IMainViewController mainViewRef) { - return new TouchMenuToolbarViewController(); + return new TouchMenuToolbarViewController(mainViewRef); } @Override diff --git a/PlayWall/src/de/tobias/playpad/layout/touch/TouchMenuToolbarViewController.java b/PlayWall/src/de/tobias/playpad/layout/touch/TouchMenuToolbarViewController.java index dc037696..a34ba1a0 100644 --- a/PlayWall/src/de/tobias/playpad/layout/touch/TouchMenuToolbarViewController.java +++ b/PlayWall/src/de/tobias/playpad/layout/touch/TouchMenuToolbarViewController.java @@ -3,17 +3,19 @@ package de.tobias.playpad.layout.touch; import de.tobias.playpad.PlayPadMain; import de.tobias.playpad.layout.desktop.BasicMenuToolbarViewController; import de.tobias.playpad.view.main.MenuType; +import de.tobias.playpad.viewcontroller.main.IMainViewController; +import javafx.event.ActionEvent; import javafx.scene.control.MenuItem; import javafx.scene.image.Image; public class TouchMenuToolbarViewController extends BasicMenuToolbarViewController { - public TouchMenuToolbarViewController() { - super("header", "de/tobias/playpad/assets/view/main/touch/", PlayPadMain.getUiResourceBundle()); + public TouchMenuToolbarViewController(IMainViewController mainViewController) { + super("header", "de/tobias/playpad/assets/view/main/touch/", PlayPadMain.getUiResourceBundle(), mainViewController); } @Override - public void initPages() { + public void initPageButtons() { } @@ -57,4 +59,10 @@ public class TouchMenuToolbarViewController extends BasicMenuToolbarViewControll } + @Override + public void handle(ActionEvent event) { + // TODO Auto-generated method stub + + } + } \ No newline at end of file diff --git a/PlayWall/src/de/tobias/playpad/layout/touch/TouchPadView.java b/PlayWall/src/de/tobias/playpad/layout/touch/TouchPadView.java index 0a7096d2..bba559de 100644 --- a/PlayWall/src/de/tobias/playpad/layout/touch/TouchPadView.java +++ b/PlayWall/src/de/tobias/playpad/layout/touch/TouchPadView.java @@ -81,4 +81,10 @@ public class TouchPadView implements IPadViewV2 { // TODO Auto-generated method stub } + + @Override + public void setPlaybarVisible(boolean visible) { + // TODO Auto-generated method stub + + } } diff --git a/PlayWall/src/de/tobias/playpad/layout/touch/TouchPadViewController.java b/PlayWall/src/de/tobias/playpad/layout/touch/TouchPadViewController.java index fea00dee..9d0601b3 100644 --- a/PlayWall/src/de/tobias/playpad/layout/touch/TouchPadViewController.java +++ b/PlayWall/src/de/tobias/playpad/layout/touch/TouchPadViewController.java @@ -1,8 +1,11 @@ package de.tobias.playpad.layout.touch; import de.tobias.playpad.pad.Pad; +import de.tobias.playpad.pad.listener.IPadPositionListener; import de.tobias.playpad.pad.view.IPadViewV2; import de.tobias.playpad.pad.viewcontroller.IPadViewControllerV2; +import javafx.beans.value.ChangeListener; +import javafx.util.Duration; public class TouchPadViewController implements IPadViewControllerV2 { @@ -38,4 +41,16 @@ public class TouchPadViewController implements IPadViewControllerV2 { } + @Override + public IPadPositionListener getPadPositionListener() { + // TODO Auto-generated method stub + return null; + } + + @Override + public ChangeListener<Duration> getPadDurationListener() { + // TODO Auto-generated method stub + return null; + } + } diff --git a/PlayWall/src/de/tobias/playpad/pad/listener/PadContentListener.java b/PlayWall/src/de/tobias/playpad/pad/listener/PadContentListener.java index 98d4deb2..728e1590 100644 --- a/PlayWall/src/de/tobias/playpad/pad/listener/PadContentListener.java +++ b/PlayWall/src/de/tobias/playpad/pad/listener/PadContentListener.java @@ -2,6 +2,7 @@ package de.tobias.playpad.pad.listener; import de.tobias.playpad.pad.Pad; import de.tobias.playpad.pad.conntent.PadContent; +import de.tobias.playpad.pad.conntent.play.Durationable; import de.tobias.playpad.pad.viewcontroller.IPadViewControllerV2; import javafx.beans.value.ChangeListener; import javafx.beans.value.ObservableValue; @@ -22,32 +23,32 @@ public class PadContentListener implements ChangeListener<PadContent> { @Override public void changed(ObservableValue<? extends PadContent> observable, PadContent oldValue, PadContent newValue) { // wenn Content change, update preview & buttons -// controller.getView().setPreviewContent(pad); + controller.getView().setContentView(pad); controller.getView().addDefaultButton(pad); controller.updateButtonDisable(); controller.updateTimeLabel(); // TODO PadContentListener -// // Remove old listener -// if (oldValue != null && oldValue instanceof Durationable) { -// Durationable oldDurationable = (Durationable) oldValue; -// oldDurationable.durationProperty().removeListener(controller.getPadDurationListener()); -// oldDurationable.positionProperty().removeListener(controller.getPadPositionListener()); -// } -// -// // set new content listener / bindings -// if (newValue instanceof Durationable) { -// controller.getView().showPlaybar(true); -// -// Durationable durationable = (Durationable) newValue; -// durationable.durationProperty().addListener(controller.getPadDurationListener()); -// durationable.positionProperty().addListener(controller.getPadPositionListener()); -// -// // Init Duration -// controller.getPadDurationListener().changed(null, null, durationable.getDuration()); -// } else { -// controller.getParent().showPlaybar(false); -// } + // // Remove old listener + if (oldValue != null && oldValue instanceof Durationable) { + Durationable oldDurationable = (Durationable) oldValue; + oldDurationable.durationProperty().removeListener(controller.getPadDurationListener()); + oldDurationable.positionProperty().removeListener(controller.getPadPositionListener()); + } + // + // // set new content listener / bindings + if (newValue instanceof Durationable) { + controller.getView().setPlaybarVisible(true); + + Durationable durationable = (Durationable) newValue; + durationable.durationProperty().addListener(controller.getPadDurationListener()); + durationable.positionProperty().addListener(controller.getPadPositionListener()); + + // // Init Duration + controller.getPadDurationListener().changed(null, null, durationable.getDuration()); + } else { + controller.getView().setPlaybarVisible(false); + } } } diff --git a/PlayWall/src/de/tobias/playpad/pad/listener/PadPositionListener.java b/PlayWall/src/de/tobias/playpad/pad/listener/PadPositionListener.java index fe7197d1..db5081c5 100644 --- a/PlayWall/src/de/tobias/playpad/pad/listener/PadPositionListener.java +++ b/PlayWall/src/de/tobias/playpad/pad/listener/PadPositionListener.java @@ -8,11 +8,10 @@ import de.tobias.playpad.pad.conntent.play.Fadeable; import de.tobias.playpad.pad.viewcontroller.IPadViewControllerV2; import de.tobias.playpad.settings.Profile; import de.tobias.playpad.settings.Warning; -import javafx.beans.value.ChangeListener; import javafx.beans.value.ObservableValue; import javafx.util.Duration; -public class PadPositionListener implements ChangeListener<Duration>, Runnable { +public class PadPositionListener implements Runnable, IPadPositionListener { private Pad pad; private IPadViewControllerV2 controller; @@ -21,6 +20,7 @@ public class PadPositionListener implements ChangeListener<Duration>, Runnable { this.controller = controller; } + @Override public void setPad(Pad pad) { this.pad = pad; } @@ -76,6 +76,7 @@ public class PadPositionListener implements ChangeListener<Duration>, Runnable { } } + @Override public void setSend(boolean send) { this.send = send; } @@ -88,9 +89,9 @@ public class PadPositionListener implements ChangeListener<Duration>, Runnable { Warning warning = pad.getWarning(); if (pad.isCustomLayout()) { -// pad.getLayout().handleWarning(controller, warning, Profile.currentProfile().currentLayout()); TODO StartWarning + pad.getLayout().handleWarning(controller, warning, Profile.currentProfile().currentLayout()); } else { -// Profile.currentProfile().currentLayout().handleWarning(controller, warning); TODO Start Wanring + Profile.currentProfile().currentLayout().handleWarning(controller, warning); } } @@ -102,6 +103,7 @@ public class PadPositionListener implements ChangeListener<Duration>, Runnable { warningThread.start(); } + @Override public void stopWaning() { if (warningThread != null) { warningThread.interrupt(); @@ -109,9 +111,9 @@ public class PadPositionListener implements ChangeListener<Duration>, Runnable { } if (pad.isCustomLayout()) { -// pad.getLayout().stopWarning(controller); TODO Stop Warning + pad.getLayout().stopWarning(controller); } else { -// Profile.currentProfile().currentLayout().stopWarning(controller); TODO Stop Warning + Profile.currentProfile().currentLayout().stopWarning(controller); } controller.getView().setStyle(""); } diff --git a/PlayWall/src/de/tobias/playpad/pad/listener/PadStatusListener.java b/PlayWall/src/de/tobias/playpad/pad/listener/PadStatusListener.java index d3dad9d8..49329253 100644 --- a/PlayWall/src/de/tobias/playpad/pad/listener/PadStatusListener.java +++ b/PlayWall/src/de/tobias/playpad/pad/listener/PadStatusListener.java @@ -23,21 +23,21 @@ public class PadStatusListener implements ChangeListener<PadStatus> { switch (newValue) { case PLAY: // Reset Warning Feedback for UI - // controller.getPadPositionListener().setSend(false); TODO Warning + controller.getPadPositionListener().setSend(false); // UI Styling controller.getView().pseudoClassState(PseudoClasses.PLAY_CALSS, true); break; case PAUSE: - // controller.getPadPositionListener().stopWaning(); TODO Warning + controller.getPadPositionListener().stopWaning(); controller.getView().pseudoClassState(PseudoClasses.PLAY_CALSS, false); controller.getView().pseudoClassState(PseudoClasses.FADE_CLASS, false); controller.getView().pseudoClassState(PseudoClasses.WARN_CLASS, false); break; case STOP: - // controller.getPadPositionListener().stopWaning(); TODO Warning + controller.getPadPositionListener().stopWaning(); controller.getView().pseudoClassState(PseudoClasses.PLAY_CALSS, false); controller.getView().pseudoClassState(PseudoClasses.FADE_CLASS, false); controller.getView().pseudoClassState(PseudoClasses.WARN_CLASS, false); @@ -45,7 +45,7 @@ public class PadStatusListener implements ChangeListener<PadStatus> { break; case READY: - // controller.getPadPositionListener().stopWaning(); TODO Warning + controller.getPadPositionListener().stopWaning(); controller.getView().pseudoClassState(PseudoClasses.PLAY_CALSS, false); controller.getView().pseudoClassState(PseudoClasses.FADE_CLASS, false); controller.getView().pseudoClassState(PseudoClasses.WARN_CLASS, false); @@ -54,7 +54,7 @@ public class PadStatusListener implements ChangeListener<PadStatus> { case ERROR: controller.getView().setErrorLabelActive(true); - // controller.getPadPositionListener().stopWaning(); TODO Warning + controller.getPadPositionListener().stopWaning(); controller.getView().pseudoClassState(PseudoClasses.PLAY_CALSS, false); controller.getView().pseudoClassState(PseudoClasses.FADE_CLASS, false); controller.getView().pseudoClassState(PseudoClasses.WARN_CLASS, false); @@ -62,7 +62,7 @@ public class PadStatusListener implements ChangeListener<PadStatus> { break; case EMPTY: - // controller.getPadPositionListener().stopWaning(); TODO Warning + controller.getPadPositionListener().stopWaning(); controller.getView().pseudoClassState(PseudoClasses.PLAY_CALSS, false); controller.getView().pseudoClassState(PseudoClasses.FADE_CLASS, false); controller.getView().pseudoClassState(PseudoClasses.WARN_CLASS, false); diff --git a/PlayWall/src/de/tobias/playpad/viewcontroller/main/MainMenuBarController.java b/PlayWall/src/de/tobias/playpad/viewcontroller/main/MainMenuBarController.java index e27563fc..bd1b8923 100644 --- a/PlayWall/src/de/tobias/playpad/viewcontroller/main/MainMenuBarController.java +++ b/PlayWall/src/de/tobias/playpad/viewcontroller/main/MainMenuBarController.java @@ -181,7 +181,7 @@ public class MainMenuBarController implements EventHandler<ActionEvent>, Initial } if (settingsViewController == null) { - settingsViewController = new SettingsViewController(midi, mvc.getScreen(), mvc.getStage(), project) { + settingsViewController = new SettingsViewController(midi, mvc.getScreen(), mvc.getStage(), project, null) { @Override public void updateData() { diff --git a/PlayWall/src/de/tobias/playpad/viewcontroller/main/MainViewController.java b/PlayWall/src/de/tobias/playpad/viewcontroller/main/MainViewController.java index fb9cb7d2..eb5df881 100644 --- a/PlayWall/src/de/tobias/playpad/viewcontroller/main/MainViewController.java +++ b/PlayWall/src/de/tobias/playpad/viewcontroller/main/MainViewController.java @@ -26,6 +26,7 @@ import de.tobias.playpad.design.DesignColorAssociator; import de.tobias.playpad.midi.Midi; import de.tobias.playpad.pad.Pad; import de.tobias.playpad.pad.view.IPadViewController; +import de.tobias.playpad.pad.view.IPadViewV2; import de.tobias.playpad.plugin.WindowListener; import de.tobias.playpad.project.Project; import de.tobias.playpad.settings.Profile; @@ -191,7 +192,7 @@ public class MainViewController extends ViewController implements IMainViewContr } } - void setTitle() { + public void setTitle() { if (project != null && Profile.currentProfile() != null) { getStage().setTitle(Localization.getString(Strings.UI_Window_Main_Title, project.getRef().getName(), Profile.currentProfile().getRef().getName())); @@ -718,4 +719,16 @@ public class MainViewController extends ViewController implements IMainViewContr public void registerKeyboardListener(EventType<KeyEvent> eventType, EventHandler<KeyEvent> listener) { getParent().getScene().addEventHandler(eventType, listener); } + + @Override + public List<IPadViewV2> getPadViews() { + // TODO Auto-generated method stub + return null; + } + + @Override + public MenuToolbarViewController getMenuToolbarController() { + // TODO Auto-generated method stub + return null; + } } diff --git a/PlayWall/src/de/tobias/playpad/viewcontroller/main/MainViewControllerV2.java b/PlayWall/src/de/tobias/playpad/viewcontroller/main/MainViewControllerV2.java index 74f2f114..044444c2 100644 --- a/PlayWall/src/de/tobias/playpad/viewcontroller/main/MainViewControllerV2.java +++ b/PlayWall/src/de/tobias/playpad/viewcontroller/main/MainViewControllerV2.java @@ -1,12 +1,20 @@ package de.tobias.playpad.viewcontroller.main; +import java.lang.reflect.Field; import java.util.ArrayList; import java.util.List; +import java.util.Optional; + +import javax.sound.midi.MidiUnavailableException; import de.tobias.playpad.PlayPadMain; import de.tobias.playpad.Strings; +import de.tobias.playpad.action.mapper.listener.KeyboardHandler; +import de.tobias.playpad.action.mapper.listener.MidiHandler; import de.tobias.playpad.design.GlobalDesign; import de.tobias.playpad.layout.desktop.DesktopMainLayoutConnect; +import de.tobias.playpad.midi.Midi; +import de.tobias.playpad.midi.MidiListener; import de.tobias.playpad.pad.Pad; import de.tobias.playpad.pad.view.IPadViewV2; import de.tobias.playpad.plugin.WindowListener; @@ -15,33 +23,48 @@ import de.tobias.playpad.settings.Profile; import de.tobias.playpad.settings.ProfileListener; import de.tobias.playpad.settings.ProfileSettings; import de.tobias.playpad.view.main.MainLayoutConnect; +import de.tobias.playpad.viewcontroller.pad.PadDragListener; import de.tobias.utils.ui.BasicControllerSettings; import de.tobias.utils.ui.NotificationHandler; import de.tobias.utils.ui.ViewController; +import de.tobias.utils.ui.scene.NotificationPane; import de.tobias.utils.util.Localization; import de.tobias.utils.util.OS; import de.tobias.utils.util.OS.OSType; +import javafx.application.Platform; import javafx.event.EventHandler; import javafx.event.EventType; import javafx.fxml.FXML; +import javafx.scene.Group; +import javafx.scene.Node; +import javafx.scene.control.Alert; +import javafx.scene.control.Alert.AlertType; +import javafx.scene.control.Button; +import javafx.scene.control.ButtonType; import javafx.scene.input.KeyCombination; import javafx.scene.input.KeyEvent; +import javafx.scene.layout.AnchorPane; import javafx.scene.layout.ColumnConstraints; import javafx.scene.layout.GridPane; import javafx.scene.layout.RowConstraints; import javafx.scene.layout.VBox; import javafx.scene.paint.Color; +import javafx.scene.shape.Line; +import javafx.stage.Modality; import javafx.stage.Screen; import javafx.stage.Stage; // TODO Extract Color Adjust methodes public class MainViewControllerV2 extends ViewController implements IMainViewController, NotificationHandler, ProfileListener { - private static final String CURRENT_PAGE_BUTTON = "current-page-button"; private static final int FIRST_PAGE = 0; @FXML private VBox headerBox; @FXML private GridPane padGridPane; + + @FXML private AnchorPane gridContainer; + private NotificationPane notificationPane; + private List<IPadViewV2> padViews; private MenuToolbarViewController menuToolbarViewController; @@ -50,6 +73,14 @@ public class MainViewControllerV2 extends ViewController implements IMainViewCon private Project openProject; private int currentPageShowing = -1; + // Mapper + private Midi midi; + private MidiHandler midiHandler; + private KeyboardHandler keyboardHandler; + + // Style + private Color gridColor; + public MainViewControllerV2(List<WindowListener<IMainViewController>> listener) { super("mainViewV2", "de/tobias/playpad/assets/view/main/", null, PlayPadMain.getUiResourceBundle()); padViews = new ArrayList<>(); @@ -57,6 +88,49 @@ public class MainViewControllerV2 extends ViewController implements IMainViewCon setMainLayout(new DesktopMainLayoutConnect()); // DEBUG Profile.registerListener(this); + + /* + * Gridline Color + */ + try { + Field field = padGridPane.getClass().getDeclaredField("gridLines"); + field.setAccessible(true); + Group group = (Group) field.get(padGridPane); + if (group != null) { + group.getChildren().addListener((javafx.collections.ListChangeListener.Change<? extends Node> c) -> + { + for (Node node : group.getChildren()) { + if (node instanceof Line) { + ((Line) node).setStroke(gridColor); + } + } + }); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + private void initMapper(Project project) { + /* + * Mapper Setup & Listener + */ + this.midi = Midi.getInstance(); + this.midiHandler = new MidiHandler(midi, this, project); + this.midi.setListener(midiHandler); + this.keyboardHandler = new KeyboardHandler(project, this); + + } + + @Override + public void init() { + padGridPane.getStyleClass().add("pad-grid"); + + notificationPane = new NotificationPane(padGridPane); + notificationPane.getStyleClass().add(NotificationPane.STYLE_CLASS_DARK); + + gridContainer.getChildren().add(notificationPane); + setAnchor(notificationPane, 0, 0, 0, 0); } // main layout @@ -119,6 +193,102 @@ public class MainViewControllerV2 extends ViewController implements IMainViewCon settings.height = getStage().getHeight(); } + @Override + public boolean closeRequest() { + // TODO Close Error Window + + if (Profile.currentProfile() != null) { + ProfileSettings profilSettings = Profile.currentProfile().getProfileSettings(); + + // Frag den Nutzer ob das Programm wirdklich geschlossen werden sol + // wenn ein Pad noch im Status Play ist + if (openProject.getPlayedPlayers() > 0 && profilSettings.isLiveMode()) { + Alert alert = new Alert(AlertType.CONFIRMATION); + alert.setContentText(Localization.getString(Strings.UI_Window_Main_CloseRequest)); + + alert.initOwner(getStage()); + alert.initModality(Modality.WINDOW_MODAL); + Stage alertStage = (Stage) alert.getDialogPane().getScene().getWindow(); + PlayPadMain.stageIcon.ifPresent(alertStage.getIcons()::add); + + Optional<ButtonType> result = alert.showAndWait(); + if (result.isPresent()) + if (result.get() != ButtonType.OK) + return false; + } + + Alert alert = new Alert(AlertType.CONFIRMATION); + alert.setContentText(Localization.getString(Strings.UI_Window_Main_SaveRequest)); + alert.getButtonTypes().setAll(ButtonType.CANCEL, ButtonType.NO, ButtonType.YES); + + Button yesButton = (Button) alert.getDialogPane().lookupButton(ButtonType.YES); + yesButton.defaultButtonProperty().bind(yesButton.focusedProperty()); + + Button noButton = (Button) alert.getDialogPane().lookupButton(ButtonType.NO); + noButton.defaultButtonProperty().bind(noButton.focusedProperty()); + + Button cancelButton = (Button) alert.getDialogPane().lookupButton(ButtonType.CANCEL); + cancelButton.defaultButtonProperty().bind(cancelButton.focusedProperty()); + + alert.initOwner(getStage()); + alert.initModality(Modality.WINDOW_MODAL); + Stage alertStage = (Stage) alert.getDialogPane().getScene().getWindow(); + PlayPadMain.stageIcon.ifPresent(alertStage.getIcons()::add); + + Optional<ButtonType> result = alert.showAndWait(); + if (result.isPresent()) { + ButtonType buttonType = result.get(); + if (buttonType == ButtonType.YES) { + // Projekt Speichern + try { + if (openProject.getRef() != null) { + openProject.save(); + System.out.println("Saved Project: " + openProject); + } + } catch (Exception e) { + e.printStackTrace(); + showErrorMessage(Localization.getString(Strings.Error_Project_Save)); + } + } else if (buttonType == ButtonType.CANCEL) { + return false; + } + } + + // Save Config - Its unabhängig vom Dialog, da es auch an anderen Stellen schon gespeichert wird + try { + if (Profile.currentProfile() != null) + Profile.currentProfile().save(); + } catch (Exception e) { + e.printStackTrace(); + showErrorMessage(Localization.getString(Strings.Error_Profile_Save)); + } + + // Mapper Clear Feedback + Profile.currentProfile().getMappings().getActiveMapping().clearFeedback(); + + // MIDI Shutdown + // Der schließt MIDI, da er es auch öffnet und verantwortlich ist + if (profilSettings.isMidiActive()) { + try { + midi.close(); + } catch (MidiUnavailableException e1) { + e1.printStackTrace(); + } + } + } + + if (getStage().isIconified()) { + getStage().setIconified(false); + } + + // Verbindung von Pad und PadView wird getrennt. Zudem wird bei PLAY + // oder PAUSE auf STOP gesetzt + removePadsFromView(); + + saveSettings(); + return true; + } + // project /** * Öffnet ein Project. Das akutelle project ist in PlayPadImpl gespeichert. @@ -132,8 +302,16 @@ public class MainViewControllerV2 extends ViewController implements IMainViewCon createPadViews(); // TODO Weg hier, nur wenn sich profile ändert openProject = project; + + initMapper(project); + + midiHandler.setProject(project); + keyboardHandler.setProject(project); + PadDragListener.setProject(project); + showPage(FIRST_PAGE); loadUserCss(); + setTitle(); } // Pad, Pages @@ -183,7 +361,7 @@ public class MainViewControllerV2 extends ViewController implements IMainViewCon getStage().setMinHeight(minHeight + 150); } - menuToolbarViewController.initPages(); + menuToolbarViewController.initPageButtons(); } /** @@ -216,21 +394,19 @@ public class MainViewControllerV2 extends ViewController implements IMainViewCon @Override public void showPage(int page) { - if (page != currentPageShowing) { - // Clean - removePadsFromView(); - // Page Button Remove highlight + // Clean + removePadsFromView(); + // Page Button Remove highlight - this.currentPageShowing = page; + this.currentPageShowing = page; - // New - addPadsToView(); - } + // New + addPadsToView(); } @Override public int getPage() { - return 0; + return currentPageShowing; } // Settings @@ -241,28 +417,58 @@ public class MainViewControllerV2 extends ViewController implements IMainViewCon @Override public void setGridColor(Color color) { - + this.gridColor = color; + try { + Field field = padGridPane.getClass().getDeclaredField("gridLines"); + field.setAccessible(true); + Group group = (Group) field.get(padGridPane); + if (group != null) { + for (Node node : group.getChildren()) { + if (node instanceof Line) { + ((Line) node).setStroke(gridColor); + } + } + } + } catch (Exception e) { + e.printStackTrace(); + } } // Notification @Override public void notify(String text, long duration) { - + if (Platform.isFxApplicationThread()) { + notificationPane.showAndHide(text, duration); + } else { + Platform.runLater(() -> notificationPane.showAndHide(text, duration)); + } } @Override public void notify(String text, long duration, Runnable finish) { - + if (Platform.isFxApplicationThread()) { + notificationPane.showAndHide(text, duration, finish); + } else { + Platform.runLater(() -> notificationPane.showAndHide(text, duration, finish)); + } } @Override public void showError(String message) { - + if (Platform.isFxApplicationThread()) { + notificationPane.showError(message); + } else { + Platform.runLater(() -> notificationPane.showError(message)); + } } @Override public void hide() { - + if (Platform.isFxApplicationThread()) { + notificationPane.hide(); + } else { + Platform.runLater(() -> notificationPane.hide()); + } } // Utils @@ -282,4 +488,28 @@ public class MainViewControllerV2 extends ViewController implements IMainViewCon public void applyColorsToMappers() { } + + public void setTitle() { + if (openProject != null && Profile.currentProfile() != null) { + getStage().setTitle(Localization.getString(Strings.UI_Window_Main_Title, openProject.getRef().getName(), + Profile.currentProfile().getRef().getName())); + } else { + getStage().setTitle(Localization.getString(Strings.UI_Window_Main_Title)); + } + } + + @Override + public List<IPadViewV2> getPadViews() { + return padViews; + } + + @Override + public MidiListener getMidiHandler() { + return midiHandler; + } + + @Override + public MenuToolbarViewController getMenuToolbarController() { + return menuToolbarViewController; + } } diff --git a/PlayWall/src/de/tobias/playpad/viewcontroller/option/GeneralTabViewController.java b/PlayWall/src/de/tobias/playpad/viewcontroller/option/GeneralTabViewController.java index a108b56c..2dde64d7 100644 --- a/PlayWall/src/de/tobias/playpad/viewcontroller/option/GeneralTabViewController.java +++ b/PlayWall/src/de/tobias/playpad/viewcontroller/option/GeneralTabViewController.java @@ -312,7 +312,7 @@ public class GeneralTabViewController extends SettingsTabViewController { { Platform.runLater(() -> { - controller.getToolbarController().createPageButtons(); + controller.getMenuToolbarController().initPageButtons(); controller.createPadViews(); controller.showPage(controller.getPage()); stage.close(); diff --git a/PlayWall/src/de/tobias/playpad/viewcontroller/option/SettingsViewController.java b/PlayWall/src/de/tobias/playpad/viewcontroller/option/SettingsViewController.java index 7ed38a76..11755e50 100644 --- a/PlayWall/src/de/tobias/playpad/viewcontroller/option/SettingsViewController.java +++ b/PlayWall/src/de/tobias/playpad/viewcontroller/option/SettingsViewController.java @@ -36,8 +36,11 @@ public class SettingsViewController extends ViewController implements ISettingsV protected List<SettingsTabViewController> tabs = new ArrayList<>(); - public SettingsViewController(Midi midiHandler, Screen currentScreen, Window owner, Project project) { + private Runnable onFinish; + + public SettingsViewController(Midi midiHandler, Screen currentScreen, Window owner, Project project, Runnable onFinish) { super("settingsView", "de/tobias/playpad/assets/view/option/", null, PlayPadMain.getUiResourceBundle()); + this.onFinish = onFinish; boolean activePlayer = project.hasPlayedPlayers(); @@ -156,7 +159,7 @@ public class SettingsViewController extends ViewController implements ISettingsV } saveTabs(); - updateData(); // Reload MainViewController Settings // TODO Rewrite + onFinish.run(); // Reload MainViewController Settings return true; } @@ -174,4 +177,8 @@ public class SettingsViewController extends ViewController implements ISettingsV tabs.add(controller); tabPane.getTabs().add(new Tab(controller.name(), controller.getParent())); } + + public List<SettingsTabViewController> getTabs() { + return tabs; + } } diff --git a/PlayWall/src/de/tobias/playpad/viewcontroller/pad/PadDragListener.java b/PlayWall/src/de/tobias/playpad/viewcontroller/pad/PadDragListener.java index d0a6c829..4c3df054 100644 --- a/PlayWall/src/de/tobias/playpad/viewcontroller/pad/PadDragListener.java +++ b/PlayWall/src/de/tobias/playpad/viewcontroller/pad/PadDragListener.java @@ -6,10 +6,9 @@ import java.util.Set; import de.tobias.playpad.PlayPadPlugin; import de.tobias.playpad.pad.Pad; +import de.tobias.playpad.pad.PadContentRegistry; import de.tobias.playpad.pad.conntent.PadContent; import de.tobias.playpad.pad.conntent.PadContentConnect; -import de.tobias.playpad.pad.conntent.PadContentRegistry; -import de.tobias.playpad.pad.conntent.UnkownPadContentException; import de.tobias.playpad.pad.drag.PadDragMode; import de.tobias.playpad.pad.view.IPadViewV2; import de.tobias.playpad.project.Project; @@ -32,7 +31,7 @@ import javafx.scene.paint.Color; public class PadDragListener { private static final String REGEX = "[0-9]+"; - private Pad pad; + private Pad sourcePad; final private Pane view; private static boolean dndMode; @@ -42,7 +41,7 @@ public class PadDragListener { private FileDragOptionView fileHud; public PadDragListener(Pad pad, IPadViewV2 view) { - this.pad = pad; + this.sourcePad = pad; this.view = view.getRootNode(); // Drag and Drop @@ -60,8 +59,8 @@ public class PadDragListener { if (event.getGestureSource() != this && event.getDragboard().hasFiles()) { if (event.getDragboard().getFiles().get(0).isFile()) { ProfileSettings settings = Profile.currentProfile().getProfileSettings(); - if (pad.getProject() != null) { - if (settings.isLiveMode() && settings.isLiveModeFile() && pad.getProject().getPlayedPlayers() > 0) { + if (sourcePad.getProject() != null) { + if (settings.isLiveMode() && settings.isLiveModeFile() && sourcePad.getProject().getPlayedPlayers() > 0) { PlayPadPlugin.getImplementation().getMainViewController().showLiveInfo(); return; } @@ -71,7 +70,8 @@ public class PadDragListener { // Build In Filesupport try { - Set<PadContentConnect> connects = PadContentRegistry.getPadContentConnectsForFile(file.toPath()); + PadContentRegistry registry = PlayPadPlugin.getRegistryCollection().getPadContents(); + Set<PadContentConnect> connects = registry.getPadContentConnectsForFile(file.toPath()); if (!connects.isEmpty()) { if (fileHud == null) { @@ -82,7 +82,7 @@ public class PadDragListener { event.acceptTransferModes(TransferMode.LINK); return; } - } catch (UnkownPadContentException e) { + } catch (NoSuchComponentException e) { e.printStackTrace(); } } @@ -92,19 +92,19 @@ public class PadDragListener { if (event.getDragboard().hasString() && event.getDragboard().getString().trim().matches(REGEX)) { int padID = Integer.valueOf(event.getDragboard().getString()); // TODO Pad Drag and Drop -// if (padID != view.getController().getPad().getIndex()) { -// -// Collection<PadDragMode> connects = PlayPadPlugin.getRegistryCollection().getDragModes().getComponents(); -// -// if (!connects.isEmpty()) { -// if (padHud == null) { -// padHud = new PadDragOptionView(view); -// } -// padHud.showDropOptions(connects); -// -// event.acceptTransferModes(TransferMode.MOVE); -// } -// } + if (padID != sourcePad.getIndex()) { + + Collection<PadDragMode> connects = PlayPadPlugin.getRegistryCollection().getDragModes().getComponents(); + + if (!connects.isEmpty()) { + if (padHud == null) { + padHud = new PadDragOptionView(view); + } + padHud.showDropOptions(connects); + + event.acceptTransferModes(TransferMode.MOVE); + } + } } event.consume(); } @@ -127,9 +127,9 @@ public class PadDragListener { PadContentConnect connect = fileHud.getSelectedConnect(); if (connect != null) { - PadContent content = pad.getContent(); - if (pad.getContent() == null || !pad.getContent().getType().equals(connect.getType())) { - content = connect.newInstance(pad); + PadContent content = sourcePad.getContent(); + if (sourcePad.getContent() == null || !sourcePad.getContent().getType().equals(connect.getType())) { + content = connect.newInstance(sourcePad); } try { @@ -138,12 +138,14 @@ public class PadDragListener { // TODO Auto-generated catch block e.printStackTrace(); } - this.pad.setContent(content); - this.pad.setName(FileUtils.getFilenameWithoutExtention(file.toPath().getFileName())); + this.sourcePad.setContent(content); + this.sourcePad.setName(FileUtils.getFilenameWithoutExtention(file.toPath().getFileName())); - // TODO Drag Listener -// view.setPreviewContent(pad); -// view.addDefaultButton(pad); + if (sourcePad.getController() != null) { + IPadViewV2 padView = sourcePad.getController().getView(); + padView.setContentView(sourcePad); + padView.addDefaultButton(sourcePad); + } } } @@ -151,7 +153,7 @@ public class PadDragListener { int padID = Integer.valueOf(db.getString()); PadDragMode mode = padHud.getSelectedPadDragMode(); - mode.handle(padID, pad.getIndex(), project); + mode.handle(padID, sourcePad.getIndex(), project); padHud.hide(); PlayPadPlugin.getImplementation().getMainViewController() @@ -165,8 +167,8 @@ public class PadDragListener { private void dragDetacted(MouseEvent event) { if (dndMode) { ProfileSettings settings = Profile.currentProfile().getProfileSettings(); - if (pad.getProject() != null) { - if (settings.isLiveMode() && settings.isLiveModeDrag() && pad.getProject().getPlayedPlayers() > 0) { + if (sourcePad.getProject() != null) { + if (settings.isLiveMode() && settings.isLiveModeDrag() && sourcePad.getProject().getPlayedPlayers() > 0) { PlayPadPlugin.getImplementation().getMainViewController().showLiveInfo(); return; } @@ -188,19 +190,26 @@ public class PadDragListener { dragboard.setDragView(snapshot); ClipboardContent content = new ClipboardContent(); - content.putString(String.valueOf(pad.getIndex())); + content.putString(String.valueOf(sourcePad.getIndex())); dragboard.setContent(content); event.consume(); } } + /** + * Aktiviert den Drag And Drop Modus für Kacheln. Diese Methode muss vom Menu / KeyShortcut aufgerufen werden. + * + * @param dndMode + * <code>true</code> Aktiv + */ public static void setDndMode(boolean dndMode) { PadDragListener.dndMode = dndMode; } + @Deprecated public void setPad(Pad pad) { - this.pad = pad; + this.sourcePad = pad; } public static void setProject(Project project) { diff --git a/PlayWall/src/de/tobias/playpad/viewcontroller/pad/PadViewController.java b/PlayWall/src/de/tobias/playpad/viewcontroller/pad/PadViewController.java index e4f38269..f2ef0d06 100644 --- a/PlayWall/src/de/tobias/playpad/viewcontroller/pad/PadViewController.java +++ b/PlayWall/src/de/tobias/playpad/viewcontroller/pad/PadViewController.java @@ -15,6 +15,7 @@ import de.tobias.playpad.pad.conntent.PadContentConnect; import de.tobias.playpad.pad.conntent.PadContentRegistry; import de.tobias.playpad.pad.conntent.UnkownPadContentException; import de.tobias.playpad.pad.conntent.play.Durationable; +import de.tobias.playpad.pad.listener.IPadPositionListener; import de.tobias.playpad.pad.listener.PadContentListener; import de.tobias.playpad.pad.listener.PadDurationListener; import de.tobias.playpad.pad.listener.PadLockedListener; @@ -394,7 +395,7 @@ public class PadViewController implements EventHandler<ActionEvent>, IPadViewCon return padStatusListener; } - public PadPositionListener getPadPositionListener() { + public IPadPositionListener getPadPositionListener() { return padPositionListener; } diff --git a/PlayWallCore/src/de/tobias/playpad/RegistryCollection.java b/PlayWallCore/src/de/tobias/playpad/RegistryCollection.java index 0c6a95db..43f0017a 100644 --- a/PlayWallCore/src/de/tobias/playpad/RegistryCollection.java +++ b/PlayWallCore/src/de/tobias/playpad/RegistryCollection.java @@ -4,7 +4,7 @@ import de.tobias.playpad.action.ActionConnect; import de.tobias.playpad.action.mapper.MapperConnect; import de.tobias.playpad.audio.AudioRegistry; import de.tobias.playpad.design.DesignConnect; -import de.tobias.playpad.pad.conntent.PadContentConnect; +import de.tobias.playpad.pad.PadContentRegistry; import de.tobias.playpad.pad.drag.PadDragMode; import de.tobias.playpad.registry.DefaultRegistry; import de.tobias.playpad.registry.Registry; @@ -30,7 +30,7 @@ public interface RegistryCollection { public Registry<MapperConnect> getMappers(); - public Registry<PadContentConnect> getPadContents(); + public PadContentRegistry getPadContents(); public Registry<TriggerItemConnect> getTriggerItems(); diff --git a/PlayWallCore/src/de/tobias/playpad/design/CartDesign.java b/PlayWallCore/src/de/tobias/playpad/design/CartDesign.java index f76f92bc..b57416d0 100644 --- a/PlayWallCore/src/de/tobias/playpad/design/CartDesign.java +++ b/PlayWallCore/src/de/tobias/playpad/design/CartDesign.java @@ -2,7 +2,7 @@ package de.tobias.playpad.design; import org.dom4j.Element; -import de.tobias.playpad.pad.view.IPadViewController; +import de.tobias.playpad.pad.viewcontroller.IPadViewControllerV2; import de.tobias.playpad.settings.Warning; public interface CartDesign { @@ -25,9 +25,9 @@ public interface CartDesign { * @param controller * @param warning */ - public abstract void handleWarning(IPadViewController controller, Warning warning, GlobalDesign animate); + public abstract void handleWarning(IPadViewControllerV2 controller, Warning warning, GlobalDesign animate); - public default void stopWarning(IPadViewController controller) {} + public default void stopWarning(IPadViewControllerV2 controller) {} public void reset(); diff --git a/PlayWallCore/src/de/tobias/playpad/design/GlobalDesign.java b/PlayWallCore/src/de/tobias/playpad/design/GlobalDesign.java index 9b8a9000..a0c101c0 100644 --- a/PlayWallCore/src/de/tobias/playpad/design/GlobalDesign.java +++ b/PlayWallCore/src/de/tobias/playpad/design/GlobalDesign.java @@ -15,7 +15,7 @@ import org.dom4j.io.SAXReader; import org.dom4j.io.XMLWriter; import de.tobias.playpad.PlayPadPlugin; -import de.tobias.playpad.pad.view.IPadViewController; +import de.tobias.playpad.pad.viewcontroller.IPadViewControllerV2; import de.tobias.playpad.project.Project; import de.tobias.playpad.registry.DefaultRegistry; import de.tobias.playpad.registry.NoSuchComponentException; @@ -53,9 +53,9 @@ public interface GlobalDesign { * @param controller * @param warning */ - public void handleWarning(IPadViewController controller, Warning warning); + public void handleWarning(IPadViewControllerV2 controller, Warning warning); - public default void stopWarning(IPadViewController controller) {} + public default void stopWarning(IPadViewControllerV2 controller) {} public void reset(); diff --git a/PlayWallCore/src/de/tobias/playpad/pad/PadContentRegistry.java b/PlayWallCore/src/de/tobias/playpad/pad/PadContentRegistry.java new file mode 100644 index 00000000..522a3069 --- /dev/null +++ b/PlayWallCore/src/de/tobias/playpad/pad/PadContentRegistry.java @@ -0,0 +1,43 @@ +package de.tobias.playpad.pad; + +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import de.tobias.playpad.pad.conntent.PadContentConnect; +import de.tobias.playpad.registry.ComponentRegistry; +import de.tobias.playpad.registry.NoSuchComponentException; + +public class PadContentRegistry extends ComponentRegistry<PadContentConnect> { + + public PadContentRegistry(String name) { + super(name); + } + + public Set<PadContentConnect> getPadContentConnectsForFile(Path path) throws NoSuchComponentException { + Set<PadContentConnect> connects = new HashSet<>(); + for (String type : getTypes()) { + PadContentConnect connect = getComponent(type); + for (String extension : connect.getSupportedTypes()) { + if (path.getFileName().toString().toLowerCase().matches("." + extension)) { + connects.add(connect); + } + } + } + return connects; + } + + public String[] getSupportedFileTypes() throws NoSuchComponentException { + List<String> extensions = new ArrayList<>(); + for (String type : getTypes()) { + PadContentConnect connect = getComponent(type); + String[] fileExtensions = connect.getSupportedTypes(); + Collections.addAll(extensions, fileExtensions); + } + return extensions.toArray(new String[extensions.size()]); + } + +} diff --git a/PlayWallCore/src/de/tobias/playpad/pad/listener/IPadPositionListener.java b/PlayWallCore/src/de/tobias/playpad/pad/listener/IPadPositionListener.java new file mode 100644 index 00000000..ab6d6bd4 --- /dev/null +++ b/PlayWallCore/src/de/tobias/playpad/pad/listener/IPadPositionListener.java @@ -0,0 +1,15 @@ +package de.tobias.playpad.pad.listener; + +import de.tobias.playpad.pad.Pad; +import javafx.beans.value.ChangeListener; +import javafx.util.Duration; + +public interface IPadPositionListener extends ChangeListener<Duration> { + + void setPad(Pad pad); + + void setSend(boolean send); + + void stopWaning(); + +} \ No newline at end of file diff --git a/PlayWallCore/src/de/tobias/playpad/pad/view/IPadContentView.java b/PlayWallCore/src/de/tobias/playpad/pad/view/IPadContentView.java index 8ea4e538..d2cc6821 100644 --- a/PlayWallCore/src/de/tobias/playpad/pad/view/IPadContentView.java +++ b/PlayWallCore/src/de/tobias/playpad/pad/view/IPadContentView.java @@ -27,5 +27,6 @@ public interface IPadContentView { */ public default void deinit() { // TODO Remove the default after remove unconnect from interface + unconnect(); } } diff --git a/PlayWallCore/src/de/tobias/playpad/pad/view/IPadViewV2.java b/PlayWallCore/src/de/tobias/playpad/pad/view/IPadViewV2.java index afdb4859..db2a747a 100644 --- a/PlayWallCore/src/de/tobias/playpad/pad/view/IPadViewV2.java +++ b/PlayWallCore/src/de/tobias/playpad/pad/view/IPadViewV2.java @@ -71,6 +71,14 @@ public interface IPadViewV2 { @Deprecated public ProgressBar getPlayBar(); + /** + * Setzt die Playbar sichtbar. + * + * @param visible + * <code>true</code> Sichtbar, <code>false</code> nicht sichtbar + */ + public void setPlaybarVisible(boolean visible); + public void addDefaultButton(Pad pad); public void applyStyleClasses(); diff --git a/PlayWallCore/src/de/tobias/playpad/pad/viewcontroller/IPadViewControllerV2.java b/PlayWallCore/src/de/tobias/playpad/pad/viewcontroller/IPadViewControllerV2.java index 3d3ca02b..ff96e462 100644 --- a/PlayWallCore/src/de/tobias/playpad/pad/viewcontroller/IPadViewControllerV2.java +++ b/PlayWallCore/src/de/tobias/playpad/pad/viewcontroller/IPadViewControllerV2.java @@ -1,7 +1,10 @@ package de.tobias.playpad.pad.viewcontroller; import de.tobias.playpad.pad.Pad; +import de.tobias.playpad.pad.listener.IPadPositionListener; import de.tobias.playpad.pad.view.IPadViewV2; +import javafx.beans.value.ChangeListener; +import javafx.util.Duration; /** * Schnittstellen um mit einem PadViewController zu kommunizieren. @@ -43,4 +46,7 @@ public interface IPadViewControllerV2 { public void updateButtonDisable(); + public IPadPositionListener getPadPositionListener(); + + public ChangeListener<Duration> getPadDurationListener(); } diff --git a/PlayWallCore/src/de/tobias/playpad/viewcontroller/main/IMainViewController.java b/PlayWallCore/src/de/tobias/playpad/viewcontroller/main/IMainViewController.java index 5007f411..c294f988 100644 --- a/PlayWallCore/src/de/tobias/playpad/viewcontroller/main/IMainViewController.java +++ b/PlayWallCore/src/de/tobias/playpad/viewcontroller/main/IMainViewController.java @@ -1,6 +1,11 @@ package de.tobias.playpad.viewcontroller.main; +import java.util.List; + +import de.tobias.playpad.midi.MidiListener; +import de.tobias.playpad.pad.view.IPadViewV2; import de.tobias.playpad.project.Project; +import de.tobias.utils.ui.NotificationHandler; import javafx.event.EventHandler; import javafx.event.EventType; import javafx.scene.Parent; @@ -8,9 +13,10 @@ import javafx.scene.control.MenuItem; import javafx.scene.control.Slider; import javafx.scene.input.KeyEvent; import javafx.scene.paint.Color; +import javafx.stage.Screen; import javafx.stage.Stage; -public interface IMainViewController { +public interface IMainViewController extends NotificationHandler { public void setGridColor(Color color); @@ -53,5 +59,16 @@ public interface IMainViewController { public void applyColorsToMappers(); + @Deprecated public default void showLiveInfo() {} + + public void setTitle(); + + List<IPadViewV2> getPadViews(); + + public Screen getScreen(); + + public MidiListener getMidiHandler(); + + public MenuToolbarViewController getMenuToolbarController(); } diff --git a/PlayWallCore/src/de/tobias/playpad/viewcontroller/main/MenuToolbarViewController.java b/PlayWallCore/src/de/tobias/playpad/viewcontroller/main/MenuToolbarViewController.java index a43e0600..4eaedb40 100644 --- a/PlayWallCore/src/de/tobias/playpad/viewcontroller/main/MenuToolbarViewController.java +++ b/PlayWallCore/src/de/tobias/playpad/viewcontroller/main/MenuToolbarViewController.java @@ -47,7 +47,7 @@ public abstract class MenuToolbarViewController extends ContentViewController { * Wird von MainViwController aufgerufen, wenn die Buttons für die einzelnen Seiten neu erstellt werden müssen. Das ist der Fall beim * laden eines Projektes und bei Änderungen an den Einstellungen. */ - public abstract void initPages(); + public abstract void initPageButtons(); /* * -- GitLab