From e643466653f240a9420596661bcf1ef861ede24c Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Tue, 17 Feb 2009 18:11:33 +0000 Subject: [PATCH] * little bit of refactoring * fixed unit-test --- .../filebot/ui/panel/rename/RenamePanel.java | 56 +++++++++++-------- .../net/sourceforge/tuned/ui/ActionPopup.java | 2 +- .../web/SubsceneSubtitleClientTest.java | 6 +- 3 files changed, 36 insertions(+), 28 deletions(-) diff --git a/source/net/sourceforge/filebot/ui/panel/rename/RenamePanel.java b/source/net/sourceforge/filebot/ui/panel/rename/RenamePanel.java index 87a920cd..9221db4d 100644 --- a/source/net/sourceforge/filebot/ui/panel/rename/RenamePanel.java +++ b/source/net/sourceforge/filebot/ui/panel/rename/RenamePanel.java @@ -3,10 +3,13 @@ package net.sourceforge.filebot.ui.panel.rename; import static javax.swing.SwingUtilities.getWindowAncestor; +import static net.sourceforge.filebot.FileBotUtilities.isInvalidFileName; import static net.sourceforge.tuned.ui.LoadingOverlayPane.LOADING_PROPERTY; -import static net.sourceforge.filebot.FileBotUtilities.*; + import java.awt.Insets; import java.awt.event.ActionEvent; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; import java.io.File; import java.util.ArrayList; import java.util.List; @@ -50,7 +53,7 @@ public class RenamePanel extends FileBotPanel { private RenameAction renameAction = new RenameAction(model); - private ActionPopup matchActionPopup = new ActionPopup("Fetch Episode List", ResourceManager.getIcon("action.match.small")); + private ActionPopup matchActionPopup = new ActionPopup("Fetch Episode List", ResourceManager.getIcon("action.fetch")); public RenamePanel() { @@ -98,7 +101,7 @@ public class RenamePanel extends FileBotPanel { setLayout(new MigLayout("fill, insets dialog, gapx 10px", null, "align 33%")); - add(new LoadingOverlayPane(namesList, this, "28px", "30px"), "grow, sizegroupx list"); + add(new LoadingOverlayPane(namesList, namesList, "28px", "30px"), "grow, sizegroupx list"); // make buttons larger matchButton.setMargin(new Insets(3, 14, 2, 14)); @@ -109,6 +112,15 @@ public class RenamePanel extends FileBotPanel { add(filesList, "grow, sizegroupx list"); + // set action popup status message while episode list matcher is working + namesList.addPropertyChangeListener(LOADING_PROPERTY, new PropertyChangeListener() { + + @Override + public void propertyChange(PropertyChangeEvent evt) { + matchActionPopup.setStatus((Boolean) evt.getNewValue() ? "in progress" : null); + } + }); + // repaint on change model.names().addListEventListener(new RepaintHandler()); model.files().addListEventListener(new RepaintHandler()); @@ -128,20 +140,6 @@ public class RenamePanel extends FileBotPanel { } }; - private boolean autoMatchInProgress = false; - - - protected void setAutoMatchInProgress(boolean flag) { - this.autoMatchInProgress = flag; - firePropertyChange(LOADING_PROPERTY, !flag, flag); - matchActionPopup.setStatus(flag ? "in progress" : null); - } - - - protected boolean isAutoMatchInProgress() { - return autoMatchInProgress; - } - protected class AutoFetchEpisodeListAction extends AbstractAction { @@ -152,15 +150,27 @@ public class RenamePanel extends FileBotPanel { super(client.getName(), client.getIcon()); this.client = client; + + // disable action while episode list matcher is working + namesList.addPropertyChangeListener(LOADING_PROPERTY, new PropertyChangeListener() { + + @Override + public void propertyChange(PropertyChangeEvent evt) { + setEnabled(!(Boolean) evt.getNewValue()); + } + }); } @Override public void actionPerformed(ActionEvent evt) { - if (model.files().isEmpty() || isAutoMatchInProgress()) { + if (model.files().isEmpty()) { return; } + // auto-match in progress + namesList.firePropertyChange(LOADING_PROPERTY, false, true); + // clear names list model.names().clear(); @@ -168,9 +178,6 @@ public class RenamePanel extends FileBotPanel { @Override protected void done() { - // background worker is finished - setAutoMatchInProgress(false); - try { List names = new ArrayList(); List files = new ArrayList(); @@ -208,14 +215,15 @@ public class RenamePanel extends FileBotPanel { } catch (Exception e) { Logger.getLogger("ui").log(Level.WARNING, ExceptionUtilities.getRootCauseMessage(e), e); } + + // auto-match finished + namesList.firePropertyChange(LOADING_PROPERTY, true, false); } }; worker.execute(); - - // background worker started - setAutoMatchInProgress(true); } + } diff --git a/source/net/sourceforge/tuned/ui/ActionPopup.java b/source/net/sourceforge/tuned/ui/ActionPopup.java index 3e1f6d71..9f468d40 100644 --- a/source/net/sourceforge/tuned/ui/ActionPopup.java +++ b/source/net/sourceforge/tuned/ui/ActionPopup.java @@ -38,7 +38,7 @@ public class ActionPopup extends JPopupMenu { setLayout(new MigLayout("nogrid, fill, insets 0")); - add(headerLabel, "gapx 4px 4px, gapy 1px, wrap 3px"); + add(headerLabel, "gapx 5px 5px, gapy 1px, wrap 3px"); add(new JSeparator(), "growx, wrap 1px"); add(descriptionLabel, "gapx 4px, wrap 3px"); add(actionPanel, "gapx 12px 12px, wrap"); diff --git a/test/net/sourceforge/filebot/web/SubsceneSubtitleClientTest.java b/test/net/sourceforge/filebot/web/SubsceneSubtitleClientTest.java index 14c79f3d..6b0bc308 100644 --- a/test/net/sourceforge/filebot/web/SubsceneSubtitleClientTest.java +++ b/test/net/sourceforge/filebot/web/SubsceneSubtitleClientTest.java @@ -79,10 +79,10 @@ public class SubsceneSubtitleClientTest { @Test public void getSubtitleListSearchResultMany() throws Exception { - List subtitleList = subscene.getSubtitleList(lostSearchResult, LanguageResolver.getDefault().getLocale("Vietnamese")); + List subtitleList = subscene.getSubtitleList(lostSearchResult, LanguageResolver.getDefault().getLocale("Japanese")); - // lots of subtitles, but only one is vietnamese - assertEquals(1, subtitleList.size()); + // lots of subtitles, but only a few Japanese ones + assertEquals(16, subtitleList.size()); }