* always use UTF-8 when reading and writing sfv files, lists, ...
* checksums in filenames are now highlighted in SFV panel
This commit is contained in:
parent
0c674849d8
commit
da0e730243
|
@ -27,7 +27,7 @@ public class FileBotListExportHandler extends FileExportHandler {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void export(OutputStream out) throws IOException {
|
public void export(OutputStream out) throws IOException {
|
||||||
PrintStream printer = new PrintStream(out);
|
PrintStream printer = new PrintStream(out, false, "UTF-8");
|
||||||
|
|
||||||
for (Object entry : list.getModel()) {
|
for (Object entry : list.getModel()) {
|
||||||
printer.println(entry);
|
printer.println(entry);
|
||||||
|
|
|
@ -30,7 +30,7 @@ class FileTreeTransferablePolicy extends BackgroundFileTransferablePolicy<Defaul
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void process(List<DefaultMutableTreeNode> chunks) {
|
protected void process(List<DefaultMutableTreeNode> chunks) {
|
||||||
DefaultTreeModel model = (DefaultTreeModel) tree.getModel();
|
DefaultTreeModel model = tree.getModel();
|
||||||
DefaultMutableTreeNode root = (DefaultMutableTreeNode) model.getRoot();
|
DefaultMutableTreeNode root = (DefaultMutableTreeNode) model.getRoot();
|
||||||
|
|
||||||
for (DefaultMutableTreeNode node : chunks) {
|
for (DefaultMutableTreeNode node : chunks) {
|
||||||
|
@ -46,6 +46,7 @@ class FileTreeTransferablePolicy extends BackgroundFileTransferablePolicy<Defaul
|
||||||
for (File file : files) {
|
for (File file : files) {
|
||||||
DefaultMutableTreeNode node = getTree(file);
|
DefaultMutableTreeNode node = getTree(file);
|
||||||
|
|
||||||
|
// operation may be aborted via interrupt
|
||||||
if (Thread.currentThread().isInterrupted())
|
if (Thread.currentThread().isInterrupted())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
|
@ -90,7 +90,7 @@ class NamesListTransferablePolicy extends FilesListTransferablePolicy {
|
||||||
List<ListEntry> entries = new ArrayList<ListEntry>();
|
List<ListEntry> entries = new ArrayList<ListEntry>();
|
||||||
|
|
||||||
for (File file : files) {
|
for (File file : files) {
|
||||||
BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
|
BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));
|
||||||
|
|
||||||
String line = null;
|
String line = null;
|
||||||
|
|
||||||
|
|
|
@ -7,8 +7,8 @@ import javax.swing.JComponent;
|
||||||
|
|
||||||
import net.sourceforge.filebot.resources.ResourceManager;
|
import net.sourceforge.filebot.resources.ResourceManager;
|
||||||
import net.sourceforge.filebot.ui.FileBotList;
|
import net.sourceforge.filebot.ui.FileBotList;
|
||||||
|
import net.sourceforge.filebot.ui.FileBotListExportHandler;
|
||||||
import net.sourceforge.filebot.ui.FileBotTabComponent;
|
import net.sourceforge.filebot.ui.FileBotTabComponent;
|
||||||
import net.sourceforge.filebot.ui.transfer.DefaultListExportHandler;
|
|
||||||
import net.sourceforge.filebot.web.Episode;
|
import net.sourceforge.filebot.web.Episode;
|
||||||
|
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ public class EpisodeListPanel extends FileBotList<Episode> {
|
||||||
|
|
||||||
|
|
||||||
public EpisodeListPanel() {
|
public EpisodeListPanel() {
|
||||||
setExportHandler(new DefaultListExportHandler(list));
|
setExportHandler(new FileBotListExportHandler(this));
|
||||||
getRemoveAction().setEnabled(true);
|
getRemoveAction().setEnabled(true);
|
||||||
|
|
||||||
setBorder(null);
|
setBorder(null);
|
||||||
|
|
|
@ -17,9 +17,9 @@ public class ChecksumRow {
|
||||||
private HashMap<File, Checksum> checksumMap = new HashMap<File, Checksum>();
|
private HashMap<File, Checksum> checksumMap = new HashMap<File, Checksum>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checksum that is embedded in the file name (e.g. My File [49A93C5F].txt)
|
* Checksum that is embedded in the file name (e.g. Test[49A93C5F].txt)
|
||||||
*/
|
*/
|
||||||
private Long embeddedChecksum = null;
|
private final Long embeddedChecksum;
|
||||||
|
|
||||||
|
|
||||||
public static enum State {
|
public static enum State {
|
||||||
|
@ -32,13 +32,30 @@ public class ChecksumRow {
|
||||||
|
|
||||||
public ChecksumRow(String name) {
|
public ChecksumRow(String name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
this.embeddedChecksum = getEmbeddedChecksum(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Try to parse a CRC32 checksum from the given file name. The checksum is assumed to be in
|
||||||
|
* brackets.
|
||||||
|
*
|
||||||
|
* <pre>
|
||||||
|
* e.g.
|
||||||
|
* Test[49A93C5F].txt
|
||||||
|
* </pre>
|
||||||
|
*
|
||||||
|
* @param file name that contains a checksum
|
||||||
|
* @return the checksum or null, if parameter did not contain a checksum
|
||||||
|
*/
|
||||||
|
private static Long getEmbeddedChecksum(String name) {
|
||||||
// look for a checksum pattern like [49A93C5F]
|
// look for a checksum pattern like [49A93C5F]
|
||||||
Matcher matcher = Pattern.compile("\\[(\\p{XDigit}{8})\\]").matcher(name);
|
Matcher matcher = Pattern.compile("\\[(\\p{XDigit}{8})\\]").matcher(name);
|
||||||
|
|
||||||
if (matcher.find()) {
|
if (matcher.find())
|
||||||
embeddedChecksum = Long.parseLong(matcher.group(1), 16);
|
return Long.parseLong(matcher.group(1), 16);
|
||||||
}
|
else
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -57,7 +57,7 @@ public class ChecksumTableExportHandler extends FileExportHandler {
|
||||||
|
|
||||||
|
|
||||||
public void export(OutputStream out, File column) throws IOException {
|
public void export(OutputStream out, File column) throws IOException {
|
||||||
PrintStream printer = new PrintStream(out);
|
PrintStream printer = new PrintStream(out, false, "UTF-8");
|
||||||
|
|
||||||
SimpleDateFormat date = new SimpleDateFormat("yyyy-MM-dd");
|
SimpleDateFormat date = new SimpleDateFormat("yyyy-MM-dd");
|
||||||
SimpleDateFormat time = new SimpleDateFormat("HH:mm:ss");
|
SimpleDateFormat time = new SimpleDateFormat("HH:mm:ss");
|
||||||
|
|
|
@ -10,6 +10,7 @@ import javax.swing.table.TableModel;
|
||||||
|
|
||||||
import net.sourceforge.filebot.ui.panel.sfv.ChecksumTableModel.ChecksumTableModelEvent;
|
import net.sourceforge.filebot.ui.panel.sfv.ChecksumTableModel.ChecksumTableModelEvent;
|
||||||
import net.sourceforge.filebot.ui.panel.sfv.renderer.ChecksumTableCellRenderer;
|
import net.sourceforge.filebot.ui.panel.sfv.renderer.ChecksumTableCellRenderer;
|
||||||
|
import net.sourceforge.filebot.ui.panel.sfv.renderer.FileNameTableCellRenderer;
|
||||||
import net.sourceforge.filebot.ui.panel.sfv.renderer.StateIconTableCellRenderer;
|
import net.sourceforge.filebot.ui.panel.sfv.renderer.StateIconTableCellRenderer;
|
||||||
import net.sourceforge.filebot.ui.transfer.DefaultTransferHandler;
|
import net.sourceforge.filebot.ui.transfer.DefaultTransferHandler;
|
||||||
|
|
||||||
|
@ -39,6 +40,7 @@ class SfvTable extends JTable {
|
||||||
setTransferHandler(new DefaultTransferHandler(transferablePolicy, exportHandler));
|
setTransferHandler(new DefaultTransferHandler(transferablePolicy, exportHandler));
|
||||||
setDragEnabled(true);
|
setDragEnabled(true);
|
||||||
|
|
||||||
|
setDefaultRenderer(String.class, new FileNameTableCellRenderer());
|
||||||
setDefaultRenderer(ChecksumRow.State.class, new StateIconTableCellRenderer());
|
setDefaultRenderer(ChecksumRow.State.class, new StateIconTableCellRenderer());
|
||||||
setDefaultRenderer(Checksum.class, new ChecksumTableCellRenderer());
|
setDefaultRenderer(Checksum.class, new ChecksumTableCellRenderer());
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,7 +44,7 @@ class SfvTransferablePolicy extends BackgroundFileTransferablePolicy<ChecksumTab
|
||||||
|
|
||||||
protected void loadSfvFile(File sfvFile) {
|
protected void loadSfvFile(File sfvFile) {
|
||||||
try {
|
try {
|
||||||
BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(sfvFile)));
|
BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(sfvFile), "UTF-8"));
|
||||||
|
|
||||||
String line = null;
|
String line = null;
|
||||||
Pattern pattern = Pattern.compile("(.*)\\s+(\\p{XDigit}{8})");
|
Pattern pattern = Pattern.compile("(.*)\\s+(\\p{XDigit}{8})");
|
||||||
|
|
|
@ -0,0 +1,50 @@
|
||||||
|
|
||||||
|
package net.sourceforge.filebot.ui.panel.sfv.renderer;
|
||||||
|
|
||||||
|
|
||||||
|
import java.awt.Component;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
import javax.swing.JTable;
|
||||||
|
import javax.swing.table.DefaultTableCellRenderer;
|
||||||
|
|
||||||
|
|
||||||
|
public class FileNameTableCellRenderer extends DefaultTableCellRenderer {
|
||||||
|
|
||||||
|
private final Pattern checksumPattern = Pattern.compile("\\[(\\p{XDigit}{8})\\]");
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
|
||||||
|
|
||||||
|
super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
|
||||||
|
|
||||||
|
if (hasFocus) {
|
||||||
|
// do not highlight text is focused, that just looks weird
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
String text = value.toString();
|
||||||
|
Matcher matcher = checksumPattern.matcher(text);
|
||||||
|
|
||||||
|
if (!matcher.find()) {
|
||||||
|
// break if name does not contain a checksum that needs to be highlighted
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
matcher.reset();
|
||||||
|
StringBuffer sb = new StringBuffer("<html>");
|
||||||
|
|
||||||
|
while (matcher.find()) {
|
||||||
|
matcher.appendReplacement(sb, "[<font color=#009900>$1</font>]");
|
||||||
|
}
|
||||||
|
|
||||||
|
matcher.appendTail(sb);
|
||||||
|
sb.append("</html>");
|
||||||
|
|
||||||
|
setText(sb.toString());
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,45 +0,0 @@
|
||||||
|
|
||||||
package net.sourceforge.filebot.ui.transfer;
|
|
||||||
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.io.PrintStream;
|
|
||||||
|
|
||||||
import javax.swing.JList;
|
|
||||||
import javax.swing.ListModel;
|
|
||||||
|
|
||||||
|
|
||||||
public class DefaultListExportHandler extends FileExportHandler {
|
|
||||||
|
|
||||||
private final JList list;
|
|
||||||
|
|
||||||
|
|
||||||
public DefaultListExportHandler(JList list) {
|
|
||||||
this.list = list;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean canExport() {
|
|
||||||
return list.getModel().getSize() > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void export(OutputStream out) throws IOException {
|
|
||||||
PrintStream printer = new PrintStream(out);
|
|
||||||
|
|
||||||
ListModel model = list.getModel();
|
|
||||||
|
|
||||||
for (int i = 0; i < model.getSize(); i++) {
|
|
||||||
printer.println(model.getElementAt(i));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getDefaultFileName() {
|
|
||||||
return list.getClientProperty("title") + ".txt";
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue