From 859564bc1568f40d82f5b67f123ba7523f213d29 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Sun, 29 Jul 2012 08:30:33 +0000 Subject: [PATCH] * setup double-click actions for files (reveal in explorer) and movies (open tmdb/imdb page) --- .../filebot/ui/rename/RenamePanel.java | 53 ++++++++++++++++++- .../sourceforge/filebot/web/IMDbClient.java | 6 +++ .../sourceforge/filebot/web/TMDbClient.java | 6 +++ 3 files changed, 64 insertions(+), 1 deletion(-) diff --git a/source/net/sourceforge/filebot/ui/rename/RenamePanel.java b/source/net/sourceforge/filebot/ui/rename/RenamePanel.java index 013244b8..5b63e23e 100644 --- a/source/net/sourceforge/filebot/ui/rename/RenamePanel.java +++ b/source/net/sourceforge/filebot/ui/rename/RenamePanel.java @@ -10,9 +10,13 @@ import static net.sourceforge.tuned.ui.LoadingOverlayPane.*; import static net.sourceforge.tuned.ui.TunedUtilities.*; import java.awt.Component; +import java.awt.Cursor; +import java.awt.Desktop; import java.awt.Insets; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.io.File; @@ -22,6 +26,7 @@ import java.util.LinkedList; import java.util.List; import java.util.Locale; import java.util.logging.Level; +import java.util.logging.Logger; import javax.swing.AbstractAction; import javax.swing.Action; @@ -168,8 +173,54 @@ public class RenamePanel extends JComponent { // open rename log button filesList.getButtonPanel().add(createImageButton(openHistoryAction), "gap 0"); - setLayout(new MigLayout("fill, insets dialog, gapx 10px", "[fill][align center, pref!][fill]", "align 33%")); + // reveal file location on double click + filesList.getListComponent().addMouseListener(new MouseAdapter() { + + @Override + public void mouseClicked(MouseEvent evt) { + if (evt.getClickCount() == 2) { + getWindow(evt.getSource()).setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); + try { + JList list = (JList) evt.getSource(); + File item = (File) list.getSelectedValue(); + Desktop.getDesktop().browse(item.getParentFile().toURI()); + } catch (Exception e) { + Logger.getLogger(RenamePanel.class.getName()).log(Level.WARNING, e.getMessage()); + } finally { + getWindow(evt.getSource()).setCursor(Cursor.getDefaultCursor()); + } + } + } + }); + // reveal file location on double click + namesList.getListComponent().addMouseListener(new MouseAdapter() { + + @Override + public void mouseClicked(MouseEvent evt) { + if (evt.getClickCount() == 2) { + try { + JList list = (JList) evt.getSource(); + Object item = ((FormattedFuture) list.getSelectedValue()).getMatch().getValue(); + if (item instanceof Movie) { + getWindow(evt.getSource()).setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); + Movie m = (Movie) item; + if (m.getTmdbId() > 0) { + Desktop.getDesktop().browse(WebServices.TMDb.getMoviePageLink(m.getTmdbId())); + } else if (m.getImdbId() > 0) { + Desktop.getDesktop().browse(WebServices.IMDb.getMoviePageLink(m.getImdbId())); + } + } + } catch (Exception e) { + Logger.getLogger(RenamePanel.class.getName()).log(Level.WARNING, e.getMessage()); + } finally { + getWindow(evt.getSource()).setCursor(Cursor.getDefaultCursor()); + } + } + } + }); + + setLayout(new MigLayout("fill, insets dialog, gapx 10px", "[fill][align center, pref!][fill]", "align 33%")); add(filesList, "grow, sizegroupx list"); // make buttons larger diff --git a/source/net/sourceforge/filebot/web/IMDbClient.java b/source/net/sourceforge/filebot/web/IMDbClient.java index 39397a93..83f11c48 100644 --- a/source/net/sourceforge/filebot/web/IMDbClient.java +++ b/source/net/sourceforge/filebot/web/IMDbClient.java @@ -11,6 +11,7 @@ import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.io.Reader; +import java.net.URI; import java.net.URL; import java.net.URLConnection; import java.nio.ByteBuffer; @@ -178,6 +179,11 @@ public class IMDbClient implements MovieIdentificationService { } + public URI getMoviePageLink(int imdbId) { + return URI.create(String.format("http://www.imdb.com/title/tt%07d/", imdbId)); + } + + @Override public Map getMovieDescriptors(Collection movieFiles, Locale locale) throws Exception { throw new UnsupportedOperationException(); diff --git a/source/net/sourceforge/filebot/web/TMDbClient.java b/source/net/sourceforge/filebot/web/TMDbClient.java index 46070aff..21a1316f 100644 --- a/source/net/sourceforge/filebot/web/TMDbClient.java +++ b/source/net/sourceforge/filebot/web/TMDbClient.java @@ -10,6 +10,7 @@ import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.io.Serializable; +import java.net.URI; import java.net.URL; import java.nio.ByteBuffer; import java.nio.charset.Charset; @@ -97,6 +98,11 @@ public class TMDbClient implements MovieIdentificationService { } + public URI getMoviePageLink(int tmdbid) { + return URI.create("http://www.themoviedb.org/movie/" + tmdbid); + } + + @Override public Movie getMovieDescriptor(int imdbid, Locale locale) throws IOException { try {