From 3fd908c54c48aff9a877039f7eac08845225b184 Mon Sep 17 00:00:00 2001 From: tobias <tobias.ullerich@icloud.com> Date: Sun, 14 Aug 2016 17:53:36 +0200 Subject: [PATCH] Coninue on media folder --- .../project/PathsTabViewController.java | 31 ++++++++++++++++--- .../de/tobias/playpad/project/Project.java | 11 ++++++- .../playpad/project/ProjectSettings.java | 8 +++-- .../impl/MediaSettingsTabViewController.java | 22 ++++++++++--- 4 files changed, 59 insertions(+), 13 deletions(-) diff --git a/PlayWall/src/de/tobias/playpad/viewcontroller/option/project/PathsTabViewController.java b/PlayWall/src/de/tobias/playpad/viewcontroller/option/project/PathsTabViewController.java index f4ac4dbf..5b5aee03 100644 --- a/PlayWall/src/de/tobias/playpad/viewcontroller/option/project/PathsTabViewController.java +++ b/PlayWall/src/de/tobias/playpad/viewcontroller/option/project/PathsTabViewController.java @@ -1,8 +1,11 @@ package de.tobias.playpad.viewcontroller.option.project; import java.io.File; +import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; +import java.util.Optional; +import java.util.stream.Stream; import de.tobias.playpad.PlayPadMain; import de.tobias.playpad.project.Project; @@ -26,6 +29,7 @@ public class PathsTabViewController extends ProjectSettingsTabViewController imp @FXML private CheckBox useMediaPath; private transient boolean changedMediaPath = false; + private transient Optional<Path> oldMediaPath = Optional.empty(); public PathsTabViewController() { super("pathTab.fxml", "de/tobias/playpad/assets/view/option/project/", PlayPadMain.getUiResourceBundle()); @@ -54,6 +58,9 @@ public class PathsTabViewController extends ProjectSettingsTabViewController imp Path newPath = Paths.get(mediaPathTextField.getText()); if (!settings.getMediaPath().equals(newPath)) { changedMediaPath = true; + if (settings.getMediaPath() != null && !settings.getMediaPath().toString().isEmpty()) { + oldMediaPath = Optional.of(settings.getMediaPath()); + } } if (useMediaPath.isSelected()) { @@ -86,10 +93,26 @@ public class PathsTabViewController extends ProjectSettingsTabViewController imp @Override protected Void call() throws Exception { updateTitle(name()); - for (int i = 0; i < 100; i++) { - Thread.sleep(10); - updateProgress(i, 100); - } + Path newMediaPath = settings.getMediaPath(); + + project.closeFile(); + + int i = 0; + Stream<Path> files = Files.list(oldMediaPath.get()); + files.forEach(file -> + { + // BUG Copy not work as expected + try { + Files.copy(file, newMediaPath.resolve(file.getFileName())); + Thread.sleep(500); + } catch (Exception e) { + e.printStackTrace(); + } + updateProgress(i, files.count()); + }); + files.close(); + + project.loadPadsContent(); return null; } }; diff --git a/PlayWallCore/src/de/tobias/playpad/project/Project.java b/PlayWallCore/src/de/tobias/playpad/project/Project.java index bdbb2b48..3baccb5b 100644 --- a/PlayWallCore/src/de/tobias/playpad/project/Project.java +++ b/PlayWallCore/src/de/tobias/playpad/project/Project.java @@ -151,7 +151,8 @@ public class Project { if (ref.getProfileReference() != null) { Profile.load(ref.getProfileReference()); // Lädt das entsprechende Profile und aktiviert es } else { - Profile profile = profileChooseable.getUnkownProfile(); // Lädt Profile / Erstellt neues und hat es gleich im Speicher + Profile profile = profileChooseable.getUnkownProfile(); // Lädt Profile / Erstellt neues und hat es + // gleich im Speicher ref.setProfileReference(profile.getRef()); } @@ -274,4 +275,12 @@ public class Project { public int getPadCount() { return pads.size(); } + + public void closeFile() { + pads.values().forEach(pad -> + { + if (pad.getContent() != null) + pad.getContent().unloadMedia(); + }); + } } diff --git a/PlayWallCore/src/de/tobias/playpad/project/ProjectSettings.java b/PlayWallCore/src/de/tobias/playpad/project/ProjectSettings.java index 68b6d17c..31e1cc9e 100644 --- a/PlayWallCore/src/de/tobias/playpad/project/ProjectSettings.java +++ b/PlayWallCore/src/de/tobias/playpad/project/ProjectSettings.java @@ -91,9 +91,11 @@ public class ProjectSettings { settings.setColumns(Integer.valueOf(element.element(COLUMNS_ELEMENT).getStringValue())); if (element.element(ROWS_ELEMENT) != null) settings.setRows(Integer.valueOf(element.element(ROWS_ELEMENT).getStringValue())); - if (element.element(MEDIA_PATH_ELEMENT) != null) { - settings.setMediaPath(Paths.get(element.element(MEDIA_PATH_ELEMENT).getStringValue())); - settings.setUseMediaPath(Boolean.valueOf(element.attributeValue(MEDIA_PATH_ACTIVE_ATTR))); + + Element mediaElement = element.element(MEDIA_PATH_ELEMENT); + if (mediaElement != null) { + settings.setMediaPath(Paths.get(mediaElement.getStringValue())); + settings.setUseMediaPath(Boolean.valueOf(mediaElement.attributeValue(MEDIA_PATH_ACTIVE_ATTR))); } return settings; diff --git a/PlayWallPlugins/mediaplugin/de/tobias/playpad/mediaplugin/main/impl/MediaSettingsTabViewController.java b/PlayWallPlugins/mediaplugin/de/tobias/playpad/mediaplugin/main/impl/MediaSettingsTabViewController.java index 8fc2e1df..d3451a5e 100644 --- a/PlayWallPlugins/mediaplugin/de/tobias/playpad/mediaplugin/main/impl/MediaSettingsTabViewController.java +++ b/PlayWallPlugins/mediaplugin/de/tobias/playpad/mediaplugin/main/impl/MediaSettingsTabViewController.java @@ -7,8 +7,11 @@ import java.util.ResourceBundle; import de.tobias.playpad.mediaplugin.main.VideoSettings; import de.tobias.playpad.project.Project; 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.IProfileReloadTask; import de.tobias.playpad.viewcontroller.option.ProfileSettingsTabViewController; +import javafx.concurrent.Task; import javafx.fxml.FXML; import javafx.scene.control.CheckBox; import javafx.scene.control.ComboBox; @@ -19,7 +22,7 @@ import javafx.scene.paint.Color; import javafx.scene.shape.Rectangle; import javafx.stage.Screen; -public class MediaSettingsTabViewController extends ProfileSettingsTabViewController { +public class MediaSettingsTabViewController extends ProfileSettingsTabViewController implements IProfileReloadTask { @FXML private Pane screenViewPane; @FXML private ComboBox<Integer> screenComboBox; @@ -118,13 +121,22 @@ public class MediaSettingsTabViewController extends ProfileSettingsTabViewContro } @Override - public void reload(Profile profile, Project project, IMainViewController controller) { - MediaPluginImpl.getInstance().getVideoViewController().reloadSettings(); + public boolean validSettings() { + return true; } @Override - public boolean validSettings() { - return true; + public Task<Void> getTask(ProfileSettings settings, Project project, IMainViewController controller) { + return new Task<Void>() { + @Override + protected Void call() throws Exception { + updateProgress(-1, -1); + updateTitle(name()); + + MediaPluginImpl.getInstance().getVideoViewController().reloadSettings(); + return null; + } + }; } @Override -- GitLab