private int maxPage;
private JComboBox comboSupportTypes;
- private GuiReaderSearchByNamePanel searchPanel;
+ private GuiReaderSearchByPanel searchPanel;
private boolean seeWordcount;
private GuiReaderGroup books;
setLayout(new BorderLayout());
setSize(800, 600);
- page = 1; // TODO
+ page = 1;
maxPage = -1;
supportTypes = new ArrayList<SupportType>();
comboSupportTypes.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
- updateSupportType((SupportType) comboSupportTypes
- .getSelectedItem());
+ setWaiting(true);
+ updateSupportType(
+ (SupportType) comboSupportTypes.getSelectedItem(),
+ new Runnable() {
+ @Override
+ public void run() {
+ setWaiting(false);
+ }
+ });
}
});
JPanel searchSites = new JPanel(new BorderLayout());
searchSites.add(comboSupportTypes, BorderLayout.CENTER);
searchSites.add(new JLabel(" " + "Website : "), BorderLayout.WEST);
- searchPanel = new GuiReaderSearchByNamePanel(supportType);
+ searchPanel = new GuiReaderSearchByPanel(supportType,
+ new GuiReaderSearchByPanel.Waitable() {
+ @Override
+ public void setWaiting(boolean waiting) {
+ GuiReaderSearchFrame.this.setWaiting(waiting);
+ }
+ });
+
searchPanel.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
- updatePages(0, maxPage);
+ updatePages(searchPanel.getPage(), searchPanel.getMaxPage());
List<GuiReaderBookInfo> infos = new ArrayList<GuiReaderBookInfo>();
for (MetaData meta : searchPanel.getStories()) {
infos.add(GuiReaderBookInfo.fromMeta(meta));
add(scroll, BorderLayout.CENTER);
}
- private void updateSupportType(SupportType supportType) {
- if (supportType != this.supportType) {
- this.supportType = supportType;
- comboSupportTypes.setSelectedItem(supportType);
- books.clear();
- searchPanel.setSupportType(supportType);
- }
+ private void updateSupportType(final SupportType supportType,
+ final Runnable inUi) {
+ this.supportType = supportType;
+ comboSupportTypes.setSelectedItem(supportType);
+ books.clear();
+
+ new Thread(new Runnable() {
+ @Override
+ public void run() {
+ searchPanel.setSupportType(supportType);
+ inUi(inUi);
+ }
+ }).start();
}
- private void updatePages(final int page, final Integer maxPage) {
+ private void updatePages(final int page, final int maxPage) {
inUi(new Runnable() {
@Override
public void run() {
GuiReaderSearchFrame.this.page = page;
GuiReaderSearchFrame.this.maxPage = maxPage;
-
- searchPanel.setPage(page);
-
+
// TODO: gui
System.out.println("page: " + page);
System.out.println("max page: " + maxPage);
}
private void updateBooks(final List<GuiReaderBookInfo> infos) {
- setWaitingScreen(true);
+ setWaiting(true);
inUi(new Runnable() {
@Override
public void run() {
books.refreshBooks(infos, seeWordcount);
- setWaitingScreen(false);
+ setWaiting(false);
}
});
}
// item 0 = no selection, else = default selection
public void search(final SupportType searchOn, final String keywords,
final int page, final int item) {
-
- updatePages(page, maxPage);
- searchPanel.setSupportType(searchOn);
-
- if (keywords != null) {
- setWaitingScreen(true);
- searchPanel.search(keywords, item, new Runnable() {
- @Override
- public void run() {
- setWaitingScreen(false);
- }
- });
- }
+ setWaiting(true);
+ new Thread(new Runnable() {
+ @Override
+ public void run() {
+ searchPanel.setSupportType(searchOn);
+ searchPanel.search(keywords, page, item);
+ inUi(new Runnable() {
+ @Override
+ public void run() {
+ setWaiting(false);
+ }
+ });
+ }
+ }).start();
}
// tag: null = base tags
public void searchTag(final SupportType searchOn, final int page,
final int item, final SearchableTag tag) {
-
- setWaitingScreen(true);
- updatePages(page, maxPage);
- searchPanel.setSupportType(searchOn);
- searchPanel.searchTag(tag, item, new Runnable() {
+ setWaiting(true);
+ new Thread(new Runnable() {
@Override
public void run() {
- setWaitingScreen(false);
+ searchPanel.setSupportType(searchOn);
+ searchPanel.searchTag(tag, page, item);
+ inUi(new Runnable() {
+ @Override
+ public void run() {
+ setWaiting(false);
+ }
+ });
}
- });
+ }).start();
}
/**
static void error(String e) {
Instance.getTraceHandler().error(e);
}
-
- private void setWaitingScreen(final boolean waiting) {
+
+ /**
+ * Enables or disables this component, depending on the value of the
+ * parameter <code>b</code>. An enabled component can respond to user input
+ * and generate events. Components are enabled initially by default.
+ * <p>
+ * Disabling this component will also affect its children.
+ *
+ * @param b
+ * If <code>true</code>, this component is enabled; otherwise
+ * this component is disabled
+ */
+ @Override
+ public void setEnabled(boolean b) {
+ super.setEnabled(b);
+ books.setEnabled(b);
+ searchPanel.setEnabled(b);
+ }
+
+ private void setWaiting(final boolean waiting) {
inUi(new Runnable() {
@Override
public void run() {
GuiReaderSearchFrame.this.setEnabled(!waiting);
- books.setEnabled(!waiting);
- searchPanel.setEnabled(!waiting);
}
});
}