diff --git a/PlayWall/assets/de/tobias/playpad/assets/lang/_de.properties b/PlayWall/assets/de/tobias/playpad/assets/lang/_de.properties index 79621f247fa770a2d6dcdae88b077d9fdf51bb1b..841951b5c15168623334cfc51993f7acaa11f9a7 100644 --- a/PlayWall/assets/de/tobias/playpad/assets/lang/_de.properties +++ b/PlayWall/assets/de/tobias/playpad/assets/lang/_de.properties @@ -117,7 +117,7 @@ Info.Settings.ResetWarning=Die Einstellungen wurden zur Info.Settings.CacheDelete={} Datei(en) wurden gel�scht. # Info - Print -Info.Print.Header={} - Seite {} +Info.Print.Header={} - {} # Error - Standard Error.Standard.Gen=Es ist ein Fehler aufgetreten. Bitte versuchen Sie es sp�ter erneut. ({}) diff --git a/PlayWall/src/de/tobias/playpad/layout/desktop/DesktopMenuToolbarViewController.java b/PlayWall/src/de/tobias/playpad/layout/desktop/DesktopMenuToolbarViewController.java index 453d49f820e3171e35b4c2bedb2172ae25a8a5d6..e33f2211b23a30989c405b797c0caf5d18942f24 100644 --- a/PlayWall/src/de/tobias/playpad/layout/desktop/DesktopMenuToolbarViewController.java +++ b/PlayWall/src/de/tobias/playpad/layout/desktop/DesktopMenuToolbarViewController.java @@ -672,7 +672,8 @@ public class DesktopMenuToolbarViewController extends BasicMenuToolbarViewContro field.setPromptText(Localization.getString(Strings.Search_Placeholder)); Button button = new Button(Localization.getString(Strings.Search_Button)); - button.setOnAction(new DesktopSearchController(field, this)); + Project project = PlayPadMain.getProgramInstance().getCurrentProject(); + button.setOnAction(new DesktopSearchController(project, field, mainViewController)); HBox box = new HBox(14, field, button); box.setAlignment(Pos.CENTER_LEFT); diff --git a/PlayWall/src/de/tobias/playpad/layout/desktop/DesktopSearchController.java b/PlayWall/src/de/tobias/playpad/layout/desktop/DesktopSearchController.java index eb061618c9bf592c3b26977bfbc55e104701b7c0..92acef47e403c4ec10f92c03afa0087a9bc3f2c1 100644 --- a/PlayWall/src/de/tobias/playpad/layout/desktop/DesktopSearchController.java +++ b/PlayWall/src/de/tobias/playpad/layout/desktop/DesktopSearchController.java @@ -1,6 +1,13 @@ package de.tobias.playpad.layout.desktop; -import de.tobias.utils.ui.Alertable; +import java.util.List; + +import de.tobias.playpad.PlayPadMain; +import de.tobias.playpad.Strings; +import de.tobias.playpad.pad.Pad; +import de.tobias.playpad.project.Project; +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.TextField; @@ -8,40 +15,52 @@ import javafx.scene.control.TextField; // TODO Search Pads public class DesktopSearchController implements EventHandler<ActionEvent> { + private static final int HIGHLIGHT_DURATION = 3; + + private Project currentProject; + private TextField textField; - private Alertable alertable; + private IMainViewController mainView; + + public DesktopSearchController(Project project, TextField textField, IMainViewController mainView) { + this.currentProject = project; - public DesktopSearchController(TextField textField, Alertable alertable) { this.textField = textField; - this.alertable = alertable; + this.mainView = mainView; } + // Current Search + private String lastSearchTerm; private int currentIndex = 0; + private List<Pad> searchResult; @Override public void handle(ActionEvent event) { -// if (textField.getText().isEmpty()) { -// return; -// } -// -// Project currentProject = PlayPadMain.getProgramInstance().getCurrentProject(); -// main: for (int i = currentIndex; i < currentProject.getPadCount(); i++) { -// Pad pad = currentProject.getPad(i); -// if (pad.getStatus() != PadStatus.EMPTY) { -// if (pad.getName().startsWith(textField.getText())) { -// while (pad.getController() == null) { -// if (!PlayPadPlugin.getImplementation().getMainViewController() -// .showPage(PlayPadPlugin.getImplementation().getMainViewController().getPage() + 1)) { -// break main; -// } -// } -// pad.getController().getView().highlightView(3); -// currentIndex = i + 1; -// return; -// } -// } -// } -// alertable.showInfoMessage(Localization.getString(Strings.Search_Alert_NoMatches), PlayPadMain.stageIcon.orElse(null)); -// currentIndex = 0; + String currentSearchTerm = textField.getText(); + if (currentSearchTerm.isEmpty()) { + return; + } + + // New Search + if (!currentSearchTerm.equals(lastSearchTerm)) { + this.lastSearchTerm = currentSearchTerm; + searchResult = currentProject.findPads(currentSearchTerm); + currentIndex = 0; + } + + if (searchResult.isEmpty()) { + mainView.showInfoMessage(Localization.getString(Strings.Search_Alert_NoMatches), PlayPadMain.stageIcon.orElse(null)); + } + + if (currentIndex < searchResult.size()) { + Pad result = searchResult.get(currentIndex++); + mainView.showPage(result.getPage()); + if (result.getController() != null) { + result.getController().getView().highlightView(HIGHLIGHT_DURATION); + } + } else { + mainView.showInfoMessage(Localization.getString(Strings.Search_Alert_NoMatches), PlayPadMain.stageIcon.orElse(null)); + currentIndex = 0; + } } } diff --git a/PlayWall/src/de/tobias/playpad/pad/content/AudioContent.java b/PlayWall/src/de/tobias/playpad/pad/content/AudioContent.java index c2d7d5ca85badc152a301c5c113cf4a1b8268f69..d7a07ac1327d20eafe34c6e920b3a07fe73bd053 100644 --- a/PlayWall/src/de/tobias/playpad/pad/content/AudioContent.java +++ b/PlayWall/src/de/tobias/playpad/pad/content/AudioContent.java @@ -196,6 +196,9 @@ public class AudioContent extends PadContent implements Pauseable, Durationable, @Override public void unloadMedia() { + // First Stop the pad (if playing) + getPad().setStatus(PadStatus.STOP); + durationProperty.unbind(); positionProperty.unbind(); @@ -204,7 +207,7 @@ public class AudioContent extends PadContent implements Pauseable, Durationable, if (audioHandler != null) audioHandler.unloadMedia(); - Platform.runLater(() -> + Platform.runLater(() -> // TODO Platform.runLater ? { if (getPad() != null) { getPad().setStatus(PadStatus.EMPTY); diff --git a/PlayWall/src/de/tobias/playpad/viewcontroller/cell/PageNameListCell.java b/PlayWall/src/de/tobias/playpad/viewcontroller/cell/PageNameListCell.java new file mode 100644 index 0000000000000000000000000000000000000000..a2b661dc4ed199bd4e4e008b2ba7c4abd2a2d8cf --- /dev/null +++ b/PlayWall/src/de/tobias/playpad/viewcontroller/cell/PageNameListCell.java @@ -0,0 +1,25 @@ +package de.tobias.playpad.viewcontroller.cell; + +import de.tobias.playpad.PlayPadMain; +import de.tobias.playpad.Strings; +import de.tobias.playpad.project.page.Page; +import de.tobias.utils.util.Localization; +import javafx.scene.control.ListCell; + +public final class PageNameListCell extends ListCell<Integer> { + + @Override + protected void updateItem(Integer item, boolean empty) { + super.updateItem(item, empty); + if (!empty) { + Page page = PlayPadMain.getProgramInstance().getCurrentProject().getPage(item); + String name = page.getName(); + if (name.isEmpty()) { + name = Localization.getString(Strings.UI_Window_Main_PageButton, (item)); + } + setText(name); + } else { + setText(""); + } + } +} \ No newline at end of file diff --git a/PlayWall/src/de/tobias/playpad/viewcontroller/dialog/PrintDialog.java b/PlayWall/src/de/tobias/playpad/viewcontroller/dialog/PrintDialog.java index c4ad55310bf2f14a76fa7fc71b7d18487228daab..d4fe619c978fdd49f7db89f930b981b0fb9c81f9 100644 --- a/PlayWall/src/de/tobias/playpad/viewcontroller/dialog/PrintDialog.java +++ b/PlayWall/src/de/tobias/playpad/viewcontroller/dialog/PrintDialog.java @@ -14,7 +14,9 @@ import de.tobias.playpad.pad.Pad; import de.tobias.playpad.project.Project; import de.tobias.playpad.project.ProjectSettings; import de.tobias.playpad.project.page.PadIndex; +import de.tobias.playpad.project.page.Page; import de.tobias.playpad.settings.Profile; +import de.tobias.playpad.viewcontroller.cell.PageNameListCell; import de.tobias.utils.application.ApplicationUtils; import de.tobias.utils.ui.ViewController; import de.tobias.utils.util.Localization; @@ -48,9 +50,11 @@ public class PrintDialog extends ViewController { int pages = project.getPages().size(); for (int i = 0; i < pages; i++) { - pageComboBox.getItems().add(i + 1); + pageComboBox.getItems().add(i); } pageComboBox.getSelectionModel().selectFirst(); + pageComboBox.setCellFactory(param -> new PageNameListCell()); + pageComboBox.setButtonCell(new PageNameListCell()); getStage().initOwner(owner); } @@ -59,7 +63,7 @@ public class PrintDialog extends ViewController { public void init() { pageComboBox.getSelectionModel().selectedItemProperty().addListener((a, b, c) -> { - createPreview(c - 1); + createPreview(c); }); addCloseKeyShortcut(() -> getStage().close()); @@ -76,7 +80,7 @@ public class PrintDialog extends ViewController { Profile.currentProfile().currentLayout().applyCss(getStage()); } - private void createPreview(int page) { + private void createPreview(int pageIndex) { Html html = new Html(); Body body = new Body(); body.setStyle("max-width: 1000px; font-family: sans-serif;"); @@ -84,7 +88,13 @@ public class PrintDialog extends ViewController { H1 header = new H1(); - String headerString = Localization.getString(Strings.Info_Print_Header, project.getProjectReference().getName(), page + 1); + Page page = project.getPage(pageIndex); + String pageName = page.getName(); + if (pageName.isEmpty()) { + pageName = Localization.getString(Strings.UI_Window_Main_PageButton, (pageIndex + 1)); + } + + String headerString = Localization.getString(Strings.Info_Print_Header, project.getProjectReference().getName(), pageName); header.appendText(headerString); header.setStyle("text-align: center;"); body.appendChild(header); @@ -93,7 +103,7 @@ public class PrintDialog extends ViewController { table.setStyle("border:1px solid black;border-collapse:collapse;"); ProjectSettings settings = project.getSettings(); - int i = 0; + int padIndex = 0; for (int y = 0; y < settings.getRows(); y++) { Tr tr = new Tr(); @@ -104,14 +114,14 @@ public class PrintDialog extends ViewController { + "px; padding: 5px; vertical-align: center; text-align: center; min-height: 30px; min-width: 100px;"); Div div = new Div(); div.setStyle("word-break: break-all; white-space: normal;"); - Pad pad = this.project.getPad(new PadIndex(i, page)); + Pad pad = this.project.getPad(new PadIndex(padIndex, pageIndex)); if (pad.getContent() != null && pad.getContent().isPadLoaded()) div.appendText(pad.getName()); else div.appendText("-"); td.appendChild(div); - i++; + padIndex++; tr.appendChild(td); } } diff --git a/PlayWall/src/de/tobias/playpad/viewcontroller/main/MainViewController.java b/PlayWall/src/de/tobias/playpad/viewcontroller/main/MainViewController.java index 4081a87251aa332111f1ba6b9a407fd86cbac16b..a25c1b9c63eaf9656c83d2f0e22b27cee3e9b599 100644 --- a/PlayWall/src/de/tobias/playpad/viewcontroller/main/MainViewController.java +++ b/PlayWall/src/de/tobias/playpad/viewcontroller/main/MainViewController.java @@ -36,7 +36,6 @@ import de.tobias.playpad.view.main.MainLayoutHandler; import de.tobias.playpad.viewcontroller.dialog.ErrorSummaryDialog; import de.tobias.playpad.viewcontroller.dialog.SaveDialog; 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; @@ -69,7 +68,7 @@ import javafx.stage.Modality; import javafx.stage.Screen; import javafx.stage.Stage; -public class MainViewController extends ViewController implements IMainViewController, NotificationHandler, ProfileListener { +public class MainViewController extends ViewController implements IMainViewController, ProfileListener { private static final int FIRST_PAGE = 0; diff --git a/PlayWallCore/src/de/tobias/playpad/project/Project.java b/PlayWallCore/src/de/tobias/playpad/project/Project.java index 6ed273ba2ef1b6ced6be424cd3ebfc3606033cad..100a296d8ac438e3a7fd450570b7339be4a4afb2 100644 --- a/PlayWallCore/src/de/tobias/playpad/project/Project.java +++ b/PlayWallCore/src/de/tobias/playpad/project/Project.java @@ -110,9 +110,9 @@ public class Project { public void setPad(PadIndex index, Pad pad) { if (pad != null) { + // Remove Pad from old location if (pad.getPage() != index.getPage()) { Page oldPage = getPage(pad.getPage()); - // Nur Löschen, wenn auch noch das Pad an dieser Stelle ist, und nicht an andere Stelle if (oldPage.getPad(pad.getIndex()).equals(pad)) { oldPage.removePade(index.getId()); } @@ -322,10 +322,31 @@ public class Project { if (pages.size() == ProjectSettings.MAX_PAGES) { return false; } - int index = pages.size(); - page.setId(index); + + int newIndex = pages.size(); + + page.setId(newIndex); pages.add(page); + return true; + } + /** + * Find pads, which name starts with a given string + * + * @param name + * search key + * @return found pads in project + */ + public List<Pad> findPads(String name) { + List<Pad> result = new ArrayList<>(); + for (Pad pad : getPads()) { + if (pad.getStatus() != PadStatus.EMPTY) { + if (pad.getName().startsWith(name)) { + result.add(pad); + } + } + } + return result; } } diff --git a/PlayWallCore/src/de/tobias/playpad/project/ref/ProjectReferences.java b/PlayWallCore/src/de/tobias/playpad/project/ref/ProjectReferences.java index 67fc41d20bc0a588b5a47fbb5616ddbfa54525a1..feabcc448ff93cc1d8ab2697fdc785f57a646054 100644 --- a/PlayWallCore/src/de/tobias/playpad/project/ref/ProjectReferences.java +++ b/PlayWallCore/src/de/tobias/playpad/project/ref/ProjectReferences.java @@ -61,8 +61,8 @@ public final class ProjectReferences { } private static void duplicateFiles(ProjectReference currentProject, ProjectReference newProjectReference) throws IOException { - Path oldPath = ApplicationUtils.getApplication().getPath(PathType.DOCUMENTS, currentProject.getName()); - Path newPath = ApplicationUtils.getApplication().getPath(PathType.DOCUMENTS, newProjectReference.getName()); + Path oldPath = currentProject.getProjectPath(); + Path newPath = newProjectReference.getProjectPath(); Files.copy(oldPath, newPath, StandardCopyOption.COPY_ATTRIBUTES); } diff --git a/PlayWallCore/src/de/tobias/playpad/viewcontroller/main/IMainViewController.java b/PlayWallCore/src/de/tobias/playpad/viewcontroller/main/IMainViewController.java index 5451c138c78e59a849766ce2ba5d41d700531c68..6cdbcf12808a8620c7f69d7b4e2c213faf6e7dd1 100644 --- a/PlayWallCore/src/de/tobias/playpad/viewcontroller/main/IMainViewController.java +++ b/PlayWallCore/src/de/tobias/playpad/viewcontroller/main/IMainViewController.java @@ -7,6 +7,7 @@ import de.tobias.playpad.pad.view.IPadView; import de.tobias.playpad.settings.keys.KeyCollection; import de.tobias.playpad.view.main.MainLayoutConnect; import de.tobias.playpad.view.main.MainLayoutHandler; +import de.tobias.utils.ui.Alertable; import de.tobias.utils.ui.NotificationHandler; import de.tobias.utils.ui.scene.NotificationPane; import javafx.event.Event; @@ -26,7 +27,7 @@ import javafx.stage.Stage; * @since 5.1.0 * */ -public interface IMainViewController extends NotificationHandler { +public interface IMainViewController extends NotificationHandler, Alertable { /** * Setzt die Grid Farbe. diff --git a/PlayWallNativeWin/src/de/tobias/playpad/nawin/audio/NativeAudioWinHandler.java b/PlayWallNativeWin/src/de/tobias/playpad/nawin/audio/NativeAudioWinHandler.java index 48c0508bcda7f0318cb90b64976c4725881eb146..5d7853e0ac4d7751c833966b875d3a1a127a53d5 100644 --- a/PlayWallNativeWin/src/de/tobias/playpad/nawin/audio/NativeAudioWinHandler.java +++ b/PlayWallNativeWin/src/de/tobias/playpad/nawin/audio/NativeAudioWinHandler.java @@ -32,7 +32,8 @@ public class NativeAudioWinHandler extends AudioHandler implements Soundcardable private static final int SLEEP_TIME_POSITION = 50; static { - positionThread = new Thread(() -> { + positionThread = new Thread(() -> + { while (true) { try { if (playedHandlers.isEmpty()) { @@ -136,7 +137,9 @@ public class NativeAudioWinHandler extends AudioHandler implements Soundcardable @Override public void setVolume(double volume) { - audioHandler.setVolume((float) volume); + if (audioHandler != null) { + audioHandler.setVolume((float) volume); + } } @Override @@ -146,7 +149,8 @@ public class NativeAudioWinHandler extends AudioHandler implements Soundcardable @Override public void loadMedia(Path[] paths) { - Platform.runLater(() -> { + Platform.runLater(() -> + { if (getContent().getPad().isPadVisible()) { getContent().getPad().getController().getView().showBusyView(true); } @@ -155,11 +159,11 @@ public class NativeAudioWinHandler extends AudioHandler implements Soundcardable audioHandler = new NativeAudio(); audioHandler.load(paths[0].toString()); - String name = (String) Profile.currentProfile().getProfileSettings().getAudioUserInfo() - .get(NativeAudioWinHandler.SOUND_CARD); + String name = (String) Profile.currentProfile().getProfileSettings().getAudioUserInfo().get(NativeAudioWinHandler.SOUND_CARD); audioHandler.setDevice(name); - Platform.runLater(() -> { + Platform.runLater(() -> + { durationProperty.set(Duration.millis(audioHandler.getDuration())); getContent().getPad().setStatus(PadStatus.READY); if (getContent().getPad().isPadVisible()) { diff --git a/PlayWallPlugins/mediaplugin/de/tobias/playpad/mediaplugin/image/ImageContent.java b/PlayWallPlugins/mediaplugin/de/tobias/playpad/mediaplugin/image/ImageContent.java index 1856b369ac7080c9be4548540b83ef07b5f5ec7e..65f08624ca734bdecaec52e42ab43a5c4d8fb773 100644 --- a/PlayWallPlugins/mediaplugin/de/tobias/playpad/mediaplugin/image/ImageContent.java +++ b/PlayWallPlugins/mediaplugin/de/tobias/playpad/mediaplugin/image/ImageContent.java @@ -44,8 +44,7 @@ public class ImageContent extends PadContent { } @Override - public void updateVolume() { - } + public void updateVolume() {} @Override public String getType() { @@ -79,6 +78,9 @@ public class ImageContent extends PadContent { @Override public void unloadMedia() { + // First Stop the pad (if playing) + getPad().setStatus(PadStatus.STOP); + Platform.runLater(() -> { if (getPad() != null) { @@ -130,7 +132,7 @@ public class ImageContent extends PadContent { e.printStackTrace(); } } - + @Override public PadContent clone() throws CloneNotSupportedException { ImageContent clone = (ImageContent) super.clone(); diff --git a/PlayWallPlugins/mediaplugin/de/tobias/playpad/mediaplugin/video/VideoContent.java b/PlayWallPlugins/mediaplugin/de/tobias/playpad/mediaplugin/video/VideoContent.java index a113ea1b56cfab56d627ca3c3d59147f1e3be365..0d49f9f637e3abb231dfc96e339de3b89522856d 100644 --- a/PlayWallPlugins/mediaplugin/de/tobias/playpad/mediaplugin/video/VideoContent.java +++ b/PlayWallPlugins/mediaplugin/de/tobias/playpad/mediaplugin/video/VideoContent.java @@ -187,7 +187,7 @@ public class VideoContent extends PadContent implements Pauseable, Durationable getPad().getController().getView().showBusyView(false); } }); -// getPad().throwException(path, player.getError()); TODO Error Handling User + // getPad().throwException(path, player.getError()); TODO Error Handling User }); player.setOnEndOfMedia(() -> { @@ -209,6 +209,9 @@ public class VideoContent extends PadContent implements Pauseable, Durationable @Override public void unloadMedia() { + // First Stop the pad (if playing) + getPad().setStatus(PadStatus.STOP); + durationProperty.unbind(); positionProperty.unbind(); @@ -269,7 +272,7 @@ public class VideoContent extends PadContent implements Pauseable, Durationable e.printStackTrace(); } } - + @Override public PadContent clone() throws CloneNotSupportedException { VideoContent clone = (VideoContent) super.clone();