UX improvements: Info Object (with info object as json tooltip)

This commit is contained in:
Reinhard Pointner 2016-08-07 23:57:36 +08:00
parent 542012cd90
commit 59ccb9006c
2 changed files with 13 additions and 6 deletions

View File

@ -5,6 +5,7 @@ import static net.filebot.Logging.*;
import static net.filebot.MediaTypes.*; import static net.filebot.MediaTypes.*;
import static net.filebot.UserFiles.*; import static net.filebot.UserFiles.*;
import static net.filebot.media.XattrMetaInfo.*; import static net.filebot.media.XattrMetaInfo.*;
import static net.filebot.util.JsonUtilities.*;
import static net.filebot.util.RegularExpressions.*; import static net.filebot.util.RegularExpressions.*;
import static net.filebot.util.ui.SwingUI.*; import static net.filebot.util.ui.SwingUI.*;
@ -84,7 +85,7 @@ class BindingDialog extends JDialog {
JPanel inputPanel = new JPanel(new MigLayout("nogrid, fill")); JPanel inputPanel = new JPanel(new MigLayout("nogrid, fill"));
inputPanel.setOpaque(false); 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(infoTextField, "hmin 20px, growx, wrap paragraph");
inputPanel.add(new JLabel("Media File:"), "wrap 2px"); inputPanel.add(new JLabel("Media File:"), "wrap 2px");
@ -222,7 +223,7 @@ class BindingDialog extends JDialog {
if (submit) { if (submit) {
// illegal episode string // illegal episode string
if (getInfoObject() == null) { if (getInfoObject() == null) {
log.warning(format("Failed to parse episode: '%s'", infoTextField.getText())); log.warning(format("Failed to import object: '%s'", infoTextField.getText()));
return; return;
} }
@ -243,17 +244,19 @@ class BindingDialog extends JDialog {
public void setInfoObject(Object info) { public void setInfoObject(Object info) {
infoTextField.putClientProperty("model", info); infoTextField.putClientProperty("model", info);
infoTextField.setText(info == null ? "" : infoObjectFormat.format(info));
}
public void setMediaFile(File mediaFile) { infoTextField.setText(info == null ? "" : infoObjectFormat.format(info));
mediaFileTextField.setText(mediaFile == null ? "" : mediaFile.getAbsolutePath()); infoTextField.setToolTipText(info == null ? "null" : "<html><pre>" + escapeHTML(asPrettyJsonString(info)) + "</pre></html>");
} }
public Object getInfoObject() { public Object getInfoObject() {
return infoTextField.getClientProperty("model"); return infoTextField.getClientProperty("model");
} }
public void setMediaFile(File mediaFile) {
mediaFileTextField.setText(mediaFile == null ? "" : mediaFile.getAbsolutePath());
}
public File getMediaFile() { public File getMediaFile() {
// allow only absolute paths // allow only absolute paths
String path = mediaFileTextField.getText().trim(); String path = mediaFileTextField.getText().trim();

View File

@ -28,6 +28,10 @@ public class JsonUtilities {
return JsonWriter.objectToJson(object); 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) { public static Map<?, ?> asMap(Object node) {
if (node instanceof Map) { if (node instanceof Map) {
return (Map<?, ?>) node; return (Map<?, ?>) node;