From 254e48fc124fc50bed3f899575f546e9d365d720 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Wed, 7 Dec 2011 05:48:23 +0000 Subject: [PATCH] * don't block DnD operation / File Browser while downloading subs --- .../ui/subtitle/SubtitleDropTarget.java | 46 ++++++++++++------- 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/source/net/sourceforge/filebot/ui/subtitle/SubtitleDropTarget.java b/source/net/sourceforge/filebot/ui/subtitle/SubtitleDropTarget.java index d7764dbe..c934b46c 100644 --- a/source/net/sourceforge/filebot/ui/subtitle/SubtitleDropTarget.java +++ b/source/net/sourceforge/filebot/ui/subtitle/SubtitleDropTarget.java @@ -45,7 +45,7 @@ abstract class SubtitleDropTarget extends JButton { Cancel } - + public SubtitleDropTarget() { setHorizontalAlignment(CENTER); @@ -68,12 +68,12 @@ abstract class SubtitleDropTarget extends JButton { new DropTarget(this, dropHandler); } - + private void setDropAction(DropAction dropAction) { setIcon(getIcon(dropAction)); } - + private Icon getIcon(DropAction dropAction) { switch (dropAction) { case Download: @@ -85,16 +85,16 @@ abstract class SubtitleDropTarget extends JButton { } } - + public abstract VideoHashSubtitleService[] getVideoHashSubtitleServices(); - + public abstract SubtitleProvider[] getSubtitleProviders(); - + public abstract String getQueryLanguage(); - + private boolean handleDownload(List videoFiles) { SubtitleAutoMatchDialog dialog = new SubtitleAutoMatchDialog(getWindow(this)); @@ -124,17 +124,17 @@ abstract class SubtitleDropTarget extends JButton { return true; } - + private boolean handleUpload(Map videosMappedBySubtitle) { // TODO implement upload throw new UnsupportedOperationException("Not implemented yet"); } - + private boolean handleDrop(List files) { // perform a drop action depending on the given files if (containsOnly(files, VIDEO_FILES)) { - return handleDownload(files); + return handleDownloadLater(files); } if (containsOnly(files, FOLDERS)) { @@ -142,7 +142,7 @@ abstract class SubtitleDropTarget extends JButton { List videoFiles = filter(listFiles(files, 5, false), VIDEO_FILES); if (videoFiles.size() > 0) { - return handleDownload(videoFiles); + return handleDownloadLater(videoFiles); } } @@ -159,7 +159,21 @@ abstract class SubtitleDropTarget extends JButton { return false; } - + + private boolean handleDownloadLater(final List videoFiles) { + // invoke later so we don't block the DnD operation with the download dialog + invokeLater(0, new Runnable() { + + @Override + public void run() { + handleDownload(videoFiles); + } + }); + + return true; + } + + private boolean containsOnlyVideoSubtitleMatches(List files) { List subtitles = filter(files, SUBTITLE_FILES); @@ -170,7 +184,7 @@ abstract class SubtitleDropTarget extends JButton { return subtitles.size() == filter(files, VIDEO_FILES).size(); } - + private DropAction getDropAction(List files) { // video files only, or any folder, containing video files if (containsOnly(files, VIDEO_FILES) || (containsOnly(files, FOLDERS))) { @@ -186,7 +200,7 @@ abstract class SubtitleDropTarget extends JButton { return DropAction.Cancel; } - + private final DropTargetAdapter dropHandler = new DropTargetAdapter() { @Override @@ -212,13 +226,13 @@ abstract class SubtitleDropTarget extends JButton { } } - + public void dragExit(DropTargetEvent dte) { // reset to default state setDropAction(DropAction.Download); }; - + @Override public void drop(DropTargetDropEvent dtde) { dtde.acceptDrop(DnDConstants.ACTION_REFERENCE);