Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 37 additions & 16 deletions src/main/java/net/rptools/maptool/client/swing/TooltipView.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@

public class TooltipView extends InlineView {

private boolean mlToolTips;
private final boolean mlToolTips;

/**
* Constructs a new view wrapped on an element.
*
* @param elem the element
* @param macroLinkToolTips if to show macrolinks as tooltips
* @param macroLinkToolTips if to show macroLinks as tooltips
*/
public TooltipView(Element elem, boolean macroLinkToolTips) {
super(elem);
Expand All @@ -38,35 +38,56 @@ public TooltipView(Element elem, boolean macroLinkToolTips) {

@Override
public String getToolTipText(float x, float y, Shape allocation) {
AttributeSet attSet;
boolean isInsideChat = mlToolTips;
boolean showTitleAsTooltip = AppPreferences.suppressToolTipsForMacroLinks.get();
boolean isMacroLink = false;
AttributeSet attSet = (AttributeSet) getElement().getAttributes().getAttribute(HTML.Tag.A);
String href;
String title = null;

attSet = (AttributeSet) getElement().getAttributes().getAttribute(HTML.Tag.A);
if (attSet != null) {
Object attribute = attSet.getAttribute(HTML.Attribute.HREF);
String href;

if (attribute != null) {
href = attribute.toString();
isMacroLink =
href.toLowerCase().startsWith("macro:")
|| (href.toLowerCase().startsWith("lib:")
&& href.toLowerCase().contains("/macro/"));
} else {
href = I18N.getString("macroLink.error.tooltip.bad.href");
}

if (href.startsWith("macro:")) {
boolean isInsideChat = mlToolTips;
boolean allowToolTipToShow = !AppPreferences.suppressToolTipsForMacroLinks.get();
if (isInsideChat && allowToolTipToShow) {
attribute = attSet.getAttribute(HTML.Attribute.TITLE);
if (attribute != null) {
title = attribute.toString();
}

if (isInsideChat) {
if (!isMacroLink || showTitleAsTooltip) {
// not using anti-cheat tooltip, or not a macroLink, i.e. not suppress tooltip
if (title != null) {
return title;
}
} else if (href.toLowerCase().startsWith("macro:")) {
// use anti-cheat tooltip, i.e. suppress normal tooltip
return MacroLinkFunction.getInstance().macroLinkToolTip(href);
} else if (href.toLowerCase().startsWith("lib:")) {
// just show the URL
return href;
}
// if we are not displaying macro link tooltips let if fall through so that any span
// tooltips will be displayed
} else {
return href;
}
}

// first fallback - use title
if (title != null) {
return title;
}
// second fallback - span tag
attSet = (AttributeSet) getElement().getAttributes().getAttribute(HTML.Tag.SPAN);
if (attSet != null) return (String) attSet.getAttribute(HTML.Attribute.TITLE);

if (attSet != null) {
return (String) attSet.getAttribute(HTML.Attribute.TITLE);
}
// nothing to show
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -971,8 +971,8 @@ Preferences.label.upnp.timeout.tooltip = Timeout period in millisecon
Preferences.label.macros.permissions = Enable External Macro Access
Preferences.label.macros.permissions.tooltip = Enable macros to call functions that can access your drive and http services. The following functions will be enabled: getRequest, postRequest, exportData, getEnvironmentVariable.
Preferences.label.chat.macrolinks = Suppress ToolTips for MacroLinks
Preferences.label.chat.macrolinks.tooltip = MacroLinks show normally tooltips that state informations about the link target. This is a anti cheating device. This options let you disable this tooltips for aesthetic reasons.
Preference.checkbox.chat.macrolinks.tooltip = <html>Enabled: do not show tooltips for macroLink<br>Disabled (default): show tooltips for macroLinks
Preferences.label.chat.macrolinks.tooltip = MacroLinks normally display a tooltip containing details of the link URL instead of a link's normal tooltip. This is an anti-cheating device. This option let you disable this behaviour.
Preference.checkbox.chat.macrolinks.tooltip = <html>Enabled: show normal tooltips for macroLinks<br>Disabled (default): show the link details as tooltip
PreferencesDialog.themeChangeWarning = Changing the theme requires a restart of MapTool to take effect.
PreferencesDialog.themeChangeWarningTitle = Theme Change.
Preferences.combo.themes.filter.all = All
Expand Down
Loading