diff --git a/PlayWall/src/de/tobias/playpad/audio/JavaFXAudioHandler.java b/PlayWall/src/de/tobias/playpad/audio/JavaFXAudioHandler.java index 4792e37a92538363d0473e2ffac5a974246d8054..d473e6ef63cfab4fdcd38f5704efe4f1c721a2a3 100644 --- a/PlayWall/src/de/tobias/playpad/audio/JavaFXAudioHandler.java +++ b/PlayWall/src/de/tobias/playpad/audio/JavaFXAudioHandler.java @@ -90,8 +90,7 @@ public class JavaFXAudioHandler extends AudioHandler implements Equalizable { @Override public void loadMedia(Path[] paths) { - Platform.runLater(() -> - { + Platform.runLater(() -> { if (getContent().getPad().isPadVisible()) { getContent().getPad().getController().getView().showBusyView(true); } @@ -107,24 +106,20 @@ public class JavaFXAudioHandler extends AudioHandler implements Equalizable { player = new MediaPlayer(media); // Player Listener - player.setOnReady(() -> - { + player.setOnReady(() -> { durationProperty.set(player.getTotalDuration()); getContent().getPad().setStatus(PadStatus.READY); loadedProperty.set(true); - Platform.runLater(() -> - { + Platform.runLater(() -> { if (getContent().getPad().isPadVisible()) { getContent().getPad().getController().getView().showBusyView(false); } }); }); - player.setOnError(() -> - { - Platform.runLater(() -> - { + player.setOnError(() -> { + Platform.runLater(() -> { if (getContent().getPad().isPadVisible()) { getContent().getPad().getController().getView().showBusyView(false); } @@ -132,8 +127,7 @@ public class JavaFXAudioHandler extends AudioHandler implements Equalizable { loadedProperty.set(false); getContent().getPad().throwException(path, player.getError()); }); - player.setOnEndOfMedia(() -> - { + player.setOnEndOfMedia(() -> { if (!getContent().getPad().getPadSettings().isLoop()) { getContent().getPad().setEof(true); getContent().getPad().setStatus(PadStatus.STOP); @@ -146,6 +140,8 @@ public class JavaFXAudioHandler extends AudioHandler implements Equalizable { @Override public void unloadMedia() { + if (player != null) + player.dispose(); player = null; media = null; durationProperty.set(null); diff --git a/PlayWall/src/de/tobias/playpad/viewcontroller/option/profile/DesignTabViewController.java b/PlayWall/src/de/tobias/playpad/viewcontroller/option/profile/DesignTabViewController.java index 467fc9a984cc705bbf1fa861b91c0cff3321371b..d0585f047370d9990842adf8841c03fa03fe450e 100644 --- a/PlayWall/src/de/tobias/playpad/viewcontroller/option/profile/DesignTabViewController.java +++ b/PlayWall/src/de/tobias/playpad/viewcontroller/option/profile/DesignTabViewController.java @@ -15,6 +15,7 @@ import de.tobias.playpad.viewcontroller.main.IMainViewController; import de.tobias.playpad.viewcontroller.option.IProfileReloadTask; import de.tobias.playpad.viewcontroller.option.ProfileSettingsTabViewController; import de.tobias.utils.util.Localization; +import javafx.application.Platform; import javafx.concurrent.Task; import javafx.fxml.FXML; import javafx.scene.control.ComboBox; @@ -91,7 +92,7 @@ public class DesignTabViewController extends ProfileSettingsTabViewController im updateTitle(name()); updateProgress(-1, -1); - controller.loadUserCss(); + Platform.runLater(() -> controller.loadUserCss()); return null; } }; 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 5b5aee038e648afdfd39d552bc3a8e5d2392ba46..ed6db8b6486e507d1429dd8e4188f0126a1c8012 100644 --- a/PlayWall/src/de/tobias/playpad/viewcontroller/option/project/PathsTabViewController.java +++ b/PlayWall/src/de/tobias/playpad/viewcontroller/option/project/PathsTabViewController.java @@ -1,18 +1,28 @@ package de.tobias.playpad.viewcontroller.option.project; import java.io.File; +import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; +import java.nio.file.StandardCopyOption; +import java.util.List; import java.util.Optional; -import java.util.stream.Stream; import de.tobias.playpad.PlayPadMain; +import de.tobias.playpad.pad.Pad; +import de.tobias.playpad.pad.PadStatus; +import de.tobias.playpad.pad.conntent.PadContent; +import de.tobias.playpad.pad.conntent.path.MultiPathContent; +import de.tobias.playpad.pad.conntent.path.SinglePathContent; import de.tobias.playpad.project.Project; import de.tobias.playpad.project.ProjectSettings; +import de.tobias.playpad.registry.NoSuchComponentException; import de.tobias.playpad.viewcontroller.main.IMainViewController; import de.tobias.playpad.viewcontroller.option.IProjectReloadTask; import de.tobias.playpad.viewcontroller.option.ProjectSettingsTabViewController; +import de.tobias.utils.util.FileUtils; +import javafx.application.Platform; import javafx.concurrent.Task; import javafx.event.ActionEvent; import javafx.fxml.FXML; @@ -56,13 +66,14 @@ public class PathsTabViewController extends ProjectSettingsTabViewController imp @Override public void saveSettings(ProjectSettings settings) { 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 (settings.getMediaPath() != null) { + if (!settings.getMediaPath().equals(newPath)) { + changedMediaPath = true; + if (settings.getMediaPath() != null && !settings.getMediaPath().toString().isEmpty()) { + oldMediaPath = Optional.of(settings.getMediaPath()); + } } } - if (useMediaPath.isSelected()) { settings.setMediaPath(newPath); } @@ -90,6 +101,7 @@ public class PathsTabViewController extends ProjectSettingsTabViewController imp @Override public Task<Void> getTask(ProjectSettings settings, Project project, IMainViewController controller) { return new Task<Void>() { + @Override protected Void call() throws Exception { updateTitle(name()); @@ -97,22 +109,54 @@ public class PathsTabViewController extends ProjectSettingsTabViewController imp project.closeFile(); - int i = 0; - Stream<Path> files = Files.list(oldMediaPath.get()); - files.forEach(file -> - { - // BUG Copy not work as expected + for (Pad pad : project.getPads().values()) { try { - Files.copy(file, newMediaPath.resolve(file.getFileName())); - Thread.sleep(500); + if (pad.getStatus() != PadStatus.EMPTY) { + PadContent content = pad.getContent(); + if (content instanceof SinglePathContent) { + Path path = ((SinglePathContent) content).getPath(); + Path copiedFile = newMediaPath.resolve(path.getFileName()); + + Files.copy(path, copiedFile, StandardCopyOption.REPLACE_EXISTING); + + Platform.runLater(() -> { + try { + content.handlePath(copiedFile); + } catch (NoSuchComponentException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + }); + } else if (content instanceof MultiPathContent) { + MultiPathContent pathHandler = (MultiPathContent) content; + List<Path> paths = pathHandler.getPaths(); + // TEST handle Paths in PadContent + + pathHandler.clearPaths(); + + for (Path path : paths) { + Path copiedFile = newMediaPath.resolve(path.getFileName()); + + Files.copy(path, copiedFile, StandardCopyOption.REPLACE_EXISTING); + content.handlePath(copiedFile); + } + } + } } catch (Exception e) { e.printStackTrace(); } - updateProgress(i, files.count()); - }); - files.close(); + } - project.loadPadsContent(); + // TODO Clear old media folder + if (oldMediaPath.isPresent()) + try { + FileUtils.deleteDirectory(oldMediaPath.get()); + } catch (IOException e) { + e.printStackTrace(); + } return null; } }; diff --git a/PlayWallCore/src/de/tobias/playpad/pad/conntent/path/MultiPathContent.java b/PlayWallCore/src/de/tobias/playpad/pad/conntent/path/MultiPathContent.java index 6f62b246257d96bda64073465dfe142b0bacf455..e10aa8b85e4e09a56b0e53e810fe03b8700bace9 100644 --- a/PlayWallCore/src/de/tobias/playpad/pad/conntent/path/MultiPathContent.java +++ b/PlayWallCore/src/de/tobias/playpad/pad/conntent/path/MultiPathContent.java @@ -6,4 +6,6 @@ import java.util.List; public interface MultiPathContent { public List<Path> getPaths(); + + public void clearPaths(); }