From daa665c00e1402389e135886fc9a4f54bf161ee6 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Sat, 14 Mar 2009 16:02:27 +0000 Subject: [PATCH] * fixed annoying layout bug * remember search engine in episodelist and subtitle panel --- .../filebot/ui/AbstractSearchPanel.java | 41 ++++++++++++++++++- .../net/sourceforge/filebot/ui/MainFrame.java | 18 ++------ .../panel/episodelist/EpisodeListPanel.java | 20 +-------- .../ui/panel/subtitle/SubtitlePanel.java | 20 +-------- .../sourceforge/tuned/ui/SelectButton.java | 5 +++ 5 files changed, 52 insertions(+), 52 deletions(-) diff --git a/source/net/sourceforge/filebot/ui/AbstractSearchPanel.java b/source/net/sourceforge/filebot/ui/AbstractSearchPanel.java index 17b03a38..5837d52d 100644 --- a/source/net/sourceforge/filebot/ui/AbstractSearchPanel.java +++ b/source/net/sourceforge/filebot/ui/AbstractSearchPanel.java @@ -24,14 +24,19 @@ import javax.swing.JTabbedPane; import javax.swing.KeyStroke; import javax.swing.SwingUtilities; import javax.swing.SwingWorker; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; import net.miginfocom.swing.MigLayout; import net.sourceforge.filebot.ResourceManager; +import net.sourceforge.filebot.Settings; import net.sourceforge.filebot.similarity.SeriesNameMatcher; import net.sourceforge.filebot.web.SearchResult; import net.sourceforge.tuned.ExceptionUtilities; +import net.sourceforge.tuned.ListChangeSynchronizer; import net.sourceforge.tuned.ui.LabelProvider; import net.sourceforge.tuned.ui.TunedUtilities; +import ca.odell.glazedlists.BasicEventList; import ca.odell.glazedlists.EventList; import ca.odell.glazedlists.matchers.TextMatcherEditor; import ca.odell.glazedlists.swing.AutoCompleteSupport; @@ -73,6 +78,22 @@ public abstract class AbstractSearchPanel extends JComponent { searchTextField.getSelectButton().setModel(createSearchEngines()); searchTextField.getSelectButton().setLabelProvider(createSearchEngineLabelProvider()); + try { + // restore selected subtitle client + searchTextField.getSelectButton().setSelectedIndex(Integer.parseInt(getSettings().get("search"))); + } catch (Exception e) { + // ignore + } + + // save selected client on change + searchTextField.getSelectButton().getSelectionModel().addChangeListener(new ChangeListener() { + + @Override + public void stateChanged(ChangeEvent e) { + getSettings().put("search", Integer.toString(searchTextField.getSelectButton().getSelectedIndex())); + } + }); + AutoCompleteSupport.install(searchTextField.getEditor(), searchHistory).setFilterMode(TextMatcherEditor.CONTAINS); TunedUtilities.putActionForKeystroke(this, KeyStroke.getKeyStroke("ENTER"), searchAction); @@ -85,7 +106,7 @@ public abstract class AbstractSearchPanel extends JComponent { protected abstract LabelProvider createSearchEngineLabelProvider(); - protected abstract EventList createSearchHistory(); + protected abstract Settings getSettings(); protected abstract RequestProcessor createRequestProcessor(); @@ -106,6 +127,24 @@ public abstract class AbstractSearchPanel extends JComponent { new SearchTask(requestProcessor).execute(); } + + protected EventList createSearchHistory() { + // create in-memory history + BasicEventList history = new BasicEventList(); + + // get the preferences node that contains the history entries + // and get a StringList that read and writes directly from and to the preferences + List persistentHistory = getSettings().node("history").asList(); + + // add history from the preferences to the current in-memory history (for completion) + history.addAll(persistentHistory); + + // perform all insert/add/remove operations on the in-memory history on the preferences node as well + ListChangeSynchronizer.syncEventListToList(history, persistentHistory); + + return history; + } + private final AbstractAction searchAction = new AbstractAction("Find", ResourceManager.getIcon("action.find")) { public void actionPerformed(ActionEvent e) { diff --git a/source/net/sourceforge/filebot/ui/MainFrame.java b/source/net/sourceforge/filebot/ui/MainFrame.java index c5931139..9c6a3133 100644 --- a/source/net/sourceforge/filebot/ui/MainFrame.java +++ b/source/net/sourceforge/filebot/ui/MainFrame.java @@ -37,6 +37,7 @@ import net.sourceforge.filebot.ui.panel.episodelist.EpisodeListPanelBuilder; import net.sourceforge.filebot.ui.panel.list.ListPanelBuilder; import net.sourceforge.filebot.ui.panel.rename.RenamePanelBuilder; import net.sourceforge.filebot.ui.panel.sfv.SfvPanelBuilder; +import net.sourceforge.filebot.ui.panel.subtitle.SubtitlePanelBuilder; import net.sourceforge.tuned.PreferencesMap.PreferencesEntry; import net.sourceforge.tuned.PreferencesMap.SimpleAdapter; import net.sourceforge.tuned.ui.ArrayListModel; @@ -79,7 +80,7 @@ public class MainFrame extends JFrame { JComponent c = (JComponent) getContentPane(); c.setLayout(new MigLayout("insets 0, fill, hidemode 3", "95px[fill]", "fill")); - c.add(selectionListScrollPane, "pos visual.x+6 visual.y+10 n visual.y2-12"); + c.add(selectionListScrollPane, "pos 6px 10px n 100%-12px"); c.add(headerPanel, "growx, dock north"); // show initial panel @@ -94,15 +95,6 @@ public class MainFrame extends JFrame { if (!e.getValueIsAdjusting()) { persistentSelectedPanel.setValue(selectionList.getSelectedIndex()); } - - // this seems to fix a very annoying layout/render issue, I've got no clue why - SwingUtilities.invokeLater(new Runnable() { - - @Override - public void run() { - getContentPane().validate(); - } - }); } }); @@ -117,6 +109,7 @@ public class MainFrame extends JFrame { builders.add(new RenamePanelBuilder()); builders.add(new AnalyzePanelBuilder()); builders.add(new EpisodeListPanelBuilder()); + builders.add(new SubtitlePanelBuilder()); builders.add(new SfvPanelBuilder()); return builders; @@ -146,15 +139,10 @@ public class MainFrame extends JFrame { panel.putClientProperty("panelBuilder", selectedBuilder); contentPane.add(panel); - } else if (panel.isVisible()) { - // no need to do anything - return; } headerPanel.setTitle(selectedBuilder.getName()); panel.setVisible(true); - - contentPane.validate(); } diff --git a/source/net/sourceforge/filebot/ui/panel/episodelist/EpisodeListPanel.java b/source/net/sourceforge/filebot/ui/panel/episodelist/EpisodeListPanel.java index aeea142f..933fb6a4 100644 --- a/source/net/sourceforge/filebot/ui/panel/episodelist/EpisodeListPanel.java +++ b/source/net/sourceforge/filebot/ui/panel/episodelist/EpisodeListPanel.java @@ -34,13 +34,10 @@ import net.sourceforge.filebot.web.SearchResult; import net.sourceforge.filebot.web.TVDotComClient; import net.sourceforge.filebot.web.TVRageClient; import net.sourceforge.filebot.web.TheTVDBClient; -import net.sourceforge.tuned.ListChangeSynchronizer; import net.sourceforge.tuned.ui.LabelProvider; import net.sourceforge.tuned.ui.SelectButton; import net.sourceforge.tuned.ui.SimpleLabelProvider; import net.sourceforge.tuned.ui.TunedUtilities; -import ca.odell.glazedlists.BasicEventList; -import ca.odell.glazedlists.EventList; public class EpisodeListPanel extends AbstractSearchPanel { @@ -90,21 +87,8 @@ public class EpisodeListPanel extends AbstractSearchPanel createSearchHistory() { - // create in-memory list - BasicEventList searchHistory = new BasicEventList(); - - // get the preferences node that contains the history entries - // and get a StringList that read and writes directly from and to the preferences - List persistentSearchHistory = Settings.userRoot().node("episodelist/history").asList(); - - // add history from the preferences to the current in-memory history (for completion) - searchHistory.addAll(persistentSearchHistory); - - // perform all insert/add/remove operations on the in-memory history on the preferences node as well - ListChangeSynchronizer.syncEventListToList(searchHistory, persistentSearchHistory); - - return searchHistory; + protected Settings getSettings() { + return Settings.userRoot().node("episodelist"); } diff --git a/source/net/sourceforge/filebot/ui/panel/subtitle/SubtitlePanel.java b/source/net/sourceforge/filebot/ui/panel/subtitle/SubtitlePanel.java index 93d48c3a..bf8b284a 100644 --- a/source/net/sourceforge/filebot/ui/panel/subtitle/SubtitlePanel.java +++ b/source/net/sourceforge/filebot/ui/panel/subtitle/SubtitlePanel.java @@ -22,11 +22,8 @@ import net.sourceforge.filebot.web.SubsceneSubtitleClient; import net.sourceforge.filebot.web.SubtitleClient; import net.sourceforge.filebot.web.SubtitleDescriptor; import net.sourceforge.filebot.web.SubtitleSourceClient; -import net.sourceforge.tuned.ListChangeSynchronizer; import net.sourceforge.tuned.ui.LabelProvider; import net.sourceforge.tuned.ui.SimpleLabelProvider; -import ca.odell.glazedlists.BasicEventList; -import ca.odell.glazedlists.EventList; public class SubtitlePanel extends AbstractSearchPanel { @@ -56,21 +53,8 @@ public class SubtitlePanel extends AbstractSearchPanel createSearchHistory() { - // create in-memory history - BasicEventList history = new BasicEventList(); - - // get the preferences node that contains the history entries - // and get a StringList that read and writes directly from and to the preferences - List persistentHistory = Settings.userRoot().node("subtitles/history").asList(); - - // add history from the preferences to the current in-memory history (for completion) - history.addAll(persistentHistory); - - // perform all insert/add/remove operations on the in-memory history on the preferences node as well - ListChangeSynchronizer.syncEventListToList(history, persistentHistory); - - return history; + protected Settings getSettings() { + return Settings.userRoot().node("subtitle"); } diff --git a/source/net/sourceforge/tuned/ui/SelectButton.java b/source/net/sourceforge/tuned/ui/SelectButton.java index 0f0ae2b0..9804c8dc 100644 --- a/source/net/sourceforge/tuned/ui/SelectButton.java +++ b/source/net/sourceforge/tuned/ui/SelectButton.java @@ -128,6 +128,11 @@ public class SelectButton extends JButton { } + public SingleSelectionModel getSelectionModel() { + return selectionModel; + } + + public void spinValue(int spin) { int size = model.size();