我试图在 World Wind 中通过鼠标单击来禁用地球的移动。我希望能够做到:
void disableGlobeDrag(WorldWindowGLCanvas ww) {
ww.addMouseMotionListener(new MyMouseMotionListener());
}
whereMyMouseMotionListener
消耗所有的鼠标事件。这不起作用,所以我必须这样做:
void disableGlobeDrag(WorldWindowGLCanvas ww) {
for(MouseMotionListener l : ww.getMouseMotionListeners()) {
if(l.getClass().toString().equals("class gov.nasa.worldwind.awt.AWTInputHandler")) {
ww.removeMouseMotionListener(l);
}
}
}
是否预期消耗的鼠标事件仍应到达gov.nasa.worldwind.awt.AWTInputHandler
侦听器?
更新: WorldWindowGLCanvas
只是打电话addMouseMotionListener()
,java.awt.Component
所以显然我不明白消费事件是如何工作的。
更新 2:尽管与 Swing 共享接口,但调用WorldWindowGLCanvas.removeMouseMotionListener()
withAWTInputHandler
作为参数将阻止所有其他MouseMotionListener
s 接收事件。AWTInputHandler
应该使用add 和 remove 方法。