Lines 106-111
Link Here
|
106 |
*/ |
106 |
*/ |
107 |
public class ToolTipSupport { |
107 |
public class ToolTipSupport { |
108 |
|
108 |
|
|
|
109 |
// -J-Dorg.netbeans.editor.ext.ToolTipSupport.level=FINE |
109 |
private static final Logger LOG = Logger.getLogger(ToolTipSupport.class.getName()); |
110 |
private static final Logger LOG = Logger.getLogger(ToolTipSupport.class.getName()); |
110 |
|
111 |
|
111 |
static { |
112 |
static { |
Lines 189-222
Link Here
|
189 |
|
190 |
|
190 |
private static final MouseListener NO_OP_MOUSE_LISTENER = new MouseAdapter() {}; |
191 |
private static final MouseListener NO_OP_MOUSE_LISTENER = new MouseAdapter() {}; |
191 |
|
192 |
|
|
|
193 |
/** @Since 2.10 */ |
194 |
public static final int FLAG_HIDE_ON_MOUSE_MOVE = 1; |
195 |
/** @Since 2.10 */ |
196 |
public static final int FLAG_HIDE_ON_TIMER = 2; |
197 |
/** @Since 2.10 */ |
198 |
public static final int FLAG_PERMANENT = 4; |
199 |
|
200 |
/** @Since 2.10 */ |
201 |
public static final int FLAGS_LIGHTWEIGHT_TOOLTIP = FLAG_HIDE_ON_MOUSE_MOVE | FLAG_HIDE_ON_TIMER; |
202 |
/** @Since 2.10 */ |
203 |
public static final int FLAGS_HEAVYWEIGHT_TOOLTIP = FLAG_PERMANENT; |
204 |
|
192 |
private final EditorUI extEditorUI; |
205 |
private final EditorUI extEditorUI; |
193 |
|
|
|
194 |
private JComponent toolTip; |
195 |
|
196 |
private String toolTipText; |
197 |
|
198 |
private final Timer enterTimer; |
206 |
private final Timer enterTimer; |
199 |
|
|
|
200 |
private final Timer exitTimer; |
207 |
private final Timer exitTimer; |
|
|
208 |
private final PropertyChangeSupport pcs = new PropertyChangeSupport(this); |
209 |
private final Listener listener = new Listener(); |
201 |
|
210 |
|
202 |
private boolean enabled; |
211 |
private boolean enabled; |
203 |
|
212 |
private MouseEvent lastMouseEvent; |
204 |
/** Status of the tooltip visibility. */ |
213 |
private boolean glyphListenerAdded = false; |
205 |
private int status; |
|
|
206 |
|
214 |
|
207 |
private MouseEvent lastMouseEvent; |
215 |
// The actual tooltip instance related information |
208 |
|
216 |
private int status; // Status of the tooltip visibility |
209 |
private PropertyChangeSupport pcs; |
217 |
private JComponent toolTip; |
210 |
|
218 |
private String toolTipText; |
211 |
private PopupManager.HorizontalBounds horizontalBounds = PopupManager.ViewPortBounds; |
219 |
private PopupManager.HorizontalBounds horizontalBounds = PopupManager.ViewPortBounds; |
212 |
private PopupManager.Placement placement = PopupManager.AbovePreferred; |
220 |
private PopupManager.Placement placement = PopupManager.AbovePreferred; |
213 |
|
|
|
214 |
private int verticalAdjustment; |
221 |
private int verticalAdjustment; |
215 |
private int horizontalAdjustment; |
222 |
private int horizontalAdjustment; |
216 |
|
223 |
private int flags; |
217 |
private boolean glyphListenerAdded = false; |
|
|
218 |
|
219 |
private final Listener listener = new Listener(); |
220 |
|
224 |
|
221 |
/** Construct new support for tooltips. |
225 |
/** Construct new support for tooltips. |
222 |
*/ |
226 |
*/ |
Lines 258-279
Link Here
|
258 |
setToolTip(toolTip, PopupManager.ViewPortBounds, PopupManager.AbovePreferred); |
262 |
setToolTip(toolTip, PopupManager.ViewPortBounds, PopupManager.AbovePreferred); |
259 |
} |
263 |
} |
260 |
|
264 |
|
261 |
public void setToolTip(JComponent toolTip, PopupManager.HorizontalBounds horizontalBounds, |
265 |
public void setToolTip(JComponent toolTip, PopupManager.HorizontalBounds horizontalBounds, PopupManager.Placement placement) { |
262 |
PopupManager.Placement placement) { |
|
|
263 |
setToolTip(toolTip, PopupManager.ViewPortBounds, PopupManager.AbovePreferred, 0, 0); |
266 |
setToolTip(toolTip, PopupManager.ViewPortBounds, PopupManager.AbovePreferred, 0, 0); |
264 |
} |
267 |
} |
265 |
|
268 |
|
266 |
public void setToolTip(JComponent toolTip, PopupManager.HorizontalBounds horizontalBounds, |
269 |
public void setToolTip( |
267 |
PopupManager.Placement placement, int horizontalAdjustment, int verticalAdjustment) { |
270 |
JComponent toolTip, |
|
|
271 |
PopupManager.HorizontalBounds horizontalBounds, |
272 |
PopupManager.Placement placement, |
273 |
int horizontalAdjustment, |
274 |
int verticalAdjustment |
275 |
) { |
276 |
setToolTip(toolTip, horizontalBounds, placement, horizontalAdjustment, verticalAdjustment, FLAGS_LIGHTWEIGHT_TOOLTIP); |
277 |
} |
278 |
|
279 |
/** |
280 |
* @Since 2.10 |
281 |
*/ |
282 |
public void setToolTip( |
283 |
JComponent toolTip, |
284 |
PopupManager.HorizontalBounds horizontalBounds, |
285 |
PopupManager.Placement placement, |
286 |
int horizontalAdjustment, |
287 |
int verticalAdjustment, |
288 |
int flags |
289 |
) { |
268 |
JComponent oldToolTip = this.toolTip; |
290 |
JComponent oldToolTip = this.toolTip; |
269 |
|
291 |
|
270 |
LOG.log(Level.FINE, "setTooltip: {0}", toolTip); //NOI18N |
292 |
if (LOG.isLoggable(Level.FINE)) { |
|
|
293 |
LOG.log(Level.FINE, "setTooltip: {0}, horizontalBounds={1}, placement={2}, horizontalAdjustment={3}, verticalAdjustment={4}, flags={5}", new Object [] { //NOI18N |
294 |
toolTip, horizontalBounds, placement, horizontalAdjustment, verticalAdjustment, flags |
295 |
}); |
296 |
} |
271 |
|
297 |
|
272 |
this.toolTip = toolTip; |
298 |
this.toolTip = toolTip; |
273 |
this.horizontalBounds = horizontalBounds; |
299 |
this.horizontalBounds = horizontalBounds; |
274 |
this.placement = placement; |
300 |
this.placement = placement; |
275 |
this.horizontalAdjustment = horizontalAdjustment; |
301 |
this.horizontalAdjustment = horizontalAdjustment; |
276 |
this.verticalAdjustment = verticalAdjustment; |
302 |
this.verticalAdjustment = verticalAdjustment; |
|
|
303 |
this.flags = flags; |
277 |
|
304 |
|
278 |
if (this.toolTip.getClientProperty(MOUSE_LISTENER) == null) { |
305 |
if (this.toolTip.getClientProperty(MOUSE_LISTENER) == null) { |
279 |
this.toolTip.putClientProperty(MOUSE_LISTENER, NO_OP_MOUSE_LISTENER); |
306 |
this.toolTip.putClientProperty(MOUSE_LISTENER, NO_OP_MOUSE_LISTENER); |
Lines 499-504
Link Here
|
499 |
* @since 2.3 |
526 |
* @since 2.3 |
500 |
*/ |
527 |
*/ |
501 |
public void setToolTipVisible(boolean visible) { |
528 |
public void setToolTipVisible(boolean visible) { |
|
|
529 |
LOG.log(Level.FINE, "setToolTipVisible: visible={0}, status={1}, enabled={2}", new Object [] { //NOI18N |
530 |
visible, status, enabled |
531 |
}); |
532 |
|
502 |
if (!visible) { // ensure the timers are stopped |
533 |
if (!visible) { // ensure the timers are stopped |
503 |
enterTimer.stop(); |
534 |
enterTimer.stop(); |
504 |
exitTimer.stop(); |
535 |
exitTimer.stop(); |
Lines 524-529
Link Here
|
524 |
pm.uninstall(toolTip); |
555 |
pm.uninstall(toolTip); |
525 |
} |
556 |
} |
526 |
} |
557 |
} |
|
|
558 |
toolTip = null; |
527 |
} |
559 |
} |
528 |
|
560 |
|
529 |
setStatus(STATUS_HIDDEN); |
561 |
setStatus(STATUS_HIDDEN); |
Lines 537-542
Link Here
|
537 |
public boolean isToolTipVisible() { |
569 |
public boolean isToolTipVisible() { |
538 |
return status > STATUS_VISIBILITY_ENABLED; |
570 |
return status > STATUS_VISIBILITY_ENABLED; |
539 |
} |
571 |
} |
|
|
572 |
|
573 |
private boolean isToolTipShowing() { |
574 |
return toolTip != null && toolTip.isShowing(); |
575 |
} |
540 |
|
576 |
|
541 |
/** @return status of the tooltip visibility. It can |
577 |
/** @return status of the tooltip visibility. It can |
542 |
* be {@link #STATUS_HIDDEN} |
578 |
* be {@link #STATUS_HIDDEN} |
Lines 849-872
Link Here
|
849 |
setToolTipText(component.getToolTipText()); |
885 |
setToolTipText(component.getToolTipText()); |
850 |
} |
886 |
} |
851 |
|
887 |
|
852 |
private synchronized PropertyChangeSupport getPCS() { |
|
|
853 |
if (pcs == null) { |
854 |
pcs = new PropertyChangeSupport(this); |
855 |
} |
856 |
return pcs; |
857 |
} |
858 |
|
859 |
/** Add the listener for the property changes. The names |
888 |
/** Add the listener for the property changes. The names |
860 |
* of the supported properties are defined |
889 |
* of the supported properties are defined |
861 |
* as "PROP_" public static string constants. |
890 |
* as "PROP_" public static string constants. |
862 |
* @param listener listener to be added. |
891 |
* @param listener listener to be added. |
863 |
*/ |
892 |
*/ |
864 |
public void addPropertyChangeListener(PropertyChangeListener listener) { |
893 |
public void addPropertyChangeListener(PropertyChangeListener listener) { |
865 |
getPCS().addPropertyChangeListener(listener); |
894 |
pcs.addPropertyChangeListener(listener); |
866 |
} |
895 |
} |
867 |
|
896 |
|
868 |
public void removePropertyChangeListener(PropertyChangeListener listener) { |
897 |
public void removePropertyChangeListener(PropertyChangeListener listener) { |
869 |
getPCS().removePropertyChangeListener(listener); |
898 |
pcs.removePropertyChangeListener(listener); |
870 |
} |
899 |
} |
871 |
|
900 |
|
872 |
/** Fire the change of the given property. |
901 |
/** Fire the change of the given property. |
Lines 874-882
Link Here
|
874 |
* @param oldValue old value of the property |
903 |
* @param oldValue old value of the property |
875 |
* @param newValue new value of the property. |
904 |
* @param newValue new value of the property. |
876 |
*/ |
905 |
*/ |
877 |
protected void firePropertyChange(String propertyName, |
906 |
protected void firePropertyChange(String propertyName, Object oldValue, Object newValue) { |
878 |
Object oldValue, Object newValue) { |
907 |
pcs.firePropertyChange(propertyName, oldValue, newValue); |
879 |
getPCS().firePropertyChange(propertyName, oldValue, newValue); |
|
|
880 |
} |
908 |
} |
881 |
|
909 |
|
882 |
private static void filterBindings(ActionMap actionMap) { |
910 |
private static void filterBindings(ActionMap actionMap) { |
Lines 956-965
Link Here
|
956 |
|
984 |
|
957 |
public @Override void actionPerformed(ActionEvent evt) { |
985 |
public @Override void actionPerformed(ActionEvent evt) { |
958 |
if (evt.getSource() == enterTimer) { |
986 |
if (evt.getSource() == enterTimer) { |
959 |
setToolTipVisible(true); |
987 |
if (!isToolTipShowing() || (flags & FLAG_PERMANENT) == 0) { |
|
|
988 |
setToolTipVisible(true); |
989 |
} |
960 |
|
990 |
|
961 |
} else if (evt.getSource() == exitTimer) { |
991 |
} else if (evt.getSource() == exitTimer) { |
962 |
setToolTipVisible(false); |
992 |
if (!isToolTipShowing() || (flags & FLAG_HIDE_ON_TIMER) != 0) { |
|
|
993 |
setToolTipVisible(false); |
994 |
} |
963 |
} |
995 |
} |
964 |
} |
996 |
} |
965 |
|
997 |
|
Lines 1001-1007
Link Here
|
1001 |
|
1033 |
|
1002 |
public @Override void mouseExited(MouseEvent evt) { |
1034 |
public @Override void mouseExited(MouseEvent evt) { |
1003 |
lastMouseEvent = evt; |
1035 |
lastMouseEvent = evt; |
1004 |
if (toolTip != null && toolTip.isShowing()) { |
1036 |
if (isToolTipShowing()) { |
1005 |
Rectangle r = new Rectangle(toolTip.getLocationOnScreen(), toolTip.getSize()); |
1037 |
Rectangle r = new Rectangle(toolTip.getLocationOnScreen(), toolTip.getSize()); |
1006 |
|
1038 |
|
1007 |
if (LOG.isLoggable(Level.FINE)) { |
1039 |
if (LOG.isLoggable(Level.FINE)) { |
Lines 1013-1019
Link Here
|
1013 |
return; |
1045 |
return; |
1014 |
} |
1046 |
} |
1015 |
} |
1047 |
} |
1016 |
setToolTipVisible(false); |
1048 |
|
|
|
1049 |
if (!isToolTipShowing() || (flags & FLAG_HIDE_ON_MOUSE_MOVE) != 0) { |
1050 |
setToolTipVisible(false); |
1051 |
} |
1017 |
} |
1052 |
} |
1018 |
|
1053 |
|
1019 |
// ------------------------------------------------------------------- |
1054 |
// ------------------------------------------------------------------- |
Lines 1026-1031
Link Here
|
1026 |
} |
1061 |
} |
1027 |
|
1062 |
|
1028 |
public @Override void mouseMoved(MouseEvent evt) { |
1063 |
public @Override void mouseMoved(MouseEvent evt) { |
|
|
1064 |
if (LOG.isLoggable(Level.FINE)) { |
1065 |
LOG.log(Level.FINE, "mouseMoved: x=" + evt.getX() + "; y=" + evt.getY() + "enabled=" + enabled + ", status=" + status + ", flags=" + flags); //NOI18N |
1066 |
} |
1067 |
|
1029 |
if (toolTip != null) { |
1068 |
if (toolTip != null) { |
1030 |
Rectangle r = (Rectangle) toolTip.getClientProperty(MOUSE_MOVE_IGNORED_AREA); |
1069 |
Rectangle r = (Rectangle) toolTip.getClientProperty(MOUSE_MOVE_IGNORED_AREA); |
1031 |
if (LOG.isLoggable(Level.FINE)) { |
1070 |
if (LOG.isLoggable(Level.FINE)) { |
Lines 1037-1043
Link Here
|
1037 |
} |
1076 |
} |
1038 |
} |
1077 |
} |
1039 |
|
1078 |
|
1040 |
setToolTipVisible(false); |
1079 |
if (!isToolTipShowing() || (flags & FLAG_HIDE_ON_MOUSE_MOVE) != 0) { |
|
|
1080 |
setToolTipVisible(false); |
1081 |
} |
1082 |
|
1041 |
if (enabled) { |
1083 |
if (enabled) { |
1042 |
enterTimer.restart(); |
1084 |
enterTimer.restart(); |
1043 |
} |
1085 |
} |