I’ve added a popup-menu to the JGoView canvas using its
addMouseListener method. The popup-menu is supposed to act on the
current object selection. However, the right-click changes this
selection, so this has to be suppressed. The following does this:
new JGoView(document)
{
public boolean
doMouseDown(int modifiers, Point dc, Point vc)
{
return
&nbs p; (modifiers & MouseEvent.BUTTON3_MASK) == 0 &&
&nbs p; super.doMouseDown(modifiers, dc, vc);
}
public boolean
doMouseUp(int modifiers, Point dc, Point vc)
{
return
&nbs p; (modifiers & MouseEvent.BUTTON3_MASK) == 0 &&
&nbs p; super.doMouseUp(modifiers, dc, vc);
}
};
The problem with this solution is that it tests which button was
physically clicked, while it should test whether the mouse event was a
popup-trigger, as an ordinary mouse event listener does. Only then it
will be portable. Is there a way to achieve this?
I haven’t tried this, but maybe something like:
public boolean doMouseUp(int modifiers, Point dc, Point vc) { if (getCurrentMouseEvent() != null && getCurrentMouseEvent().i sPopupTrigger()) { return doPopupMenu(modifiers, dc, vc); } // otherwise implement the default behavior return super.doMouseUp(modifiers, dc, vc); }
Same for doMouseDown, of course.
I did indeed make a mistake when looking at the traces. Sorry for that.
Now I see that the down event is a popup trigger while the up isn’t.
This means I’ll have to keep state between the two methods in order to
kill the mouse event in other when one is a popup trigger, otherwise
the selection will still change. This will probably work, so thank you
very much again!