From c499d79f13535082dd25c7ee46e897d3372c4299 Mon Sep 17 00:00:00 2001 From: Niki Roo Date: Tue, 16 Apr 2019 09:33:40 +0200 Subject: [PATCH] GUI search: waiting --- .../fanfix/reader/ui/GuiReaderGroup.java | 49 ++++++++-- .../fanfix/reader/ui/GuiReaderSearch.java | 98 ++++++++++++------- 2 files changed, 106 insertions(+), 41 deletions(-) diff --git a/src/be/nikiroo/fanfix/reader/ui/GuiReaderGroup.java b/src/be/nikiroo/fanfix/reader/ui/GuiReaderGroup.java index 3e86fba9..df3b74a0 100644 --- a/src/be/nikiroo/fanfix/reader/ui/GuiReaderGroup.java +++ b/src/be/nikiroo/fanfix/reader/ui/GuiReaderGroup.java @@ -29,6 +29,8 @@ public class GuiReaderGroup extends JPanel { private static final long serialVersionUID = 1L; private BookActionListener action; private Color backgroundColor; + private Color backgroundColorDef; + private Color backgroundColorDefPane; private GuiReader reader; private List infos; private List books; @@ -51,15 +53,13 @@ public class GuiReaderGroup extends JPanel { */ public GuiReaderGroup(GuiReader reader, String title, Color backgroundColor) { this.reader = reader; - this.backgroundColor = backgroundColor; this.pane = new JPanel(); - pane.setLayout(new WrapLayout(WrapLayout.LEADING, 5, 5)); - if (backgroundColor != null) { - pane.setBackground(backgroundColor); - setBackground(backgroundColor); - } + + this.backgroundColorDef = getBackground(); + this.backgroundColorDefPane = pane.getBackground(); + setBackground(backgroundColor); setLayout(new BorderLayout(0, 10)); @@ -113,6 +113,43 @@ public class GuiReaderGroup extends JPanel { }); } + /** + * Note: this class supports NULL as a background color, which will revert + * it to its default state. + *

+ * Note: this class' implementation will also set the main pane background + * color at the same time. + *

+ * Sets the background color of this component. The background color is used + * only if the component is opaque, and only by subclasses of + * JComponent or ComponentUI implementations. + * Direct subclasses of JComponent must override + * paintComponent to honor this property. + *

+ * It is up to the look and feel to honor this property, some may choose to + * ignore it. + * + * @param bg + * the desired background Color + * @see java.awt.Component#getBackground + * @see #setOpaque + * + * @beaninfo preferred: true bound: true attribute: visualUpdate true + * description: The background color of the component. + */ + @Override + public void setBackground(Color backgroundColor) { + Color cme = backgroundColor == null ? backgroundColorDef + : backgroundColor; + Color cpane = backgroundColor == null ? backgroundColorDefPane + : backgroundColor; + + if (pane != null) { // can happen at theme setup time + pane.setBackground(cpane); + } + super.setBackground(cme); + } + /** * The title of this group (can be NULL for "no title", an empty * {@link String} will trigger a default title for empty groups) diff --git a/src/be/nikiroo/fanfix/reader/ui/GuiReaderSearch.java b/src/be/nikiroo/fanfix/reader/ui/GuiReaderSearch.java index 59d4f217..e7a1f2b5 100644 --- a/src/be/nikiroo/fanfix/reader/ui/GuiReaderSearch.java +++ b/src/be/nikiroo/fanfix/reader/ui/GuiReaderSearch.java @@ -1,6 +1,7 @@ package be.nikiroo.fanfix.reader.ui; import java.awt.BorderLayout; +import java.awt.Color; import java.awt.Component; import java.awt.EventQueue; import java.awt.event.ActionEvent; @@ -198,10 +199,12 @@ public class GuiReaderSearch extends JFrame { } private void updateBooks(final List infos) { + setWaitingScreen(true); inUi(new Runnable() { @Override public void run() { books.refreshBooks(infos, seeWordcount); + setWaitingScreen(false); } }); } @@ -252,57 +255,67 @@ public class GuiReaderSearch extends JFrame { }).start(); } - public void searchTag(SupportType searchOn, int page, int item, - SearchableTag tag) { + public void searchTag(final SupportType searchOn, final int page, + final int item, final SearchableTag tag) { + + setWaitingScreen(true); updateSupportType(searchOn); updateSearchBy(true); updateTags(tag); updatePages(page, maxPage); - BasicSearchable search = BasicSearchable.getSearchable(searchOn); - - if (tag != null) { - int maxPage = 0; - try { - maxPage = search.searchPages(tag); - } catch (IOException e) { - Instance.getTraceHandler().error(e); - } - - updatePages(page, maxPage); - - if (page > 0) { - List metas = null; - List subtags = null; - int count; + new Thread(new Runnable() { + @Override + public void run() { + BasicSearchable search = BasicSearchable + .getSearchable(searchOn); - if (tag.isLeaf()) { + if (tag != null) { + int maxPage = 0; try { - metas = search.search(tag, page); + maxPage = search.searchPages(tag); } catch (IOException e) { - metas = new ArrayList(); Instance.getTraceHandler().error(e); } - count = metas.size(); - } else { - subtags = tag.getChildren(); - count = subtags.size(); - } - if (item > 0) { - if (item <= count) { - if (metas != null) { - MetaData meta = metas.get(item - 1); - // TODO: select story + updatePages(page, maxPage); + + if (page > 0) { + List metas = null; + List subtags = null; + int count; + + if (tag.isLeaf()) { + try { + metas = search.search(tag, page); + } catch (IOException e) { + metas = new ArrayList(); + Instance.getTraceHandler().error(e); + } + count = metas.size(); } else { - SearchableTag subtag = subtags.get(item - 1); - // TODO: search on tag + subtags = tag.getChildren(); + count = subtags.size(); + } + + if (item > 0) { + if (item <= count) { + if (metas != null) { + MetaData meta = metas.get(item - 1); + // TODO: select story + } else { + SearchableTag subtag = subtags + .get(item - 1); + // TODO: search on tag + } + } } } } + setWaitingScreen(false); } - } + }).start(); } /** @@ -316,7 +329,7 @@ public class GuiReaderSearch extends JFrame { * @param run * the action to run */ - public void inUi(final Runnable run) { + private void inUi(final Runnable run) { if (EventQueue.isDispatchThread()) { run.run(); } else { @@ -329,4 +342,19 @@ public class GuiReaderSearch extends JFrame { } } } + + private void setWaitingScreen(final boolean waiting) { + inUi(new Runnable() { + @Override + public void run() { + GuiReaderSearch.this.setEnabled(!waiting); + // TODO: this is just an example of something to do + if (waiting) { + books.setBackground(Color.RED); + } else { + books.setBackground(null); + } + } + }); + } } -- 2.27.0