You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-users@xmlgraphics.apache.org by Peter Wagener <pe...@hypoluxo.com> on 2006/05/03 18:00:51 UTC
Setting Tooltip Font Family Work-Around
Hi All,
I've been reading an old thread in the archives that discussed how to
set the font of a tooltip in JSVGCanvas. The original poster was
wondering why the font of his tooltips could change size, but setting
the font family itself wouldn't have any effect. I was having a
similar issue, where my tooltips that came from SVG weren't the same
font as the tooltips from the rest of my non-SVG GUI.
The original poster was trying to use this code to set the font, font
size, and background of the tooltip box:
Font font = new Font("SansSerif", Font.PLAIN, 24); // only size shows
an effect
FontUIResource fontRes = new FontUIResource(font);
UIManager.put("ToolTip.font", fontRes);
UIManager.put("ToolTip.background", new ColorUIResource(Color.CYAN));
The result of this is that the tooltip would show up with the correct
size (24 point) and background (cyan), but the font family would not
be SanSerif. Strangely this was the only thing that was ignored.
The thread ended without a solution to this problem, and I haven't
been able to find another thread discussing this issue either.
After some digging, I think I've found the cause of the original
issue. JSVGCanvas is using 'setToolTipText(...)' to set the content
that gets displayed as a typical Swing tooltip. When calling
'setToolTip(...)' the content is formatted as HTML -- something like
this:
<html><body><tt>Some Tooltip Here</tt></body></html>
Note that the content is being wrapped up in HTML TeleType tags. By
doing this, the HTML display of the tooltip will always use TeleType;
any font set in the UIManager (including the defaults for the UI) are
overridden. This made my work-around pretty easy: in my subclass of
JSVGCanvas, override 'getToolTip()' and strip out the <tt> and </tt>
tags from the content (see code at the end).
I haven't dug into the Batik codebase enough to find out what the
reason is for using the <tt> tags in the first place though. Does
anyone know why it's doing that? I'd like to get rid of this
workaround at some point....
Thanks,
Peter
The Work-Around: In some subclass of JSVGCanvas, strip out any <tt>
and </tt> tags prior to returning the tooltip HTML:
/**
* Overriding <tt>getToolTipText</tt> in order to remove the
* TeleType tags that JSVGCanvas normally wraps any
* tooltip text in.
* @return The HTML content to be used as a tooltip
*/
public String getToolTipText() {
String text = super.getToolTipText();
if (text != null) {
text = stripTeletypeTags(text);
}
return (text);
}
/**
* Strip out TeleType tags ("<tt>" and "</tt>") from
* the given text.
* @param text The text to strip the tags out of.
* @return the modified text.
*/
private String stripTeletypeTags(String text) {
StringBuffer buff = new StringBuffer();
int ttStart = text.indexOf("<tt>");
buff.append(text.substring(0, ttStart));
int ttEndIndex = text.indexOf("</tt>");
buff.append(text.substring(ttStart + 4, ttEndIndex));
buff.append(text.substring(ttEndIndex + 5));
return (buff.toString());
}
---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
Re: Setting Tooltip Font Family Work-Around
Posted by "V. de Weger" <ba...@beno-delft.nl>.
Hi, I just noticed this old post. The way to handle this is to change the
'JSVGCanvas.CanvasUserAgent.ToolTip.descOnly' message in the batik resource
bundle.
Does anybody know how to do this from code, I prefer not to change it in my
SVN copy...
Vincent
--
View this message in context: http://www.nabble.com/Setting-Tooltip-Font-Family-Work-Around-tf1550993.html#a12869737
Sent from the Batik - Users mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org