Hi Adrian, Frédéric,
Adrian describes the base way to do this for classes that extend Layer.
The OMGraphicHandlerLayer in OpenMap 4.6, however, has been updated to
do the heavy lifting for mouse event handling for you. To get tooltips
to appear for any OMGraphic in an OMGraphicHandlerLayer like DemoLayer
you need to do three things. First, you have to let the layer be able
to say which MouseMode it should receive events from. This can be done
in the properties file by setting the mouseModes property to the Mouse
Mode IDs, like:
demo.mouseModes=Gestures
or programmatically, like the DemoLayer in it's constructor:
setMouseModeIDsForEvents(new String[] {"Gestures"});
Next, the layer will be asked if an OMGraphic is highlightable, which
means if you want things to happen when the mouse moves over a
particular OMGraphic. The OMGraphicHandlerLayer's
isHighlightable(OMGraphic) method is called when the mouse is moved
over that OMGraphic. If you return true, three other methods will be
called:
String getToolTipTextFor(OMGraphic); //return the tooltip text
String getInfoTextFor(OMGraphic); // return info line text
void highlight(OMGraphic); // modify the OMGraphic to highlight it,
and call repaint() if needed.
You only respond to the method you want to. You don't have to disable
the tooltip or get rid of the info line text when the mouse moves off
of the OMGraphic, that's handled for you, and unhighlight gets called
when that happens, too.
The isSelectable(OMGraphic) method gets called when an OMGraphic is
clicked on, and a positive return gets the select(OMGraphic) method
called.
Hope this helps,
Don
On Jun 2, 2004, at 5:15 PM, Adrian Lumsden wrote:
>
> Hi Frédéric,
>
> I use the fireRequestToolTip method in Layer to set the tool tip.
> Assuming that you can get a mouse event (the "e" below) to figure out
> which OMGraphic the pointer is over then you can do something like
> this:
>
> OMGraphic g = gList.getOMGraphicAt(selectedOMG);
> // Get the graphic
> FeaturePlotPoint fpp = (FeaturePlotPoint)g.getAppObject();
> // Get the FeaturePlotPoint
> SegmentFeature f = fpp.getSegmentFeature();
> // Get the feature
> StringBuffer sb = new StringBuffer("<html>" +
> // Start off the HTML tool tip
> "<b><u>" + f.getFeatureType() + "</u></b>" +
> // Feature type
> "<small>");
> // Then go into small text
> String[] stuff = f.getFieldsAndData();
> // Get field names and data
> for (int i = 0; i < stuff.length;)
> // For each one
> sb.append("<br><b>" + stuff[i++] + ": </b>" + stuff[i++]);
> // Make into a line of HTML
>
> sb.append("</small></html>");
> // Wind it up
> fireRequestToolTip(e, sb.toString());
> // Set as the tool tip
>
> My OMGraphics use the AppObject to hold a reference to the object the
> OMGraphic was made from. I go back to that object and build a tool tip
> in HTML and set it. This seems to set the tool tip for the whole layer
> so when there is no OMGraphic under the mouse pointer you need to:
>
> fireHideToolTip(e);
> // Hide tool tips
>
> to turn them off. I have also found that if you set the tool tip in
> one layer and have a code path that allows you to switch layers
> without turning the tip off then you can get the tool tip for the
> other layer appearing. I have code that makes sure that the tool tip
> is cleared by using the initToolTip() method of the
> InformationDelegator.
>
> I hope that helps. If you need more information then drop me a line.
>
> all the best,
>
> Adrian
> _____________________________________________
>
> Dr. Adrian Lumsden
> Product Specialist
> Scientific Software and Systems Limited
>
> Tel: +64 4 917-6680 (direct)
> +64 4 917-6670 (reception)
> Fax: +64 4 917-6671
> E-mail: Adrian.Lumsden@blackhole4spam.sss.co.nz
>
> Visit us on the Web at: http://www.sss.co.nz
> _____________________________________________
>
> This e-mail passed SSS's content security scan.
> It is covered by the confidentiality clauses at
> http://www.sss.co.nz/content_and_confidentiality
>
>
>
>
>
> Frédéric Trifiro <job@trifiro.net>
> Sent by: owner-openmap-users@bbn.com
>
> 03/06/04 02:35
>
>
> To: openmap-users@bbn.com
> cc:
> Subject: [OpenMap Users] ToolTip for OMGraphic
>
>
>
> Hi everyone,
>
> I want to add a tooltip when the mouse comes over an OMGraphic. I saw
> that the
> mechanism was used in the DemoLayer but i don't really understand how
> it works.
> I saw the method getToolTipFor() but i can't see where, when and how
> it is
> called :p !
>
> Thanks, Fred
>
>
>
> --
> [To unsubscribe to this list send an email to "majdart@bbn.com"
> with the following text in the BODY of the message "unsubscribe
> openmap-users"]
>
>
>
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Don Dietrick, dietrick@bbn.com
BBN Technologies, Cambridge, MA
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-- [To unsubscribe to this list send an email to "majdart@bbn.com" with the following text in the BODY of the message "unsubscribe openmap-users"]Received on Wed Jun 2 20:46:57 2004
This archive was generated by hypermail 2.1.8 : Thu May 12 2005 - 07:18:38 EDT