This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 107107 - Tooltips for highlights
Summary: Tooltips for highlights
Alias: None
Product: editor
Classification: Unclassified
Component: Painting & Printing (show other bugs)
Version: 6.x
Hardware: All All
: P2 blocker (vote)
Assignee: Vitezslav Stejskal
Depends on:
Blocks: 108179
  Show dependency tree
Reported: 2007-06-19 00:39 UTC by Vitezslav Stejskal
Modified: 2007-11-05 13:45 UTC (History)
2 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Note You need to log in before you can comment on or make changes to this bug.
Description Vitezslav Stejskal 2007-06-19 00:39:47 UTC
In many situations highlights are provided to signal a problem to a user, eg. an error or warning in the code, use of
deprecated API, etc. Presently modules have no easy way how to provide a tooltip for the areas marked with those highlights.

It would be beneficial if modules could simply add tooltip text to the highlight itself and if the editor infrastructure
could show that text when a user hovers their mouse over the highlighted text. For module this should be the easiest
way, because they already have all they need in place for creating the highlight and they know what the highlight means.

Please see the UI spec for details:
Comment 1 Miloslav Metelka 2007-06-19 08:46:45 UTC
Yes, we should have something like this.
I've looked into StyleConstants whether there isn't a suitable AttributeSet key already but there isn't. So we could add
it to EditorStyleConstants.
IMHO we should consider having an evaluator-like approach since it could be significantly faster to just pass evaluator
and only evaluate once the user hovers with the mouse over the highlight. We should also consider evaluator instances
reuse by having args like component and offset.
The text should support html (like JLabel) i.e. "<html>..."

public final class EditorStyleConstants {

     * Name of the display name attribute.
    public static final Object ToolTipEvaluatorName = new EditorStyleConstants("tool tip evaluator"); //NOI18N

Off-topic: Names of constants: Do we want the above "tool tip evaluator" or "ToolTipEvaluator"? The StyleConstants mixes
both. Personally I would a bit more prefer the latter one.

public interface ToolTipEvaluator {

    String getToolTipText(JTextComponent c, int offset); // Or JComponent ??


The TTE would be in the settings api package.
What do you think?
Comment 2 Vitezslav Stejskal 2007-08-30 10:44:22 UTC
I think we could make it a little bit more generic and have something like:

interface HighlightAttributeValue {
  Object getValue(JTextComponent component, Object attributeKey, int startOffset, int endOffset);

It would be in and modules could use instances of this interface as values for attributes
in their highlights (AttributeSets). The meaning of the value returned from getValue would be determined by the
attribute key it was supplied for. So, we could have EditorStyleConstants.Tooltip key, which value would either be a
String or HighlightAttributeValue instance returning String from its getValue method. The meaning of this string would
be a tooltip for the area in the editor that spans the highlight with such an attribute.
Comment 3 Vitezslav Stejskal 2007-09-13 12:00:02 UTC
It's now possible to add EditorStyleConstants.Tooltip attribute to highlights and specify its value either as String or

Checking in editor/nbproject/project.xml;
/cvs/editor/nbproject/project.xml,v  <--  project.xml
new revision: 1.36; previous revision: 1.35
Checking in editor/lib2/nbproject/;
/cvs/editor/lib2/nbproject/,v  <--
new revision: 1.6; previous revision: 1.5
Checking in editor/settings/src/org/netbeans/api/editor/settings/;
/cvs/editor/settings/src/org/netbeans/api/editor/settings/,v  <--
new revision: 1.5; previous revision: 1.4
RCS file: /cvs/editor/lib2/src/org/netbeans/spi/editor/highlighting/,v
Checking in editor/lib2/src/org/netbeans/spi/editor/highlighting/;
/cvs/editor/lib2/src/org/netbeans/spi/editor/highlighting/,v  <--
initial revision: 1.1
Checking in editor/lib2/apichanges.xml;
/cvs/editor/lib2/apichanges.xml,v  <--  apichanges.xml
new revision: 1.6; previous revision: 1.5
Checking in editor/settings/api/apichanges.xml;
/cvs/editor/settings/api/apichanges.xml,v  <--  apichanges.xml
new revision: 1.13; previous revision: 1.12
Checking in editor/src/org/netbeans/modules/editor/;
/cvs/editor/src/org/netbeans/modules/editor/,v  <--
new revision: 1.20; previous revision: 1.19
Checking in editor/settings/;
/cvs/editor/settings/,v  <--
new revision: 1.12; previous revision: 1.11
Checking in editor/lib2/src/org/netbeans/modules/editor/lib2/highlighting/;
/cvs/editor/lib2/src/org/netbeans/modules/editor/lib2/highlighting/,v  <--
new revision: 1.8; previous revision: 1.7