From 7c94d6cd4d09b617ad1ca4e0a6f6f0f942403480 Mon Sep 17 00:00:00 2001
From: tobias <tobias.ullerich@icloud.com>
Date: Sat, 13 Aug 2016 19:03:53 +0200
Subject: [PATCH] Add GUI for Media Folder Settings

Fixed minor bugs
---
 .../playpad/assets/lang/ui_de.properties      |  6 +-
 .../assets/view/option/global/keysTab.fxml    |  2 +-
 .../assets/view/option/project/pathTab.fxml   | 30 ++++++++
 .../DesktopMenuToolbarViewController.java     |  6 +-
 .../project/PathsTabViewController.java       | 70 +++++++++++++++++++
 .../ProjectSettingsViewController.java        |  5 +-
 .../playpad/project/ProjectSettings.java      | 34 +++++++++
 7 files changed, 145 insertions(+), 8 deletions(-)
 create mode 100644 PlayWall/assets/de/tobias/playpad/assets/view/option/project/pathTab.fxml
 create mode 100644 PlayWall/src/de/tobias/playpad/viewcontroller/option/project/PathsTabViewController.java

diff --git a/PlayWall/assets/de/tobias/playpad/assets/lang/ui_de.properties b/PlayWall/assets/de/tobias/playpad/assets/lang/ui_de.properties
index 743131ff..811b3f95 100644
--- a/PlayWall/assets/de/tobias/playpad/assets/lang/ui_de.properties
+++ b/PlayWall/assets/de/tobias/playpad/assets/lang/ui_de.properties
@@ -87,7 +87,11 @@ settings.keys.button.change=Neu
 settings.keys.button.delete=Verbindung aufheben
 settings.keys.table.name=Name
 settings.keys.table.shortcut=Kurzbefehl
-settings.keys.textfieldsearch=Suchen...
+settings.keys.textfield.search=Suchen...
+
+settings.paths.label.media=Mediendateien:
+settings.paths.button.choose=W�hlen...
+settings.paths.checkbox.mediaActive=Mediendateien in Medienordner kopieren (oder am Orgenialpfad lassen) // TODO
 
 settings.button.finish=Fertig
 settings.checkbox.activate=Aktivieren
diff --git a/PlayWall/assets/de/tobias/playpad/assets/view/option/global/keysTab.fxml b/PlayWall/assets/de/tobias/playpad/assets/view/option/global/keysTab.fxml
index 212bd549..53e304a2 100644
--- a/PlayWall/assets/de/tobias/playpad/assets/view/option/global/keysTab.fxml
+++ b/PlayWall/assets/de/tobias/playpad/assets/view/option/global/keysTab.fxml
@@ -8,7 +8,7 @@
 <VBox maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="-Infinity" minWidth="-Infinity" spacing="14.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
    <children>
       <Label text="%settings.keys.label.headline" underline="true" />
-      <TextField fx:id="searchTextField" promptText="%settings.keys.textfieldsearch" />
+      <TextField fx:id="searchTextField" promptText="%settings.keys.textfield.search" />
       <TableView fx:id="table" prefHeight="200.0" prefWidth="200.0" VBox.vgrow="ALWAYS">
         <columns>
           <TableColumn fx:id="nameTableColumn" editable="false" prefWidth="378.0" text="%settings.keys.table.name" />
diff --git a/PlayWall/assets/de/tobias/playpad/assets/view/option/project/pathTab.fxml b/PlayWall/assets/de/tobias/playpad/assets/view/option/project/pathTab.fxml
new file mode 100644
index 00000000..1929289e
--- /dev/null
+++ b/PlayWall/assets/de/tobias/playpad/assets/view/option/project/pathTab.fxml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<?import javafx.geometry.*?>
+<?import javafx.scene.control.*?>
+<?import java.lang.*?>
+<?import javafx.scene.layout.*?>
+
+<VBox maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" spacing="14.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
+   <children>
+      <HBox alignment="CENTER_LEFT" spacing="14.0">
+         <children>
+            <Label prefWidth="150.0" text="%settings.paths.label.media" />
+            <TextField fx:id="mediaPathTextField" editable="false" HBox.hgrow="ALWAYS" />
+            <Button fx:id="mediaPathChooseButton" mnemonicParsing="false" onAction="#mediaPathChooseHandler" text="%settings.paths.button.choose" />
+         </children>
+      </HBox>
+      <HBox spacing="14.0">
+         <children>
+            <CheckBox fx:id="useMediaPath" mnemonicParsing="false" text="%settings.paths.checkbox.mediaActive">
+               <HBox.margin>
+                  <Insets left="164.0" />
+               </HBox.margin>
+            </CheckBox>
+         </children>
+      </HBox>
+   </children>
+   <padding>
+      <Insets bottom="14.0" left="14.0" right="14.0" top="14.0" />
+   </padding>
+</VBox>
diff --git a/PlayWall/src/de/tobias/playpad/layout/desktop/DesktopMenuToolbarViewController.java b/PlayWall/src/de/tobias/playpad/layout/desktop/DesktopMenuToolbarViewController.java
index b6fec8b7..e1f9e1b3 100644
--- a/PlayWall/src/de/tobias/playpad/layout/desktop/DesktopMenuToolbarViewController.java
+++ b/PlayWall/src/de/tobias/playpad/layout/desktop/DesktopMenuToolbarViewController.java
@@ -468,7 +468,6 @@ public class DesktopMenuToolbarViewController extends BasicMenuToolbarViewContro
 
 	@FXML
 	void projectSettingsHandler(ActionEvent event) {
-		Midi midi = Midi.getInstance();
 		Project currentProject = PlayPadMain.getProgramInstance().getCurrentProject();
 
 		if (projectSettingsViewController == null) {
@@ -476,16 +475,15 @@ public class DesktopMenuToolbarViewController extends BasicMenuToolbarViewContro
 
 			Runnable onFinish = () ->
 			{
-				midi.setListener(mainViewController.getMidiHandler());
-
 				for (ProjectSettingsTabViewController controller : projectSettingsViewController.getTabs()) {
 					if (controller.needReload()) {
 						controller.reload(currentProject.getSettings(), currentProject, mainViewController);
 					}
 				}
 
-				profileSettingsViewController = null;
+				projectSettingsViewController = null;
 				mainStage.toFront();
+				System.out.println("Done");
 			};
 
 			projectSettingsViewController = new ProjectSettingsViewController(mainViewController.getScreen(), mainStage, currentProject,
diff --git a/PlayWall/src/de/tobias/playpad/viewcontroller/option/project/PathsTabViewController.java b/PlayWall/src/de/tobias/playpad/viewcontroller/option/project/PathsTabViewController.java
new file mode 100644
index 00000000..354e1157
--- /dev/null
+++ b/PlayWall/src/de/tobias/playpad/viewcontroller/option/project/PathsTabViewController.java
@@ -0,0 +1,70 @@
+package de.tobias.playpad.viewcontroller.option.project;
+
+import java.io.File;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+
+import de.tobias.playpad.PlayPadMain;
+import de.tobias.playpad.project.ProjectSettings;
+import de.tobias.playpad.viewcontroller.option.ProjectSettingsTabViewController;
+import javafx.event.ActionEvent;
+import javafx.fxml.FXML;
+import javafx.scene.control.Button;
+import javafx.scene.control.CheckBox;
+import javafx.scene.control.TextField;
+import javafx.stage.DirectoryChooser;
+
+public class PathsTabViewController extends ProjectSettingsTabViewController {
+
+	// Media Path
+	@FXML private TextField mediaPathTextField;
+	@FXML private Button mediaPathChooseButton;
+	@FXML private CheckBox useMediaPath;
+
+	public PathsTabViewController() {
+		super("pathTab.fxml", "de/tobias/playpad/assets/view/option/project/", PlayPadMain.getUiResourceBundle());
+		// TODO Auto-generated constructor stub
+	}
+
+	@FXML
+	void mediaPathChooseHandler(ActionEvent event) {
+		DirectoryChooser chooser = new DirectoryChooser();
+		File folder = chooser.showDialog(getStage());
+		if (folder != null) {
+			Path path = folder.toPath();
+		}
+	}
+
+	@Override
+	public void loadSettings(ProjectSettings settings) {
+		if (settings.isUseMediaPath())
+			mediaPathTextField.setText(settings.getMediaPath().toString());
+		useMediaPath.setSelected(settings.isUseMediaPath());
+
+	}
+
+	@Override
+	public void saveSettings(ProjectSettings settings) {
+		if (useMediaPath.isSelected()) {
+			settings.setMediaPath(Paths.get(mediaPathTextField.getText()));
+		}
+		settings.setUseMediaPath(useMediaPath.isSelected());
+
+	}
+
+	@Override
+	public boolean needReload() {
+		return false;
+	}
+
+	@Override
+	public boolean validSettings() {
+		return true;
+	}
+
+	@Override
+	public String name() {
+		return "Pfade (i18n)"; // TODO
+	}
+
+}
diff --git a/PlayWall/src/de/tobias/playpad/viewcontroller/option/project/ProjectSettingsViewController.java b/PlayWall/src/de/tobias/playpad/viewcontroller/option/project/ProjectSettingsViewController.java
index 455df638..64b2fe03 100644
--- a/PlayWall/src/de/tobias/playpad/viewcontroller/option/project/ProjectSettingsViewController.java
+++ b/PlayWall/src/de/tobias/playpad/viewcontroller/option/project/ProjectSettingsViewController.java
@@ -42,6 +42,7 @@ public class ProjectSettingsViewController extends ViewController implements IPr
 		boolean activePlayer = project.hasPlayedPlayers();
 
 		addTab(new GeneralTabViewController(currentScreen, this, activePlayer));
+		addTab(new PathsTabViewController());
 
 		// Show Current Settings
 		loadTabs(settings);
@@ -60,7 +61,7 @@ public class ProjectSettingsViewController extends ViewController implements IPr
 		PlayPadMain.stageIcon.ifPresent(stage.getIcons()::add);
 
 		stage.setMinWidth(715);
-		stage.setMinHeight(700);
+		stage.setMinHeight(500);
 		stage.setTitle(Localization.getString(Strings.UI_Window_GlobalSettings_Title));
 
 		Profile.currentProfile().currentLayout().applyCss(getStage());
@@ -70,7 +71,6 @@ public class ProjectSettingsViewController extends ViewController implements IPr
 	 * Zeigt die aktuellen Einstellungen für die Tabs an.
 	 */
 	private void loadTabs(ProjectSettings settings) {
-
 		for (ProjectSettingsTabViewController controller : tabs) {
 			controller.loadSettings(settings);
 		}
@@ -85,6 +85,7 @@ public class ProjectSettingsViewController extends ViewController implements IPr
 		}
 	}
 
+	@Override
 	public boolean closeRequest() {
 		return onFinish();
 	}
diff --git a/PlayWallCore/src/de/tobias/playpad/project/ProjectSettings.java b/PlayWallCore/src/de/tobias/playpad/project/ProjectSettings.java
index 36bff9fa..68b6d17c 100644
--- a/PlayWallCore/src/de/tobias/playpad/project/ProjectSettings.java
+++ b/PlayWallCore/src/de/tobias/playpad/project/ProjectSettings.java
@@ -1,5 +1,8 @@
 package de.tobias.playpad.project;
 
+import java.nio.file.Path;
+import java.nio.file.Paths;
+
 import org.dom4j.Element;
 
 import de.tobias.utils.settings.Storable;
@@ -14,6 +17,9 @@ public class ProjectSettings {
 	@Storable private int columns = 6;
 	@Storable private int rows = 5;
 
+	private boolean useMediaPath = false;
+	private Path mediaPath = null;
+
 	public int getPageCount() {
 		return pageCount;
 	}
@@ -36,6 +42,14 @@ public class ProjectSettings {
 		return rows;
 	}
 
+	public Path getMediaPath() {
+		return mediaPath;
+	}
+
+	public boolean isUseMediaPath() {
+		return useMediaPath;
+	}
+
 	public void setPageCount(int pageCount) {
 		if (pageCount > MAX_PAGES)
 			pageCount = MAX_PAGES;
@@ -54,10 +68,21 @@ public class ProjectSettings {
 		this.rows = rows;
 	}
 
+	public void setMediaPath(Path mediaPath) {
+		this.mediaPath = mediaPath;
+	}
+
+	public void setUseMediaPath(boolean useMediaPath) {
+		this.useMediaPath = useMediaPath;
+	}
+
 	private static final String ROWS_ELEMENT = "Rows";
 	private static final String COLUMNS_ELEMENT = "Columns";
 	private static final String PAGE_COUNT_ELEMENT = "PageCount";
 
+	private static final String MEDIA_PATH_ELEMENT = "MediaPath";
+	private static final String MEDIA_PATH_ACTIVE_ATTR = "active";
+
 	public static ProjectSettings load(Element element) {
 		ProjectSettings settings = new ProjectSettings();
 		if (element.element(PAGE_COUNT_ELEMENT) != null)
@@ -66,6 +91,10 @@ 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)));
+		}
 
 		return settings;
 	}
@@ -74,5 +103,10 @@ public class ProjectSettings {
 		element.addElement(PAGE_COUNT_ELEMENT).addText(String.valueOf(pageCount));
 		element.addElement(COLUMNS_ELEMENT).addText(String.valueOf(columns));
 		element.addElement(ROWS_ELEMENT).addText(String.valueOf(rows));
+
+		Element mediaPath = element.addElement(MEDIA_PATH_ELEMENT);
+		if (this.mediaPath != null)
+			mediaPath.addText(this.mediaPath.toString());
+		mediaPath.addAttribute(MEDIA_PATH_ACTIVE_ATTR, String.valueOf(useMediaPath));
 	}
 }
-- 
GitLab