From c4fb1e145371de7968858e1ed50ff3110ce81578 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Sun, 29 Jun 2014 12:22:01 +0000 Subject: [PATCH] * added missing file --- .../net/filebot/ui/rename/FileNameFormat.java | 21 +++++++++++++++++++ .../net/filebot/ui/rename/FormatDialog.java | 2 +- source/net/filebot/ui/rename/RenamePanel.java | 4 ++-- 3 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 source/net/filebot/ui/rename/FileNameFormat.java diff --git a/source/net/filebot/ui/rename/FileNameFormat.java b/source/net/filebot/ui/rename/FileNameFormat.java new file mode 100644 index 00000000..9b017151 --- /dev/null +++ b/source/net/filebot/ui/rename/FileNameFormat.java @@ -0,0 +1,21 @@ +package net.filebot.ui.rename; + +import java.io.File; +import java.text.FieldPosition; +import java.text.Format; +import java.text.ParsePosition; + +import net.filebot.util.FileUtilities; + +public class FileNameFormat extends Format { + + @Override + public StringBuffer format(Object obj, StringBuffer toAppendTo, FieldPosition pos) { + return toAppendTo.append(FileUtilities.getName((File) obj)); + } + + @Override + public Object parseObject(String source, ParsePosition pos) { + return new File(source); + } +} diff --git a/source/net/filebot/ui/rename/FormatDialog.java b/source/net/filebot/ui/rename/FormatDialog.java index 42dc5045..ee3d266e 100644 --- a/source/net/filebot/ui/rename/FormatDialog.java +++ b/source/net/filebot/ui/rename/FormatDialog.java @@ -138,7 +138,7 @@ public class FormatDialog extends JDialog { case Music: return new AudioTrackFormat(); default: - return new FileFormat(); + return new FileNameFormat(); } } diff --git a/source/net/filebot/ui/rename/RenamePanel.java b/source/net/filebot/ui/rename/RenamePanel.java index a7e12bdf..8c51cf18 100644 --- a/source/net/filebot/ui/rename/RenamePanel.java +++ b/source/net/filebot/ui/rename/RenamePanel.java @@ -128,7 +128,7 @@ public class RenamePanel extends JComponent { try { // restore custom music formatter - renameModel.useFormatter(File.class, new ExpressionFormatter(persistentFileFormat.getValue(), new FileFormat(), File.class)); + renameModel.useFormatter(File.class, new ExpressionFormatter(persistentFileFormat.getValue(), new FileNameFormat(), File.class)); } catch (Exception e) { // use default filename formatter renameModel.useFormatter(File.class, new FileNameFormatter(renameModel.preserveExtension())); @@ -497,7 +497,7 @@ public class RenamePanel extends JComponent { persistentMusicFormat.setValue(dialog.getFormat().getExpression()); break; case File: - renameModel.useFormatter(File.class, new ExpressionFormatter(dialog.getFormat().getExpression(), new FileFormat(), File.class)); + renameModel.useFormatter(File.class, new ExpressionFormatter(dialog.getFormat().getExpression(), new FileNameFormat(), File.class)); persistentFileFormat.setValue(dialog.getFormat().getExpression()); break; }