GUI search
[fanfix.git] / src / be / nikiroo / fanfix / reader / ui / GuiReaderGroup.java
index 7b15425682b96e363df67c66d7a87ac7be35da9d..a0023898bb5cadd31dc91be00e9e6c47727e2aea 100644 (file)
@@ -179,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;
+               }
        }
 
        /**
@@ -192,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<GuiReaderBookInfo>());
+       }
+
+       /**
+        * 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<GuiReaderBookInfo> infos) {
                refreshBooks(infos, words);
        }
 
@@ -270,6 +302,8 @@ public class GuiReaderGroup extends JPanel {
                pane.repaint();
                validate();
                repaint();
+
+               computeItemsPerLine();
        }
 
        /**