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

Summary: Tooltips for highlights
Product: editor Reporter: Vitezslav Stejskal <vstejskal>
Component: Painting & PrintingAssignee: Vitezslav Stejskal <vstejskal>
Status: RESOLVED FIXED    
Severity: blocker CC: jlahoda, phrebejk
Priority: P2    
Version: 6.x   
Hardware: All   
OS: All   
Issue Type: DEFECT Exception Reporter:
Bug Depends on:    
Bug Blocks: 108179    

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:
http://ui.netbeans.org/docs/ui/editor_fonts_colors/Editor_fonts_and_colors.htm
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>..."
E.g.

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 o.n.spi.e.highlighting.support 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
HighlightAttributeValue<String>.


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