From 66b0565f51f1177104846b9ba77d2d937233c9a0 Mon Sep 17 00:00:00 2001 From: Kennedy Odife Date: Wed, 20 Dec 2023 02:35:49 +0100 Subject: [PATCH] Enable custom title for ImageGroupDisplayable #558 (#590) * Enable custom title for ImageGroupDisplayable #558 * Show a dialog after selecting and adding multiple images. * The user can give the image group a title * If no title is provided, the file names would be concatenated to form the image group name. * Image group title is saved with schedule. * Handle backwards compatibility of ImageGroup xml New structure of ImageGroup xml ``` Image Group Title file1;file2; ``` * Remove unused LOGGER property * Move dialog image group texts to language file #558 Also set the editor text with the default concatenated file names --- Quelea/languages/gb.lang | 4 +- .../displayable/ImageGroupDisplayable.java | 91 ++++++++++++------- .../actionhandlers/AddImageActionHandler.java | 30 ++++-- 3 files changed, 83 insertions(+), 42 deletions(-) diff --git a/Quelea/languages/gb.lang b/Quelea/languages/gb.lang index a86b4f9b2..d84e38572 100644 --- a/Quelea/languages/gb.lang +++ b/Quelea/languages/gb.lang @@ -782,4 +782,6 @@ general.text.options=General Text Options translation.text.options=Translation Text Options use.default.translation.label=Use Default Translation translation.name.label=Translation name -ccli.licence=CCLI Licence \ No newline at end of file +ccli.licence=CCLI Licence +dialog.image.group.header=Image Group +dialog.image.group.title=Rename image group \ No newline at end of file diff --git a/Quelea/src/main/java/org/quelea/data/displayable/ImageGroupDisplayable.java b/Quelea/src/main/java/org/quelea/data/displayable/ImageGroupDisplayable.java index f2f5468a2..615ffa9b9 100644 --- a/Quelea/src/main/java/org/quelea/data/displayable/ImageGroupDisplayable.java +++ b/Quelea/src/main/java/org/quelea/data/displayable/ImageGroupDisplayable.java @@ -17,42 +17,36 @@ */ package org.quelea.data.displayable; -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.logging.Logger; -import javafx.scene.image.Image; -import javafx.scene.image.ImageView; -import org.quelea.data.imagegroup.ImageGroup; -import org.quelea.data.imagegroup.ImageGroupFactory; -import org.quelea.services.utils.LoggerUtils; -import org.quelea.services.utils.QueleaProperties; -import org.quelea.services.utils.Utils; -import org.w3c.dom.Node; + import java.io.File; + import java.io.IOException; + import java.util.ArrayList; + import java.util.Arrays; + import java.util.Collection; + import java.util.Collections; + import java.util.List; + import java.util.Map; + import javafx.scene.image.Image; + import javafx.scene.image.ImageView; + import org.quelea.data.imagegroup.ImageGroup; + import org.quelea.data.imagegroup.ImageGroupFactory; + import org.quelea.services.utils.QueleaProperties; + import org.quelea.services.utils.Utils; + import org.w3c.dom.Node; + import org.w3c.dom.NodeList; -/** + /** * A displayable that's an image group. *

* @author Arvid, based on PresentationDisplayable */ public class ImageGroupDisplayable implements Displayable { - - private static final Logger LOGGER = LoggerUtils.getLogger(); private final File[] files; private final ImageGroup presentation; + private final String title; - /** - * Create a new image group displayable - *

- * @param file the file to create the PDF presentation from. - */ - public ImageGroupDisplayable(File[] file) throws IOException { + public ImageGroupDisplayable(File[] file, String groupTitle) throws IOException { this.files = file; + this.title = groupTitle; presentation = new ImageGroupFactory().getPresentation(file); if (presentation == null) { throw new IOException("Error with image group, couldn't open " + Arrays.toString(file)); @@ -79,6 +73,10 @@ public boolean supportClear() { public String getXML() { StringBuilder ret = new StringBuilder(); ret.append(""); + ret.append(""); + ret.append(Utils.escapeXML(title)); + ret.append(""); + ret.append(""); for (File f : files) { String loc; if (QueleaProperties.get().getEmbedMediaInScheduleFile()) { @@ -88,6 +86,7 @@ public String getXML() { } ret.append(Utils.escapeXML(loc)).append(";"); } + ret.append(""); ret.append(""); return ret.toString(); } @@ -100,15 +99,35 @@ public String getXML() { * @return the object as defined by the XML. */ public static ImageGroupDisplayable parseXML(Node node, Map fileChanges) throws IOException { - String[] files = node.getTextContent().split(";"); - ArrayList tmp = new ArrayList<>(); - for (String f : files) { - tmp.add(Utils.getChangedFile(f, fileChanges)); + // Check for the title node. Since title is a later update, we want to maintain compatibility with older exports. + String title = null; + NodeList childNodes = node.getChildNodes(); + if (childNodes.getLength() > 0) { + for (int i = 0; i < childNodes.getLength(); i++) { + Node childNode = childNodes.item(i); + if ("title".equals(childNode.getNodeName())) { + title = childNode.getTextContent(); + } else if ("files".equals(childNode.getNodeName())) { + node = childNode; + } + } } - return new ImageGroupDisplayable(tmp.toArray(new File[tmp.size()])); + return imageGroupFromXml(node, fileChanges, title); } - /** + + private static ImageGroupDisplayable imageGroupFromXml(Node node, Map fileChanges, String title) throws IOException { + String[] files = node.getTextContent().split(";"); + ArrayList tmp = new ArrayList<>(); + for (String f : files) { + tmp.add(Utils.getChangedFile(f, fileChanges)); + } + File[] fileArray = tmp.toArray(new File[0]); + if (title == null) title = concatenatedFileNames(fileArray); + return new ImageGroupDisplayable(fileArray, title); + } + + /** * Get the preview icon of this image group. *

* @return the imagegroup preview icon. @@ -125,11 +144,15 @@ public ImageView getPreviewIcon() { */ @Override public String getPreviewText() { - StringBuilder sb = new StringBuilder(""); + return this.title; + } + + public static String concatenatedFileNames(File[] files) { + StringBuilder sb = new StringBuilder(); for (File f : files) { sb.append(f.getName()).append(", "); } - return "Image Group: " + sb.toString().substring(0, sb.toString().lastIndexOf(",")); + return "Image Group: " + sb.substring(0, sb.toString().lastIndexOf(",")); } /** diff --git a/Quelea/src/main/java/org/quelea/windows/main/actionhandlers/AddImageActionHandler.java b/Quelea/src/main/java/org/quelea/windows/main/actionhandlers/AddImageActionHandler.java index da0b0fa2f..021944f92 100644 --- a/Quelea/src/main/java/org/quelea/windows/main/actionhandlers/AddImageActionHandler.java +++ b/Quelea/src/main/java/org/quelea/windows/main/actionhandlers/AddImageActionHandler.java @@ -18,14 +18,12 @@ */ package org.quelea.windows.main.actionhandlers; -import java.io.File; -import java.io.IOException; -import java.util.List; -import java.util.logging.Level; -import java.util.logging.Logger; import javafx.application.Platform; import javafx.event.ActionEvent; import javafx.event.EventHandler; +import javafx.scene.control.TextInputDialog; +import javafx.scene.image.Image; +import javafx.scene.image.ImageView; import javafx.stage.FileChooser; import org.javafx.dialog.Dialog; import org.quelea.data.displayable.ImageDisplayable; @@ -37,6 +35,13 @@ import org.quelea.windows.main.QueleaApp; import org.quelea.windows.main.StatusPanel; +import java.io.File; +import java.io.IOException; +import java.util.List; +import java.util.Optional; +import java.util.logging.Level; +import java.util.logging.Logger; + /** * The action handler for adding images. * @@ -72,13 +77,24 @@ public void run() { try { if (!halt) { Platform.runLater(() -> { + File[] filesArray = files.toArray(new File[0]); + + TextInputDialog dialog = new TextInputDialog(); + dialog.setTitle(LabelGrabber.INSTANCE.getLabel("dialog.image.group.title")); + dialog.setHeaderText(LabelGrabber.INSTANCE.getLabel("dialog.image.group.header")); + dialog.setGraphic(new ImageView(new Image("file:icons/image-group-schedule.png"))); + + String fallbackTitle = ImageGroupDisplayable.concatenatedFileNames(filesArray); + dialog.getEditor().setText(fallbackTitle); + Optional result = dialog.showAndWait(); + String imageGroupTitle = result.orElse(fallbackTitle); try { - ImageGroupDisplayable displayable = new ImageGroupDisplayable(files.toArray(new File[files.size()])); + ImageGroupDisplayable displayable = new ImageGroupDisplayable(filesArray, imageGroupTitle); QueleaApp.get().getMainWindow().getMainPanel().getSchedulePanel().getScheduleList().add(displayable); } catch (IOException ex) { System.err.println("IO " + ex); if (!halt) { - Platform.runLater(() -> Dialog.showError(LabelGrabber.INSTANCE.getLabel("adding.presentation.error.title"), LabelGrabber.INSTANCE.getLabel("adding.presentation.error.message"))); + Platform.runLater(() -> Dialog.showError(LabelGrabber.INSTANCE.getLabel("adding.presentation.error.imageGroupTitle"), LabelGrabber.INSTANCE.getLabel("adding.presentation.error.message"))); } } });