From 427c696eeeb5f024aac880ab91891725fe2b8449 Mon Sep 17 00:00:00 2001
From: tobias <thinkdifferent055@gmail.com>
Date: Sun, 30 Oct 2016 14:45:12 +0100
Subject: [PATCH] Add Page Names to Print Dialog

---
 .../tobias/playpad/assets/lang/_de.properties |  2 +-
 .../viewcontroller/cell/PageNameListCell.java | 25 +++++++++++++++++++
 .../viewcontroller/dialog/PrintDialog.java    | 24 ++++++++++++------
 3 files changed, 43 insertions(+), 8 deletions(-)
 create mode 100644 PlayWall/src/de/tobias/playpad/viewcontroller/cell/PageNameListCell.java

diff --git a/PlayWall/assets/de/tobias/playpad/assets/lang/_de.properties b/PlayWall/assets/de/tobias/playpad/assets/lang/_de.properties
index 79621f24..841951b5 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/viewcontroller/cell/PageNameListCell.java b/PlayWall/src/de/tobias/playpad/viewcontroller/cell/PageNameListCell.java
new file mode 100644
index 00000000..a2b661dc
--- /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 c4ad5531..d4fe619c 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);
 			}
 		}
-- 
GitLab