mirror of
https://github.com/mitb-archive/filebot
synced 2024-12-24 08:48:51 -05:00
Fix various compiler warnings
This commit is contained in:
parent
537144187a
commit
d76f625328
@ -8,7 +8,7 @@
|
|||||||
<classpathentry kind="lib" path="lib/jars/simmetrics.jar"/>
|
<classpathentry kind="lib" path="lib/jars/simmetrics.jar"/>
|
||||||
<classpathentry kind="lib" path="lib/jars/xmlrpc.jar"/>
|
<classpathentry kind="lib" path="lib/jars/xmlrpc.jar"/>
|
||||||
<classpathentry kind="lib" path="lib/ivy/jar/ehcache.jar" sourcepath="lib/ivy/source/ehcache.jar"/>
|
<classpathentry kind="lib" path="lib/ivy/jar/ehcache.jar" sourcepath="lib/ivy/source/ehcache.jar"/>
|
||||||
<classpathentry kind="lib" path="lib/ivy/jar/glazedlists_java15.jar"/>
|
<classpathentry kind="lib" path="lib/ivy/jar/glazedlists_java15.jar" sourcepath="lib/ivy/source/glazedlists_java15.jar"/>
|
||||||
<classpathentry kind="lib" path="lib/ivy/jar/icu4j.jar"/>
|
<classpathentry kind="lib" path="lib/ivy/jar/icu4j.jar"/>
|
||||||
<classpathentry kind="lib" path="lib/ivy/jar/jna.jar"/>
|
<classpathentry kind="lib" path="lib/ivy/jar/jna.jar"/>
|
||||||
<classpathentry kind="lib" path="lib/ivy/jar/junit.jar"/>
|
<classpathentry kind="lib" path="lib/ivy/jar/junit.jar"/>
|
||||||
|
@ -24,6 +24,7 @@ public enum CacheType {
|
|||||||
this.diskPersistent = diskPersistent;
|
this.diskPersistent = diskPersistent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
CacheConfiguration getConfiguration(String name) {
|
CacheConfiguration getConfiguration(String name) {
|
||||||
// Strategy.LOCALTEMPSWAP is not restartable so we can't but use the deprecated disk persistent code (see http://stackoverflow.com/a/24623527/1514467)
|
// Strategy.LOCALTEMPSWAP is not restartable so we can't but use the deprecated disk persistent code (see http://stackoverflow.com/a/24623527/1514467)
|
||||||
return new CacheConfiguration().name(name).maxEntriesLocalHeap(diskPersistent ? 200 : 0).maxEntriesLocalDisk(0).eternal(false).timeToLiveSeconds(timeToLiveSeconds).timeToIdleSeconds(timeToLiveSeconds).overflowToDisk(diskPersistent).diskPersistent(diskPersistent);
|
return new CacheConfiguration().name(name).maxEntriesLocalHeap(diskPersistent ? 200 : 0).maxEntriesLocalDisk(0).eternal(false).timeToLiveSeconds(timeToLiveSeconds).timeToIdleSeconds(timeToLiveSeconds).overflowToDisk(diskPersistent).diskPersistent(diskPersistent);
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
|
|
||||||
package net.filebot.archive;
|
package net.filebot.archive;
|
||||||
|
|
||||||
|
|
||||||
import java.io.Closeable;
|
import java.io.Closeable;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -16,7 +14,6 @@ import net.sf.sevenzipjbinding.PropID;
|
|||||||
import net.sf.sevenzipjbinding.SevenZipException;
|
import net.sf.sevenzipjbinding.SevenZipException;
|
||||||
import net.sf.sevenzipjbinding.impl.RandomAccessFileInStream;
|
import net.sf.sevenzipjbinding.impl.RandomAccessFileInStream;
|
||||||
|
|
||||||
|
|
||||||
class ArchiveOpenVolumeCallback implements IArchiveOpenVolumeCallback, IArchiveOpenCallback, Closeable {
|
class ArchiveOpenVolumeCallback implements IArchiveOpenVolumeCallback, IArchiveOpenCallback, Closeable {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -29,10 +26,8 @@ class ArchiveOpenVolumeCallback implements IArchiveOpenVolumeCallback, IArchiveO
|
|||||||
*/
|
*/
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method should at least provide the name of the last
|
* This method should at least provide the name of the last opened volume (propID=PropID.NAME).
|
||||||
* opened volume (propID=PropID.NAME).
|
|
||||||
*
|
*
|
||||||
* @see IArchiveOpenVolumeCallback#getProperty(PropID)
|
* @see IArchiveOpenVolumeCallback#getProperty(PropID)
|
||||||
*/
|
*/
|
||||||
@ -41,16 +36,13 @@ class ArchiveOpenVolumeCallback implements IArchiveOpenVolumeCallback, IArchiveO
|
|||||||
switch (propID) {
|
switch (propID) {
|
||||||
case NAME:
|
case NAME:
|
||||||
return name;
|
return name;
|
||||||
}
|
default:
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The name of the required volume will be calculated out of the
|
* The name of the required volume will be calculated out of the name of the first volume and a volume index. In case of RAR file, the substring ".partNN." in the name of the volume file will indicate a volume with id NN. For example:
|
||||||
* name of the first volume and a volume index. In case of RAR file,
|
|
||||||
* the substring ".partNN." in the name of the volume file will
|
|
||||||
* indicate a volume with id NN. For example:
|
|
||||||
* <ul>
|
* <ul>
|
||||||
* <li>test.rar - single part archive or multi-part archive with a single volume</li>
|
* <li>test.rar - single part archive or multi-part archive with a single volume</li>
|
||||||
* <li>test.part23.rar - 23-th part of a multi-part archive</li>
|
* <li>test.part23.rar - 23-th part of a multi-part archive</li>
|
||||||
@ -96,7 +88,6 @@ class ArchiveOpenVolumeCallback implements IArchiveOpenVolumeCallback, IArchiveO
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Close all opened streams
|
* Close all opened streams
|
||||||
*/
|
*/
|
||||||
@ -107,12 +98,10 @@ class ArchiveOpenVolumeCallback implements IArchiveOpenVolumeCallback, IArchiveO
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setCompleted(Long files, Long bytes) throws SevenZipException {
|
public void setCompleted(Long files, Long bytes) throws SevenZipException {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setTotal(Long files, Long bytes) throws SevenZipException {
|
public void setTotal(Long files, Long bytes) throws SevenZipException {
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package net.filebot.archive;
|
package net.filebot.archive;
|
||||||
|
|
||||||
import static java.nio.charset.StandardCharsets.*;
|
import static java.nio.charset.StandardCharsets.*;
|
||||||
|
import static java.util.Arrays.*;
|
||||||
|
import static net.filebot.Logging.*;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileFilter;
|
import java.io.FileFilter;
|
||||||
@ -40,21 +42,20 @@ public class SevenZipExecutable implements ArchiveExtractor {
|
|||||||
protected CharSequence execute(String... command) throws IOException {
|
protected CharSequence execute(String... command) throws IOException {
|
||||||
Process process = new ProcessBuilder(command).redirectError(Redirect.INHERIT).start();
|
Process process = new ProcessBuilder(command).redirectError(Redirect.INHERIT).start();
|
||||||
|
|
||||||
ByteBufferOutputStream bb = new ByteBufferOutputStream(8 * 1024);
|
try (ByteBufferOutputStream bb = new ByteBufferOutputStream(8 * 1024)) {
|
||||||
bb.transferFully(process.getInputStream());
|
bb.transferFully(process.getInputStream());
|
||||||
|
|
||||||
try {
|
|
||||||
int returnCode = process.waitFor();
|
int returnCode = process.waitFor();
|
||||||
CharSequence output = UTF_8.decode(bb.getByteBuffer());
|
String output = UTF_8.decode(bb.getByteBuffer()).toString();
|
||||||
|
|
||||||
// DEBUG
|
// DEBUG
|
||||||
// System.out.println("Execute: " + Arrays.asList(command));
|
debug.fine(format("Execute: %s", asList(command)));
|
||||||
// System.out.println(output);
|
debug.finest(output);
|
||||||
|
|
||||||
if (returnCode == 0) {
|
if (returnCode == 0) {
|
||||||
return output;
|
return output;
|
||||||
} else {
|
} else {
|
||||||
throw new IOException(String.format("%s failed with exit code %d: %s", get7zCommand(), returnCode, output.toString().replaceAll("\\s+", " ").trim()));
|
throw new IOException(String.format("%s failed with exit code %d: %s", get7zCommand(), returnCode, output.replaceAll("\\s+", " ").trim()));
|
||||||
}
|
}
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
throw new IOException(String.format("%s timed out", get7zCommand()), e);
|
throw new IOException(String.format("%s timed out", get7zCommand()), e);
|
||||||
|
@ -16,12 +16,10 @@ import java.io.PrintStream;
|
|||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
import javax.script.Bindings;
|
import javax.script.Bindings;
|
||||||
import javax.script.ScriptException;
|
import javax.script.ScriptException;
|
||||||
import javax.script.SimpleBindings;
|
import javax.script.SimpleBindings;
|
||||||
import javax.swing.AbstractAction;
|
|
||||||
import javax.swing.Action;
|
import javax.swing.Action;
|
||||||
import javax.swing.JComponent;
|
import javax.swing.JComponent;
|
||||||
import javax.swing.JFrame;
|
import javax.swing.JFrame;
|
||||||
|
@ -27,9 +27,9 @@ import java.util.Locale;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Scanner;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.SortedSet;
|
import java.util.SortedSet;
|
||||||
|
import java.util.StringTokenizer;
|
||||||
import java.util.TreeSet;
|
import java.util.TreeSet;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
@ -301,7 +301,7 @@ public class MediaBindingBean {
|
|||||||
String codec = getMediaInfo(StreamKind.Video, 0, "Encoded_Library_Name", "Encoded_Library/Name", "CodecID/Hint", "Format");
|
String codec = getMediaInfo(StreamKind.Video, 0, "Encoded_Library_Name", "Encoded_Library/Name", "CodecID/Hint", "Format");
|
||||||
|
|
||||||
// get first token (e.g. DivX 5 => DivX)
|
// get first token (e.g. DivX 5 => DivX)
|
||||||
return new Scanner(codec).next();
|
return new StringTokenizer(codec).nextToken();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Define("ac")
|
@Define("ac")
|
||||||
|
@ -512,7 +512,7 @@ public class MediaDetection {
|
|||||||
for (CollationKey[] name : names) {
|
for (CollationKey[] name : names) {
|
||||||
IndexEntry<SearchResult> bestMatch = null;
|
IndexEntry<SearchResult> bestMatch = null;
|
||||||
for (IndexEntry<SearchResult> it : index) {
|
for (IndexEntry<SearchResult> it : index) {
|
||||||
CollationKey[] commonName = nameMatcher.matchFirstCommonSequence(name, it.getLenientKey());
|
CollationKey[] commonName = nameMatcher.matchFirstCommonSequence(new CollationKey[][] { name, it.getLenientKey() });
|
||||||
if (commonName != null && commonName.length >= it.getLenientKey().length && (bestMatch == null || commonName.length > bestMatch.getLenientKey().length)) {
|
if (commonName != null && commonName.length >= it.getLenientKey().length && (bestMatch == null || commonName.length > bestMatch.getLenientKey().length)) {
|
||||||
bestMatch = it;
|
bestMatch = it;
|
||||||
}
|
}
|
||||||
@ -871,9 +871,9 @@ public class MediaDetection {
|
|||||||
|
|
||||||
for (IndexEntry<Movie> movie : getMovieIndex()) {
|
for (IndexEntry<Movie> movie : getMovieIndex()) {
|
||||||
for (CollationKey[] name : names) {
|
for (CollationKey[] name : names) {
|
||||||
CollationKey[] commonName = nameMatcher.matchFirstCommonSequence(name, movie.getLenientKey());
|
CollationKey[] commonName = nameMatcher.matchFirstCommonSequence(new CollationKey[][] { name, movie.getLenientKey() });
|
||||||
if (commonName != null && commonName.length >= movie.getLenientKey().length) {
|
if (commonName != null && commonName.length >= movie.getLenientKey().length) {
|
||||||
CollationKey[] strictCommonName = nameMatcher.matchFirstCommonSequence(name, movie.getStrictKey());
|
CollationKey[] strictCommonName = nameMatcher.matchFirstCommonSequence(new CollationKey[][] { name, movie.getStrictKey() });
|
||||||
if (strictCommonName != null && strictCommonName.length >= movie.getStrictKey().length) {
|
if (strictCommonName != null && strictCommonName.length >= movie.getStrictKey().length) {
|
||||||
// prefer strict match
|
// prefer strict match
|
||||||
matchMap.put(movie.getObject(), movie.getStrictName());
|
matchMap.put(movie.getObject(), movie.getStrictName());
|
||||||
@ -998,7 +998,7 @@ public class MediaDetection {
|
|||||||
for (Movie movie : options) {
|
for (Movie movie : options) {
|
||||||
for (String alias : movie.getEffectiveNames()) {
|
for (String alias : movie.getEffectiveNames()) {
|
||||||
CollationKey[] movieSeq = HighPerformanceMatcher.prepare(normalizePunctuation(alias));
|
CollationKey[] movieSeq = HighPerformanceMatcher.prepare(normalizePunctuation(alias));
|
||||||
CollationKey[] commonSeq = nameMatcher.matchFirstCommonSequence(nameSeq, movieSeq);
|
CollationKey[] commonSeq = nameMatcher.matchFirstCommonSequence(new CollationKey[][] { nameSeq, movieSeq });
|
||||||
|
|
||||||
if (commonSeq != null && commonSeq.length >= movieSeq.length) {
|
if (commonSeq != null && commonSeq.length >= movieSeq.length) {
|
||||||
movies.add(movie);
|
movies.add(movie);
|
||||||
|
@ -41,7 +41,7 @@ public class CommonSequenceMatcher {
|
|||||||
return synth(matchFirstCommonSequence(words));
|
return synth(matchFirstCommonSequence(words));
|
||||||
}
|
}
|
||||||
|
|
||||||
public <E extends Comparable<E>> E[] matchFirstCommonSequence(E[]... names) {
|
public <E extends Comparable<E>> E[] matchFirstCommonSequence(E[][] names) {
|
||||||
E[] common = null;
|
E[] common = null;
|
||||||
|
|
||||||
for (E[] words : names) {
|
for (E[] words : names) {
|
||||||
|
@ -55,7 +55,7 @@ public class FileBotList<E> extends JComponent {
|
|||||||
|
|
||||||
public void setModel(EventList<E> model) {
|
public void setModel(EventList<E> model) {
|
||||||
this.model = model;
|
this.model = model;
|
||||||
list.setModel(new EventListModel<E>(model));
|
list.setModel(new EventListModel(model));
|
||||||
}
|
}
|
||||||
|
|
||||||
public JList getListComponent() {
|
public JList getListComponent() {
|
||||||
@ -110,15 +110,16 @@ public class FileBotList<E> extends JComponent {
|
|||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
int index = list.getSelectedIndex();
|
int index = list.getSelectedIndex();
|
||||||
Object values[] = list.getSelectedValues();
|
|
||||||
|
|
||||||
for (Object value : values)
|
for (Object value : list.getSelectedValuesList()) {
|
||||||
getModel().remove(value);
|
getModel().remove(value);
|
||||||
|
}
|
||||||
|
|
||||||
int maxIndex = list.getModel().getSize() - 1;
|
int maxIndex = list.getModel().getSize() - 1;
|
||||||
|
|
||||||
if (index > maxIndex)
|
if (index > maxIndex) {
|
||||||
index = maxIndex;
|
index = maxIndex;
|
||||||
|
}
|
||||||
|
|
||||||
list.setSelectedIndex(index);
|
list.setSelectedIndex(index);
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,7 @@ public class SelectButtonTextField<T> extends JComponent {
|
|||||||
|
|
||||||
private SelectButton<T> selectButton = new SelectButton<T>();
|
private SelectButton<T> selectButton = new SelectButton<T>();
|
||||||
|
|
||||||
private JComboBox editor = new JComboBox();
|
private JComboBox<Object> editor = new JComboBox<Object>();
|
||||||
|
|
||||||
public SelectButtonTextField() {
|
public SelectButtonTextField() {
|
||||||
selectButton.addActionListener(textFieldFocusOnClick);
|
selectButton.addActionListener(textFieldFocusOnClick);
|
||||||
@ -53,7 +53,7 @@ public class SelectButtonTextField<T> extends JComponent {
|
|||||||
|
|
||||||
editor.setPrototypeDisplayValue("X");
|
editor.setPrototypeDisplayValue("X");
|
||||||
editor.setRenderer(new CompletionCellRenderer());
|
editor.setRenderer(new CompletionCellRenderer());
|
||||||
editor.setUI(new TextFieldComboBoxUI());
|
editor.setUI(new TextFieldComboBoxUI(selectButton));
|
||||||
editor.setMaximumRowCount(10);
|
editor.setMaximumRowCount(10);
|
||||||
|
|
||||||
SwingUI.installAction(this, KeyStroke.getKeyStroke(KeyEvent.VK_UP, KeyEvent.CTRL_MASK), new SpinClientAction(-1));
|
SwingUI.installAction(this, KeyStroke.getKeyStroke(KeyEvent.VK_UP, KeyEvent.CTRL_MASK), new SpinClientAction(-1));
|
||||||
@ -102,6 +102,7 @@ public class SelectButtonTextField<T> extends JComponent {
|
|||||||
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
|
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
|
||||||
super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
|
super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
|
||||||
setBorder(new EmptyBorder(1, 4, 1, 4));
|
setBorder(new EmptyBorder(1, 4, 1, 4));
|
||||||
|
|
||||||
String highlightText = SelectButtonTextField.this.getText().substring(0, ((TextFieldComboBoxUI) editor.getUI()).getEditor().getSelectionStart());
|
String highlightText = SelectButtonTextField.this.getText().substring(0, ((TextFieldComboBoxUI) editor.getUI()).getEditor().getSelectionStart());
|
||||||
|
|
||||||
// highlight the matching sequence
|
// highlight the matching sequence
|
||||||
@ -124,7 +125,13 @@ public class SelectButtonTextField<T> extends JComponent {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class TextFieldComboBoxUI extends BasicComboBoxUI {
|
private static class TextFieldComboBoxUI extends BasicComboBoxUI {
|
||||||
|
|
||||||
|
private SelectButton<?> button;
|
||||||
|
|
||||||
|
public TextFieldComboBoxUI(SelectButton<?> button) {
|
||||||
|
this.button = button;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected JButton createArrowButton() {
|
protected JButton createArrowButton() {
|
||||||
@ -192,13 +199,13 @@ public class SelectButtonTextField<T> extends JComponent {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void show(Component invoker, int x, int y) {
|
public void show(Component invoker, int x, int y) {
|
||||||
super.show(invoker, x - selectButton.getWidth(), y);
|
super.show(invoker, x - button.getWidth(), y);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Rectangle computePopupBounds(int px, int py, int pw, int ph) {
|
protected Rectangle computePopupBounds(int px, int py, int pw, int ph) {
|
||||||
Rectangle bounds = super.computePopupBounds(px, py, pw, ph);
|
Rectangle bounds = super.computePopupBounds(px, py, pw, ph);
|
||||||
bounds.width += selectButton.getWidth();
|
bounds.width += button.getWidth();
|
||||||
|
|
||||||
return bounds;
|
return bounds;
|
||||||
}
|
}
|
||||||
|
@ -116,7 +116,7 @@ public class FileTree extends JTree {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent event) {
|
public void actionPerformed(ActionEvent event) {
|
||||||
UserFiles.revealFiles((Collection<File>) getValue("files"));
|
UserFiles.revealFiles((Collection) getValue("files"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,7 +72,8 @@ class FileTreeTransferablePolicy extends BackgroundFileTransferablePolicy<TreeNo
|
|||||||
FastFile root = FastFile.create(filter(files, FOLDERS))[0];
|
FastFile root = FastFile.create(filter(files, FOLDERS))[0];
|
||||||
|
|
||||||
// publish on EDT
|
// publish on EDT
|
||||||
publish(getTreeNode(root));
|
TreeNode[] node = { getTreeNode(root) };
|
||||||
|
publish(node);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
// supposed to happen if background execution was aborted
|
// supposed to happen if background execution was aborted
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,6 @@ import java.io.File;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
@ -306,11 +305,10 @@ public class EpisodeListPanel extends AbstractSearchPanel<EpisodeListProvider, E
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void exportToClipboard(JComponent c, Clipboard clipboard, int action) throws IllegalStateException {
|
public void exportToClipboard(JComponent c, Clipboard clipboard, int action) throws IllegalStateException {
|
||||||
Object[] selection = list.getListComponent().getSelectedValues();
|
Episode[] selection = ((List<?>) list.getListComponent().getSelectedValuesList()).stream().map(Episode.class::cast).toArray(Episode[]::new);
|
||||||
Episode[] episodes = Arrays.copyOf(selection, selection.length, Episode[].class);
|
|
||||||
|
|
||||||
Transferable episodeArray = new ArrayTransferable<Episode>(episodes);
|
Transferable episodeArray = new ArrayTransferable<Episode>(selection);
|
||||||
Transferable stringSelection = new StringSelection(StringUtilities.join(episodes, "\n"));
|
Transferable stringSelection = new StringSelection(StringUtilities.join(selection, "\n"));
|
||||||
|
|
||||||
clipboard.setContents(new CompositeTranserable(episodeArray, stringSelection), null);
|
clipboard.setContents(new CompositeTranserable(episodeArray, stringSelection), null);
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
|
|
||||||
package net.filebot.ui.rename;
|
package net.filebot.ui.rename;
|
||||||
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.text.Format;
|
import java.text.Format;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -12,7 +10,6 @@ import net.filebot.format.ExpressionFormat;
|
|||||||
import net.filebot.format.MediaBindingBean;
|
import net.filebot.format.MediaBindingBean;
|
||||||
import net.filebot.similarity.Match;
|
import net.filebot.similarity.Match;
|
||||||
|
|
||||||
|
|
||||||
class ExpressionFormatter implements MatchFormatter {
|
class ExpressionFormatter implements MatchFormatter {
|
||||||
|
|
||||||
private final String expression;
|
private final String expression;
|
||||||
@ -21,7 +18,6 @@ class ExpressionFormatter implements MatchFormatter {
|
|||||||
private Format preview;
|
private Format preview;
|
||||||
private Class<?> target;
|
private Class<?> target;
|
||||||
|
|
||||||
|
|
||||||
public ExpressionFormatter(String expression, Format preview, Class<?> target) {
|
public ExpressionFormatter(String expression, Format preview, Class<?> target) {
|
||||||
if (expression == null || expression.isEmpty())
|
if (expression == null || expression.isEmpty())
|
||||||
throw new IllegalArgumentException("Expression must not be null or empty");
|
throw new IllegalArgumentException("Expression must not be null or empty");
|
||||||
@ -32,20 +28,17 @@ class ExpressionFormatter implements MatchFormatter {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canFormat(Match<?, ?> match) {
|
public boolean canFormat(Match<?, ?> match) {
|
||||||
// target object is required, file is optional
|
// target object is required, file is optional
|
||||||
return target.isInstance(match.getValue()) && (match.getCandidate() == null || match.getCandidate() instanceof File);
|
return target.isInstance(match.getValue()) && (match.getCandidate() == null || match.getCandidate() instanceof File);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String preview(Match<?, ?> match) {
|
public String preview(Match<?, ?> match) {
|
||||||
return preview != null ? preview.format(match.getValue()) : match.getValue().toString();
|
return preview != null ? preview.format(match.getValue()) : match.getValue().toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized String format(Match<?, ?> match, Map<?, ?> context) throws ScriptException {
|
public synchronized String format(Match<?, ?> match, Map<?, ?> context) throws ScriptException {
|
||||||
// lazy initialize script engine
|
// lazy initialize script engine
|
||||||
@ -54,7 +47,7 @@ class ExpressionFormatter implements MatchFormatter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// evaluate the expression using the given bindings
|
// evaluate the expression using the given bindings
|
||||||
Object bindingBean = new MediaBindingBean(match.getValue(), (File) match.getCandidate(), (Map<File, Object>) context);
|
Object bindingBean = new MediaBindingBean(match.getValue(), (File) match.getCandidate(), (Map) context);
|
||||||
String result = format.format(bindingBean).trim();
|
String result = format.format(bindingBean).trim();
|
||||||
|
|
||||||
// if result is empty, check for script exceptions
|
// if result is empty, check for script exceptions
|
||||||
|
@ -252,7 +252,7 @@ public class PresetEditor extends JDialog {
|
|||||||
JComboBox<Datasource> combo = new JComboBox<Datasource>(providers);
|
JComboBox<Datasource> combo = new JComboBox<Datasource>(providers);
|
||||||
combo.setRenderer(new ListCellRenderer<Object>() {
|
combo.setRenderer(new ListCellRenderer<Object>() {
|
||||||
|
|
||||||
private final ListCellRenderer<Object> parent = (ListCellRenderer<Object>) combo.getRenderer();
|
private final ListCellRenderer<Object> parent = (ListCellRenderer) combo.getRenderer();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
|
public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
|
||||||
@ -289,7 +289,7 @@ public class PresetEditor extends JDialog {
|
|||||||
JComboBox<Language> combo = new JComboBox<Language>(languages);
|
JComboBox<Language> combo = new JComboBox<Language>(languages);
|
||||||
combo.setRenderer(new ListCellRenderer<Language>() {
|
combo.setRenderer(new ListCellRenderer<Language>() {
|
||||||
|
|
||||||
private final ListCellRenderer<Language> parent = (ListCellRenderer<Language>) combo.getRenderer();
|
private final ListCellRenderer<Language> parent = (ListCellRenderer) combo.getRenderer();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Component getListCellRendererComponent(JList<? extends Language> list, Language value, int index, boolean isSelected, boolean cellHasFocus) {
|
public Component getListCellRendererComponent(JList<? extends Language> list, Language value, int index, boolean isSelected, boolean cellHasFocus) {
|
||||||
@ -318,7 +318,7 @@ public class PresetEditor extends JDialog {
|
|||||||
JComboBox<RenameAction> combo = new JComboBox<RenameAction>(actions);
|
JComboBox<RenameAction> combo = new JComboBox<RenameAction>(actions);
|
||||||
combo.setRenderer(new ListCellRenderer<RenameAction>() {
|
combo.setRenderer(new ListCellRenderer<RenameAction>() {
|
||||||
|
|
||||||
private final ListCellRenderer<RenameAction> parent = (ListCellRenderer<RenameAction>) combo.getRenderer();
|
private final ListCellRenderer<RenameAction> parent = (ListCellRenderer) combo.getRenderer();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Component getListCellRendererComponent(JList<? extends RenameAction> list, RenameAction value, int index, boolean isSelected, boolean cellHasFocus) {
|
public Component getListCellRendererComponent(JList<? extends RenameAction> list, RenameAction value, int index, boolean isSelected, boolean cellHasFocus) {
|
||||||
|
@ -132,6 +132,8 @@ class RenameListCellRenderer extends DefaultFancyListCellRenderer {
|
|||||||
case STARTED:
|
case STARTED:
|
||||||
setIcon(ResourceManager.getIcon("worker.started"));
|
setIcon(ResourceManager.getIcon("worker.started"));
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (renameModel.hasComplement(index)) {
|
if (renameModel.hasComplement(index)) {
|
||||||
|
@ -131,7 +131,8 @@ class ChecksumTableTransferablePolicy extends BackgroundFileTransferablePolicy<C
|
|||||||
ChecksumCell correct = new ChecksumCell(name, file, singletonMap(type, hash));
|
ChecksumCell correct = new ChecksumCell(name, file, singletonMap(type, hash));
|
||||||
ChecksumCell current = createComputationCell(name, baseFolder, type);
|
ChecksumCell current = createComputationCell(name, baseFolder, type);
|
||||||
|
|
||||||
publish(correct, current);
|
ChecksumCell[] columns = { correct, current };
|
||||||
|
publish(columns);
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
parser.close();
|
parser.close();
|
||||||
@ -158,14 +159,17 @@ class ChecksumTableTransferablePolicy extends BackgroundFileTransferablePolicy<C
|
|||||||
String name = normalizePathSeparators(relativeFile.getPath());
|
String name = normalizePathSeparators(relativeFile.getPath());
|
||||||
|
|
||||||
// publish computation cell first
|
// publish computation cell first
|
||||||
publish(createComputationCell(name, root, model.getHashType()));
|
ChecksumCell[] computeCell = { createComputationCell(name, root, model.getHashType()) };
|
||||||
|
publish(computeCell);
|
||||||
|
|
||||||
// publish verification cell, if we can
|
// publish verification cell, if we can
|
||||||
Map<File, String> hashByVerificationFile = verificationTracker.get().getHashByVerificationFile(absoluteFile);
|
Map<File, String> hashByVerificationFile = verificationTracker.get().getHashByVerificationFile(absoluteFile);
|
||||||
|
|
||||||
for (Entry<File, String> entry : hashByVerificationFile.entrySet()) {
|
for (Entry<File, String> entry : hashByVerificationFile.entrySet()) {
|
||||||
HashType hashType = verificationTracker.get().getVerificationFileType(entry.getKey());
|
HashType hashType = verificationTracker.get().getVerificationFileType(entry.getKey());
|
||||||
publish(new ChecksumCell(name, entry.getKey(), singletonMap(hashType, entry.getValue())));
|
|
||||||
|
ChecksumCell[] verifyCell = { new ChecksumCell(name, entry.getKey(), singletonMap(hashType, entry.getValue())) };
|
||||||
|
publish(verifyCell);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,10 @@
|
|||||||
|
|
||||||
package net.filebot.ui.subtitle;
|
package net.filebot.ui.subtitle;
|
||||||
|
|
||||||
|
import static java.util.stream.Collectors.*;
|
||||||
|
|
||||||
import java.awt.datatransfer.Clipboard;
|
import java.awt.datatransfer.Clipboard;
|
||||||
import java.awt.datatransfer.Transferable;
|
import java.awt.datatransfer.Transferable;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.util.AbstractList;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -19,46 +18,27 @@ import net.filebot.ui.transfer.ClipboardHandler;
|
|||||||
import net.filebot.ui.transfer.TransferableExportHandler;
|
import net.filebot.ui.transfer.TransferableExportHandler;
|
||||||
import net.filebot.vfs.MemoryFile;
|
import net.filebot.vfs.MemoryFile;
|
||||||
|
|
||||||
|
|
||||||
class MemoryFileListExportHandler implements TransferableExportHandler, ClipboardHandler {
|
class MemoryFileListExportHandler implements TransferableExportHandler, ClipboardHandler {
|
||||||
|
|
||||||
public boolean canExport(JComponent component) {
|
public boolean canExport(JComponent component) {
|
||||||
JList list = (JList) component;
|
JList<?> list = (JList<?>) component;
|
||||||
|
|
||||||
// can't export anything, if nothing is selected
|
// can't export anything, if nothing is selected
|
||||||
return !list.isSelectionEmpty();
|
return !list.isSelectionEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public List<MemoryFile> export(JComponent component) {
|
public List<MemoryFile> export(JComponent component) {
|
||||||
JList list = (JList) component;
|
JList<?> list = (JList<?>) component;
|
||||||
|
|
||||||
// get selected values
|
// get selected values as list
|
||||||
final Object[] selection = list.getSelectedValues();
|
return list.getSelectedValuesList().stream().map(MemoryFile.class::cast).collect(toList());
|
||||||
|
|
||||||
// as file list
|
|
||||||
return new AbstractList<MemoryFile>() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public MemoryFile get(int index) {
|
|
||||||
return (MemoryFile) selection[index];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int size() {
|
|
||||||
return selection.length;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getSourceActions(JComponent component) {
|
public int getSourceActions(JComponent component) {
|
||||||
return canExport(component) ? TransferHandler.COPY_OR_MOVE : TransferHandler.NONE;
|
return canExport(component) ? TransferHandler.COPY_OR_MOVE : TransferHandler.NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Transferable createTransferable(JComponent component) {
|
public Transferable createTransferable(JComponent component) {
|
||||||
Map<String, ByteBuffer> vfs = new HashMap<String, ByteBuffer>();
|
Map<String, ByteBuffer> vfs = new HashMap<String, ByteBuffer>();
|
||||||
@ -70,13 +50,11 @@ class MemoryFileListExportHandler implements TransferableExportHandler, Clipboar
|
|||||||
return new ByteBufferTransferable(vfs);
|
return new ByteBufferTransferable(vfs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void exportToClipboard(JComponent component, Clipboard clip, int action) {
|
public void exportToClipboard(JComponent component, Clipboard clip, int action) {
|
||||||
clip.setContents(createTransferable(component), null);
|
clip.setContents(createTransferable(component), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void exportDone(JComponent source, Transferable data, int action) {
|
public void exportDone(JComponent source, Transferable data, int action) {
|
||||||
|
|
||||||
|
@ -135,7 +135,7 @@ class SubtitleDownloadComponent extends JComponent {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
fetch(packageList.getSelectedValues());
|
fetch(packageList.getSelectedValuesList().toArray());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -144,7 +144,7 @@ class SubtitleDownloadComponent extends JComponent {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
open(fileList.getSelectedValues());
|
open(fileList.getSelectedValuesList().toArray());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -345,8 +345,7 @@ class SubtitleDownloadComponent extends JComponent {
|
|||||||
// fetch on double click
|
// fetch on double click
|
||||||
if (SwingUtilities.isLeftMouseButton(e) && (e.getClickCount() == 2)) {
|
if (SwingUtilities.isLeftMouseButton(e) && (e.getClickCount() == 2)) {
|
||||||
JList list = (JList) e.getSource();
|
JList list = (JList) e.getSource();
|
||||||
|
fetch(list.getSelectedValuesList().toArray());
|
||||||
fetch(list.getSelectedValues());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -371,7 +370,7 @@ class SubtitleDownloadComponent extends JComponent {
|
|||||||
list.setSelectedIndex(index);
|
list.setSelectedIndex(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
final Object[] selection = list.getSelectedValues();
|
final Object[] selection = list.getSelectedValuesList().toArray();
|
||||||
|
|
||||||
if (selection.length > 0) {
|
if (selection.length > 0) {
|
||||||
JPopupMenu contextMenu = new JPopupMenu();
|
JPopupMenu contextMenu = new JPopupMenu();
|
||||||
@ -415,7 +414,7 @@ class SubtitleDownloadComponent extends JComponent {
|
|||||||
JList list = (JList) e.getSource();
|
JList list = (JList) e.getSource();
|
||||||
|
|
||||||
// open selection
|
// open selection
|
||||||
open(list.getSelectedValues());
|
open(list.getSelectedValuesList().toArray());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -440,7 +439,7 @@ class SubtitleDownloadComponent extends JComponent {
|
|||||||
list.setSelectedIndex(index);
|
list.setSelectedIndex(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
final Object[] selection = list.getSelectedValues();
|
final Object[] selection = list.getSelectedValuesList().toArray();
|
||||||
|
|
||||||
if (selection.length > 0) {
|
if (selection.length > 0) {
|
||||||
JPopupMenu contextMenu = new JPopupMenu();
|
JPopupMenu contextMenu = new JPopupMenu();
|
||||||
|
@ -1,14 +1,11 @@
|
|||||||
|
|
||||||
package net.filebot.ui.transfer;
|
package net.filebot.ui.transfer;
|
||||||
|
|
||||||
|
|
||||||
import java.awt.datatransfer.DataFlavor;
|
import java.awt.datatransfer.DataFlavor;
|
||||||
import java.awt.datatransfer.Transferable;
|
import java.awt.datatransfer.Transferable;
|
||||||
import java.awt.datatransfer.UnsupportedFlavorException;
|
import java.awt.datatransfer.UnsupportedFlavorException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.reflect.Array;
|
import java.lang.reflect.Array;
|
||||||
|
|
||||||
|
|
||||||
public class ArrayTransferable<T> implements Transferable {
|
public class ArrayTransferable<T> implements Transferable {
|
||||||
|
|
||||||
public static DataFlavor flavor(Class<?> componentType) {
|
public static DataFlavor flavor(Class<?> componentType) {
|
||||||
@ -17,12 +14,10 @@ public class ArrayTransferable<T> implements Transferable {
|
|||||||
|
|
||||||
private final T[] array;
|
private final T[] array;
|
||||||
|
|
||||||
|
public ArrayTransferable(T[] array) {
|
||||||
public ArrayTransferable(T... array) {
|
|
||||||
this.array = array;
|
this.array = array;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
|
public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
|
||||||
if (isDataFlavorSupported(flavor)) {
|
if (isDataFlavorSupported(flavor)) {
|
||||||
@ -32,13 +27,11 @@ public class ArrayTransferable<T> implements Transferable {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DataFlavor[] getTransferDataFlavors() {
|
public DataFlavor[] getTransferDataFlavors() {
|
||||||
return new DataFlavor[] { new DataFlavor(array.getClass(), "Array") };
|
return new DataFlavor[] { new DataFlavor(array.getClass(), "Array") };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isDataFlavorSupported(DataFlavor flavor) {
|
public boolean isDataFlavorSupported(DataFlavor flavor) {
|
||||||
return array.getClass().equals(flavor.getRepresentationClass());
|
return array.getClass().equals(flavor.getRepresentationClass());
|
||||||
|
@ -64,7 +64,7 @@ public abstract class BackgroundFileTransferablePolicy<V> extends FileTransferab
|
|||||||
|
|
||||||
protected abstract void process(Exception exception);
|
protected abstract void process(Exception exception);
|
||||||
|
|
||||||
protected final void publish(V... chunks) {
|
protected final void publish(V[] chunks) {
|
||||||
BackgroundWorker worker = threadLocalWorker.get();
|
BackgroundWorker worker = threadLocalWorker.get();
|
||||||
|
|
||||||
if (worker == null) {
|
if (worker == null) {
|
||||||
@ -116,7 +116,7 @@ public abstract class BackgroundFileTransferablePolicy<V> extends FileTransferab
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void offer(V... chunks) {
|
public void offer(V[] chunks) {
|
||||||
if (!isCancelled()) {
|
if (!isCancelled()) {
|
||||||
publish(chunks);
|
publish(chunks);
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,13 @@
|
|||||||
|
|
||||||
package net.filebot.ui.transfer;
|
package net.filebot.ui.transfer;
|
||||||
|
|
||||||
|
import static java.util.Arrays.*;
|
||||||
|
import static java.util.stream.Collectors.*;
|
||||||
|
|
||||||
import java.awt.datatransfer.Clipboard;
|
import java.awt.datatransfer.Clipboard;
|
||||||
import java.awt.datatransfer.StringSelection;
|
import java.awt.datatransfer.StringSelection;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.stream.IntStream;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
import javax.swing.JComponent;
|
import javax.swing.JComponent;
|
||||||
import javax.swing.JList;
|
import javax.swing.JList;
|
||||||
@ -11,70 +15,45 @@ import javax.swing.JTable;
|
|||||||
import javax.swing.JTree;
|
import javax.swing.JTree;
|
||||||
import javax.swing.tree.TreePath;
|
import javax.swing.tree.TreePath;
|
||||||
|
|
||||||
|
import net.filebot.util.StringUtilities;
|
||||||
|
|
||||||
public class DefaultClipboardHandler implements ClipboardHandler {
|
public class DefaultClipboardHandler implements ClipboardHandler {
|
||||||
|
|
||||||
protected final String newLine = System.getProperty("line.separator");
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void exportToClipboard(JComponent component, Clipboard clip, int action) throws IllegalStateException {
|
public void exportToClipboard(JComponent component, Clipboard clip, int action) throws IllegalStateException {
|
||||||
StringBuilder sb = new StringBuilder();
|
clip.setContents(new StringSelection(export(component)), null);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String export(JComponent component) {
|
||||||
if (component instanceof JList) {
|
if (component instanceof JList) {
|
||||||
export(sb, (JList) component);
|
return export((JList) component);
|
||||||
} else if (component instanceof JTree) {
|
}
|
||||||
export(sb, (JTree) component);
|
if (component instanceof JTree) {
|
||||||
} else if (component instanceof JTable) {
|
return export((JTree) component);
|
||||||
export(sb, (JTable) component);
|
}
|
||||||
|
if (component instanceof JTable) {
|
||||||
|
return export((JTable) component);
|
||||||
|
}
|
||||||
|
throw new IllegalArgumentException("JComponent not supported: " + component);
|
||||||
}
|
}
|
||||||
|
|
||||||
clip.setContents(new StringSelection(sb.toString()), null);
|
protected String export(Stream<?> values) {
|
||||||
|
return StringUtilities.join(values, System.lineSeparator());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected String export(JList list) {
|
||||||
protected void export(StringBuilder sb, JList list) {
|
return export(list.getSelectedValuesList().stream());
|
||||||
for (Object value : list.getSelectedValues()) {
|
|
||||||
sb.append(value == null ? "" : value).append(newLine);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// delete last newline
|
protected String export(JTree tree) {
|
||||||
sb.delete(sb.length() - newLine.length(), sb.length());
|
return export(stream(tree.getSelectionPaths()).map(TreePath::getLastPathComponent));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected String export(JTable table) {
|
||||||
protected void export(StringBuilder sb, JTree tree) {
|
return export(stream(table.getSelectedRows()).map(row -> table.getRowSorter().convertRowIndexToModel(row)).mapToObj(row -> {
|
||||||
for (TreePath path : tree.getSelectionPaths()) {
|
return IntStream.range(0, table.getColumnCount()).mapToObj(column -> {
|
||||||
Object value = path.getLastPathComponent();
|
return table.getModel().getValueAt(row, column);
|
||||||
|
}).map(v -> Objects.toString(v, "")).collect(joining("\t"));
|
||||||
sb.append(value == null ? "" : value).append(newLine);
|
}));
|
||||||
}
|
|
||||||
|
|
||||||
// delete last newline
|
|
||||||
sb.delete(sb.length() - newLine.length(), sb.length());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
protected void export(StringBuilder sb, JTable table) {
|
|
||||||
for (int row : table.getSelectedRows()) {
|
|
||||||
int modelRow = table.getRowSorter().convertRowIndexToModel(row);
|
|
||||||
|
|
||||||
for (int column = 0; column < table.getColumnCount(); column++) {
|
|
||||||
Object value = table.getModel().getValueAt(modelRow, column);
|
|
||||||
|
|
||||||
if (value != null) {
|
|
||||||
sb.append(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (column < table.getColumnCount() - 1) {
|
|
||||||
sb.append("\t");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
sb.append(newLine);
|
|
||||||
}
|
|
||||||
|
|
||||||
// delete last newline
|
|
||||||
sb.delete(sb.length() - newLine.length(), sb.length());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -75,11 +75,15 @@ public final class StringUtilities {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static String join(Collection<?> values, CharSequence delimiter) {
|
public static String join(Collection<?> values, CharSequence delimiter) {
|
||||||
return join(values.stream(), delimiter, "", "");
|
return join(values.stream(), delimiter);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String join(Object[] values, CharSequence delimiter) {
|
public static String join(Object[] values, CharSequence delimiter) {
|
||||||
return join(stream(values), delimiter, "", "");
|
return join(stream(values), delimiter);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String join(Stream<?> values, CharSequence delimiter) {
|
||||||
|
return join(values, delimiter, "", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String join(Stream<?> values, CharSequence delimiter, CharSequence prefix, CharSequence suffix) {
|
public static String join(Stream<?> values, CharSequence delimiter, CharSequence prefix, CharSequence suffix) {
|
||||||
|
@ -1,13 +1,10 @@
|
|||||||
|
|
||||||
package net.filebot.util.ui;
|
package net.filebot.util.ui;
|
||||||
|
|
||||||
|
|
||||||
import java.beans.PropertyChangeEvent;
|
import java.beans.PropertyChangeEvent;
|
||||||
import java.beans.PropertyChangeListener;
|
import java.beans.PropertyChangeListener;
|
||||||
|
|
||||||
import javax.swing.SwingWorker.StateValue;
|
import javax.swing.SwingWorker.StateValue;
|
||||||
|
|
||||||
|
|
||||||
public abstract class SwingWorkerPropertyChangeAdapter implements PropertyChangeListener {
|
public abstract class SwingWorkerPropertyChangeAdapter implements PropertyChangeListener {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -21,7 +18,6 @@ public abstract class SwingWorkerPropertyChangeAdapter implements PropertyChange
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected void state(PropertyChangeEvent evt) {
|
protected void state(PropertyChangeEvent evt) {
|
||||||
switch ((StateValue) evt.getNewValue()) {
|
switch ((StateValue) evt.getNewValue()) {
|
||||||
case STARTED:
|
case STARTED:
|
||||||
@ -30,22 +26,20 @@ public abstract class SwingWorkerPropertyChangeAdapter implements PropertyChange
|
|||||||
case DONE:
|
case DONE:
|
||||||
done(evt);
|
done(evt);
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected void progress(PropertyChangeEvent evt) {
|
protected void progress(PropertyChangeEvent evt) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected void started(PropertyChangeEvent evt) {
|
protected void started(PropertyChangeEvent evt) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected void done(PropertyChangeEvent evt) {
|
protected void done(PropertyChangeEvent evt) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected void event(String name, Object oldValue, Object newValue) {
|
protected void event(String name, Object oldValue, Object newValue) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -153,6 +153,7 @@ public final class WebRequest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ByteBufferOutputStream buffer = new ByteBufferOutputStream(contentLength >= 0 ? contentLength : 4 * 1024);
|
ByteBufferOutputStream buffer = new ByteBufferOutputStream(contentLength >= 0 ? contentLength : 4 * 1024);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// read all
|
// read all
|
||||||
buffer.transferFully(in);
|
buffer.transferFully(in);
|
||||||
|
@ -9,6 +9,7 @@ import java.nio.channels.Channels;
|
|||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
@SuppressWarnings("resource")
|
||||||
public class ByteBufferOutputStreamTest {
|
public class ByteBufferOutputStreamTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
Loading…
Reference in New Issue
Block a user