space = popup
authorNiki Roo <niki@nikiroo.be>
Thu, 28 Mar 2019 07:39:17 +0000 (08:39 +0100)
committerNiki Roo <niki@nikiroo.be>
Thu, 28 Mar 2019 07:39:17 +0000 (08:39 +0100)
src/be/nikiroo/fanfix/reader/ui/GuiReaderBook.java
src/be/nikiroo/fanfix/reader/ui/GuiReaderGroup.java
src/be/nikiroo/fanfix/reader/ui/GuiReaderMainPanel.java

index 728964baa3faa82676f3b7a6fb6c875b6529bebf..47b462360eeb7e6f5cc634c2957866e0dde25a7b 100644 (file)
@@ -1,6 +1,7 @@
 package be.nikiroo.fanfix.reader.ui;
 
 import java.awt.BorderLayout;
+import java.awt.Component;
 import java.awt.Graphics;
 import java.awt.event.MouseEvent;
 import java.awt.event.MouseListener;
@@ -48,10 +49,19 @@ class GuiReaderBook extends JPanel {
                 * 
                 * @param book
                 *            the {@link GuiReaderBook} itself
-                * @param e
-                *            the {@link MouseEvent} that generated this call
+                * @param target
+                *            the target component for the popup
+                * @param x
+                *            the X position of the click/request (in case of popup
+                *            request from the keyboard, the center of the target is
+                *            selected as point of reference)
+                * @param y
+                *            the Y position of the click/request (in case of popup
+                *            request from the keyboard, the center of the target is
+                *            selected as point of reference)
                 */
-               public void popupRequested(GuiReaderBook book, MouseEvent e);
+               public void popupRequested(GuiReaderBook book, Component target, int x,
+                               int y);
        }
 
        private static final long serialVersionUID = 1L;
@@ -135,7 +145,7 @@ class GuiReaderBook extends JPanel {
         * 
         * @return TRUE if it is mouse-hovered
         */
-       private boolean isHovered() {
+       public boolean isHovered() {
                return this.hovered;
        }
 
@@ -145,7 +155,7 @@ class GuiReaderBook extends JPanel {
         * @param hovered
         *            TRUE if it is mouse-hovered
         */
-       private void setHovered(boolean hovered) {
+       public void setHovered(boolean hovered) {
                if (this.hovered != hovered) {
                        this.hovered = hovered;
                        repaint();
@@ -208,11 +218,8 @@ class GuiReaderBook extends JPanel {
                        }
 
                        private void popup(MouseEvent e) {
-                               for (BookActionListener listener : listeners) {
-                                       listener.select((GuiReaderBook.this));
-                                       listener.popupRequested(GuiReaderBook.this, e);
-                               }
-
+                               GuiReaderBook.this
+                                               .popup(GuiReaderBook.this, e.getX(), e.getY());
                                e.consume();
                        }
                });
@@ -239,6 +246,8 @@ class GuiReaderBook extends JPanel {
 
        /**
         * Cause a select event on this {@link GuiReaderBook}.
+        * <p>
+        * Have a look at {@link GuiReaderBook#setSelected(boolean)}.
         */
        private void select() {
                for (BookActionListener listener : listeners) {
@@ -246,6 +255,27 @@ class GuiReaderBook extends JPanel {
                }
        }
 
+       /**
+        * Request a popup.
+        * 
+        * @param target
+        *            the target component for the popup
+        * @param x
+        *            the X position of the click/request (in case of popup request
+        *            from the keyboard, the center of the target should be selected
+        *            as point of reference)
+        * @param y
+        *            the Y position of the click/request (in case of popup request
+        *            from the keyboard, the center of the target should be selected
+        *            as point of reference)
+        */
+       public void popup(Component target, int x, int y) {
+               for (BookActionListener listener : listeners) {
+                       listener.select((GuiReaderBook.this));
+                       listener.popupRequested(GuiReaderBook.this, target, x, y);
+               }
+       }
+
        /**
         * The information about the book represented by this item.
         * 
index db21c49c8c0d9414c4be0d6e3b1d4f41c043ed52..ffbcda37b19fbc19d62d44d43a94900fd205b001 100644 (file)
@@ -2,6 +2,7 @@ package be.nikiroo.fanfix.reader.ui;
 
 import java.awt.BorderLayout;
 import java.awt.Color;
+import java.awt.Component;
 import java.awt.event.ActionListener;
 import java.awt.event.ComponentAdapter;
 import java.awt.event.ComponentEvent;
@@ -9,7 +10,6 @@ import java.awt.event.FocusAdapter;
 import java.awt.event.FocusEvent;
 import java.awt.event.KeyAdapter;
 import java.awt.event.KeyEvent;
-import java.awt.event.MouseEvent;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -194,7 +194,8 @@ public class GuiReaderGroup extends JPanel {
                                        }
 
                                        @Override
-                                       public void popupRequested(GuiReaderBook book, MouseEvent e) {
+                                       public void popupRequested(GuiReaderBook book,
+                                                       Component target, int x, int y) {
                                        }
 
                                        @Override
@@ -300,12 +301,19 @@ public class GuiReaderGroup extends JPanel {
         */
        private void onKeyTyped(KeyEvent e) {
                boolean consumed = false;
-               if (e.getKeyChar() == '\n') {
+               boolean action = e.getKeyChar() == '\n';
+               boolean popup = e.getKeyChar() == ' ';
+               if (action || popup) {
                        consumed = true;
 
                        int index = getSelectedBookIndex();
                        if (index >= 0) {
-                               books.get(index).action();
+                               GuiReaderBook book = books.get(index);
+                               if (action) {
+                                       book.action();
+                               } else if (popup) {
+                                       book.popup(book, book.getWidth() / 2, book.getHeight() / 2);
+                               }
                        }
                }
 
index be523648739f9a4d80cdcf65eea2e2c95478af14..5192278992ee03e5cfae845dc4891ff5621fd3ad 100644 (file)
@@ -2,13 +2,13 @@ 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.Frame;
 import java.awt.Toolkit;
 import java.awt.datatransfer.DataFlavor;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
-import java.awt.event.MouseEvent;
 import java.io.File;
 import java.io.IOException;
 import java.lang.reflect.InvocationTargetException;
@@ -305,9 +305,10 @@ class GuiReaderMainPanel extends JPanel {
                        }
 
                        @Override
-                       public void popupRequested(GuiReaderBook book, MouseEvent e) {
+                       public void popupRequested(GuiReaderBook book, Component target,
+                                       int x, int y) {
                                JPopupMenu popup = helper.createBookPopup();
-                               popup.show(e.getComponent(), e.getX(), e.getY());
+                               popup.show(target, x, y);
                        }
 
                        @Override
@@ -635,9 +636,10 @@ class GuiReaderMainPanel extends JPanel {
                        }
 
                        @Override
-                       public void popupRequested(GuiReaderBook book, MouseEvent e) {
+                       public void popupRequested(GuiReaderBook book, Component target,
+                                       int x, int y) {
                                JPopupMenu popup = helper.createSourceAuthorPopup();
-                               popup.show(e.getComponent(), e.getX(), e.getY());
+                               popup.show(target, x, y);
                        }
 
                        @Override