diff --git a/source/net/sourceforge/filebot/ui/AbstractSearchPanel.java b/source/net/sourceforge/filebot/ui/AbstractSearchPanel.java index 04cec0ea..cb9838ca 100644 --- a/source/net/sourceforge/filebot/ui/AbstractSearchPanel.java +++ b/source/net/sourceforge/filebot/ui/AbstractSearchPanel.java @@ -71,7 +71,7 @@ public abstract class AbstractSearchPanel extends JComponent { setLayout(new MigLayout("nogrid, fill, insets 10px 10px 15px 10px", "align center", "[pref!]10px[fill]")); - add(searchTextField, "gapafter indent"); + add(searchTextField); add(new JButton(searchAction), "gap 18px, wrap"); add(tabbedPaneGroup, "grow"); diff --git a/source/net/sourceforge/filebot/ui/LanguageComboBox.java b/source/net/sourceforge/filebot/ui/LanguageComboBox.java new file mode 100644 index 00000000..6f3835f1 --- /dev/null +++ b/source/net/sourceforge/filebot/ui/LanguageComboBox.java @@ -0,0 +1,126 @@ + +package net.sourceforge.filebot.ui; + + +import static java.awt.event.ItemEvent.*; +import static net.sourceforge.filebot.ui.Language.*; +import static net.sourceforge.filebot.ui.LanguageComboBoxModel.*; + +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; +import java.util.AbstractList; +import java.util.Locale; + +import javax.swing.JComboBox; +import javax.swing.JComponent; +import javax.swing.event.PopupMenuEvent; +import javax.swing.event.PopupMenuListener; + +import net.sourceforge.filebot.Settings; +import net.sourceforge.tuned.PreferencesList; +import net.sourceforge.tuned.PreferencesMap.PreferencesEntry; + + +public class LanguageComboBox extends JComboBox { + + private final PreferencesEntry persistentSelectedLanguage; + private final PreferencesList persistentFavoriteLanguages; + + + public LanguageComboBox(JComponent parent, Language initialSelection) { + super(new LanguageComboBoxModel(initialSelection != ALL_LANGUAGES, initialSelection)); + setRenderer(new LanguageComboBoxCellRenderer(super.getRenderer())); + + persistentSelectedLanguage = Settings.forPackage(parent.getClass()).entry("language.selected"); + persistentFavoriteLanguages = Settings.forPackage(parent.getClass()).node("language.favorites").asList(); + + // restore selected language + getModel().setSelectedItem(Language.getLanguage(persistentSelectedLanguage.getValue())); + + // restore favorite languages + for (String favoriteLanguage : persistentFavoriteLanguages) { + getModel().favorites().add(getModel().favorites().size(), getLanguage(favoriteLanguage)); + } + + // guess favorite languages + if (getModel().favorites().isEmpty()) { + for (Locale locale : new Locale[] { Locale.getDefault(), Locale.ENGLISH }) { + getModel().favorites().add(getLanguage(locale.getLanguage())); + } + } + + // update favorites on change + addPopupMenuListener(new PopupSelectionListener() { + + @Override + public void itemStateChanged(ItemEvent e) { + Language language = (Language) e.getItem(); + + if (getModel().favorites().add(language)) { + persistentFavoriteLanguages.set(new AbstractList() { + + @Override + public String get(int index) { + return getModel().favorites().get(index).getCode(); + } + + + @Override + public int size() { + return getModel().favorites().size(); + } + }); + } + + persistentSelectedLanguage.setValue(language.getCode()); + } + }); + } + + + @Override + public LanguageComboBoxModel getModel() { + return (LanguageComboBoxModel) super.getModel(); + } + + + private static class PopupSelectionListener implements PopupMenuListener, ItemListener { + + private Object selected = null; + + + @Override + public void popupMenuWillBecomeVisible(PopupMenuEvent e) { + JComboBox comboBox = (JComboBox) e.getSource(); + + // selected item before popup + selected = comboBox.getSelectedItem(); + } + + + @Override + public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { + JComboBox comboBox = (JComboBox) e.getSource(); + + // check selected item after popup + if (selected != comboBox.getSelectedItem()) { + itemStateChanged(new ItemEvent(comboBox, ITEM_STATE_CHANGED, comboBox.getSelectedItem(), SELECTED)); + } + + selected = null; + } + + + @Override + public void popupMenuCanceled(PopupMenuEvent e) { + selected = null; + } + + + @Override + public void itemStateChanged(ItemEvent e) { + + } + } + +} diff --git a/source/net/sourceforge/filebot/ui/subtitle/LanguageComboBoxCellRenderer.java b/source/net/sourceforge/filebot/ui/LanguageComboBoxCellRenderer.java similarity index 90% rename from source/net/sourceforge/filebot/ui/subtitle/LanguageComboBoxCellRenderer.java rename to source/net/sourceforge/filebot/ui/LanguageComboBoxCellRenderer.java index 61f19322..3bf066ee 100644 --- a/source/net/sourceforge/filebot/ui/subtitle/LanguageComboBoxCellRenderer.java +++ b/source/net/sourceforge/filebot/ui/LanguageComboBoxCellRenderer.java @@ -1,5 +1,5 @@ -package net.sourceforge.filebot.ui.subtitle; +package net.sourceforge.filebot.ui; import java.awt.Color; @@ -13,10 +13,10 @@ import javax.swing.border.CompoundBorder; import javax.swing.border.EmptyBorder; import net.sourceforge.filebot.ResourceManager; -import net.sourceforge.filebot.ui.Language; +import net.sourceforge.tuned.ui.DashedSeparator; -class LanguageComboBoxCellRenderer implements ListCellRenderer { +public class LanguageComboBoxCellRenderer implements ListCellRenderer { private Border padding = new EmptyBorder(2, 2, 2, 2); diff --git a/source/net/sourceforge/filebot/ui/subtitle/LanguageComboBoxModel.java b/source/net/sourceforge/filebot/ui/LanguageComboBoxModel.java similarity index 83% rename from source/net/sourceforge/filebot/ui/subtitle/LanguageComboBoxModel.java rename to source/net/sourceforge/filebot/ui/LanguageComboBoxModel.java index 9ca773a1..b201ead1 100644 --- a/source/net/sourceforge/filebot/ui/subtitle/LanguageComboBoxModel.java +++ b/source/net/sourceforge/filebot/ui/LanguageComboBoxModel.java @@ -1,5 +1,5 @@ -package net.sourceforge.filebot.ui.subtitle; +package net.sourceforge.filebot.ui; import static net.sourceforge.filebot.ui.Language.*; @@ -12,30 +12,36 @@ import java.util.Set; import javax.swing.AbstractListModel; import javax.swing.ComboBoxModel; -import net.sourceforge.filebot.ui.Language; - -class LanguageComboBoxModel extends AbstractListModel implements ComboBoxModel { +public class LanguageComboBoxModel extends AbstractListModel implements ComboBoxModel { public static final Language ALL_LANGUAGES = new Language("undefined", "All Languages"); - private Language selection = ALL_LANGUAGES; + private boolean requireSpecificLanguage; + private Language selection; private List favorites = new Favorites(2); private List values = availableLanguages(); + public LanguageComboBoxModel(boolean requireSpecificLanguage, Language initialSelection) { + this.requireSpecificLanguage = requireSpecificLanguage; + this.selection = initialSelection; + } + + @Override public Language getElementAt(int index) { // "All Languages" - if (index == 0) { - return ALL_LANGUAGES; + if (!requireSpecificLanguage) { + if (index == 0) + return ALL_LANGUAGES; + + // "All Languages" offset + index -= 1; } - // "All Languages" offset - index -= 1; - if (index < favorites.size()) { return favorites.get(index); } @@ -50,7 +56,7 @@ class LanguageComboBoxModel extends AbstractListModel implements ComboBoxModel { @Override public int getSize() { // "All Languages" : favorites[] : values[] - return 1 + favorites.size() + values.size(); + return (requireSpecificLanguage ? 0 : 1) + favorites.size() + values.size(); } @@ -74,7 +80,7 @@ class LanguageComboBoxModel extends AbstractListModel implements ComboBoxModel { protected int convertFavoriteIndexToModel(int favoriteIndex) { - return 1 + favoriteIndex; + return (requireSpecificLanguage ? 0 : 1) + favoriteIndex; } diff --git a/source/net/sourceforge/filebot/ui/episodelist/EpisodeListPanel.java b/source/net/sourceforge/filebot/ui/episodelist/EpisodeListPanel.java index 10f66e00..35b63afb 100644 --- a/source/net/sourceforge/filebot/ui/episodelist/EpisodeListPanel.java +++ b/source/net/sourceforge/filebot/ui/episodelist/EpisodeListPanel.java @@ -15,6 +15,7 @@ import java.io.IOException; import java.net.URI; import java.util.Arrays; import java.util.Collection; +import java.util.Locale; import javax.swing.AbstractAction; import javax.swing.Icon; @@ -29,6 +30,8 @@ import net.sourceforge.filebot.ui.AbstractSearchPanel; import net.sourceforge.filebot.ui.FileBotList; import net.sourceforge.filebot.ui.FileBotListExportHandler; import net.sourceforge.filebot.ui.FileBotTab; +import net.sourceforge.filebot.ui.Language; +import net.sourceforge.filebot.ui.LanguageComboBox; import net.sourceforge.filebot.ui.SelectDialog; import net.sourceforge.filebot.ui.transfer.ArrayTransferable; import net.sourceforge.filebot.ui.transfer.ClipboardHandler; @@ -48,6 +51,7 @@ import net.sourceforge.tuned.ui.TunedUtilities; public class EpisodeListPanel extends AbstractSearchPanel { private SeasonSpinnerModel seasonSpinnerModel = new SeasonSpinnerModel(); + private LanguageComboBox languageComboBox = new LanguageComboBox(this, Language.getLanguage("en")); public EpisodeListPanel() { @@ -61,7 +65,8 @@ public class EpisodeListPanel extends AbstractSearchPanel search() throws Exception { - return request.getProvider().search(request.getSearchText()); + return request.getProvider().search(request.getSearchText(), request.getLanguage()); } @Override public Collection fetch() throws Exception { if (request.getSeason() != ALL_SEASONS) - return request.getProvider().getEpisodeList(getSearchResult(), request.getSeason()); + return request.getProvider().getEpisodeList(getSearchResult(), request.getSeason(), request.getLanguage()); else - return request.getProvider().getEpisodeList(getSearchResult()); + return request.getProvider().getEpisodeList(getSearchResult(), request.getLanguage()); } diff --git a/source/net/sourceforge/filebot/ui/subtitle/PopupSelectionListener.java b/source/net/sourceforge/filebot/ui/subtitle/PopupSelectionListener.java deleted file mode 100644 index 8b158936..00000000 --- a/source/net/sourceforge/filebot/ui/subtitle/PopupSelectionListener.java +++ /dev/null @@ -1,52 +0,0 @@ - -package net.sourceforge.filebot.ui.subtitle; - - -import static java.awt.event.ItemEvent.*; - -import java.awt.event.ItemEvent; -import java.awt.event.ItemListener; - -import javax.swing.JComboBox; -import javax.swing.event.PopupMenuEvent; -import javax.swing.event.PopupMenuListener; - - -class PopupSelectionListener implements PopupMenuListener, ItemListener { - - private Object selected = null; - - - @Override - public void popupMenuWillBecomeVisible(PopupMenuEvent e) { - JComboBox comboBox = (JComboBox) e.getSource(); - - // selected item before popup - selected = comboBox.getSelectedItem(); - } - - - @Override - public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { - JComboBox comboBox = (JComboBox) e.getSource(); - - // check selected item after popup - if (selected != comboBox.getSelectedItem()) { - itemStateChanged(new ItemEvent(comboBox, ITEM_STATE_CHANGED, comboBox.getSelectedItem(), SELECTED)); - } - - selected = null; - } - - - @Override - public void popupMenuCanceled(PopupMenuEvent e) { - selected = null; - } - - - @Override - public void itemStateChanged(ItemEvent e) { - - } -} diff --git a/source/net/sourceforge/filebot/ui/subtitle/SubtitlePackageCellRenderer.java b/source/net/sourceforge/filebot/ui/subtitle/SubtitlePackageCellRenderer.java index 304c0fbe..5948d93b 100644 --- a/source/net/sourceforge/filebot/ui/subtitle/SubtitlePackageCellRenderer.java +++ b/source/net/sourceforge/filebot/ui/subtitle/SubtitlePackageCellRenderer.java @@ -16,6 +16,7 @@ import net.miginfocom.swing.MigLayout; import net.sourceforge.filebot.ResourceManager; import net.sourceforge.filebot.vfs.ArchiveType; import net.sourceforge.tuned.ui.AbstractFancyListCellRenderer; +import net.sourceforge.tuned.ui.DashedSeparator; class SubtitlePackageCellRenderer extends AbstractFancyListCellRenderer { diff --git a/source/net/sourceforge/filebot/ui/subtitle/SubtitlePanel.java b/source/net/sourceforge/filebot/ui/subtitle/SubtitlePanel.java index abc2e563..f6342226 100644 --- a/source/net/sourceforge/filebot/ui/subtitle/SubtitlePanel.java +++ b/source/net/sourceforge/filebot/ui/subtitle/SubtitlePanel.java @@ -2,101 +2,46 @@ package net.sourceforge.filebot.ui.subtitle; -import static net.sourceforge.filebot.ui.Language.*; -import static net.sourceforge.filebot.ui.subtitle.LanguageComboBoxModel.*; +import static net.sourceforge.filebot.ui.LanguageComboBoxModel.*; import java.awt.Color; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.RenderingHints; -import java.awt.event.ItemEvent; import java.awt.geom.Path2D; import java.net.URI; -import java.util.AbstractList; import java.util.ArrayList; import java.util.Collection; import java.util.List; -import java.util.Locale; import javax.swing.Icon; -import javax.swing.JComboBox; import net.sourceforge.filebot.Analytics; import net.sourceforge.filebot.Settings; import net.sourceforge.filebot.WebServices; import net.sourceforge.filebot.ui.AbstractSearchPanel; import net.sourceforge.filebot.ui.Language; +import net.sourceforge.filebot.ui.LanguageComboBox; import net.sourceforge.filebot.ui.SelectDialog; import net.sourceforge.filebot.web.SearchResult; import net.sourceforge.filebot.web.SubtitleDescriptor; import net.sourceforge.filebot.web.SubtitleProvider; import net.sourceforge.filebot.web.VideoHashSubtitleService; -import net.sourceforge.tuned.PreferencesList; -import net.sourceforge.tuned.PreferencesMap.PreferencesEntry; import net.sourceforge.tuned.ui.LabelProvider; import net.sourceforge.tuned.ui.SimpleLabelProvider; public class SubtitlePanel extends AbstractSearchPanel { - private final LanguageComboBoxModel languageModel = new LanguageComboBoxModel(); - - private static final PreferencesEntry persistentSelectedLanguage = Settings.forPackage(SubtitlePanel.class).entry("language.selected"); - private static final PreferencesList persistentFavoriteLanguages = Settings.forPackage(SubtitlePanel.class).node("language.favorites").asList(); + private LanguageComboBox languageComboBox = new LanguageComboBox(this, ALL_LANGUAGES); public SubtitlePanel() { historyPanel.setColumnHeader(0, "Show / Movie"); historyPanel.setColumnHeader(1, "Number of Subtitles"); - JComboBox languageComboBox = new JComboBox(languageModel); - - languageComboBox.setRenderer(new LanguageComboBoxCellRenderer(languageComboBox.getRenderer())); - - // restore selected language - languageModel.setSelectedItem(Language.getLanguage(persistentSelectedLanguage.getValue())); - - // restore favorite languages - for (String favoriteLanguage : persistentFavoriteLanguages) { - languageModel.favorites().add(languageModel.favorites().size(), getLanguage(favoriteLanguage)); - } - - // guess favorite languages - if (languageModel.favorites().isEmpty()) { - for (Locale locale : new Locale[] { Locale.getDefault(), Locale.ENGLISH }) { - languageModel.favorites().add(getLanguage(locale.getLanguage())); - } - } - - // update favorites on change - languageComboBox.addPopupMenuListener(new PopupSelectionListener() { - - @Override - public void itemStateChanged(ItemEvent e) { - Language language = (Language) e.getItem(); - - if (languageModel.favorites().add(language)) { - persistentFavoriteLanguages.set(new AbstractList() { - - @Override - public String get(int index) { - return languageModel.favorites().get(index).getCode(); - } - - - @Override - public int size() { - return languageModel.favorites().size(); - } - }); - } - - persistentSelectedLanguage.setValue(language.getCode()); - } - }); - // add after text field - add(languageComboBox, 1); + add(languageComboBox, "gap indent", 1); // add at the top right corner add(dropTarget, "width 1.6cm!, height 1.2cm!, pos n 0% 100% n", 0); @@ -114,7 +59,7 @@ public class SubtitlePanel extends AbstractSearchPanel search(String query) throws Exception { return search(query, Locale.ENGLISH); } - @Override public List getEpisodeList(SearchResult searchResult) throws Exception { return getEpisodeList(searchResult, Locale.ENGLISH); } - @Override public List getEpisodeList(SearchResult searchResult, int season) throws Exception { return getEpisodeList(searchResult, season, Locale.ENGLISH); } diff --git a/source/net/sourceforge/filebot/web/EpisodeListProvider.java b/source/net/sourceforge/filebot/web/EpisodeListProvider.java index 25e187fc..edc8f9b6 100644 --- a/source/net/sourceforge/filebot/web/EpisodeListProvider.java +++ b/source/net/sourceforge/filebot/web/EpisodeListProvider.java @@ -23,18 +23,9 @@ public interface EpisodeListProvider { public boolean hasLocaleSupport(); - public List search(String query) throws Exception; - - public List search(String query, Locale locale) throws Exception; - public List getEpisodeList(SearchResult searchResult) throws Exception; - - - public List getEpisodeList(SearchResult searchResult, int season) throws Exception; - - public List getEpisodeList(SearchResult searchResult, Locale locale) throws Exception; diff --git a/source/net/sourceforge/filebot/ui/subtitle/DashedSeparator.java b/source/net/sourceforge/tuned/ui/DashedSeparator.java similarity index 93% rename from source/net/sourceforge/filebot/ui/subtitle/DashedSeparator.java rename to source/net/sourceforge/tuned/ui/DashedSeparator.java index 4e3a1de0..55ddc97e 100644 --- a/source/net/sourceforge/filebot/ui/subtitle/DashedSeparator.java +++ b/source/net/sourceforge/tuned/ui/DashedSeparator.java @@ -1,5 +1,5 @@ -package net.sourceforge.filebot.ui.subtitle; +package net.sourceforge.tuned.ui; import static java.awt.BasicStroke.*; @@ -15,7 +15,7 @@ import java.awt.Insets; import javax.swing.border.Border; -class DashedSeparator implements Border { +public class DashedSeparator implements Border { private final int height; private final int dash; @@ -23,7 +23,7 @@ class DashedSeparator implements Border { private final Color foreground; private final Color background; - + public DashedSeparator(int height, int dash, Color foreground, Color background) { this.height = height; this.dash = dash;