GUI: fix keyboard up/down in lib
authorNiki Roo <niki@nikiroo.be>
Tue, 16 Apr 2019 17:12:50 +0000 (19:12 +0200)
committerNiki Roo <niki@nikiroo.be>
Tue, 16 Apr 2019 17:12:50 +0000 (19:12 +0200)
src/be/nikiroo/fanfix/reader/ui/GuiReaderCoverImager.java
src/be/nikiroo/fanfix/reader/ui/GuiReaderGroup.java

index 0bbf82eb47c29dcaab4a4a3fdee38cf9a995e7c3..f46ec1bb8c2d9279b58666d015b4ab9e7c7ad48b 100644 (file)
@@ -129,6 +129,24 @@ class GuiReaderCoverImager {
                return generateCoverIcon(lib, GuiReaderBookInfo.fromMeta(meta));
        }
 
+       /**
+        * The width of a cover image.
+        * 
+        * @return the width
+        */
+       static public int getCoverWidth() {
+               return SPINE_WIDTH + COVER_WIDTH;
+       }
+
+       /**
+        * The height of a cover image.
+        * 
+        * @return the height
+        */
+       static public int getCoverHeight() {
+               return COVER_HEIGHT + HOFFSET;
+       }
+
        /**
         * Generate a cover icon based upon the given {@link GuiReaderBookInfo}.
         * 
@@ -158,9 +176,8 @@ class GuiReaderCoverImager {
                if (resizedImage == null) {
                        try {
                                Image cover = info.getBaseImage(lib);
-                               resizedImage = new BufferedImage(SPINE_WIDTH + COVER_WIDTH,
-                                               SPINE_HEIGHT + COVER_HEIGHT + HOFFSET,
-                                               BufferedImage.TYPE_4BYTE_ABGR);
+                               resizedImage = new BufferedImage(getCoverWidth(),
+                                               getCoverHeight(), BufferedImage.TYPE_4BYTE_ABGR);
 
                                Graphics2D g = resizedImage.createGraphics();
                                try {
index 7b15425682b96e363df67c66d7a87ac7be35da9d..17bf43cbb455a66bb357e68ddb53f0d97d426ebb 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;
+               }
        }
 
        /**
@@ -270,6 +275,8 @@ public class GuiReaderGroup extends JPanel {
                pane.repaint();
                validate();
                repaint();
+
+               computeItemsPerLine();
        }
 
        /**