BooksPanel: tooltips for books
authorNiki Roo <niki@nikiroo.be>
Wed, 29 Apr 2020 21:52:16 +0000 (23:52 +0200)
committerNiki Roo <niki@nikiroo.be>
Wed, 29 Apr 2020 21:52:16 +0000 (23:52 +0200)
src/be/nikiroo/fanfix_swing/gui/BooksPanel.java
src/be/nikiroo/fanfix_swing/gui/PropertiesFrame.java
src/be/nikiroo/fanfix_swing/gui/PropertiesPanel.java

index a81441b69f1a248536411ae634bcc2a661ef327f..7842e7d8d779965c9e9c72c6bf738673e5dc94e2 100644 (file)
@@ -4,6 +4,7 @@ import java.awt.BorderLayout;
 import java.awt.Component;
 import java.awt.Dimension;
 import java.awt.Image;
+import java.awt.Window;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
 import java.awt.event.KeyAdapter;
@@ -244,7 +245,22 @@ public class BooksPanel extends ListenerPanel {
                popup = new BookPopup(Instance.getInstance().getLibrary(), informer);
                actions = new BooksPanelActions(this, informer);
                final JList6<BookInfo> list = new JList6<BookInfo>();
-               data = new ListModel<BookInfo>(list, popup);
+               data = new ListModel<BookInfo>(list, popup,
+                               new ListModel.TooltipCreator<BookInfo>() {
+                                       @Override
+                                       public Window generateTooltip(BookInfo book,
+                                                       boolean undecorated) {
+                                               if (book != null && book.getMeta() != null) {
+                                                       PropertiesFrame tooltip = new PropertiesFrame(
+                                                                       Instance.getInstance().getLibrary(),
+                                                                       book.getMeta());
+                                                       tooltip.setUndecorated(undecorated);
+                                                       return tooltip;
+                                               }
+
+                                               return null;
+                                       }
+                               });
 
                list.addMouseListener(new MouseAdapter() {
                        @Override
index cb0dcba4add82c781618a7e56cf4e2005f2353e4..9c00b5e0d3e52bc9cce5c7fa00133e659d821126 100644 (file)
@@ -1,6 +1,7 @@
 package be.nikiroo.fanfix_swing.gui;
 
 import java.awt.BorderLayout;
+import java.awt.event.MouseListener;
 
 import javax.swing.JDialog;
 import javax.swing.JPanel;
@@ -45,6 +46,12 @@ public class PropertiesFrame extends JDialog {
                int titleBarHeight = Math
                                .abs(getContentPane().getHeight() - getHeight());
 
-               this.setSize(800, desc.getHeight() + titleBarHeight);
+               this.setSize(600, desc.getHeight() + titleBarHeight);
+       }
+
+       @Override
+       public synchronized void addMouseListener(MouseListener l) {
+               super.addMouseListener(l);
+               desc.addMouseListener(l);
        }
 }
index 8bc1e02cfcd9964924b57358fca6165c94be81e1..e84816b21d731a1fd6e641686d1e7ec85b4f70c3 100644 (file)
@@ -2,7 +2,11 @@ package be.nikiroo.fanfix_swing.gui;
 
 import java.awt.BorderLayout;
 import java.awt.Color;
+import java.awt.Component;
 import java.awt.Font;
+import java.awt.event.MouseListener;
+import java.util.ArrayList;
+import java.util.List;
 import java.util.Map;
 
 import javax.swing.BorderFactory;
@@ -30,6 +34,7 @@ public class PropertiesPanel extends JPanel {
        private final int space = 10; // empty space for visual correctness
        private final int hscroll = 10; // we reserve space at the bottom for a
                                                                        // potential HScroll
+       private List<Component> listenables;
 
        /**
         * Create a new {@link PropertiesPanel}.
@@ -40,6 +45,8 @@ public class PropertiesPanel extends JPanel {
         *            the meta to describe
         */
        public PropertiesPanel(BasicLibrary lib, MetaData meta) {
+               listenables = new ArrayList<Component>();
+
                // Image
                ImageIcon img = new ImageIcon(CoverImager.generateCoverImage(lib,
                                BookInfo.fromMeta(lib, meta)));
@@ -69,12 +76,14 @@ public class PropertiesPanel extends JPanel {
                        jKey.setEditable(false);
                        jKey.setLineWrap(false);
                        jKey.setBackground(trans);
+                       listenables.add(jKey);
                        mainPanelKeys.add(jKey);
 
                        final JTextArea jValue = new JTextArea(desc.get(key));
                        jValue.setEditable(false);
                        jValue.setLineWrap(false);
                        jValue.setBackground(base);
+                       listenables.add(jValue);
                        mainPanelValues.add(jValue);
                }
 
@@ -93,15 +102,19 @@ public class PropertiesPanel extends JPanel {
                // Add all
                add(imgLabel, BorderLayout.WEST);
                add(mainPanel, BorderLayout.CENTER);
+
+               listenables.add(imgLabel);
+               listenables.add(mainPanel);
+               listenables.add(mainPanelKeys);
+               listenables.add(mainPanelValues);
        }
 
-       /**
-        * The invisible border size (multiply by 2 if you need the total width or
-        * the total height).
-        * 
-        * @return the invisible border thickness
-        */
-       public int getBorderThickness() {
-               return space;
+       @Override
+       public synchronized void addMouseListener(MouseListener l) {
+               super.addMouseListener(l);
+
+               for (Component comp : listenables) {
+                       comp.addMouseListener(l);
+               }
        }
 }