if (component.getBounds().contains(ev.getPoint())) {
if (component instanceof Container) {
Container container = (Container)component;
for (int i = container.getComponentCount() - 1; i >= 0; i--) {
Component c = container.getComponent(i);
MouseEvent retargetedEvent = deriveEvent(ev, component, ev.getID(),
ev.getX() - component.getX(), ev.getY() - component.getY());
Component mouseEventTarget = retargetMouseEvent(c, retargetedEvent);
if (mouseEventTarget != null) {
return mouseEventTarget;
}
}
}
int newX = ev.getX() - component.getX();
int newY = ev.getY() - component.getY();
if (dispatchRetargetedEvent(deriveEvent(ev, component, ev.getID(), newX, newY))) {
if (ev.getID() == MouseEvent.MOUSE_PRESSED) {
this.grabComponent = component;
}
return component;
}
}
return null;
}
/**
* Dispatches the given event to its component and returns <code>true</code> if component needs to be redrawn.
*/
private boolean dispatchRetargetedEvent(MouseEvent ev) {
ev.getComponent().dispatchEvent(ev);
if (!RepaintManager.currentManager(ev.getComponent()).getDirtyRegion((JComponent)ev.getComponent()).isEmpty()) {
updateNavigationPanelImage();
component3D.repaint();
return true;
}
return false;
}
/**
* Returns a new <code>MouseEvent</code> derived from the one given in parameter.
*/
private MouseEvent deriveEvent(MouseEvent ev, Component component, int id, int x, int y) {
return new MouseEvent(component, id, ev.getWhen(),
ev.getModifiersEx() | ev.getModifiers(), x, y,
ev.getClickCount(), ev.isPopupTrigger(), ev.getButton());
}
};
MouseWheelListener mouseWheelListener = new MouseWheelListener() {