Is it possible to deactivate the mouse motion and key events on the JMap by simple setting a flag? For instance, if someone tries to develop a custom tool which creates graphics on the map by clicking on it, the map still listen and reacts to the mouse motion events. If the user click on the map and drags the mouse a little bit the map extent changes unintentually. This is not a nice user experience.Right now, we are removing the mouse, mouse motion, mouse wheel listener and the action map from the JMap instance. Create for each instance a decorator (offering setActivated) and add these decorated listeners back to the JMap instance. If the custom tool is active the decorators are deactivated and the user can create graphics by clicking on the map.E.g. MouseMotionListenerDecorator
public class MouseMotionListenerDecorator implements MouseMotionListener {
private final MouseMotionListener mouseMotionListener;
private boolean activated = true;
public MouseMotionListenerDecorator(MouseMotionListener mouseMotionListener) {
this.mouseMotionListener = mouseMotionListener;
}
public boolean isActivated() {
return activated;
}
public void setActivated(boolean activated) {
this.activated = activated;
}
@Override
public void mouseDragged(MouseEvent e) {
if (!isActivated())
return;
mouseMotionListener.mouseDragged(e);
}
@Override
public void mouseMoved(MouseEvent e) {
if (!isActivated())
return;
mouseMotionListener.mouseMoved(e);
}
}
Is there any better way by using the API?Thank you
Product Manager
Developers and Location Services
Germany and Switzerland