protected void processMouseEvent(MouseEvent e) {
   MouseEvent transformedEvent = transformMouseEvent(e);
   switch (e.getID()) {
     case MouseEvent.MOUSE_ENTERED:
       if (mouseDraggedComponent == null || mouseCurrentComponent == mouseDraggedComponent) {
         dispatchMouseEvent(transformedEvent);
       }
       break;
     case MouseEvent.MOUSE_EXITED:
       if (mouseEnteredComponent != null) {
         dispatchMouseEvent(
             createEnterExitEvent(mouseEnteredComponent, MouseEvent.MOUSE_EXITED, e));
         mouseEnteredComponent = null;
       }
       break;
     case MouseEvent.MOUSE_RELEASED:
       if (mouseDraggedComponent != null && e.getButton() == MouseEvent.BUTTON1) {
         transformedEvent.setSource(mouseDraggedComponent);
         mouseDraggedComponent = null;
       }
       dispatchMouseEvent(transformedEvent);
       break;
     default:
       dispatchMouseEvent(transformedEvent);
   }
   super.processMouseEvent(e);
 }
示例#2
0
 private MouseEvent transformMouseEvent(MouseEvent e) {
   if (this == e.getComponent()) {
     return e;
   } else {
     Point lp = getLocationInQueryTextArea(e.getComponent());
     e.setSource(this);
     e.translatePoint(lp.x, lp.y);
     return e;
   }
 }
示例#3
0
 @Override
 public void handleJavaMouseEvent(MouseEvent mouseEvent) {
   super.handleJavaMouseEvent(mouseEvent);
   if (xtext != null) {
     mouseEvent.setSource(xtext);
     int id = mouseEvent.getID();
     if (id == MouseEvent.MOUSE_DRAGGED || id == MouseEvent.MOUSE_MOVED)
       xtext.processMouseMotionEventImpl(mouseEvent);
     else xtext.processMouseEventImpl(mouseEvent);
   }
 }
 protected void processMouseMotionEvent(MouseEvent e) {
   MouseEvent transformedEvent = transformMouseEvent(e);
   if (mouseEnteredComponent == null) {
     mouseEnteredComponent = mouseCurrentComponent;
   }
   switch (e.getID()) {
     case MouseEvent.MOUSE_MOVED:
       if (mouseCurrentComponent != mouseEnteredComponent) {
         dispatchMouseEvent(
             createEnterExitEvent(mouseEnteredComponent, MouseEvent.MOUSE_EXITED, e));
         dispatchMouseEvent(
             createEnterExitEvent(mouseCurrentComponent, MouseEvent.MOUSE_ENTERED, e));
       }
       break;
     case MouseEvent.MOUSE_DRAGGED:
       if (mouseDraggedComponent == null) {
         mouseDraggedComponent = mouseEnteredComponent;
       }
       if (mouseEnteredComponent == mouseDraggedComponent
           && mouseCurrentComponent != mouseDraggedComponent) {
         dispatchMouseEvent(
             createEnterExitEvent(mouseDraggedComponent, MouseEvent.MOUSE_EXITED, e));
       } else if (mouseEnteredComponent != mouseDraggedComponent
           && mouseCurrentComponent == mouseDraggedComponent) {
         dispatchMouseEvent(
             createEnterExitEvent(mouseDraggedComponent, MouseEvent.MOUSE_ENTERED, e));
       }
       if (mouseDraggedComponent != null) {
         transformedEvent.setSource(mouseDraggedComponent);
       }
       break;
   }
   mouseEnteredComponent = mouseCurrentComponent;
   // dispatch MouseMotionEvent
   MouseMotionListener[] mouseMotionListeners =
       transformedEvent.getComponent().getMouseMotionListeners();
   for (MouseMotionListener listener : mouseMotionListeners) {
     // skip all ToolTipManager's related listeners
     if (!listener.getClass().getName().startsWith("javax.swing.ToolTipManager")) {
       switch (transformedEvent.getID()) {
         case MouseEvent.MOUSE_MOVED:
           listener.mouseMoved(transformedEvent);
           break;
         case MouseEvent.MOUSE_DRAGGED:
           listener.mouseDragged(transformedEvent);
           break;
         default:
           throw new AssertionError();
       }
     }
   }
   super.processMouseMotionEvent(e);
 }
    private MouseEvent transformMouseEvent(MouseEvent event) {
      if (event == null) {
        throw new IllegalArgumentException("MouseEvent is null");
      }
      MouseEvent newEvent;
      if (event instanceof MouseWheelEvent) {
        MouseWheelEvent mouseWheelEvent = (MouseWheelEvent) event;
        newEvent =
            new MouseWheelEvent(
                mouseWheelEvent.getComponent(),
                mouseWheelEvent.getID(),
                mouseWheelEvent.getWhen(),
                mouseWheelEvent.getModifiers(),
                mouseWheelEvent.getX(),
                mouseWheelEvent.getY(),
                mouseWheelEvent.getClickCount(),
                mouseWheelEvent.isPopupTrigger(),
                mouseWheelEvent.getScrollType(),
                mouseWheelEvent.getScrollAmount(),
                mouseWheelEvent.getWheelRotation());
      } else {
        newEvent =
            new MouseEvent(
                event.getComponent(),
                event.getID(),
                event.getWhen(),
                event.getModifiers(),
                event.getX(),
                event.getY(),
                event.getClickCount(),
                event.isPopupTrigger(),
                event.getButton());
      }
      if (view != null && at.getDeterminant() != 0) {
        Rectangle viewBounds = getTransformedSize();
        Insets insets = JXTransformer.this.getInsets();
        int xgap = (getWidth() - (viewBounds.width + insets.left + insets.right)) / 2;
        int ygap = (getHeight() - (viewBounds.height + insets.top + insets.bottom)) / 2;

        double x = newEvent.getX() + viewBounds.getX() - insets.left;
        double y = newEvent.getY() + viewBounds.getY() - insets.top;
        Point2D p = new Point2D.Double(x - xgap, y - ygap);

        Point2D tp;
        try {
          tp = at.inverseTransform(p, null);
        } catch (NoninvertibleTransformException ex) {
          // can't happen, we check it before
          throw new AssertionError("NoninvertibleTransformException");
        }
        // Use transformed coordinates to get the current component
        mouseCurrentComponent =
            SwingUtilities.getDeepestComponentAt(view, (int) tp.getX(), (int) tp.getY());
        if (mouseCurrentComponent == null) {
          mouseCurrentComponent = JXTransformer.this;
        }
        Component tempComponent = mouseCurrentComponent;
        if (mouseDraggedComponent != null) {
          tempComponent = mouseDraggedComponent;
        }

        Point point =
            SwingUtilities.convertPoint(view, (int) tp.getX(), (int) tp.getY(), tempComponent);
        newEvent.setSource(tempComponent);
        newEvent.translatePoint(point.x - event.getX(), point.y - event.getY());
      }
      return newEvent;
    }