diff --git a/source/net/filebot/ui/HistoryPanel.java b/source/net/filebot/ui/HistoryPanel.java index 61a70d1b..af2362e2 100644 --- a/source/net/filebot/ui/HistoryPanel.java +++ b/source/net/filebot/ui/HistoryPanel.java @@ -1,7 +1,5 @@ - package net.filebot.ui; - import java.awt.Color; import java.awt.Font; import java.net.URI; @@ -17,63 +15,57 @@ import javax.swing.SwingConstants; import net.filebot.util.ui.LinkButton; import net.miginfocom.swing.MigLayout; - public class HistoryPanel extends JPanel { - + private final List columnHeaders = new ArrayList(3); - - + public HistoryPanel() { super(new MigLayout("fillx, insets 10 30 10 50, wrap 3")); - + setBackground(Color.WHITE); setOpaque(true); - + setupHeader(); } - private void setupHeader() { for (int i = 0; i < 3; i++) { JLabel columnHeader = new JLabel(); - + columnHeader.setFont(columnHeader.getFont().deriveFont(Font.BOLD)); - + columnHeaders.add(columnHeader); - + add(columnHeader, getHeaderConstraint(i)); } } - private String getHeaderConstraint(int headerIndex) { switch (headerIndex) { - case 0: - return "align left, gapbefore 24"; - case 1: - return "align center"; - default: - return "align right, gapafter 12"; + case 0: + return "align left, gapbefore 24"; + case 1: + return "align center"; + default: + return "align right, gapafter 12"; } } - public void setColumnHeader(int index, String text) { columnHeaders.get(index).setText(text); } - public void add(String column1, URI link, Icon icon, String column2, String column3) { - JComponent c1 = link != null ? new LinkButton(column1, icon, link) : new JLabel(column1, icon, SwingConstants.LEFT); + JComponent c1 = link != null ? new LinkButton(column1, null, icon, link) : new JLabel(column1, icon, SwingConstants.LEFT); JComponent c2 = new JLabel(column2, SwingConstants.RIGHT); JComponent c3 = new JLabel(column3, SwingConstants.RIGHT); - + add(c1, "align left"); - + // set minimum with to 100px so the text is aligned to the right, // even though the whole label is centered add(c2, "align center, wmin 100"); - + add(c3, "align right"); } } diff --git a/source/net/filebot/ui/subtitle/SubtitleAutoMatchDialog.java b/source/net/filebot/ui/subtitle/SubtitleAutoMatchDialog.java index 9b7566d4..079f48f8 100644 --- a/source/net/filebot/ui/subtitle/SubtitleAutoMatchDialog.java +++ b/source/net/filebot/ui/subtitle/SubtitleAutoMatchDialog.java @@ -170,7 +170,7 @@ class SubtitleAutoMatchDialog extends JDialog { } protected void addSubtitleService(final SubtitleServiceBean service, final JPanel servicePanel) { - final LinkButton component = new LinkButton(service.getName(), ResourceManager.getIcon("database"), service.getLink()); + final LinkButton component = new LinkButton(service.getName(), null, ResourceManager.getIcon("database"), service.getLink()); component.setBorder(BorderFactory.createEmptyBorder()); component.setVisible(false); diff --git a/source/net/filebot/ui/subtitle/SubtitlePanel.java b/source/net/filebot/ui/subtitle/SubtitlePanel.java index b2e3158e..4d8a5b8d 100644 --- a/source/net/filebot/ui/subtitle/SubtitlePanel.java +++ b/source/net/filebot/ui/subtitle/SubtitlePanel.java @@ -18,7 +18,9 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.List; +import java.util.Map; import java.util.logging.Level; +import java.util.logging.Logger; import javax.swing.AbstractAction; import javax.swing.Action; @@ -284,9 +286,9 @@ public class SubtitlePanel extends AbstractSearchPanel 0 && osdbPass.getPassword().length > 0) { - OpenSubtitlesClient osdb = new OpenSubtitlesClient(getApplicationName(), getApplicationVersion()); + final OpenSubtitlesClient osdb = new OpenSubtitlesClient(getApplicationName(), getApplicationVersion()); osdb.setUser(osdbUser.getText(), new String(osdbPass.getPassword())); osdb.login(); + + // do some status checks in background (since OpenSubtitles can be really really slow) + WebServices.requestThreadPool.submit(() -> { + try { + // check download quota for the current user + Map limits = (Map) osdb.getServerInfo().get("download_limits"); + UILogger.log(Level.INFO, String.format("Your daily download quota is at %s of %s.", limits.get("client_24h_download_count"), limits.get("client_24h_download_limit"))); + + // logout from test session + osdb.logout(); + } catch (Exception e) { + Logger.getLogger(SubtitlePanel.class.getName()).log(Level.WARNING, e.toString()); + } + }); } } catch (Exception e) { UILogger.log(Level.WARNING, "OpenSubtitles: " + e.getMessage()); diff --git a/source/net/filebot/util/ui/LinkButton.java b/source/net/filebot/util/ui/LinkButton.java index be20d177..2de97502 100644 --- a/source/net/filebot/util/ui/LinkButton.java +++ b/source/net/filebot/util/ui/LinkButton.java @@ -1,7 +1,5 @@ - package net.filebot.util.ui; - import java.awt.Color; import java.awt.Cursor; import java.awt.Desktop; @@ -18,99 +16,92 @@ import javax.swing.Action; import javax.swing.Icon; import javax.swing.JButton; - public class LinkButton extends JButton { - + private Color color = getForeground(); private Color rolloverColor = new Color(0x3399FF); - - - public LinkButton(String text, Icon icon, URI uri) { - this(new OpenUriAction(text, icon, uri)); + + public LinkButton(String text, String tooltip, Icon icon, URI uri) { + this(new OpenUriAction(text, tooltip, icon, uri)); } - - + public LinkButton(Action action) { setAction(action); - + setFocusPainted(false); setOpaque(false); setContentAreaFilled(false); setBorder(null); - + setHorizontalAlignment(LEFT); setIconTextGap(6); setRolloverEnabled(true); - + setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); } - - + @Override public void setRolloverEnabled(boolean enabled) { super.setRolloverEnabled(enabled); - + // always remove listener if there is one removeMouseListener(rolloverListener); - + if (enabled) { // add listener again, if enabled addMouseListener(rolloverListener); } } - - + public Color getColor() { return color; } - - + public void setColor(Color color) { this.color = color; this.setForeground(color); } - - + public Color getRolloverColor() { return rolloverColor; } - - + public void setRolloverColor(Color rolloverColor) { this.rolloverColor = rolloverColor; } - + protected final MouseListener rolloverListener = new MouseAdapter() { - + @Override public void mouseEntered(MouseEvent e) { setForeground(rolloverColor); } - - + @Override public void mouseExited(MouseEvent e) { setForeground(color); } }; - - + protected static class OpenUriAction extends AbstractAction { - + public static final String URI = "uri"; - - - public OpenUriAction(String text, Icon icon, URI uri) { + + public OpenUriAction(String text, String tooltip, Icon icon, URI uri) { super(text, icon); - putValue(URI, uri); + if (uri != null) { + putValue(URI, uri); + } + if (tooltip != null) { + putValue(SHORT_DESCRIPTION, tooltip); + } } - - + @Override public void actionPerformed(ActionEvent evt) { try { URI uri = (URI) getValue(URI); - + if (uri != null) { Desktop.getDesktop().browse(uri); } @@ -120,5 +111,5 @@ public class LinkButton extends JButton { } } } - + } diff --git a/source/net/filebot/web/OpenSubtitlesClient.java b/source/net/filebot/web/OpenSubtitlesClient.java index ff922975..76bda316 100644 --- a/source/net/filebot/web/OpenSubtitlesClient.java +++ b/source/net/filebot/web/OpenSubtitlesClient.java @@ -505,7 +505,7 @@ public class OpenSubtitlesClient implements SubtitleProvider, VideoHashSubtitleS logoutTimer.set(10, TimeUnit.MINUTES, true); } - protected synchronized void logout() { + public synchronized void logout() { if (xmlrpc.isLoggedOn()) { try { xmlrpc.logout(); diff --git a/source/net/filebot/web/OpenSubtitlesXmlRpc.java b/source/net/filebot/web/OpenSubtitlesXmlRpc.java index 91776bc9..48e5eb38 100644 --- a/source/net/filebot/web/OpenSubtitlesXmlRpc.java +++ b/source/net/filebot/web/OpenSubtitlesXmlRpc.java @@ -324,6 +324,8 @@ public class OpenSubtitlesXmlRpc { // rethrow exception throw e; + } catch (ClassCastException e) { + throw new XmlRpcFault(500, "The remote server returned an unexpected response"); } }