* visual improvements to FileBotTabComponent

* some refactoring of FileBotUtil and Timer
This commit is contained in:
Reinhard Pointner 2008-12-31 11:54:44 +00:00
parent d7c08bc4ca
commit 396176c2f6
11 changed files with 105 additions and 96 deletions

View File

@ -3,8 +3,8 @@ package net.sourceforge.filebot;
import java.io.File;
import java.io.FileFilter;
import java.io.FilenameFilter;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@ -66,13 +66,18 @@ public final class FileBotUtil {
return embeddedChecksum;
}
private static final String[] TORRENT_FILE_EXTENSIONS = { "torrent" };
private static final String[] SFV_FILE_EXTENSIONS = { "sfv" };
private static final String[] LIST_FILE_EXTENSIONS = { "txt", "list", "" };
private static final String[] SUBTITLE_FILE_EXTENSIONS = { "srt", "sub", "ssa", "smi" };
public static final List<String> TORRENT_FILE_EXTENSIONS = unmodifiableList("torrent");
public static final List<String> SFV_FILE_EXTENSIONS = unmodifiableList("sfv");
public static final List<String> LIST_FILE_EXTENSIONS = unmodifiableList("txt", "list", "");
public static final List<String> SUBTITLE_FILE_EXTENSIONS = unmodifiableList("srt", "sub", "ssa", "smi");
public static boolean containsOnlyFolders(List<File> files) {
private static List<String> unmodifiableList(String... elements) {
return Collections.unmodifiableList(Arrays.asList(elements));
}
public static boolean containsOnlyFolders(Iterable<File> files) {
for (File file : files) {
if (!file.isDirectory())
return false;
@ -82,22 +87,7 @@ public final class FileBotUtil {
}
public static boolean containsOnlyTorrentFiles(List<File> files) {
return containsOnly(files, TORRENT_FILE_EXTENSIONS);
}
public static boolean containsOnlySfvFiles(List<File> files) {
return containsOnly(files, SFV_FILE_EXTENSIONS);
}
public static boolean containsOnlyListFiles(List<File> files) {
return containsOnly(files, LIST_FILE_EXTENSIONS);
}
public static boolean containsOnly(List<File> files, String... extensions) {
public static boolean containsOnly(Iterable<File> files, Iterable<String> extensions) {
for (File file : files) {
if (!FileUtil.hasExtension(file, extensions))
return false;
@ -106,34 +96,7 @@ public final class FileBotUtil {
return true;
}
public static final FileFilter FOLDERS_ONLY = new FileFilter() {
@Override
public boolean accept(File file) {
return file.isDirectory();
}
};
public static final FileFilter FILES_ONLY = new FileFilter() {
@Override
public boolean accept(File file) {
return file.isFile();
}
};
public static final FilenameFilter SUBTITLES_ONLY = new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
return FileUtil.hasExtension(name, SUBTITLE_FILE_EXTENSIONS);
}
};
/**
* Dummy constructor to prevent instantiation.
*/

View File

@ -2,41 +2,51 @@
package net.sourceforge.filebot.ui;
import java.awt.Dimension;
import javax.swing.AbstractButton;
import javax.swing.Icon;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.SwingConstants;
import net.miginfocom.swing.MigLayout;
import net.sourceforge.filebot.ResourceManager;
import net.sourceforge.tuned.ui.ProgressIndicator;
import net.sourceforge.tuned.ui.TunedUtil;
public class FileBotTabComponent extends JComponent {
private ProgressIndicator progressIndicator = new ProgressIndicator();
private JLabel label = new JLabel();
private JButton closeButton = createCloseButton();
private JLabel textLabel = new JLabel();
private JLabel iconLabel = new JLabel();
private AbstractButton closeButton = createCloseButton();
private Icon icon = null;
private boolean loading = false;
public FileBotTabComponent() {
setLayout(new MigLayout("nogrid, fill, insets 0"));
iconLabel.setHorizontalAlignment(SwingConstants.CENTER);
textLabel.setHorizontalAlignment(SwingConstants.LEFT);
progressIndicator.setVisible(loading);
progressIndicator.setMinimumSize(new Dimension(16, 16));
add(progressIndicator, "gap right 4px, w 17px!, h 17px!, hidemode 3");
add(label, "grow");
add(closeButton, "gap 3px:push, w 17!, h 17!");
setLayout(new MigLayout("nogrid, insets 0 0 1 3"));
add(progressIndicator, "hidemode 3");
add(iconLabel, "hidemode 3");
add(textLabel, "gap rel, align left");
add(closeButton, "gap unrel:push, hidemode 3, align center 45%");
}
public void setLoading(boolean loading) {
this.loading = loading;
progressIndicator.setVisible(loading);
label.setIcon(loading ? null : icon);
iconLabel.setVisible(!loading);
}
@ -46,43 +56,46 @@ public class FileBotTabComponent extends JComponent {
public void setIcon(Icon icon) {
this.icon = icon;
label.setIcon(loading ? null : icon);
iconLabel.setIcon(icon);
progressIndicator.setPreferredSize(icon != null ? TunedUtil.getDimension(icon) : progressIndicator.getMinimumSize());
}
public Icon getIcon() {
return icon;
return iconLabel.getIcon();
}
public void setText(String text) {
label.setText(text);
textLabel.setText(text);
}
public String getText() {
return label.getText();
return textLabel.getText();
}
public JButton getCloseButton() {
public AbstractButton getCloseButton() {
return closeButton;
}
private JButton createCloseButton() {
JButton button = new JButton();
protected AbstractButton createCloseButton() {
Icon icon = ResourceManager.getIcon("tab.close");
Icon rolloverIcon = ResourceManager.getIcon("tab.close.hover");
JButton button = new JButton(icon);
button.setRolloverIcon(rolloverIcon);
button.setPreferredSize(TunedUtil.getDimension(rolloverIcon));
button.setMaximumSize(button.getPreferredSize());
button.setContentAreaFilled(false);
button.setBorderPainted(false);
button.setFocusable(false);
button.setRolloverEnabled(true);
button.setIcon(ResourceManager.getIcon("tab.close"));
button.setRolloverIcon(ResourceManager.getIcon("tab.close.hover"));
return button;
}
}

View File

@ -2,6 +2,10 @@
package net.sourceforge.filebot.ui.panel.list;
import static net.sourceforge.filebot.FileBotUtil.TORRENT_FILE_EXTENSIONS;
import static net.sourceforge.filebot.FileBotUtil.containsOnly;
import static net.sourceforge.filebot.FileBotUtil.containsOnlyFolders;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
@ -9,7 +13,6 @@ import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import net.sourceforge.filebot.FileBotUtil;
import net.sourceforge.filebot.torrent.Torrent;
import net.sourceforge.filebot.ui.FileBotList;
import net.sourceforge.filebot.ui.transfer.FileTransferablePolicy;
@ -43,9 +46,9 @@ class FileListTransferablePolicy extends FileTransferablePolicy {
// set title based on parent folder of first file
list.setTitle(FileUtil.getFolderName(files.get(0).getParentFile()));
if (FileBotUtil.containsOnlyFolders(files)) {
if (containsOnlyFolders(files)) {
loadFolders(files);
} else if (FileBotUtil.containsOnlyTorrentFiles(files)) {
} else if (containsOnly(files, TORRENT_FILE_EXTENSIONS)) {
loadTorrents(files);
} else {
for (File file : files) {

View File

@ -2,11 +2,12 @@
package net.sourceforge.filebot.ui.panel.rename;
import static net.sourceforge.filebot.FileBotUtil.containsOnlyFolders;
import java.io.File;
import java.util.Arrays;
import java.util.List;
import net.sourceforge.filebot.FileBotUtil;
import net.sourceforge.filebot.ui.panel.rename.entry.FileEntry;
import net.sourceforge.filebot.ui.transfer.FileTransferablePolicy;
import ca.odell.glazedlists.EventList;
@ -36,7 +37,7 @@ class FilesListTransferablePolicy extends FileTransferablePolicy {
@Override
protected void load(List<File> files) {
if (FileBotUtil.containsOnlyFolders(files)) {
if (containsOnlyFolders(files)) {
for (File folder : files) {
loadFiles(Arrays.asList(folder.listFiles()));
}

View File

@ -2,6 +2,10 @@
package net.sourceforge.filebot.ui.panel.rename;
import static net.sourceforge.filebot.FileBotUtil.LIST_FILE_EXTENSIONS;
import static net.sourceforge.filebot.FileBotUtil.TORRENT_FILE_EXTENSIONS;
import static net.sourceforge.filebot.FileBotUtil.containsOnly;
import java.awt.datatransfer.Transferable;
import java.io.BufferedReader;
import java.io.File;
@ -75,9 +79,9 @@ class NamesListTransferablePolicy extends FilesListTransferablePolicy {
@Override
protected void load(List<File> files) {
if (FileBotUtil.containsOnlyListFiles(files)) {
if (containsOnly(files, LIST_FILE_EXTENSIONS)) {
loadListFiles(files);
} else if (FileBotUtil.containsOnlyTorrentFiles(files)) {
} else if (containsOnly(files, TORRENT_FILE_EXTENSIONS)) {
loadTorrentFiles(files);
} else {
super.load(files);

View File

@ -2,6 +2,9 @@
package net.sourceforge.filebot.ui.panel.sfv;
import static net.sourceforge.filebot.FileBotUtil.SFV_FILE_EXTENSIONS;
import static net.sourceforge.filebot.FileBotUtil.containsOnly;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
@ -13,7 +16,6 @@ import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import net.sourceforge.filebot.FileBotUtil;
import net.sourceforge.filebot.ui.transfer.BackgroundFileTransferablePolicy;
@ -94,7 +96,7 @@ class SfvTransferablePolicy extends BackgroundFileTransferablePolicy<ChecksumTab
@Override
protected void load(List<File> files) {
try {
if (FileBotUtil.containsOnlySfvFiles(files)) {
if (containsOnly(files, SFV_FILE_EXTENSIONS)) {
// one or more sfv files
for (File file : files) {
loadSfvFile(file);

View File

@ -3,14 +3,13 @@ package net.sourceforge.filebot.ui.panel.subtitle;
import java.io.File;
import java.io.FileFilter;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.concurrent.TimeoutException;
import java.util.logging.Level;
import java.util.logging.Logger;
import net.sourceforge.filebot.FileBotUtil;
public class Unrar {
@ -64,11 +63,11 @@ public class Unrar {
if (System.getProperty("os.name").toLowerCase().contains("windows")) {
File programFiles = new File(System.getenv("PROGRAMFILES"));
for (File folder : programFiles.listFiles(FileBotUtil.FOLDERS_ONLY)) {
for (File folder : programFiles.listFiles(FOLDERS_ONLY)) {
String name = folder.getName().toLowerCase();
if (name.contains("rar") || name.contains("zip")) {
for (File file : folder.listFiles(FileBotUtil.FILES_ONLY)) {
for (File file : folder.listFiles(FILES_ONLY)) {
String filename = file.getName();
if (filename.equalsIgnoreCase("unrar.exe") || filename.equalsIgnoreCase("7z.exe")) {
@ -89,7 +88,7 @@ public class Unrar {
return new Command(command);
}
} catch (Exception e) {
Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).log(Level.WARNING, "Cannot initialize unrar facility: " + e.getMessage());
Logger.getLogger("global").log(Level.WARNING, "Cannot initialize unrar facility: " + e.getMessage());
}
return null;
@ -135,4 +134,23 @@ public class Unrar {
}
}
private static final FileFilter FOLDERS_ONLY = new FileFilter() {
@Override
public boolean accept(File file) {
return file.isDirectory();
}
};
private static final FileFilter FILES_ONLY = new FileFilter() {
@Override
public boolean accept(File file) {
return file.isFile();
}
};
}

View File

@ -24,7 +24,7 @@ public final class FileUtil {
}
public static boolean hasExtension(File file, String... extensions) {
public static boolean hasExtension(File file, Iterable<String> extensions) {
if (file.isDirectory())
return false;
@ -32,7 +32,7 @@ public final class FileUtil {
}
public static boolean hasExtension(String filename, String... extensions) {
public static boolean hasExtension(String filename, Iterable<String> extensions) {
String extension = getExtension(filename, false);
for (String ext : extensions) {

View File

@ -2,7 +2,7 @@
package net.sourceforge.tuned;
import java.util.concurrent.RunnableScheduledFuture;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
@ -11,7 +11,7 @@ public abstract class Timer implements Runnable {
private final ScheduledThreadPoolExecutor executor;
private RunnableScheduledFuture<?> scheduledFuture;
private ScheduledFuture<?> scheduledFuture;
private Thread shutdownHook;
@ -47,7 +47,7 @@ public abstract class Timer implements Runnable {
removeShutdownHook();
}
scheduledFuture = (RunnableScheduledFuture<?>) executor.schedule(r, delay, unit);
scheduledFuture = executor.schedule(r, delay, unit);
}
@ -60,8 +60,8 @@ public abstract class Timer implements Runnable {
private synchronized void removeScheduledFuture() {
if (scheduledFuture != null) {
try {
scheduledFuture.cancel(false);
executor.remove(scheduledFuture);
scheduledFuture.cancel(true);
executor.purge();
} finally {
scheduledFuture = null;
}

View File

@ -53,14 +53,14 @@ public class ProgressIndicator extends JComponent {
addComponentListener(new ComponentAdapter() {
@Override
public void componentHidden(ComponentEvent e) {
stopAnimation();
public void componentShown(ComponentEvent e) {
startAnimation();
}
@Override
public void componentShown(ComponentEvent e) {
startAnimation();
public void componentHidden(ComponentEvent e) {
stopAnimation();
}
});
}

View File

@ -69,6 +69,11 @@ public final class TunedUtil {
}
public static Dimension getDimension(Icon icon) {
return new Dimension(icon.getIconWidth(), icon.getIconHeight());
}
public static Timer invokeLater(int delay, final Runnable runnable) {
Timer timer = new Timer(delay, new ActionListener() {