X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Ffanfix%2Freader%2Fui%2FGuiReaderGroup.java;h=a0023898bb5cadd31dc91be00e9e6c47727e2aea;hb=a12b668f37bdaf852ca2377739fd73b610f928c8;hp=2d466294a1483781d3a64148bc4aa5955c3d568d;hpb=e92e4ae338d932e6b65e855b4b710e14b5ace1b7;p=fanfix.git diff --git a/src/be/nikiroo/fanfix/reader/ui/GuiReaderGroup.java b/src/be/nikiroo/fanfix/reader/ui/GuiReaderGroup.java index 2d46629..a002389 100644 --- a/src/be/nikiroo/fanfix/reader/ui/GuiReaderGroup.java +++ b/src/be/nikiroo/fanfix/reader/ui/GuiReaderGroup.java @@ -3,6 +3,8 @@ package be.nikiroo.fanfix.reader.ui; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Component; +import java.awt.Graphics; +import java.awt.Rectangle; import java.awt.event.ActionListener; import java.awt.event.ComponentAdapter; import java.awt.event.ComponentEvent; @@ -29,6 +31,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 +55,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 +115,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) @@ -140,8 +179,13 @@ public class GuiReaderGroup extends JPanel { * up/down one line at a time. */ private void computeItemsPerLine() { - // TODO - itemsPerLine = 5; + itemsPerLine = 1; + + if (books != null && books.size() > 0) { + // this.pane holds all the books with a hgap of 5 px + int wbook = books.get(0).getWidth() + 5; + itemsPerLine = pane.getWidth() / wbook; + } } /** @@ -153,6 +197,33 @@ public class GuiReaderGroup extends JPanel { */ public void setActionListener(BookActionListener action) { this.action = action; + refreshBooks(); + } + + /** + * Clear all the books in this {@link GuiReaderGroup}. + */ + public void clear() { + refreshBooks(new ArrayList()); + } + + /** + * Refresh the list of {@link GuiReaderBook}s displayed in the control. + * + * @param infos + * the new list of infos + */ + public void refreshBooks() { + refreshBooks(infos, words); + } + + /** + * Refresh the list of {@link GuiReaderBook}s displayed in the control. + * + * @param infos + * the new list of infos + */ + public void refreshBooks(List infos) { refreshBooks(infos, words); } @@ -188,7 +259,7 @@ public class GuiReaderGroup extends JPanel { if (infos != null) { for (GuiReaderBookInfo info : infos) { boolean isCached = false; - if (info.getMeta() != null) { + if (info.getMeta() != null && info.getMeta().getLuid() != null) { isCached = reader.isCached(info.getMeta().getLuid()); } @@ -231,6 +302,8 @@ public class GuiReaderGroup extends JPanel { pane.repaint(); validate(); repaint(); + + computeItemsPerLine(); } /** @@ -386,4 +459,19 @@ public class GuiReaderGroup extends JPanel { e.consume(); } } + + @Override + public void paint(Graphics g) { + super.paint(g); + + Rectangle clip = g.getClipBounds(); + if (clip.getWidth() <= 0 || clip.getHeight() <= 0) { + return; + } + + if (!isEnabled()) { + g.setColor(new Color(128, 128, 128, 128)); + g.fillRect(clip.x, clip.y, clip.width, clip.height); + } + } }