@Override
protected CoordinateHandler createCoordinateHandler(JComponent parent, Point2D point, MouseEvent e) {
logger.fine("Enter WSET.createCoordinateHandler, frame coords: mouseEvent = " + e);
// Temporarily convert event from frame coords into canvas coords
Canvas canvas = JmeClientMain.getFrame().getCanvas();
JFrame frame = (JFrame) e.getSource();
Point framePoint = e.getPoint();
Point canvasPoint = SwingUtilities.convertPoint(frame, framePoint, canvas);
e.translatePoint(canvasPoint.x - framePoint.x, canvasPoint.y - framePoint.y);
logger.fine("Canvas coords, mouseEvent = " + e);
InputManager.PickEventReturn ret = InputManager.inputManager().pickMouseEventSwing(e);
if (ret == null || ret.entity == null || ret.destPickDetails == null) {
logger.fine("WindowSwing miss");
e.translatePoint(-(canvasPoint.x - framePoint.x), -(canvasPoint.y - framePoint.y));
// OWL issue #71: if the previous event was on a swing window and
// this one is not, generate a fake mouse event outside of the
// last swing window to ensure that a MouseExit event is generated.
if (lastWindow != null) {
logger.fine("Exit swing");
// request focus in main window
InputManager.ensureKeyFocusInMainWindow();
// send a fake mouse event to generate an exit
final EmbeddedPeer targetEmbeddedPeer = lastWindow.getEmbeddedPeer();
lastWindow = null;
return new CoordinateHandler() {
public EmbeddedPeer getEmbeddedPeer() {
return targetEmbeddedPeer;
}
public Point2D transform(Point2D src, Point2D dst,
MouseEvent event)
{
if (dst == null) {
dst = new Point2D.Float();
}
dst.setLocation(-1, -1);
return dst;
}
};
} else {
return null;
}
}
logger.fine("WindowSwing hit");
logger.fine("Pick hit entity = " + ret.entity);
EntityComponent comp = ret.entity.getComponent(WindowSwing.WindowSwingViewReference.class);
assert comp != null;
final View2D view = ((WindowSwing.WindowSwingViewReference) comp).getView();
WindowSwing windowSwing = (WindowSwing) view.getWindow();
// Keep track of the last window we hit
if (lastWindow == null) {
logger.fine("Enter swing");
}
lastWindow = windowSwing;
// TODO: someday: I don't think we need to set this anymore for drag events. But it doesn't hurt.
final Vector3f intersectionPointWorld = ret.destPickDetails.getPosition();
logger.fine("intersectionPointWorld = " + intersectionPointWorld);
if (e.getID() == MouseEvent.MOUSE_PRESSED) {
lastPressPointScreen = new Point(e.getX(), e.getY());
lastPressEventHook = windowSwing.getEventHook();
if (lastPressEventHook != null) {
WindowSwing.EventHookInfo hookInfo = new WindowSwing.EventHookInfo(intersectionPointWorld,
e.getX(), e.getY());
lastPressEventHook.specifyHookInfoForEvent(e, hookInfo);
}
}
final EmbeddedPeer targetEmbeddedPeer = windowSwing.getEmbeddedPeer();
CoordinateHandler coordinateHandler = new CoordinateHandler() {
public EmbeddedPeer getEmbeddedPeer() {
return targetEmbeddedPeer;
}
// Note: event is in frame coordinates
public Point2D transform(Point2D src, Point2D dst, MouseEvent event) {
logger.fine("event = " + event);
logger.fine("src = " + src);
Point pt;
if (event.getID() == MouseEvent.MOUSE_DRAGGED) {
// We will need the event in canvas coordinates
Canvas canvas = JmeClientMain.getFrame().getCanvas();
JFrame frame = (JFrame) event.getSource();
Point framePoint = event.getPoint();
Point canvasPoint = SwingUtilities.convertPoint(frame, framePoint, canvas);
int canvasX = event.getX() + canvasPoint.x - framePoint.x;
int canvasY = event.getY() + canvasPoint.y - framePoint.y;