From 04c4baf9b905094a9cf9eaee73cb5e945d4eee09 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Wed, 19 Mar 2008 22:14:38 +0000 Subject: [PATCH] * support for arguments * better tempfile management * lots of refactoring --- source/Main.java | 65 +++++++++- .../net/sourceforge/filebot/FileBotUtil.java | 17 +++ .../net/sourceforge/filebot/FileFormat.java | 26 ++-- source/net/sourceforge/filebot/Settings.java | 2 +- .../filebot/resources/ResourceManager.java | 4 +- ...continue.valid.png => dialog.continue.png} | Bin .../sourceforge/filebot/torrent/Torrent.java | 2 +- .../sourceforge/filebot/ui/FileBotPanel.java | 45 ++++++- .../filebot/ui/FileBotPanelSelectionList.java | 23 +--- .../sourceforge/filebot/ui/FileBotWindow.java | 31 +++-- .../ui/FileTransferableMessageHandler.java | 48 ++++++++ .../{tuned => filebot}/ui/SelectDialog.java | 24 ++-- .../ui/panel/analyze/AnalyzePanel.java | 41 ++++--- .../ui/panel/analyze/FileTreePanel.java | 23 +--- .../ui/panel/analyze/tools/SplitPanel.java | 10 +- .../ui/panel/analyze/tools/ToolPanel.java | 32 +---- .../ui/panel/analyze/tools/TypePanel.java | 17 ++- .../list/FileListTransferablePolicy.java | 8 +- .../filebot/ui/panel/list/ListPanel.java | 4 + .../rename/NamesListTransferablePolicy.java | 14 ++- .../filebot/ui/panel/rename/RenameAction.java | 2 +- .../filebot/ui/panel/rename/RenamePanel.java | 10 +- .../ui/panel/rename/ValidateNamesDialog.java | 16 +-- .../ui/panel/rename/entry/FileEntry.java | 2 +- .../ui/panel/rename/entry/TorrentEntry.java | 2 +- .../ui/panel/search/EpisodeListPanel.java | 24 ++-- .../filebot/ui/panel/search/SearchPanel.java | 10 +- .../filebot/ui/panel/sfv/SfvPanel.java | 8 +- .../filebot/ui/panel/sfv/SfvTable.java | 2 +- .../ui/panel/sfv/SfvTransferablePolicy.java | 2 +- .../ui/transfer/DefaultClipboardHandler.java | 10 +- .../filebot/ui/transfer/FileTransferable.java | 18 ++- .../ui/transfer/SaveableExportHandler.java | 37 ++---- .../FileTransferablePolicy.java | 2 +- .../MultiTransferablePolicy.java | 11 +- .../TextTransferablePolicy.java | 3 + .../sourceforge/filebot/web/DownloadTask.java | 7 +- .../net/sourceforge/filebot/web/Episode.java | 2 +- .../filebot/web/EpisodeListClient.java | 4 +- source/net/sourceforge/tuned/MessageBus.java | 86 +++++++++++++ .../net/sourceforge/tuned/MessageHandler.java | 12 ++ .../tuned/PausableThreadPoolExecutor.java | 7 +- .../sourceforge/tuned/TemporaryFolder.java | 95 +++++++++++++++ .../sourceforge/tuned/TimeIntervalFormat.java | 4 +- .../tuned/ui/LoadingOverlayPane.java | 114 ++++++++++++++++++ .../tuned/ui/LoadingOverlayPanel.java | 90 -------------- .../sourceforge/tuned/ui/SimpleListModel.java | 2 +- 47 files changed, 675 insertions(+), 343 deletions(-) rename source/net/sourceforge/filebot/resources/{dialog.continue.valid.png => dialog.continue.png} (100%) create mode 100644 source/net/sourceforge/filebot/ui/FileTransferableMessageHandler.java rename source/net/sourceforge/{tuned => filebot}/ui/SelectDialog.java (90%) create mode 100644 source/net/sourceforge/tuned/MessageBus.java create mode 100644 source/net/sourceforge/tuned/MessageHandler.java create mode 100644 source/net/sourceforge/tuned/TemporaryFolder.java create mode 100644 source/net/sourceforge/tuned/ui/LoadingOverlayPane.java delete mode 100644 source/net/sourceforge/tuned/ui/LoadingOverlayPanel.java diff --git a/source/Main.java b/source/Main.java index 9b975a05..0f98bf0c 100644 --- a/source/Main.java +++ b/source/Main.java @@ -1,10 +1,20 @@ +import java.util.ArrayList; +import java.util.HashSet; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; import java.util.logging.Level; import java.util.logging.Logger; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import javax.swing.SwingUtilities; import javax.swing.UIManager; +import net.sourceforge.filebot.Settings; import net.sourceforge.filebot.ui.FileBotWindow; +import net.sourceforge.tuned.MessageBus; public class Main { @@ -14,18 +24,69 @@ public class Main { */ public static void main(String[] args) { + final Arguments arguments = new Arguments(args); + + if (arguments.containsParameter("clear")) { + Settings.getSettings().clear(); + } + try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (Exception e) { - // should not happen Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).log(Level.SEVERE, e.toString(), e); } + final FileBotWindow window = new FileBotWindow(); + + // publish messages from arguments to the newly created components + arguments.publishMessages(); + SwingUtilities.invokeLater(new Runnable() { + @Override public void run() { - new FileBotWindow().setVisible(true); + window.setVisible(true); } }); } + + + private static class Arguments { + + private final Set parameters = new HashSet(3); + private final Map> messages = new LinkedHashMap>(); + + + public Arguments(String[] args) { + Pattern topicPattern = Pattern.compile("--(\\w+)"); + + String currentTopic = null; + + for (String arg : args) { + Matcher m = topicPattern.matcher(arg); + + if (m.matches()) { + currentTopic = m.group(1).toLowerCase(); + messages.put(currentTopic, new ArrayList(1)); + } else if (currentTopic != null) { + messages.get(currentTopic).add(arg); + } else { + parameters.add(arg.toLowerCase()); + } + } + } + + + public boolean containsParameter(String argument) { + return parameters.contains(argument); + } + + + public void publishMessages() { + for (String topic : messages.keySet()) { + MessageBus.getDefault().publish(topic, messages.get(topic).toArray(new String[0])); + } + } + } + } diff --git a/source/net/sourceforge/filebot/FileBotUtil.java b/source/net/sourceforge/filebot/FileBotUtil.java index 7eb4c18c..f6e7039f 100644 --- a/source/net/sourceforge/filebot/FileBotUtil.java +++ b/source/net/sourceforge/filebot/FileBotUtil.java @@ -2,11 +2,15 @@ package net.sourceforge.filebot; +import java.awt.Dimension; +import java.awt.Point; +import java.awt.Window; import java.util.Iterator; import java.util.regex.Pattern; import javax.swing.Action; import javax.swing.JComponent; +import javax.swing.JDialog; import javax.swing.KeyStroke; @@ -70,4 +74,17 @@ public class FileBotUtil { return sb.toString(); } + + + public static Point getPreferredLocation(JDialog dialog) { + Window owner = dialog.getOwner(); + + if (owner == null) + return new Point(120, 80); + + Point p = owner.getLocation(); + Dimension d = owner.getSize(); + + return new Point(p.x + d.width / 4, p.y + d.height / 7); + } } diff --git a/source/net/sourceforge/filebot/FileFormat.java b/source/net/sourceforge/filebot/FileFormat.java index d80e3fff..061b3b70 100644 --- a/source/net/sourceforge/filebot/FileFormat.java +++ b/source/net/sourceforge/filebot/FileFormat.java @@ -8,7 +8,7 @@ import java.text.NumberFormat; public class FileFormat { - private static NumberFormat nf = NumberFormat.getNumberInstance(); + private static final NumberFormat numberFormat = NumberFormat.getNumberInstance(); public final static long KILO = 1024; @@ -17,17 +17,17 @@ public class FileFormat { public final static long GIGA = MEGA * 1024; static { - nf.setMaximumFractionDigits(0); + numberFormat.setMaximumFractionDigits(0); } public static String formatSize(long size) { if (size >= MEGA) - return nf.format((double) size / MEGA) + " MB"; + return numberFormat.format((double) size / MEGA) + " MB"; else if (size >= KILO) - return nf.format((double) size / KILO) + " KB"; + return numberFormat.format((double) size / KILO) + " KB"; else - return nf.format(size) + " Byte"; + return numberFormat.format(size) + " Byte"; } @@ -37,7 +37,7 @@ public class FileFormat { if (f.isDirectory()) return name; - return getNameWithoutSuffix(name); + return getNameWithoutExtension(name); } @@ -49,16 +49,16 @@ public class FileFormat { } - public static String getSuffix(File f) { - return getSuffix(f, false); + public static String getExtension(File f) { + return getExtension(f, false); } - public static String getSuffix(File f, boolean includeDot) { + public static String getExtension(File f, boolean includeDot) { String name = f.getName(); int dotIndex = name.lastIndexOf("."); - // .config -> no suffix + // .config -> no extension if (dotIndex >= 1) { int startIndex = dotIndex; @@ -74,7 +74,7 @@ public class FileFormat { } - public static String getNameWithoutSuffix(String name) { + public static String getNameWithoutExtension(String name) { int dotIndex = name.lastIndexOf("."); if (dotIndex < 1) @@ -84,8 +84,8 @@ public class FileFormat { } - public static String getNameWithoutSuffix(File file) { - return getNameWithoutSuffix(file.getName()); + public static String getNameWithoutExtension(File file) { + return getNameWithoutExtension(file.getName()); } diff --git a/source/net/sourceforge/filebot/Settings.java b/source/net/sourceforge/filebot/Settings.java index b1fda030..a0dcfe63 100644 --- a/source/net/sourceforge/filebot/Settings.java +++ b/source/net/sourceforge/filebot/Settings.java @@ -18,7 +18,7 @@ public class Settings { private static Settings settings = new Settings(); - private static final String ROOT = "filebot"; + public static final String ROOT = "filebot"; public static final String SELECTED_PANEL = "panel"; public static final String SEARCH_HISTORY = "history/search"; diff --git a/source/net/sourceforge/filebot/resources/ResourceManager.java b/source/net/sourceforge/filebot/resources/ResourceManager.java index 49df53a5..d72462db 100644 --- a/source/net/sourceforge/filebot/resources/ResourceManager.java +++ b/source/net/sourceforge/filebot/resources/ResourceManager.java @@ -52,10 +52,10 @@ public class ResourceManager { public static ImageIcon getArchiveIcon(String type) { - URL url = ResourceManager.class.getResource(String.format("archive/%s.png", type.toLowerCase())); + URL url = ResourceManager.class.getResource(String.format("archives/%s.png", type.toLowerCase())); if (url == null) - url = ResourceManager.class.getResource(String.format("archive/default.png")); + url = ResourceManager.class.getResource(String.format("archives/default.png")); return new ImageIcon(url); } diff --git a/source/net/sourceforge/filebot/resources/dialog.continue.valid.png b/source/net/sourceforge/filebot/resources/dialog.continue.png similarity index 100% rename from source/net/sourceforge/filebot/resources/dialog.continue.valid.png rename to source/net/sourceforge/filebot/resources/dialog.continue.png diff --git a/source/net/sourceforge/filebot/torrent/Torrent.java b/source/net/sourceforge/filebot/torrent/Torrent.java index 7e35d51c..09e144e1 100644 --- a/source/net/sourceforge/filebot/torrent/Torrent.java +++ b/source/net/sourceforge/filebot/torrent/Torrent.java @@ -65,7 +65,7 @@ public class Torrent { Map fileMap = (Map) fileMapObject; List pathList = (List) fileMap.get("path"); - StringBuffer pathBuffer = new StringBuffer(); + StringBuilder pathBuffer = new StringBuilder(); String entryName = null; Iterator iterator = pathList.iterator(); diff --git a/source/net/sourceforge/filebot/ui/FileBotPanel.java b/source/net/sourceforge/filebot/ui/FileBotPanel.java index e8a10779..f9ad27ac 100644 --- a/source/net/sourceforge/filebot/ui/FileBotPanel.java +++ b/source/net/sourceforge/filebot/ui/FileBotPanel.java @@ -3,20 +3,54 @@ package net.sourceforge.filebot.ui; import java.awt.BorderLayout; +import java.util.LinkedHashSet; import javax.swing.Icon; import javax.swing.JPanel; +import net.sourceforge.filebot.ui.panel.analyze.AnalyzePanel; +import net.sourceforge.filebot.ui.panel.list.ListPanel; +import net.sourceforge.filebot.ui.panel.rename.RenamePanel; +import net.sourceforge.filebot.ui.panel.search.SearchPanel; +import net.sourceforge.filebot.ui.panel.sfv.SfvPanel; +import net.sourceforge.filebot.ui.panel.subtitle.SubtitlePanel; + public class FileBotPanel extends JPanel { - private String title; - private Icon icon; + private static final LinkedHashSet registry = new LinkedHashSet(); + + static { + registry.add(new ListPanel()); + registry.add(new RenamePanel()); + registry.add(new AnalyzePanel()); + registry.add(new SearchPanel()); + registry.add(new SubtitlePanel()); + registry.add(new SfvPanel()); + } + + + public static Iterable getAvailablePanels() { + return registry; + } + + + public static FileBotPanel forName(String name) { + for (FileBotPanel panel : registry) { + if (name.equalsIgnoreCase(panel.getPanelName())) + return panel; + } + + return null; + } + + private final String name; + private final Icon icon; public FileBotPanel(String title, Icon icon) { super(new BorderLayout(10, 0)); - this.title = title; + this.name = title; this.icon = icon; } @@ -26,8 +60,7 @@ public class FileBotPanel extends JPanel { } - public String getTitle() { - return title; + public String getPanelName() { + return name; } - } diff --git a/source/net/sourceforge/filebot/ui/FileBotPanelSelectionList.java b/source/net/sourceforge/filebot/ui/FileBotPanelSelectionList.java index b2ecf9ec..5f74c213 100644 --- a/source/net/sourceforge/filebot/ui/FileBotPanelSelectionList.java +++ b/source/net/sourceforge/filebot/ui/FileBotPanelSelectionList.java @@ -11,8 +11,6 @@ import java.awt.dnd.DropTargetDropEvent; import java.awt.dnd.DropTargetEvent; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; -import java.util.ArrayList; -import java.util.List; import javax.swing.JList; import javax.swing.ListSelectionModel; @@ -21,12 +19,6 @@ import javax.swing.SwingUtilities; import javax.swing.Timer; import javax.swing.border.EmptyBorder; -import net.sourceforge.filebot.ui.panel.analyze.AnalyzePanel; -import net.sourceforge.filebot.ui.panel.list.ListPanel; -import net.sourceforge.filebot.ui.panel.rename.RenamePanel; -import net.sourceforge.filebot.ui.panel.search.SearchPanel; -import net.sourceforge.filebot.ui.panel.sfv.SfvPanel; -import net.sourceforge.filebot.ui.panel.subtitle.SubtitlePanel; import net.sourceforge.tuned.ui.FancyListCellRenderer; import net.sourceforge.tuned.ui.GradientStyle; import net.sourceforge.tuned.ui.SimpleListModel; @@ -45,16 +37,13 @@ class FileBotPanelSelectionList extends JList { new DropTarget(this, new DragDropListener()); - List panels = new ArrayList(); + SimpleListModel model = new SimpleListModel(); - panels.add(new ListPanel()); - panels.add(new RenamePanel()); - panels.add(new AnalyzePanel()); - panels.add(new SearchPanel()); - panels.add(new SubtitlePanel()); - panels.add(new SfvPanel()); + for (FileBotPanel panel : FileBotPanel.getAvailablePanels()) { + model.add(panel); + } - setModel(new SimpleListModel(panels)); + setModel(model); } @@ -72,7 +61,7 @@ class FileBotPanelSelectionList extends JList { super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); FileBotPanel panel = (FileBotPanel) value; - setText(panel.getTitle()); + setText(panel.getPanelName()); setIcon(panel.getIcon()); return this; diff --git a/source/net/sourceforge/filebot/ui/FileBotWindow.java b/source/net/sourceforge/filebot/ui/FileBotWindow.java index d1eab5b5..783a80fe 100644 --- a/source/net/sourceforge/filebot/ui/FileBotWindow.java +++ b/source/net/sourceforge/filebot/ui/FileBotWindow.java @@ -7,6 +7,7 @@ import java.awt.CardLayout; import java.awt.Image; import java.awt.event.ActionEvent; import java.util.ArrayList; +import java.util.List; import javax.swing.AbstractAction; import javax.swing.JComponent; @@ -14,7 +15,6 @@ import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.KeyStroke; -import javax.swing.ListModel; import javax.swing.OverlayLayout; import javax.swing.ScrollPaneConstants; import javax.swing.border.EmptyBorder; @@ -24,7 +24,10 @@ import javax.swing.event.ListSelectionListener; import net.sourceforge.filebot.FileBotUtil; import net.sourceforge.filebot.Settings; import net.sourceforge.filebot.resources.ResourceManager; +import net.sourceforge.tuned.MessageBus; +import net.sourceforge.tuned.MessageHandler; import net.sourceforge.tuned.ui.ShadowBorder; +import net.sourceforge.tuned.ui.SimpleListModel; public class FileBotWindow extends JFrame implements ListSelectionListener { @@ -58,15 +61,17 @@ public class FileBotWindow extends JFrame implements ListSelectionListener { setSize(760, 615); selectionListPanel.setSelectedIndex(Settings.getSettings().getInt(Settings.SELECTED_PANEL, 3)); + + MessageBus.getDefault().addMessageHandler("panel", panelMessageHandler); } public void valueChanged(ListSelectionEvent e) { FileBotPanel currentPanel = (FileBotPanel) selectionListPanel.getSelectedValue(); - headerPanel.setTitle(currentPanel.getTitle()); + headerPanel.setTitle(currentPanel.getPanelName()); CardLayout cardLayout = (CardLayout) pagePanel.getLayout(); - cardLayout.show(pagePanel, currentPanel.getTitle()); + cardLayout.show(pagePanel, currentPanel.getPanelName()); JComponent c = (JComponent) getContentPane(); @@ -101,6 +106,7 @@ public class FileBotWindow extends JFrame implements ListSelectionListener { } + @SuppressWarnings("unchecked") private JComponent createPageLayer() { JPanel pageLayer = new JPanel(new BorderLayout()); @@ -109,12 +115,11 @@ public class FileBotWindow extends JFrame implements ListSelectionListener { pageLayer.add(headerPanel, BorderLayout.NORTH); pageLayer.add(pagePanel, BorderLayout.CENTER); - ListModel model = selectionListPanel.getModel(); + SimpleListModel model = (SimpleListModel) selectionListPanel.getModel(); - for (int i = 0; i < model.getSize(); i++) { - FileBotPanel panel = (FileBotPanel) model.getElementAt(i); + for (FileBotPanel panel : (List) model.getCopy()) { panel.setVisible(false); - pagePanel.add(panel, panel.getTitle()); + pagePanel.add(panel, panel.getPanelName()); } pageLayer.setAlignmentX(0.0f); @@ -134,6 +139,17 @@ public class FileBotWindow extends JFrame implements ListSelectionListener { return contentPane; } + private final MessageHandler panelMessageHandler = new MessageHandler() { + + @Override + public void handle(String topic, String... messages) { + for (String panel : messages) { + selectionListPanel.setSelectedValue(FileBotPanel.forName(panel), true); + } + } + + }; + private final AbstractAction closeAction = new AbstractAction("Close") { public void actionPerformed(ActionEvent e) { @@ -142,4 +158,5 @@ public class FileBotWindow extends JFrame implements ListSelectionListener { System.exit(0); } }; + } diff --git a/source/net/sourceforge/filebot/ui/FileTransferableMessageHandler.java b/source/net/sourceforge/filebot/ui/FileTransferableMessageHandler.java new file mode 100644 index 00000000..aef4a098 --- /dev/null +++ b/source/net/sourceforge/filebot/ui/FileTransferableMessageHandler.java @@ -0,0 +1,48 @@ + +package net.sourceforge.filebot.ui; + + +import java.io.File; +import java.util.ArrayList; +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; + +import net.sourceforge.filebot.ui.transfer.FileTransferable; +import net.sourceforge.filebot.ui.transfer.TransferablePolicySupport; +import net.sourceforge.tuned.MessageBus; +import net.sourceforge.tuned.MessageHandler; + + +public class FileTransferableMessageHandler implements MessageHandler { + + private final String name; + private final TransferablePolicySupport transferablePolicySupport; + + + public FileTransferableMessageHandler(String name, TransferablePolicySupport transferablePolicySupport) { + this.name = name; + this.transferablePolicySupport = transferablePolicySupport; + } + + + @Override + public void handle(String topic, String... messages) { + + MessageBus.getDefault().publish("panel", name); + + List files = new ArrayList(messages.length); + + for (String filename : messages) { + File file = new File(filename); + + if (file.exists()) { + files.add(file); + } else { + Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).log(Level.WARNING, String.format("Invalid File: %s", filename)); + } + } + + transferablePolicySupport.getTransferablePolicy().handleTransferable(new FileTransferable(files), true); + } +} diff --git a/source/net/sourceforge/tuned/ui/SelectDialog.java b/source/net/sourceforge/filebot/ui/SelectDialog.java similarity index 90% rename from source/net/sourceforge/tuned/ui/SelectDialog.java rename to source/net/sourceforge/filebot/ui/SelectDialog.java index 87cdc069..35e5e2ea 100644 --- a/source/net/sourceforge/tuned/ui/SelectDialog.java +++ b/source/net/sourceforge/filebot/ui/SelectDialog.java @@ -1,11 +1,10 @@ -package net.sourceforge.tuned.ui; +package net.sourceforge.filebot.ui; import java.awt.BorderLayout; import java.awt.Component; import java.awt.Dimension; -import java.awt.Point; import java.awt.Window; import java.awt.event.ActionEvent; import java.awt.event.MouseAdapter; @@ -26,6 +25,11 @@ import javax.swing.KeyStroke; import javax.swing.SwingUtilities; import javax.swing.border.EmptyBorder; +import net.sourceforge.filebot.FileBotUtil; +import net.sourceforge.filebot.resources.ResourceManager; +import net.sourceforge.tuned.ui.FancyListCellRenderer; +import net.sourceforge.tuned.ui.SimpleListModel; + public class SelectDialog extends JDialog { @@ -72,7 +76,7 @@ public class SelectDialog extends JDialog { // bounds and location setMinimumSize(new Dimension(175, 175)); setSize(new Dimension(200, 190)); - setLocation(getDefaultLocation()); + setLocation(FileBotUtil.getPreferredLocation(this)); // default selection list.setModel(new SimpleListModel(options)); @@ -90,16 +94,6 @@ public class SelectDialog extends JDialog { } - public Point getDefaultLocation() { - Point p = getOwner().getLocation(); - Dimension d = getOwner().getSize(); - - Point offset = new Point(d.width / 4, d.height / 7); - - return new Point(p.x + offset.x, p.y + offset.y); - } - - public void setText(String s) { label.setText(s); } @@ -115,7 +109,7 @@ public class SelectDialog extends JDialog { list.setSelectedValue(value, true); } - private AbstractAction selectAction = new AbstractAction("Select") { + private AbstractAction selectAction = new AbstractAction("Select", ResourceManager.getIcon("dialog.continue")) { @SuppressWarnings("unchecked") public void actionPerformed(ActionEvent e) { @@ -125,7 +119,7 @@ public class SelectDialog extends JDialog { } }; - private AbstractAction cancelAction = new AbstractAction("Cancel") { + private AbstractAction cancelAction = new AbstractAction("Cancel", ResourceManager.getIcon("dialog.cancel")) { public void actionPerformed(ActionEvent e) { selectedValue = null; diff --git a/source/net/sourceforge/filebot/ui/panel/analyze/AnalyzePanel.java b/source/net/sourceforge/filebot/ui/panel/analyze/AnalyzePanel.java index 075183c0..9603a24c 100644 --- a/source/net/sourceforge/filebot/ui/panel/analyze/AnalyzePanel.java +++ b/source/net/sourceforge/filebot/ui/panel/analyze/AnalyzePanel.java @@ -19,15 +19,19 @@ import javax.swing.SwingConstants; import net.sourceforge.filebot.resources.ResourceManager; import net.sourceforge.filebot.ui.FileBotPanel; +import net.sourceforge.filebot.ui.FileTransferableMessageHandler; import net.sourceforge.filebot.ui.panel.analyze.tools.SplitPanel; import net.sourceforge.filebot.ui.panel.analyze.tools.ToolPanel; import net.sourceforge.filebot.ui.panel.analyze.tools.TypePanel; +import net.sourceforge.tuned.MessageBus; public class AnalyzePanel extends FileBotPanel { - private FileTreePanel filePanel = new FileTreePanel(); - private JTabbedPane toolsPanel = new JTabbedPane(SwingConstants.TOP, JTabbedPane.SCROLL_TAB_LAYOUT); + private final FileTreePanel fileTreePanel = new FileTreePanel(); + private final JTabbedPane toolsPanel = new JTabbedPane(SwingConstants.TOP, JTabbedPane.SCROLL_TAB_LAYOUT); + + private final List toolPanels = new ArrayList(); public AnalyzePanel() { @@ -35,7 +39,7 @@ public class AnalyzePanel extends FileBotPanel { Box panel = new Box(BoxLayout.X_AXIS); - panel.add(filePanel); + panel.add(fileTreePanel); panel.add(Box.createHorizontalStrut(50)); @@ -49,14 +53,22 @@ public class AnalyzePanel extends FileBotPanel { add(panel, BorderLayout.CENTER); - filePanel.getFileTree().addPropertyChangeListener(FileTree.CONTENT_PROPERTY, fileTreeChangeListener); - - addTool(new TypePanel()); - addTool(new SplitPanel()); - Dimension min = new Dimension(300, 300); - filePanel.setMinimumSize(min); + fileTreePanel.setMinimumSize(min); toolsPanel.setMinimumSize(min); + + addTool(new SplitPanel()); + addTool(new TypePanel()); + + fileTreePanel.getFileTree().addPropertyChangeListener(FileTree.CONTENT_PROPERTY, fileTreeChangeListener); + + MessageBus.getDefault().addMessageHandler(getPanelName(), new FileTransferableMessageHandler(getPanelName(), fileTreePanel.getFileTree())); + } + + + private void addTool(ToolPanel toolPanel) { + toolsPanel.addTab(toolPanel.getToolName(), toolPanel); + toolPanels.add(toolPanel); } private PropertyChangeListener fileTreeChangeListener = new PropertyChangeListener() { @@ -65,17 +77,10 @@ public class AnalyzePanel extends FileBotPanel { public void propertyChange(PropertyChangeEvent evt) { List files = (List) evt.getNewValue(); - for (ToolPanel toolPanel : toolPanels) + for (ToolPanel toolPanel : toolPanels) { toolPanel.update(files); + } } }; - private List toolPanels = new ArrayList(); - - - public void addTool(ToolPanel toolPanel) { - toolsPanel.addTab(toolPanel.getName(), toolPanel); - toolPanels.add(toolPanel); - } - } diff --git a/source/net/sourceforge/filebot/ui/panel/analyze/FileTreePanel.java b/source/net/sourceforge/filebot/ui/panel/analyze/FileTreePanel.java index 9e86cf18..d8906b13 100644 --- a/source/net/sourceforge/filebot/ui/panel/analyze/FileTreePanel.java +++ b/source/net/sourceforge/filebot/ui/panel/analyze/FileTreePanel.java @@ -4,8 +4,6 @@ package net.sourceforge.filebot.ui.panel.analyze; import java.awt.BorderLayout; import java.awt.event.ActionEvent; -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; import javax.swing.AbstractAction; import javax.swing.BorderFactory; @@ -19,24 +17,19 @@ import javax.swing.border.EmptyBorder; import net.sourceforge.filebot.FileBotUtil; import net.sourceforge.filebot.resources.ResourceManager; import net.sourceforge.filebot.ui.transfer.LoadAction; -import net.sourceforge.tuned.ui.LoadingOverlayPanel; +import net.sourceforge.tuned.ui.LoadingOverlayPane; class FileTreePanel extends JPanel { private FileTree fileTree = new FileTree(); - private LoadingOverlayPanel loadingOverlay; - public FileTreePanel() { super(new BorderLayout()); - fileTree.addPropertyChangeListener(FileTree.LOADING_PROPERTY, loadingOverlayUpdateListener); setBorder(BorderFactory.createTitledBorder("File Tree")); - loadingOverlay = new LoadingOverlayPanel(new JScrollPane(fileTree), ResourceManager.getIcon("loading")); - Box buttons = Box.createHorizontalBox(); buttons.setBorder(new EmptyBorder(5, 5, 5, 5)); buttons.add(Box.createGlue()); @@ -48,21 +41,11 @@ class FileTreePanel extends JPanel { // Shortcut DELETE FileBotUtil.registerActionForKeystroke(fileTree, KeyStroke.getKeyStroke("pressed DELETE"), removeAction); - add(loadingOverlay, BorderLayout.CENTER); + add(new LoadingOverlayPane(new JScrollPane(fileTree), ResourceManager.getIcon("loading")), BorderLayout.CENTER); add(buttons, BorderLayout.SOUTH); } - private PropertyChangeListener loadingOverlayUpdateListener = new PropertyChangeListener() { - - public void propertyChange(PropertyChangeEvent evt) { - Boolean loading = (Boolean) evt.getNewValue(); - - loadingOverlay.setOverlayVisible(loading); - loadingOverlay.updateOverlay(); - } - }; - - + public FileTree getFileTree() { return fileTree; } diff --git a/source/net/sourceforge/filebot/ui/panel/analyze/tools/SplitPanel.java b/source/net/sourceforge/filebot/ui/panel/analyze/tools/SplitPanel.java index 6a030294..1cacf597 100644 --- a/source/net/sourceforge/filebot/ui/panel/analyze/tools/SplitPanel.java +++ b/source/net/sourceforge/filebot/ui/panel/analyze/tools/SplitPanel.java @@ -29,7 +29,7 @@ import net.sourceforge.filebot.resources.ResourceManager; import net.sourceforge.filebot.ui.FileBotTree; import net.sourceforge.filebot.ui.transfer.DefaultTransferHandler; import net.sourceforge.tuned.ui.GradientStyle; -import net.sourceforge.tuned.ui.LoadingOverlayPanel; +import net.sourceforge.tuned.ui.LoadingOverlayPane; import net.sourceforge.tuned.ui.notification.SeparatorBorder; @@ -46,7 +46,6 @@ public class SplitPanel extends ToolPanel implements ChangeListener { JScrollPane sp = new JScrollPane(tree); sp.setBorder(BorderFactory.createEmptyBorder()); - LoadingOverlayPanel loadingOverlay = new LoadingOverlayPanel(sp, ResourceManager.getIcon("loading")); JSpinner spinner = new JSpinner(spinnerModel); spinner.setMaximumSize(spinner.getPreferredSize()); spinner.setEditor(new JSpinner.NumberEditor(spinner, "#")); @@ -60,7 +59,7 @@ public class SplitPanel extends ToolPanel implements ChangeListener { spinnerBox.add(new JLabel("MB.")); spinnerBox.add(Box.createGlue()); - add(loadingOverlay, BorderLayout.CENTER); + add(new LoadingOverlayPane(sp, ResourceManager.getIcon("loading")), BorderLayout.CENTER); add(spinnerBox, BorderLayout.SOUTH); tree.setTransferHandler(new DefaultTransferHandler(null, new FileTreeExportHandler())); @@ -70,7 +69,6 @@ public class SplitPanel extends ToolPanel implements ChangeListener { SeparatorBorder separatorBorder = new SeparatorBorder(2, beginColor, GradientStyle.TOP_TO_BOTTOM, SeparatorBorder.Position.TOP); spinnerBox.setBorder(new CompoundBorder(separatorBorder, new EmptyBorder(6, 5, 7, 5))); - setLoadingOverlayPane(loadingOverlay); spinnerModel.addChangeListener(this); spinner.setPreferredSize(new Dimension(80, 20)); } @@ -103,7 +101,7 @@ public class SplitPanel extends ToolPanel implements ChangeListener { private void update() { latestUpdateTask = new UpdateTask(); - firePropertyChange(LOADING_PROPERTY, null, true); + tree.firePropertyChange(LoadingOverlayPane.LOADING_PROPERTY, false, true); latestUpdateTask.execute(); } @@ -185,7 +183,7 @@ public class SplitPanel extends ToolPanel implements ChangeListener { Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).log(Level.SEVERE, e.toString(), e); } - SplitPanel.this.firePropertyChange(LOADING_PROPERTY, null, false); + tree.firePropertyChange(LoadingOverlayPane.LOADING_PROPERTY, true, false); } } diff --git a/source/net/sourceforge/filebot/ui/panel/analyze/tools/ToolPanel.java b/source/net/sourceforge/filebot/ui/panel/analyze/tools/ToolPanel.java index 0a29b6f0..8e6ea42b 100644 --- a/source/net/sourceforge/filebot/ui/panel/analyze/tools/ToolPanel.java +++ b/source/net/sourceforge/filebot/ui/panel/analyze/tools/ToolPanel.java @@ -2,54 +2,26 @@ package net.sourceforge.filebot.ui.panel.analyze.tools; -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; import java.io.File; import java.util.Collection; import javax.swing.JComponent; -import net.sourceforge.tuned.ui.LoadingOverlayPanel; - public abstract class ToolPanel extends JComponent { - private String name = null; - - private LoadingOverlayPanel loadingOverlay; - - public static final String LOADING_PROPERTY = "loading"; + private final String name; public ToolPanel(String name) { this.name = name; - addPropertyChangeListener(LOADING_PROPERTY, loadingOverlayUpdateListener); } - @Override - public String getName() { + public String getToolName() { return name; } - protected void setLoadingOverlayPane(LoadingOverlayPanel c) { - loadingOverlay = c; - } - - private PropertyChangeListener loadingOverlayUpdateListener = new PropertyChangeListener() { - - public void propertyChange(PropertyChangeEvent evt) { - Boolean loading = (Boolean) evt.getNewValue(); - - if (loadingOverlay == null) - return; - - loadingOverlay.setOverlayVisible(loading); - loadingOverlay.updateOverlay(); - } - }; - - public abstract void update(Collection list); } diff --git a/source/net/sourceforge/filebot/ui/panel/analyze/tools/TypePanel.java b/source/net/sourceforge/filebot/ui/panel/analyze/tools/TypePanel.java index c6c924cb..3f943849 100644 --- a/source/net/sourceforge/filebot/ui/panel/analyze/tools/TypePanel.java +++ b/source/net/sourceforge/filebot/ui/panel/analyze/tools/TypePanel.java @@ -22,7 +22,7 @@ import net.sourceforge.filebot.FileFormat; import net.sourceforge.filebot.resources.ResourceManager; import net.sourceforge.filebot.ui.FileBotTree; import net.sourceforge.filebot.ui.transfer.DefaultTransferHandler; -import net.sourceforge.tuned.ui.LoadingOverlayPanel; +import net.sourceforge.tuned.ui.LoadingOverlayPane; public class TypePanel extends ToolPanel { @@ -36,13 +36,10 @@ public class TypePanel extends ToolPanel { JScrollPane sp = new JScrollPane(tree); sp.setBorder(BorderFactory.createEmptyBorder()); - LoadingOverlayPanel loadingOverlay = new LoadingOverlayPanel(sp, ResourceManager.getIcon("loading")); - add(loadingOverlay, BorderLayout.CENTER); + add(new LoadingOverlayPane(sp, ResourceManager.getIcon("loading")), BorderLayout.CENTER); tree.setTransferHandler(new DefaultTransferHandler(null, new FileTreeExportHandler())); tree.setDragEnabled(true); - - setLoadingOverlayPane(loadingOverlay); } private UpdateTask latestUpdateTask; @@ -52,7 +49,7 @@ public class TypePanel extends ToolPanel { public void update(Collection files) { latestUpdateTask = new UpdateTask(files); - firePropertyChange(LOADING_PROPERTY, null, true); + tree.firePropertyChange(LoadingOverlayPane.LOADING_PROPERTY, false, true); latestUpdateTask.execute(); } @@ -80,16 +77,16 @@ public class TypePanel extends ToolPanel { Map> map = new HashMap>(); for (File f : files) { - String suffix = FileFormat.getSuffix(f); + String extension = FileFormat.getExtension(f); - Collection list = map.get(suffix); + Collection list = map.get(extension); if (list != null) list.add(f); else { list = new ArrayList(); list.add(f); - map.put(suffix, list); + map.put(extension, list); } if (!isLatest()) @@ -135,7 +132,7 @@ public class TypePanel extends ToolPanel { Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).log(Level.SEVERE, e.toString(), e); } - TypePanel.this.firePropertyChange(LOADING_PROPERTY, null, false); + tree.firePropertyChange(LoadingOverlayPane.LOADING_PROPERTY, true, false); } } diff --git a/source/net/sourceforge/filebot/ui/panel/list/FileListTransferablePolicy.java b/source/net/sourceforge/filebot/ui/panel/list/FileListTransferablePolicy.java index fd2b7d60..061d37b3 100644 --- a/source/net/sourceforge/filebot/ui/panel/list/FileListTransferablePolicy.java +++ b/source/net/sourceforge/filebot/ui/panel/list/FileListTransferablePolicy.java @@ -25,7 +25,7 @@ class FileListTransferablePolicy extends FileTransferablePolicy { @Override protected boolean accept(File file) { - return file.isDirectory() || FileFormat.getSuffix(file).equalsIgnoreCase("torrent"); + return file.isDirectory() || FileFormat.getExtension(file).equalsIgnoreCase("torrent"); } @@ -44,13 +44,13 @@ class FileListTransferablePolicy extends FileTransferablePolicy { list.getModel().add(FileFormat.formatName(f)); } } else { - if (FileFormat.getSuffix(file).equalsIgnoreCase("torrent")) { + if (FileFormat.getExtension(file).equalsIgnoreCase("torrent")) { try { Torrent torrent = new Torrent(file); - list.setTitle(FileFormat.getNameWithoutSuffix(torrent.getName())); + list.setTitle(FileFormat.getNameWithoutExtension(torrent.getName())); for (Torrent.Entry entry : torrent.getFiles()) { - list.getModel().add(FileFormat.getNameWithoutSuffix(entry.getName())); + list.getModel().add(FileFormat.getNameWithoutExtension(entry.getName())); } } catch (IOException e) { // should not happen diff --git a/source/net/sourceforge/filebot/ui/panel/list/ListPanel.java b/source/net/sourceforge/filebot/ui/panel/list/ListPanel.java index 092bc53c..2d879302 100644 --- a/source/net/sourceforge/filebot/ui/panel/list/ListPanel.java +++ b/source/net/sourceforge/filebot/ui/panel/list/ListPanel.java @@ -26,8 +26,10 @@ import net.sourceforge.filebot.resources.ResourceManager; import net.sourceforge.filebot.ui.FileBotList; import net.sourceforge.filebot.ui.FileBotPanel; import net.sourceforge.filebot.ui.MessageManager; +import net.sourceforge.filebot.ui.FileTransferableMessageHandler; import net.sourceforge.filebot.ui.transfer.LoadAction; import net.sourceforge.filebot.ui.transfer.SaveAction; +import net.sourceforge.tuned.MessageBus; public class ListPanel extends FileBotPanel { @@ -87,6 +89,8 @@ public class ListPanel extends FileBotPanel { add(list, BorderLayout.CENTER); FileBotUtil.registerActionForKeystroke(this, KeyStroke.getKeyStroke("ENTER"), createAction); + + MessageBus.getDefault().addMessageHandler(getPanelName(), new FileTransferableMessageHandler(getPanelName(), list)); } diff --git a/source/net/sourceforge/filebot/ui/panel/rename/NamesListTransferablePolicy.java b/source/net/sourceforge/filebot/ui/panel/rename/NamesListTransferablePolicy.java index 43570892..a6fed9c0 100644 --- a/source/net/sourceforge/filebot/ui/panel/rename/NamesListTransferablePolicy.java +++ b/source/net/sourceforge/filebot/ui/panel/rename/NamesListTransferablePolicy.java @@ -45,11 +45,13 @@ class NamesListTransferablePolicy extends MultiTransferablePolicy { invalidEntries.add(entry); } - ValidateNamesDialog dialog = new ValidateNamesDialog(SwingUtilities.getWindowAncestor(list), invalidEntries); - dialog.setVisible(true); - - if (dialog.isCancelled()) - return; + if (!invalidEntries.isEmpty()) { + ValidateNamesDialog dialog = new ValidateNamesDialog(SwingUtilities.getWindowAncestor(list), invalidEntries); + dialog.setVisible(true); + + if (dialog.isCancelled()) + return; + } list.getModel().addAll(entries); } @@ -77,7 +79,7 @@ class NamesListTransferablePolicy extends MultiTransferablePolicy { try { List> entries = new ArrayList>(); - if (FileFormat.getSuffix(file).equalsIgnoreCase("torrent")) { + if (FileFormat.getExtension(file).equalsIgnoreCase("torrent")) { Torrent torrent = new Torrent(file); for (Torrent.Entry entry : torrent.getFiles()) { diff --git a/source/net/sourceforge/filebot/ui/panel/rename/RenameAction.java b/source/net/sourceforge/filebot/ui/panel/rename/RenameAction.java index dbb23901..a655d87a 100644 --- a/source/net/sourceforge/filebot/ui/panel/rename/RenameAction.java +++ b/source/net/sourceforge/filebot/ui/panel/rename/RenameAction.java @@ -45,7 +45,7 @@ public class RenameAction extends AbstractAction { FileEntry fileEntry = fileEntries.get(i); File f = fileEntry.getValue(); - String newName = nameEntries.get(i).toString() + FileFormat.getSuffix(f, true); + String newName = nameEntries.get(i).toString() + FileFormat.getExtension(f, true); File newFile = new File(f.getParentFile(), newName); diff --git a/source/net/sourceforge/filebot/ui/panel/rename/RenamePanel.java b/source/net/sourceforge/filebot/ui/panel/rename/RenamePanel.java index cdf32594..c8ad57f2 100644 --- a/source/net/sourceforge/filebot/ui/panel/rename/RenamePanel.java +++ b/source/net/sourceforge/filebot/ui/panel/rename/RenamePanel.java @@ -25,6 +25,8 @@ import javax.swing.event.ListDataListener; import net.sourceforge.filebot.resources.ResourceManager; import net.sourceforge.filebot.ui.FileBotPanel; +import net.sourceforge.filebot.ui.FileTransferableMessageHandler; +import net.sourceforge.tuned.MessageBus; public class RenamePanel extends FileBotPanel { @@ -80,6 +82,8 @@ public class RenamePanel extends FileBotPanel { namesList.getModel().addListDataListener(repaintOnDataChange); filesList.getModel().addListDataListener(repaintOnDataChange); + + MessageBus.getDefault().addMessageHandler(getPanelName(), new FileTransferableMessageHandler(getPanelName(), namesList)); } @@ -117,16 +121,16 @@ public class RenamePanel extends FileBotPanel { public void intervalAdded(ListDataEvent e) { - update(); + repaintBoth(); } public void intervalRemoved(ListDataEvent e) { - update(); + repaintBoth(); } - public void update() { + public void repaintBoth() { namesList.repaint(); filesList.repaint(); } diff --git a/source/net/sourceforge/filebot/ui/panel/rename/ValidateNamesDialog.java b/source/net/sourceforge/filebot/ui/panel/rename/ValidateNamesDialog.java index 61708c6f..7fe84618 100644 --- a/source/net/sourceforge/filebot/ui/panel/rename/ValidateNamesDialog.java +++ b/source/net/sourceforge/filebot/ui/panel/rename/ValidateNamesDialog.java @@ -5,10 +5,8 @@ package net.sourceforge.filebot.ui.panel.rename; import java.awt.AlphaComposite; import java.awt.BorderLayout; import java.awt.Color; -import java.awt.Dimension; import java.awt.Graphics; import java.awt.Graphics2D; -import java.awt.Point; import java.awt.Window; import java.awt.event.ActionEvent; import java.util.List; @@ -84,7 +82,7 @@ public class ValidateNamesDialog extends JDialog { c.add(listPanel, BorderLayout.CENTER); c.add(buttonBox, BorderLayout.SOUTH); - setLocation(getDefaultLocation()); + setLocation(FileBotUtil.getPreferredLocation(this)); // Shortcut Escape FileBotUtil.registerActionForKeystroke(c, KeyStroke.getKeyStroke("released ESCAPE"), cancelAction); @@ -93,16 +91,6 @@ public class ValidateNamesDialog extends JDialog { } - public Point getDefaultLocation() { - Point p = getOwner().getLocation(); - Dimension d = getOwner().getSize(); - - Point offset = new Point(d.width / 4, d.height / 7); - - return new Point(p.x + offset.x, p.y + offset.y); - } - - public boolean isCancelled() { return cancelled; } @@ -119,7 +107,7 @@ public class ValidateNamesDialog extends JDialog { private class ValidateAction extends AbstractAction { public ValidateAction() { - super("Validate", ResourceManager.getIcon("dialog.continue.valid")); + super("Validate", ResourceManager.getIcon("dialog.continue")); putValue(SHORT_DESCRIPTION, "Remove invalid characters"); } diff --git a/source/net/sourceforge/filebot/ui/panel/rename/entry/FileEntry.java b/source/net/sourceforge/filebot/ui/panel/rename/entry/FileEntry.java index 8a96feb7..d94a615c 100644 --- a/source/net/sourceforge/filebot/ui/panel/rename/entry/FileEntry.java +++ b/source/net/sourceforge/filebot/ui/panel/rename/entry/FileEntry.java @@ -16,7 +16,7 @@ public class FileEntry extends AbstractFileEntry { @Override public String getName(File value) { - return FileFormat.getNameWithoutSuffix(getValue()); + return FileFormat.getNameWithoutExtension(getValue()); } diff --git a/source/net/sourceforge/filebot/ui/panel/rename/entry/TorrentEntry.java b/source/net/sourceforge/filebot/ui/panel/rename/entry/TorrentEntry.java index 7829ac05..d776ad54 100644 --- a/source/net/sourceforge/filebot/ui/panel/rename/entry/TorrentEntry.java +++ b/source/net/sourceforge/filebot/ui/panel/rename/entry/TorrentEntry.java @@ -16,7 +16,7 @@ public class TorrentEntry extends AbstractFileEntry { @Override public String getName(Torrent.Entry value) { - return FileFormat.getNameWithoutSuffix(getValue().getName()); + return FileFormat.getNameWithoutExtension(getValue().getName()); } diff --git a/source/net/sourceforge/filebot/ui/panel/search/EpisodeListPanel.java b/source/net/sourceforge/filebot/ui/panel/search/EpisodeListPanel.java index b572337e..97b0a634 100644 --- a/source/net/sourceforge/filebot/ui/panel/search/EpisodeListPanel.java +++ b/source/net/sourceforge/filebot/ui/panel/search/EpisodeListPanel.java @@ -10,7 +10,8 @@ import net.sourceforge.filebot.ui.FileBotList; class EpisodeListPanel extends FileBotList { - private TabComponentWithClose tabComponent; + private final TabComponentWithClose tabComponent = new TabComponentWithClose(); + private ImageIcon icon; private boolean loading = false; @@ -18,7 +19,6 @@ class EpisodeListPanel extends FileBotList { public EpisodeListPanel() { super(false, true, true, false); - tabComponent = new TabComponentWithClose(); } @@ -35,10 +35,12 @@ class EpisodeListPanel extends FileBotList { public void setIcon(ImageIcon icon) { - this.icon = icon; - - if (!loading) { - tabComponent.setIcon(icon); + synchronized (tabComponent) { + this.icon = icon; + + if (!loading) { + tabComponent.setIcon(icon); + } } } @@ -49,10 +51,12 @@ class EpisodeListPanel extends FileBotList { public void setLoading(boolean loading) { - if (loading) { - tabComponent.setIcon(ResourceManager.getIcon("tab.loading")); - } else { - tabComponent.setIcon(icon); + synchronized (tabComponent) { + if (loading) { + tabComponent.setIcon(ResourceManager.getIcon("tab.loading")); + } else { + tabComponent.setIcon(icon); + } } } diff --git a/source/net/sourceforge/filebot/ui/panel/search/SearchPanel.java b/source/net/sourceforge/filebot/ui/panel/search/SearchPanel.java index e84e7ed0..b2f06a39 100644 --- a/source/net/sourceforge/filebot/ui/panel/search/SearchPanel.java +++ b/source/net/sourceforge/filebot/ui/panel/search/SearchPanel.java @@ -34,14 +34,14 @@ import javax.swing.border.EmptyBorder; import net.sourceforge.filebot.FileBotUtil; import net.sourceforge.filebot.Settings; import net.sourceforge.filebot.resources.ResourceManager; -import net.sourceforge.filebot.ui.FileBotList; import net.sourceforge.filebot.ui.FileBotPanel; import net.sourceforge.filebot.ui.MessageManager; +import net.sourceforge.filebot.ui.SelectDialog; import net.sourceforge.filebot.ui.transfer.SaveAction; +import net.sourceforge.filebot.ui.transfer.Saveable; import net.sourceforge.filebot.web.Episode; import net.sourceforge.filebot.web.EpisodeListClient; import net.sourceforge.tuned.ui.SelectButton; -import net.sourceforge.tuned.ui.SelectDialog; import net.sourceforge.tuned.ui.SwingWorkerPropertyChangeAdapter; import net.sourceforge.tuned.ui.TextCompletion; import net.sourceforge.tuned.ui.TextFieldWithSelect; @@ -176,15 +176,15 @@ public class SearchPanel extends FileBotPanel { private final SaveAction saveAction = new SaveAction(null) { - private FileBotList current; + private Saveable current; @Override public void actionPerformed(ActionEvent e) { Component c = tabbedPane.getSelectedComponent(); - if (c instanceof FileBotList) { - current = (FileBotList) c; + if (c instanceof Saveable) { + current = (Saveable) c; super.actionPerformed(e); } } diff --git a/source/net/sourceforge/filebot/ui/panel/sfv/SfvPanel.java b/source/net/sourceforge/filebot/ui/panel/sfv/SfvPanel.java index b413b5ee..50560701 100644 --- a/source/net/sourceforge/filebot/ui/panel/sfv/SfvPanel.java +++ b/source/net/sourceforge/filebot/ui/panel/sfv/SfvPanel.java @@ -21,9 +21,11 @@ import net.sourceforge.filebot.FileBotUtil; import net.sourceforge.filebot.FileFormat; import net.sourceforge.filebot.resources.ResourceManager; import net.sourceforge.filebot.ui.FileBotPanel; +import net.sourceforge.filebot.ui.FileTransferableMessageHandler; +import net.sourceforge.filebot.ui.SelectDialog; import net.sourceforge.filebot.ui.transfer.LoadAction; import net.sourceforge.filebot.ui.transfer.SaveAction; -import net.sourceforge.tuned.ui.SelectDialog; +import net.sourceforge.tuned.MessageBus; public class SfvPanel extends FileBotPanel { @@ -60,6 +62,8 @@ public class SfvPanel extends FileBotPanel { // Shortcut DELETE FileBotUtil.registerActionForKeystroke(this, KeyStroke.getKeyStroke("pressed DELETE"), removeAction); + + MessageBus.getDefault().addMessageHandler(getPanelName(), new FileTransferableMessageHandler(getPanelName(), sfvTable)); } private final SaveAction saveAction = new SaveAction(sfvTable) { @@ -114,7 +118,7 @@ public class SfvPanel extends FileBotPanel { return; index = options.indexOf(selected); - name = FileFormat.getNameWithoutSuffix(selected); + name = FileFormat.getNameWithoutExtension(selected); if (name.isEmpty()) name = "name"; diff --git a/source/net/sourceforge/filebot/ui/panel/sfv/SfvTable.java b/source/net/sourceforge/filebot/ui/panel/sfv/SfvTable.java index 3ccf4a5f..60f37c8c 100644 --- a/source/net/sourceforge/filebot/ui/panel/sfv/SfvTable.java +++ b/source/net/sourceforge/filebot/ui/panel/sfv/SfvTable.java @@ -122,7 +122,7 @@ class SfvTable extends JTable implements TransferablePolicySupport, Saveable { String name = ""; if (columnRoot != null) - name = FileFormat.getNameWithoutSuffix(columnRoot); + name = FileFormat.getNameWithoutExtension(columnRoot); if (name.isEmpty()) name = "name"; diff --git a/source/net/sourceforge/filebot/ui/panel/sfv/SfvTransferablePolicy.java b/source/net/sourceforge/filebot/ui/panel/sfv/SfvTransferablePolicy.java index 6bf9f5ef..b40f9d94 100644 --- a/source/net/sourceforge/filebot/ui/panel/sfv/SfvTransferablePolicy.java +++ b/source/net/sourceforge/filebot/ui/panel/sfv/SfvTransferablePolicy.java @@ -91,7 +91,7 @@ class SfvTransferablePolicy extends BackgroundFileTransferablePolicy files) { for (File file : files) { - if (!FileFormat.getSuffix(file).equalsIgnoreCase("sfv")) + if (!FileFormat.getExtension(file).equalsIgnoreCase("sfv")) return false; } diff --git a/source/net/sourceforge/filebot/ui/transfer/DefaultClipboardHandler.java b/source/net/sourceforge/filebot/ui/transfer/DefaultClipboardHandler.java index 909e0a4c..60e44f36 100644 --- a/source/net/sourceforge/filebot/ui/transfer/DefaultClipboardHandler.java +++ b/source/net/sourceforge/filebot/ui/transfer/DefaultClipboardHandler.java @@ -34,20 +34,20 @@ public class DefaultClipboardHandler implements ClipboardHandler { JTable table = (JTable) comp; for (int row : table.getSelectedRows()) { - StringBuffer b = new StringBuffer(); + StringBuilder sb = new StringBuilder(); int maxCol = table.getColumnCount() - 1; for (int col = 0; col <= maxCol; col++) { - b.append(table.getModel().getValueAt(row, col)); + sb.append(table.getModel().getValueAt(row, col)); if (col != maxCol) - b.append("\t"); + sb.append("\t"); } - lines.add(b.toString()); + lines.add(sb.toString()); } } - StringBuffer buffer = new StringBuffer(); + StringBuilder buffer = new StringBuilder(); Iterator it = lines.iterator(); while (it.hasNext()) { diff --git a/source/net/sourceforge/filebot/ui/transfer/FileTransferable.java b/source/net/sourceforge/filebot/ui/transfer/FileTransferable.java index f12b30db..65137e6f 100644 --- a/source/net/sourceforge/filebot/ui/transfer/FileTransferable.java +++ b/source/net/sourceforge/filebot/ui/transfer/FileTransferable.java @@ -7,6 +7,7 @@ import java.awt.datatransfer.Transferable; import java.awt.datatransfer.UnsupportedFlavorException; import java.io.File; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.List; import java.util.logging.Level; @@ -29,21 +30,18 @@ public class FileTransferable implements Transferable { return null; } - private List files; + private final List files; - private DataFlavor[] supportedFlavors = { DataFlavor.javaFileListFlavor, uriListFlavor }; + private final DataFlavor[] supportedFlavors = { DataFlavor.javaFileListFlavor, uriListFlavor }; - public FileTransferable(File... fileArray) { - files = new ArrayList(fileArray.length); - - for (File file : fileArray) - files.add(file); + public FileTransferable(File... files) { + this(Arrays.asList(files)); } - public FileTransferable(Collection fileCollection) { - files = new ArrayList(fileCollection); + public FileTransferable(Collection files) { + this.files = new ArrayList(files); } @@ -62,7 +60,7 @@ public class FileTransferable implements Transferable { * @return line separated list of file uris */ private String getUriList() { - StringBuffer sb = new StringBuffer(); + StringBuilder sb = new StringBuilder(); for (File file : files) { sb.append("file://" + file.toURI().getPath()); diff --git a/source/net/sourceforge/filebot/ui/transfer/SaveableExportHandler.java b/source/net/sourceforge/filebot/ui/transfer/SaveableExportHandler.java index a44ae18a..15694e93 100644 --- a/source/net/sourceforge/filebot/ui/transfer/SaveableExportHandler.java +++ b/source/net/sourceforge/filebot/ui/transfer/SaveableExportHandler.java @@ -2,11 +2,9 @@ package net.sourceforge.filebot.ui.transfer; -import java.awt.datatransfer.DataFlavor; import java.awt.datatransfer.Transferable; import java.io.File; import java.io.IOException; -import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; @@ -14,13 +12,13 @@ import javax.swing.JComponent; import javax.swing.TransferHandler; import net.sourceforge.filebot.FileBotUtil; +import net.sourceforge.filebot.Settings; +import net.sourceforge.tuned.TemporaryFolder; public class SaveableExportHandler implements ExportHandler { - private Saveable saveable; - - private String tmpdir = System.getProperty("java.io.tmpdir"); + private final Saveable saveable; public SaveableExportHandler(Saveable saveable) { @@ -28,23 +26,6 @@ public class SaveableExportHandler implements ExportHandler { } - @SuppressWarnings("unchecked") - @Override - public void exportDone(JComponent source, Transferable data, int action) { - try { - List files = (List) data.getTransferData(DataFlavor.javaFileListFlavor); - - for (File file : files) { - if (file.exists()) - file.deleteOnExit(); - } - } catch (Exception e) { - // should not happen - Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).log(Level.SEVERE, e.toString(), e); - } - } - - @Override public int getSourceActions(JComponent c) { if ((saveable == null) || !saveable.isSaveable()) @@ -57,10 +38,12 @@ public class SaveableExportHandler implements ExportHandler { @Override public Transferable createTransferable(JComponent c) { try { - File temporaryFile = new File(tmpdir, FileBotUtil.validateFileName(saveable.getDefaultFileName())); - temporaryFile.createNewFile(); + // Remove invalid characters from default filename + String name = FileBotUtil.validateFileName(saveable.getDefaultFileName()); + File temporaryFile = TemporaryFolder.getFolder(Settings.ROOT).createFile(name); saveable.save(temporaryFile); + return new FileTransferable(temporaryFile); } catch (IOException e) { // should not happen @@ -69,4 +52,10 @@ public class SaveableExportHandler implements ExportHandler { return null; } + + + @Override + public void exportDone(JComponent source, Transferable data, int action) { + + } } diff --git a/source/net/sourceforge/filebot/ui/transferablepolicies/FileTransferablePolicy.java b/source/net/sourceforge/filebot/ui/transferablepolicies/FileTransferablePolicy.java index e37fbd50..97cc36ae 100644 --- a/source/net/sourceforge/filebot/ui/transferablepolicies/FileTransferablePolicy.java +++ b/source/net/sourceforge/filebot/ui/transferablepolicies/FileTransferablePolicy.java @@ -81,7 +81,7 @@ public abstract class FileTransferablePolicy implements TransferablePolicy { public void handleTransferable(Transferable tr, boolean add) { List files = getFilesFromTransferable(tr); - if (files == null) + if ((files == null) || files.isEmpty()) return; Collections.sort(files); diff --git a/source/net/sourceforge/filebot/ui/transferablepolicies/MultiTransferablePolicy.java b/source/net/sourceforge/filebot/ui/transferablepolicies/MultiTransferablePolicy.java index 0c7c9fc3..39a3fe49 100644 --- a/source/net/sourceforge/filebot/ui/transferablepolicies/MultiTransferablePolicy.java +++ b/source/net/sourceforge/filebot/ui/transferablepolicies/MultiTransferablePolicy.java @@ -40,13 +40,14 @@ public class MultiTransferablePolicy implements TransferablePolicy { public void handleTransferable(Transferable tr, boolean add) { TransferablePolicy policy = getFirstAccepted(tr); - if (policy != null) { - if (!add) - clear(); - - policy.handleTransferable(tr, add); + if (policy == null) + return; + + if (!add) { + clear(); } + policy.handleTransferable(tr, add); } diff --git a/source/net/sourceforge/filebot/ui/transferablepolicies/TextTransferablePolicy.java b/source/net/sourceforge/filebot/ui/transferablepolicies/TextTransferablePolicy.java index a3687799..fd396eb4 100644 --- a/source/net/sourceforge/filebot/ui/transferablepolicies/TextTransferablePolicy.java +++ b/source/net/sourceforge/filebot/ui/transferablepolicies/TextTransferablePolicy.java @@ -18,6 +18,9 @@ public abstract class TextTransferablePolicy implements TransferablePolicy { @Override public void handleTransferable(Transferable tr, boolean add) { + if (!accept(tr)) + return; + try { String string = (String) tr.getTransferData(DataFlavor.stringFlavor); diff --git a/source/net/sourceforge/filebot/web/DownloadTask.java b/source/net/sourceforge/filebot/web/DownloadTask.java index 69443396..700f3223 100644 --- a/source/net/sourceforge/filebot/web/DownloadTask.java +++ b/source/net/sourceforge/filebot/web/DownloadTask.java @@ -27,7 +27,10 @@ public class DownloadTask extends SwingWorker { public static enum DownloadState { - PENDING, CONNECTING, DOWNLOADING, DONE; + PENDING, + CONNECTING, + DOWNLOADING, + DONE; } private static final int BUFFER_SIZE = 4 * 1024; @@ -132,7 +135,7 @@ public class DownloadTask extends SwingWorker { private static ByteBuffer encodeParameters(Map parameters) { - StringBuffer sb = new StringBuffer(); + StringBuilder sb = new StringBuilder(); int i = 0; diff --git a/source/net/sourceforge/filebot/web/Episode.java b/source/net/sourceforge/filebot/web/Episode.java index 5ae72c91..96cddf6d 100644 --- a/source/net/sourceforge/filebot/web/Episode.java +++ b/source/net/sourceforge/filebot/web/Episode.java @@ -45,7 +45,7 @@ public class Episode { @Override public String toString() { - StringBuffer sb = new StringBuffer(); + StringBuilder sb = new StringBuilder(); sb.append(showName + " - "); diff --git a/source/net/sourceforge/filebot/web/EpisodeListClient.java b/source/net/sourceforge/filebot/web/EpisodeListClient.java index 3dfd1cc8..6adf5de2 100644 --- a/source/net/sourceforge/filebot/web/EpisodeListClient.java +++ b/source/net/sourceforge/filebot/web/EpisodeListClient.java @@ -11,7 +11,7 @@ import javax.swing.ImageIcon; public abstract class EpisodeListClient { - private static LinkedHashSet registry = new LinkedHashSet(); + private static final LinkedHashSet registry = new LinkedHashSet(); static { registry.add(new TvdotcomClient()); @@ -27,7 +27,7 @@ public abstract class EpisodeListClient { public static EpisodeListClient forName(String name) { for (EpisodeListClient client : registry) { - if (name.equals(client.getName())) + if (name.equalsIgnoreCase(client.getName())) return client; } diff --git a/source/net/sourceforge/tuned/MessageBus.java b/source/net/sourceforge/tuned/MessageBus.java new file mode 100644 index 00000000..b4fe0c90 --- /dev/null +++ b/source/net/sourceforge/tuned/MessageBus.java @@ -0,0 +1,86 @@ + +package net.sourceforge.tuned; + + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.swing.SwingUtilities; + + +public class MessageBus { + + private static final MessageBus instance = new MessageBus(); + + + public static MessageBus getDefault() { + return instance; + } + + + private MessageBus() { + + } + + private final Map> handlers = new HashMap>() { + + @Override + public List get(Object key) { + return super.get(key.toString().toLowerCase()); + } + + + @Override + public List put(String key, List value) { + return super.put(key.toLowerCase(), value); + } + }; + + + public synchronized void addMessageHandler(String topic, MessageHandler handler) { + List list = handlers.get(topic); + + if (list == null) { + list = new ArrayList(3); + handlers.put(topic, list); + } + + list.add(handler); + } + + + public synchronized void removeMessageHandler(String topic, MessageHandler handler) { + List list = handlers.get(topic); + + if (list != null) { + list.remove(handler); + } + } + + + public synchronized MessageHandler[] getHandlers(String topic) { + List list = handlers.get(topic); + + if (list == null) + return new MessageHandler[0]; + + return list.toArray(new MessageHandler[0]); + } + + + public void publish(final String topic, final String... messages) { + + SwingUtilities.invokeLater(new Runnable() { + + @Override + public void run() { + for (MessageHandler handler : getHandlers(topic)) { + handler.handle(topic, messages); + } + } + }); + } + +} diff --git a/source/net/sourceforge/tuned/MessageHandler.java b/source/net/sourceforge/tuned/MessageHandler.java new file mode 100644 index 00000000..fb38947a --- /dev/null +++ b/source/net/sourceforge/tuned/MessageHandler.java @@ -0,0 +1,12 @@ + +package net.sourceforge.tuned; + + +import java.util.EventListener; + + +public interface MessageHandler extends EventListener { + + public void handle(String topic, String... messages); + +} diff --git a/source/net/sourceforge/tuned/PausableThreadPoolExecutor.java b/source/net/sourceforge/tuned/PausableThreadPoolExecutor.java index ddcb1464..ae4393f4 100644 --- a/source/net/sourceforge/tuned/PausableThreadPoolExecutor.java +++ b/source/net/sourceforge/tuned/PausableThreadPoolExecutor.java @@ -22,6 +22,7 @@ public class PausableThreadPoolExecutor extends ThreadPoolExecutor { } + @Override protected void beforeExecute(Thread t, Runnable r) { super.beforeExecute(t, r); pauseLock.lock(); @@ -56,8 +57,8 @@ public class PausableThreadPoolExecutor extends ThreadPoolExecutor { } } - - public boolean isPaused() { - return paused; + + public boolean isPaused() { + return paused; } } diff --git a/source/net/sourceforge/tuned/TemporaryFolder.java b/source/net/sourceforge/tuned/TemporaryFolder.java new file mode 100644 index 00000000..b796b83e --- /dev/null +++ b/source/net/sourceforge/tuned/TemporaryFolder.java @@ -0,0 +1,95 @@ + +package net.sourceforge.tuned; + + +import java.io.File; +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + + +public class TemporaryFolder { + + private static final String tmpdir = System.getProperty("java.io.tmpdir"); + + private static final Map folders = new HashMap(); + + + public static TemporaryFolder getFolder(String name) { + synchronized (folders) { + TemporaryFolder folder = folders.get(name); + + if (folder == null) { + folder = new TemporaryFolder(new File(tmpdir, name)); + folders.put(name, folder); + } + + return folder; + } + } + + /** + * Delete all temporary folders on shutdown + */ + static { + Runtime.getRuntime().addShutdownHook(new Thread() { + + @Override + public void run() { + synchronized (folders) { + for (TemporaryFolder folder : folders.values()) { + folder.delete(); + } + + folders.clear(); + } + } + }); + } + + private final File root; + + + private TemporaryFolder(File root) { + this.root = root; + this.root.mkdir(); + } + + + public File createFile(String name) throws IOException { + File file = new File(root, name); + file.createNewFile(); + return file; + } + + + public void deleteFile(String name) { + File file = new File(root, name); + + if (file.exists()) { + file.delete(); + } + } + + + public void delete() { + delete(root); + } + + + /** + * Delete files/folders recursively + * + * @param file file/folder that will be deleted + */ + private void delete(File file) { + if (file.isDirectory()) { + for (File entry : file.listFiles()) { + delete(entry); + } + } + + file.delete(); + } + +} diff --git a/source/net/sourceforge/tuned/TimeIntervalFormat.java b/source/net/sourceforge/tuned/TimeIntervalFormat.java index cd98402f..51fb296f 100644 --- a/source/net/sourceforge/tuned/TimeIntervalFormat.java +++ b/source/net/sourceforge/tuned/TimeIntervalFormat.java @@ -25,13 +25,13 @@ public class TimeIntervalFormat { negativ = true; } - StringBuffer sb = new StringBuffer(); + StringBuilder sb = new StringBuilder(); for (long unitBaseTime : unitMap.descendingKeySet()) { int quotient = (int) (millis / unitBaseTime); boolean isLastKey = (unitBaseTime == unitMap.firstKey()); - if (zerounits || quotient != 0 || isLastKey) { + if (zerounits || (quotient != 0) || isLastKey) { sb.append(quotient + unitMap.get(unitBaseTime)); if (!isLastKey) diff --git a/source/net/sourceforge/tuned/ui/LoadingOverlayPane.java b/source/net/sourceforge/tuned/ui/LoadingOverlayPane.java new file mode 100644 index 00000000..7092fe00 --- /dev/null +++ b/source/net/sourceforge/tuned/ui/LoadingOverlayPane.java @@ -0,0 +1,114 @@ + +package net.sourceforge.tuned.ui; + + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; + +import javax.swing.BorderFactory; +import javax.swing.Icon; +import javax.swing.JComponent; +import javax.swing.JLabel; +import javax.swing.JScrollPane; +import javax.swing.OverlayLayout; +import javax.swing.Timer; + + +public class LoadingOverlayPane extends JComponent { + + public static final String LOADING_PROPERTY = "loading"; + + private final JLabel loadingLabel; + + private boolean overlayEnabled = false; + + private int millisToOverlay = 500; + + private final JComponent view; + + + public LoadingOverlayPane(JComponent component, Icon animation) { + this(component, animation, getView(component)); + } + + + public LoadingOverlayPane(JComponent component, Icon animation, JComponent view) { + this.view = view; + + setLayout(new OverlayLayout(this)); + + component.setAlignmentX(1.0f); + component.setAlignmentY(0.0f); + + loadingLabel = new JLabel(animation); + loadingLabel.setBorder(BorderFactory.createEmptyBorder(10, 0, 0, 20)); + + loadingLabel.setAlignmentX(1.0f); + loadingLabel.setAlignmentY(0.0f); + loadingLabel.setMaximumSize(loadingLabel.getPreferredSize()); + + add(loadingLabel); + add(component); + + setOverlayVisible(false); + + view.addPropertyChangeListener(LOADING_PROPERTY, loadingListener); + } + + + private static JComponent getView(JComponent component) { + if (component instanceof JScrollPane) { + JScrollPane scrollPane = (JScrollPane) component; + return (JComponent) scrollPane.getViewport().getView(); + } + + return component; + } + + + public JComponent getView() { + return view; + } + + + public void setOverlayVisible(boolean b) { + overlayEnabled = b; + + if (overlayEnabled) { + new OverlayTimer().start(); + } else { + loadingLabel.setVisible(false); + } + } + + + private class OverlayTimer extends Timer implements ActionListener { + + public OverlayTimer() { + super(millisToOverlay, null); + addActionListener(this); + setRepeats(false); + } + + + public void actionPerformed(ActionEvent e) { + if (overlayEnabled) { + loadingLabel.setVisible(true); + } + } + } + + private final PropertyChangeListener loadingListener = new PropertyChangeListener() { + + @Override + public void propertyChange(PropertyChangeEvent evt) { + Boolean loading = (Boolean) evt.getNewValue(); + + setOverlayVisible(loading); + } + + }; + +} diff --git a/source/net/sourceforge/tuned/ui/LoadingOverlayPanel.java b/source/net/sourceforge/tuned/ui/LoadingOverlayPanel.java deleted file mode 100644 index c22b2a28..00000000 --- a/source/net/sourceforge/tuned/ui/LoadingOverlayPanel.java +++ /dev/null @@ -1,90 +0,0 @@ - -package net.sourceforge.tuned.ui; - - -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; - -import javax.swing.BorderFactory; -import javax.swing.Icon; -import javax.swing.JComponent; -import javax.swing.JLabel; -import javax.swing.JPanel; -import javax.swing.OverlayLayout; -import javax.swing.Timer; - - -public class LoadingOverlayPanel extends JPanel { - - private JLabel loadingLabel = new JLabel(); - - private boolean overlayEnabled = false; - - private int millisToOverlay = 500; - - - public LoadingOverlayPanel(JComponent component, Icon animation) { - setLayout(new OverlayLayout(this)); - - component.setAlignmentX(1.0f); - component.setAlignmentY(0.0f); - - loadingLabel.setIcon(animation); - loadingLabel.setOpaque(false); - loadingLabel.setBorder(BorderFactory.createEmptyBorder(10, 0, 0, 20)); - - loadingLabel.setAlignmentX(1.0f); - loadingLabel.setAlignmentY(0.0f); - loadingLabel.setMaximumSize(loadingLabel.getPreferredSize()); - - add(loadingLabel); - add(component); - - setOverlayVisible(false); - } - - - public void setMillisToOverlay(int millisToOverlay) { - this.millisToOverlay = millisToOverlay; - } - - - public int getMillisToOverlay() { - return millisToOverlay; - } - - - public void setOverlayVisible(boolean b) { - overlayEnabled = b; - - if (overlayEnabled) { - new EnableOverlayTimer().start(); - } else { - loadingLabel.setVisible(false); - } - } - - - private class EnableOverlayTimer extends Timer implements ActionListener { - - public EnableOverlayTimer() { - super(millisToOverlay, null); - addActionListener(this); - setRepeats(false); - } - - - public void actionPerformed(ActionEvent e) { - if (overlayEnabled) { - loadingLabel.setVisible(true); - } - } - } - - - public void updateOverlay() { - revalidate(); - repaint(); - } - -} diff --git a/source/net/sourceforge/tuned/ui/SimpleListModel.java b/source/net/sourceforge/tuned/ui/SimpleListModel.java index 77fa828b..d044b846 100644 --- a/source/net/sourceforge/tuned/ui/SimpleListModel.java +++ b/source/net/sourceforge/tuned/ui/SimpleListModel.java @@ -12,7 +12,7 @@ import javax.swing.AbstractListModel; public class SimpleListModel extends AbstractListModel { - private List list; + private final List list; public SimpleListModel() {