From 5c3848e8d6f6d37f8b411d3530511694454aae7a Mon Sep 17 00:00:00 2001 From: Niki Roo Date: Wed, 29 Apr 2020 23:52:16 +0200 Subject: [PATCH] BooksPanel: tooltips for books --- .../nikiroo/fanfix_swing/gui/BooksPanel.java | 18 +++++++++++- .../fanfix_swing/gui/PropertiesFrame.java | 9 +++++- .../fanfix_swing/gui/PropertiesPanel.java | 29 ++++++++++++++----- 3 files changed, 46 insertions(+), 10 deletions(-) diff --git a/src/be/nikiroo/fanfix_swing/gui/BooksPanel.java b/src/be/nikiroo/fanfix_swing/gui/BooksPanel.java index a81441b6..7842e7d8 100644 --- a/src/be/nikiroo/fanfix_swing/gui/BooksPanel.java +++ b/src/be/nikiroo/fanfix_swing/gui/BooksPanel.java @@ -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 list = new JList6(); - data = new ListModel(list, popup); + data = new ListModel(list, popup, + new ListModel.TooltipCreator() { + @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 diff --git a/src/be/nikiroo/fanfix_swing/gui/PropertiesFrame.java b/src/be/nikiroo/fanfix_swing/gui/PropertiesFrame.java index cb0dcba4..9c00b5e0 100644 --- a/src/be/nikiroo/fanfix_swing/gui/PropertiesFrame.java +++ b/src/be/nikiroo/fanfix_swing/gui/PropertiesFrame.java @@ -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); } } diff --git a/src/be/nikiroo/fanfix_swing/gui/PropertiesPanel.java b/src/be/nikiroo/fanfix_swing/gui/PropertiesPanel.java index 8bc1e02c..e84816b2 100644 --- a/src/be/nikiroo/fanfix_swing/gui/PropertiesPanel.java +++ b/src/be/nikiroo/fanfix_swing/gui/PropertiesPanel.java @@ -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 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(); + // 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); + } } } -- 2.27.0