Re: [OpenMap Users] mouse events

From: Don Dietrick <>
Date: Fri, 3 Dec 2004 09:45:26 -0500

Hi Cary,

Your understanding is pretty good, comments below...

On Dec 3, 2004, at 8:56 AM, Cary O'Brien wrote:

> SteveC wrote:
>> Hi,
>> I have an applet using a BufferedMapBean only. It works fine but I'm
>> not
>> getting mouse events. It basically follows the example
>> with my own Layer subclass being used. I've written a MapMouseListener
>> and the get method etc etc etc in. I know I have to use a
>> SimpleMapHandler or similar to actually get events. But I don't know
>> how.
>> There is a SimpleMap2 example here:
>> but I can't get it to work without having to use an OpenMapFrame,
>> which
>> I don't want.
>> Is there an example using just the bean (not the toolbar, menu, etc)
>> somewhere or could someone give me a quick snippet of code that should
>> work?
> DISCLAMER: I'm just getting started with OpenMap, so any and all of
> this may be
> completly wrong!
> I'm working on REALLY understanding how mouse events work in openmap,
> but I'm not there
> yet. That being said, I have gotten a few custom mouse behaviors to
> work, so I have some idea
> of how it is all put together.
> There seem to be a bunch of different ways to get mouse events, at
> different levels in the system.
> The easy way:
> The ShapeLayer subclassesOMGraphicHandlerLayer, which has extensive
> support for pre-defined
> mouse events. This means if you want to know when a specific
> OMGraphic is selected or provide
> a pop-up menu for the item, you can do this by subclassing ShapeLayer,
> and overriding any methods
> in GestureResponsePolicy you want to handle , like select() or
> getToolTipText().
> You also need to set the mouse mode, and if you want to switch between
> navigate mouse mode
> (drag out a square and go there) and Gesture mouse mode (select an
> OMGraphic) you need a
> MouseDelegator (??) and MouseModePanel.

The mouse modes are the actual listeners to the MapBean, receiving the
events. One mouse mode is active at a time, and the MouseDelegator
controls which one that is. The
MouseModePanel/MouseModeButtonPanel/MouseModeMenu are gui objects that
know how to talk to the MouseDelegator, but you can also talk to the
MouseDelegator programmatically.

> Well, perhaps this is not that easy.
> The fancy way:
> You'd have to set up your own response policy. I really don't
> understand how to do this yet.

The OMGraphicHandlerLayer can have MapMouseInterpreter object that does
the work of determining how mouse events relate to OMGraphics. It
calls it's response policy to react to what it figures out (which is
the layer). If you want different behavior, you can change the
interpreter object, change the policy object (just tell the interpreter
what it is), or override the layer's policy methods.

> A low-level way:
> Another way, I guess, would be to subclass the layer and have it return
> its own MapMouseListener when getMapMouseListener() is called. I
> haven't tried
> this, so I'm not sure what is necessary to get this to work.
> Implementing a MapMouseListener
> gets you lower level mouse movements such as mousePressed(),
> mouseReleased(), mouseDragged().
> The methods are passed only the java.awt.event.MouseEvent, so you
> don't get any map
> related events.

You actually do, the MouseEvents are actually MapMouseEvents with
lat/lon information. You just need to cast.

> Another simple way:
> At a lower level, If you want to just get the very low-level swing
> events, you can just
> do mapBean.addMouseListener(), addMouseMotionListener() and get that
> information,
> but all you'll get is x-y, you'd have to convert to lat-long with the
> projection of the bean.

You could do this, but the mouse modes work with a notion of MouseEvent
consumption - so if one layer reacts to a mouse event, other layers
below it won't also do something to react to it.

> The point?
> I guess how to get the mouse modes depends on what sort of information
> you want.


> If you want to manipulate a graphic on the map, the first way is the
> best. If you
> just want to get xy clicks, then one of the last two would be better.

I'd change this a little. If you want to relate mouse events to
OMGraphics, the OMGraphicHandlerLayer GestureResponsePolicy is
definitely the way to go - it give consistent behavior across layers,
and you really don't have to do that much with MouseEvents, you
automatically find out what's going on by paying attention to the
methods being called on the layer.

Using the MapMouseListener methods are good when you want lower level
MouseEvents with geographic information, and you want your layer to
work well with other layers.

The last method is good if your layer is dictating the mouse behavior
of the whole application, and you want to deal with low level mouse

- Don

> If you provide more information on what you are trying to do, I may be
> able to put together
> an example, either of the OMGraphic-centered events, or xy based mouse
> events.
> -- cary
>> TIA!
>> have fun,
>> SteveC
>> --
>> [To unsubscribe to this list send an email to ""
>> with the following text in the BODY of the message "unsubscribe
>> openmap-users"]
> --
> [To unsubscribe to this list send an email to ""
> with the following text in the BODY of the message "unsubscribe
> openmap-users"]

Don Dietrick,
BBN Technologies, Cambridge, MA

[To unsubscribe to this list send an email to ""
with the following text in the BODY of the message "unsubscribe openmap-users"]
Received on Fri Dec 03 2004 - 09:47:49 EST

This archive was generated by hypermail 2.3.0 : Tue Mar 28 2017 - 23:25:06 EDT