X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Ffanfix%2Freader%2Fui%2FGuiReaderGroup.java;h=7275498ff3d9c6079907886c07d092ae80adad1e;hb=dc3b0033126c7f8158499b8ae9759a22f29d78ac;hp=df3b74a0bdaaab9d9da355dd4943f7ba0e94f02f;hpb=c499d79f13535082dd25c7ee46e897d3372c4299;p=fanfix.git diff --git a/src/be/nikiroo/fanfix/reader/ui/GuiReaderGroup.java b/src/be/nikiroo/fanfix/reader/ui/GuiReaderGroup.java index df3b74a..7275498 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; @@ -177,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; + } } /** @@ -190,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); } @@ -268,6 +302,8 @@ public class GuiReaderGroup extends JPanel { pane.repaint(); validate(); repaint(); + + computeItemsPerLine(); } /** @@ -326,7 +362,7 @@ public class GuiReaderGroup extends JPanel { * @param index * the index of the book to select, can be outside the bounds * (either all the items will be unselected or the first or last - * book will then be selected, see forceRange>/tt>) + * book will then be selected, see forceRange>) * @param forceRange * TRUE to constraint the index to the first/last element, FALSE * to unselect when outside the range @@ -423,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); + } + } }