X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Ffanfix%2Freader%2Fui%2FGuiReaderBook.java;h=47b462360eeb7e6f5cc634c2957866e0dde25a7b;hb=dad7b76cdfbc1c61739fe5e38519db5d3ca23666;hp=f0e1371eda728fa02504d5a602576f4244bedbbb;hpb=e20686b41867b6cc906240fa61b751e4711bf817;p=nikiroo-utils.git diff --git a/src/be/nikiroo/fanfix/reader/ui/GuiReaderBook.java b/src/be/nikiroo/fanfix/reader/ui/GuiReaderBook.java index f0e1371..47b4623 100644 --- a/src/be/nikiroo/fanfix/reader/ui/GuiReaderBook.java +++ b/src/be/nikiroo/fanfix/reader/ui/GuiReaderBook.java @@ -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; @@ -112,6 +122,9 @@ class GuiReaderBook extends JPanel { /** * The book current selection state. + *
+ * Setting this value to true can cause a "select" action to occur if the + * previous state was "unselected". * * @param selected * TRUE if it is selected @@ -120,6 +133,10 @@ class GuiReaderBook extends JPanel { if (this.selected != selected) { this.selected = selected; repaint(); + + if (selected) { + select(); + } } } @@ -128,7 +145,7 @@ class GuiReaderBook extends JPanel { * * @return TRUE if it is mouse-hovered */ - private boolean isHovered() { + public boolean isHovered() { return this.hovered; } @@ -138,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(); @@ -193,21 +210,16 @@ class GuiReaderBook extends JPanel { } private void click(boolean doubleClick) { - for (BookActionListener listener : listeners) { - if (doubleClick) { - listener.action(GuiReaderBook.this); - } else { - listener.select(GuiReaderBook.this); - } + if (doubleClick) { + action(); + } else { + select(); } } 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(); } }); @@ -223,6 +235,47 @@ class GuiReaderBook extends JPanel { listeners.add(listener); } + /** + * Cause an action to occur on this {@link GuiReaderBook}. + */ + public void action() { + for (BookActionListener listener : listeners) { + listener.action(GuiReaderBook.this); + } + } + + /** + * Cause a select event on this {@link GuiReaderBook}. + *
+ * Have a look at {@link GuiReaderBook#setSelected(boolean)}. + */ + private void select() { + for (BookActionListener listener : listeners) { + listener.select(GuiReaderBook.this); + } + } + + /** + * 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. *