From 59ccb9006cc1c8efba90f5ca5a32058294342929 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Sun, 7 Aug 2016 23:57:36 +0800 Subject: [PATCH] UX improvements: Info Object (with info object as json tooltip) --- source/net/filebot/ui/rename/BindingDialog.java | 15 +++++++++------ source/net/filebot/util/JsonUtilities.java | 4 ++++ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/source/net/filebot/ui/rename/BindingDialog.java b/source/net/filebot/ui/rename/BindingDialog.java index d0f66d8d..2846fd6b 100644 --- a/source/net/filebot/ui/rename/BindingDialog.java +++ b/source/net/filebot/ui/rename/BindingDialog.java @@ -5,6 +5,7 @@ import static net.filebot.Logging.*; import static net.filebot.MediaTypes.*; import static net.filebot.UserFiles.*; import static net.filebot.media.XattrMetaInfo.*; +import static net.filebot.util.JsonUtilities.*; import static net.filebot.util.RegularExpressions.*; import static net.filebot.util.ui.SwingUI.*; @@ -84,7 +85,7 @@ class BindingDialog extends JDialog { JPanel inputPanel = new JPanel(new MigLayout("nogrid, fill")); inputPanel.setOpaque(false); - inputPanel.add(new JLabel("Name:"), "wrap 2px"); + inputPanel.add(new JLabel("Info Object:"), "wrap 2px"); inputPanel.add(infoTextField, "hmin 20px, growx, wrap paragraph"); inputPanel.add(new JLabel("Media File:"), "wrap 2px"); @@ -222,7 +223,7 @@ class BindingDialog extends JDialog { if (submit) { // illegal episode string if (getInfoObject() == null) { - log.warning(format("Failed to parse episode: '%s'", infoTextField.getText())); + log.warning(format("Failed to import object: '%s'", infoTextField.getText())); return; } @@ -243,17 +244,19 @@ class BindingDialog extends JDialog { public void setInfoObject(Object info) { infoTextField.putClientProperty("model", info); - infoTextField.setText(info == null ? "" : infoObjectFormat.format(info)); - } - public void setMediaFile(File mediaFile) { - mediaFileTextField.setText(mediaFile == null ? "" : mediaFile.getAbsolutePath()); + infoTextField.setText(info == null ? "" : infoObjectFormat.format(info)); + infoTextField.setToolTipText(info == null ? "null" : "
" + escapeHTML(asPrettyJsonString(info)) + "
"); } public Object getInfoObject() { return infoTextField.getClientProperty("model"); } + public void setMediaFile(File mediaFile) { + mediaFileTextField.setText(mediaFile == null ? "" : mediaFile.getAbsolutePath()); + } + public File getMediaFile() { // allow only absolute paths String path = mediaFileTextField.getText().trim(); diff --git a/source/net/filebot/util/JsonUtilities.java b/source/net/filebot/util/JsonUtilities.java index 5ff8954f..def37bcc 100644 --- a/source/net/filebot/util/JsonUtilities.java +++ b/source/net/filebot/util/JsonUtilities.java @@ -28,6 +28,10 @@ public class JsonUtilities { return JsonWriter.objectToJson(object); } + public static String asPrettyJsonString(Object object) { + return JsonWriter.objectToJson(object, singletonMap(JsonWriter.PRETTY_PRINT, true)); + } + public static Map asMap(Object node) { if (node instanceof Map) { return (Map) node;