* fixed annoying layout bug

* remember search engine in episodelist and subtitle panel
This commit is contained in:
Reinhard Pointner 2009-03-14 16:02:27 +00:00
parent 384e75576a
commit daa665c00e
5 changed files with 52 additions and 52 deletions

View File

@ -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<S, E> 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<S, E> extends JComponent {
protected abstract LabelProvider<S> createSearchEngineLabelProvider();
protected abstract EventList<String> createSearchHistory();
protected abstract Settings getSettings();
protected abstract RequestProcessor<?, E> createRequestProcessor();
@ -106,6 +127,24 @@ public abstract class AbstractSearchPanel<S, E> extends JComponent {
new SearchTask(requestProcessor).execute();
}
protected EventList<String> createSearchHistory() {
// create in-memory history
BasicEventList<String> history = new BasicEventList<String>();
// get the preferences node that contains the history entries
// and get a StringList that read and writes directly from and to the preferences
List<String> 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) {

View File

@ -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();
}

View File

@ -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<EpisodeListClient, Episode> {
@ -90,21 +87,8 @@ public class EpisodeListPanel extends AbstractSearchPanel<EpisodeListClient, Epi
@Override
protected EventList<String> createSearchHistory() {
// create in-memory list
BasicEventList<String> searchHistory = new BasicEventList<String>();
// get the preferences node that contains the history entries
// and get a StringList that read and writes directly from and to the preferences
List<String> 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");
}

View File

@ -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<SubtitleClient, SubtitlePackage> {
@ -56,21 +53,8 @@ public class SubtitlePanel extends AbstractSearchPanel<SubtitleClient, SubtitleP
@Override
protected EventList<String> createSearchHistory() {
// create in-memory history
BasicEventList<String> history = new BasicEventList<String>();
// get the preferences node that contains the history entries
// and get a StringList that read and writes directly from and to the preferences
List<String> 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");
}

View File

@ -128,6 +128,11 @@ public class SelectButton<T> extends JButton {
}
public SingleSelectionModel getSelectionModel() {
return selectionModel;
}
public void spinValue(int spin) {
int size = model.size();