From b92e1283ebc0d70da9fbcd5a3100dd36803d2cb5 Mon Sep 17 00:00:00 2001 From: Niki Roo Date: Fri, 1 May 2020 16:06:34 +0200 Subject: [PATCH] ListModel sync tooltips --- src/be/nikiroo/utils/ui/ListModel.java | 34 +++++++++++++++++++------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/src/be/nikiroo/utils/ui/ListModel.java b/src/be/nikiroo/utils/ui/ListModel.java index 7103dbac..137897ae 100644 --- a/src/be/nikiroo/utils/ui/ListModel.java +++ b/src/be/nikiroo/utils/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); } -- 2.27.0