From: Niki Roo Date: Fri, 1 May 2020 14:06:34 +0000 (+0200) Subject: ListModel sync tooltips X-Git-Url: https://git.nikiroo.be/?a=commitdiff_plain;h=a1d54d1127742f5cf7094d74dd51a8ce2b627dba;p=nikiroo-utils.git ListModel sync tooltips --- diff --git a/ui/ListModel.java b/ui/ListModel.java index 7103dba..137897a 100644 --- a/ui/ListModel.java +++ b/ui/ListModel.java @@ -276,10 +276,11 @@ public class ListModel extends DefaultListModel6 { fireElementChanged(oldIndex); fireElementChanged(index); - Window oldTooltip = tooltip; - tooltip = null; - if (oldTooltip != null) { - oldTooltip.setVisible(false); + synchronized (tooltipWatcher) { + if (tooltip != null) { + tooltip.setVisible(false); + } + tooltip = null; } if (ListModel.this.tooltipCreator != null) { @@ -293,6 +294,13 @@ public class ListModel extends DefaultListModel6 { @Override protected void done() { + synchronized (tooltipWatcher) { + if (tooltip != null) { + tooltip.setVisible(false); + } + tooltip = null; + } + if (index < 0 || index != hoveredIndex) { return; @@ -303,7 +311,12 @@ public class ListModel extends DefaultListModel6 { return; } - tooltip = newTooltip(index, me); + synchronized (tooltipWatcher) { + if (tooltip != null) { + tooltip.setVisible(false); + } + tooltip = newTooltip(index, me); + } } }); } @@ -575,16 +588,19 @@ public class ListModel extends DefaultListModel6 { newTooltip.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { - Window promotedTooltip = tooltipCreator .generateTooltip(value, false); - promotedTooltip.setLocation(newTooltip.getLocation()); + if (promotedTooltip != null) { + promotedTooltip.setLocation(me.getXOnScreen(), + me.getYOnScreen()); + promotedTooltip.setVisible(true); + } + newTooltip.setVisible(false); - promotedTooltip.setVisible(true); } }); - newTooltip.setLocation(me.getXOnScreen(), me.getYOnScreen()); + newTooltip.setLocation(me.getXOnScreen(), me.getYOnScreen()); newTooltip.setVisible(true); }