* better samples for format expression testing environment

This commit is contained in:
Reinhard Pointner 2013-01-28 17:56:14 +00:00
parent eb0027d691
commit e90a076729
3 changed files with 21 additions and 29 deletions

View File

@ -128,6 +128,7 @@ class BindingDialog extends JDialog {
mediaFileTextField.getDocument().addDocumentListener(changeListener);
// disabled by default
infoTextField.setEnabled(false);
mediaInfoAction.setEnabled(false);
// disable media info action if media file is invalid
@ -236,6 +237,7 @@ class BindingDialog extends JDialog {
public void setInfoObject(Object info) {
infoTextField.putClientProperty("model", info);
infoTextField.setText(info == null ? "" : infoObjectFormat.format(info));
}
@ -246,18 +248,7 @@ class BindingDialog extends JDialog {
public Object getInfoObject() {
try {
// try known object
Object model = infoTextField.getClientProperty("model");
if (model != null) {
return model;
}
// or parse user input
return infoObjectFormat.parseObject(infoTextField.getText());
} catch (Exception e) {
return null;
}
return infoTextField.getClientProperty("model");
}
@ -398,19 +389,15 @@ class BindingDialog extends JDialog {
// set file
mediaFileTextField.setText(file.getAbsolutePath());
// reset known model
infoTextField.putClientProperty("model", null);
infoTextField.setEnabled(true);
// set info object from xattr if possible
if (useExtendedFileAttributes()) {
try {
MetaAttributes xattr = new MetaAttributes(file);
try {
Object object = xattr.getMetaData();
infoTextField.setText(infoObjectFormat.format(object));
infoTextField.putClientProperty("model", object);
infoTextField.setEnabled(false);
if (infoObjectFormat.format(object) != null) {
setInfoObject(object);
}
} catch (Exception e) {
// ignore invalid data
}

View File

@ -22,7 +22,6 @@ import java.beans.PropertyChangeListener;
import java.io.File;
import java.net.URI;
import java.text.Format;
import java.text.ParseException;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.ResourceBundle;
@ -79,6 +78,9 @@ import net.sourceforge.tuned.ui.TunedUtilities;
import net.sourceforge.tuned.ui.notification.SeparatorBorder;
import net.sourceforge.tuned.ui.notification.SeparatorBorder.Position;
import com.cedarsoftware.util.io.JsonReader;
import com.cedarsoftware.util.io.JsonWriter;
class FormatDialog extends JDialog {
@ -386,14 +388,17 @@ class FormatDialog extends JDialog {
try {
// restore sample from user preferences
String sample = mode.persistentSample().getValue();
info = mode.getFormat().parseObject(sample);
info = JsonReader.toJava(sample);
if (info == null) {
throw new NullPointerException();
}
} catch (Exception e) {
try {
// restore sample from application properties
ResourceBundle bundle = ResourceBundle.getBundle(getClass().getName());
String sample = bundle.getString(mode.key() + ".sample");
info = mode.getFormat().parseObject(sample);
} catch (ParseException illegalSample) {
info = JsonReader.toJava(sample);
} catch (Exception illegalSample) {
throw new RuntimeException(illegalSample); // won't happen
}
}
@ -613,7 +618,7 @@ class FormatDialog extends JDialog {
sample = new MediaBindingBean(info, file, null);
// remember
mode.persistentSample().setValue(info == null ? "" : mode.getFormat().format(info));
mode.persistentSample().setValue(info == null ? "" : JsonWriter.toJson(info));
persistentSampleFile.setValue(file == null ? "" : sample.getMediaFile().getAbsolutePath());
// reevaluate everything

View File

@ -2,11 +2,11 @@ help.url = http://filebot.sourceforge.net/naming.html
episode.syntax: <html><b>{</b> <b>}</b> \u2026 expression, <b>n</b> \u2026 name, <b>s</b> \u2026 season, <b>e</b> \u2026 episode, <b>t</b> \u2026 title</html>
movie.syntax: <html><b>{</b> <b>}</b> \u2026 expression, <b>n</b> \u2026 name, <b>y</b> \u2026 year</html>
music.syntax: <html><b>{</b> <b>}</b> \u2026 expression, <b>n</b> \u2026 artist, <b>t</b> \u2026 title, <b>album</b> \u2026 album</html>
music.syntax: <html><b>{</b> <b>}</b> \u2026 expression, <b>n</b> \u2026 album artist, <b>t</b> \u2026 title, <b>album</b> \u2026 album, <b>pi</b> \u2026 track</html>
episode.sample: Dark Angel - 3x01 - Labyrinth [2009-06-01]
movie.sample: Avatar (2009) Part 1
music.sample: Leona Lewis - I See You
episode.sample: {"@type":"net.sourceforge.filebot.web.Episode","seriesName":"Firefly","seriesStartDate":{"year":2002,"month":9,"day":20},"season":1,"episode":1,"title":"Serenity","absolute":1,"special":null,"airdate":{"year":2002,"month":12,"day":20}}
movie.sample: {"@type":"net.sourceforge.filebot.web.MoviePart","partIndex":1,"partCount":2,"year":2009,"imdbId":-1,"tmdbId":19995,"name":"Avatar"}
music.sample: {"@type":"net.sourceforge.filebot.web.AudioTrack","artist":"Leona Lewis","title":"I See You","album":"Avatar","albumArtist":"James Horner","trackTitle":null,"albumReleaseDate":{"year":2009,"month":12,"day":11},"mediumIndex":1,"mediumCount":1,"trackIndex":14,"trackCount":14}
# basic 1.01
episode.example[0]: {n} - {s}.{e} - {t}
@ -27,7 +27,7 @@ movie.example[2]: {n} {[y, certification, rating]}
movie.example[3]: {n.space('.')}.{y}{'.'+source}.{vc}
# simple artist - title
music.example[0]: {n} - {t}
music.example[0]: {artist} - {t}
# simple artist - album - title
music.example[1]: {n} - {album} - {t}
# artist - title [crc32]