Java Code Examples for java.awt.event.MouseEvent#getLocationOnScreen()

The following examples show how to use java.awt.event.MouseEvent#getLocationOnScreen() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OpenTCSView.java    From openAGV with Apache License 2.0 6 votes vote down vote up
@Override
public void mouseDragged(MouseEvent e) {
  if (vehicleModel == null) {
    return;
  }
  Point eOnScreen = e.getLocationOnScreen();
  for (OpenTCSDrawingView drawView : getDrawingViews()) {
    if (drawView.isShowing()) {
      if (drawView.containsPointOnScreen(eOnScreen)) {
        drawView.setCursor(dragCursor);
      }
    }
  }

  fComponentsTreeManager.setCursor(dragCursor);
  setCursor(dragCursor);
}
 
Example 2
Source File: MouseMovementTracker.java    From consulo with Apache License 2.0 6 votes vote down vote up
public boolean isMovingTowards(@Nonnull MouseEvent me, @Nullable Rectangle rectangleOnScreen) {
  Point currentLocation = me.getLocationOnScreen();
  // finding previous location
  Point previousLocation = null;
  for (int i = 0; i < HISTORY_SIZE; i++) {
    Point p = myHistory[(myCurrentIndex - i + HISTORY_SIZE) % HISTORY_SIZE];
    if (p != null && p.distance(currentLocation) >= MOVEMENT_MARGIN_PX) {
      previousLocation = p;
      break;
    }
  }
  // storing current location
  myCurrentIndex = (myCurrentIndex + 1) % HISTORY_SIZE;
  myHistory[myCurrentIndex] = currentLocation;

  return ScreenUtil.isMovementTowards(previousLocation, currentLocation, rectangleOnScreen);
}
 
Example 3
Source File: SeaGlassRootPaneUI.java    From seaglass with Apache License 2.0 6 votes vote down vote up
/**
 * @see java.awt.event.MouseMotionListener#mouseDragged(java.awt.event.MouseEvent)
 */
public void mouseDragged(MouseEvent ev) {
    Window w  = (Window) ev.getSource();
    Point  pt = ev.getPoint();

    if (isMovingWindow) {
        Point eventLocationOnScreen = ev.getLocationOnScreen();

        w.setLocation(eventLocationOnScreen.x - dragOffsetX, eventLocationOnScreen.y - dragOffsetY);
    } else if (dragCursor != 0) {
        Rectangle r           = w.getBounds();
        Rectangle startBounds = new Rectangle(r);
        Dimension min         = w.getMinimumSize();

        switch (dragCursor) {

        case Cursor.E_RESIZE_CURSOR:
            adjust(r, min, 0, 0, pt.x + (dragWidth - dragOffsetX) - r.width, 0);
            break;

        case Cursor.S_RESIZE_CURSOR:
            adjust(r, min, 0, 0, 0, pt.y + (dragHeight - dragOffsetY) - r.height);
            break;

        case Cursor.N_RESIZE_CURSOR:
            adjust(r, min, 0, pt.y - dragOffsetY, 0, -(pt.y - dragOffsetY));
            break;

        case Cursor.W_RESIZE_CURSOR:
            adjust(r, min, pt.x - dragOffsetX, 0, -(pt.x - dragOffsetX), 0);
            break;

        case Cursor.NE_RESIZE_CURSOR:
            adjust(r, min, 0, pt.y - dragOffsetY, pt.x + (dragWidth - dragOffsetX) - r.width, -(pt.y - dragOffsetY));
            break;

        case Cursor.SE_RESIZE_CURSOR:
            adjust(r, min, 0, 0, pt.x + (dragWidth - dragOffsetX) - r.width, pt.y + (dragHeight - dragOffsetY) - r.height);
            break;

        case Cursor.NW_RESIZE_CURSOR:
            adjust(r, min, pt.x - dragOffsetX, pt.y - dragOffsetY, -(pt.x - dragOffsetX), -(pt.y - dragOffsetY));
            break;

        case Cursor.SW_RESIZE_CURSOR:
            adjust(r, min, pt.x - dragOffsetX, 0, -(pt.x - dragOffsetX), pt.y + (dragHeight - dragOffsetY) - r.height);
            break;

        default:
            break;
        }

        if (!r.equals(startBounds)) {
            w.setBounds(r);
            // Defer repaint/validate on mouseReleased unless dynamic
            // layout is active.
            if (Toolkit.getDefaultToolkit().isDynamicLayoutActive()) {
                w.validate();
                getRootPane().repaint();
            }
        }
    }
}
 
Example 4
Source File: ProfilerTableHovers.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void mouseMoved(MouseEvent e) {
            // Do not display popup when a modifier is pressed (can't read all keys)
//            if (e.getModifiers() != 0) return;
            
            currentScreenPoint = e.getLocationOnScreen();
            
            updatePopups(e.getPoint(), false);
        }
 
Example 5
Source File: ComponentMover.java    From mars-sim with GNU General Public License v3.0 5 votes vote down vote up
private void setupForDragging(MouseEvent e)
{
	source.addMouseMotionListener( this );
	potentialDrag = true;

	//  Determine the component that will ultimately be moved

	if (destinationComponent != null)
	{
		destination = destinationComponent;
	}
	else if (destinationClass == null)
	{
		destination = source;
	}
	else  //  forward events to destination component
	{
		destination = SwingUtilities.getAncestorOfClass(destinationClass, source);
	}

	pressed = e.getLocationOnScreen();
	location = destination.getLocation();

	if (changeCursor)
	{
		originalCursor = source.getCursor();
		source.setCursor( Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR) );
	}

	//  Making sure autoscrolls is false will allow for smoother dragging of
	//  individual components

	if (destination instanceof JComponent)
	{
		JComponent jc = (JComponent)destination;
		autoscrolls = jc.getAutoscrolls();
		jc.setAutoscrolls( false );
	}
}
 
Example 6
Source File: ComponentMover.java    From mars-sim with GNU General Public License v3.0 5 votes vote down vote up
/**
 *  Move the component to its new location. The dragged Point must be in
 *  the destination coordinates.
 */
@Override
public void mouseDragged(MouseEvent e)
{
	Point dragged = e.getLocationOnScreen();
	int dragX = getDragDistance(dragged.x, pressed.x, snapSize.width);
	int dragY = getDragDistance(dragged.y, pressed.y, snapSize.height);

	int locationX = location.x + dragX;
	int locationY = location.y + dragY;

	//  Mouse dragged events are not generated for every pixel the mouse
	//  is moved. Adjust the location to make sure we are still on a
	//  snap value.

	while (locationX < edgeInsets.left)
		locationX += snapSize.width;

	while (locationY < edgeInsets.top)
		locationY += snapSize.height;

	Dimension d = getBoundingSize( destination );

	while (locationX + destination.getSize().width + edgeInsets.right > d.width)
		locationX -= snapSize.width;

	while (locationY + destination.getSize().height + edgeInsets.bottom > d.height)
		locationY -= snapSize.height;

	//  Adjustments are finished, move the component

	destination.setLocation(locationX, locationY);

	isMousePressed = false;
}
 
Example 7
Source File: ProfilerTableHovers.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
public void mouseMoved(MouseEvent e) {
            // Do not display popup when a modifier is pressed (can't read all keys)
//            if (e.getModifiers() != 0) return;
            
            currentScreenPoint = e.getLocationOnScreen();
            
            updatePopups(e.getPoint(), false);
        }
 
Example 8
Source File: GhostMotionAdapter.java    From audiveris with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * In this default implementation, we don't modify the current image, we
 * simply tell the glassPane where to redraw the image
 *
 * @param e the mouse event
 */
@Override
public void mouseDragged (MouseEvent e)
{
    Point absPt = e.getLocationOnScreen();
    glassPane.setPoint(new ScreenPoint(absPt.x, absPt.y));
}
 
Example 9
Source File: ChatMouseListeners.java    From ChatGameFontificator with The Unlicense 5 votes vote down vote up
@Override
public void mouseDragged(MouseEvent e)
{
    int x = e.getLocationOnScreen().x - pressOffset.x;
    int y = e.getLocationOnScreen().y - pressOffset.y;

    chatWindow.setLocation(x, y);
}
 
Example 10
Source File: Login.java    From myqq with MIT License 5 votes vote down vote up
/**
 * 处理窗体的拖拽事件
 * @param e
 */
public void mouseDrag(MouseEvent e)
{
	Point point = e.getLocationOnScreen();
	int offsetX = point.x - lastPoint.x;
	int offsetY = point.y - lastPoint.y;
	Rectangle bounds = this.getBounds();
	bounds.x += offsetX;
	bounds.y += offsetY;
	this.setBounds(bounds);
	lastPoint = point;
}
 
Example 11
Source File: ArrangementAndMatchConditionComponent.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void onMouseRelease(@Nonnull MouseEvent event) {
  Point location = event.getLocationOnScreen();
  for (ArrangementUiComponent component : myComponents) {
    Rectangle bounds = component.getScreenBounds();
    if (bounds != null && bounds.contains(location)) {
      component.onMouseRelease(event);
      return;
    }
  }
}
 
Example 12
Source File: GhostMotionAdapter.java    From libreveris with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * In this default implementation, we don't modify the current image, we
 * simply tell the glassPane where to redraw the image
 *
 * @param e the mouse event
 */
@Override
public void mouseDragged (MouseEvent e)
{
    Point absPt = e.getLocationOnScreen();
    glassPane.setPoint(new ScreenPoint(absPt.x, absPt.y));
}
 
Example 13
Source File: EditorPane.java    From SikuliX1 with MIT License 5 votes vote down vote up
public Element getLineAtPoint(MouseEvent me) {
  Point p = me.getLocationOnScreen();
  Point pp = getLocationOnScreen();
  p.translate(-pp.x, -pp.y);
  int pos = viewToModel(p);
  Element root = getDocument().getDefaultRootElement();
  int e = root.getElementIndex(pos);
  if (e == -1) {
    return null;
  }
  return root.getElement(e);
}
 
Example 14
Source File: Login.java    From myqq with MIT License 4 votes vote down vote up
/**
 * 处理窗体的鼠标按下事件
 * @param e
 */
public void mousePress(MouseEvent e)
{
	lastPoint = e.getLocationOnScreen();
}
 
Example 15
Source File: LizziePane.java    From lizzie with GNU General Public License v3.0 4 votes vote down vote up
public void mouseDragged(MouseEvent e) {
  Window w = (Window) e.getSource();
  Point pt = e.getPoint();

  if (isMovingWindow) {
    Point eventLocationOnScreen = e.getLocationOnScreen();
    w.setLocation(eventLocationOnScreen.x - dragOffsetX, eventLocationOnScreen.y - dragOffsetY);
  } else if (dragCursor != 0) {
    Rectangle r = w.getBounds();
    Rectangle startBounds = new Rectangle(r);
    Dimension min = w.getMinimumSize();

    switch (dragCursor) {
      case Cursor.E_RESIZE_CURSOR:
        adjust(r, min, 0, 0, pt.x + (dragWidth - dragOffsetX) - r.width, 0);
        break;
      case Cursor.S_RESIZE_CURSOR:
        adjust(r, min, 0, 0, 0, pt.y + (dragHeight - dragOffsetY) - r.height);
        break;
      case Cursor.N_RESIZE_CURSOR:
        adjust(r, min, 0, pt.y - dragOffsetY, 0, -(pt.y - dragOffsetY));
        break;
      case Cursor.W_RESIZE_CURSOR:
        adjust(r, min, pt.x - dragOffsetX, 0, -(pt.x - dragOffsetX), 0);
        break;
      case Cursor.NE_RESIZE_CURSOR:
        adjust(
            r,
            min,
            0,
            pt.y - dragOffsetY,
            pt.x + (dragWidth - dragOffsetX) - r.width,
            -(pt.y - dragOffsetY));
        break;
      case Cursor.SE_RESIZE_CURSOR:
        adjust(
            r,
            min,
            0,
            0,
            pt.x + (dragWidth - dragOffsetX) - r.width,
            pt.y + (dragHeight - dragOffsetY) - r.height);
        break;
      case Cursor.NW_RESIZE_CURSOR:
        adjust(
            r,
            min,
            pt.x - dragOffsetX,
            pt.y - dragOffsetY,
            -(pt.x - dragOffsetX),
            -(pt.y - dragOffsetY));
        break;
      case Cursor.SW_RESIZE_CURSOR:
        adjust(
            r,
            min,
            pt.x - dragOffsetX,
            0,
            -(pt.x - dragOffsetX),
            pt.y + (dragHeight - dragOffsetY) - r.height);
        break;
      default:
        break;
    }
    if (!r.equals(startBounds)) {
      w.setBounds(r);
      // Defer repaint/validate on mouseReleased unless dynamic
      // layout is active.
      if (Toolkit.getDefaultToolkit().isDynamicLayoutActive()) {
        w.validate();
        getRootPane().repaint();
      }
    }
  }
}
 
Example 16
Source File: ComponentMover.java    From SikuliX1 with MIT License 4 votes vote down vote up
/**

    *  Move the component to its new location. The dragged Point must be in

    *  the destination coordinates.

    */

   @Override

   public void mouseDragged(MouseEvent e)

   {

      Point dragged = e.getLocationOnScreen();

      int dragX = getDragDistance(dragged.x, pressed.x, snapSize.width);

      int dragY = getDragDistance(dragged.y, pressed.y, snapSize.height);

      if (destination instanceof Visual)
         ((Visual) destination).setActualLocation(location.x + dragX, location.y + dragY);
      else
         destination.setLocation(location.x + dragX, location.y + dragY);

   }
 
Example 17
Source File: ComponentMover.java    From 07kit with GNU General Public License v3.0 4 votes vote down vote up
/**
     * Move the component to its new location. The dragged Point must be in
     * the destination coordinates.
     */
    @Override
    public void mouseDragged(MouseEvent e) {

        Point dragged = e.getLocationOnScreen();
        int dragX = getDragDistance(dragged.x, pressed.x, snapSize.width);
        int dragY = getDragDistance(dragged.y, pressed.y, snapSize.height);

//        if (dragX != 0 || dragY != 0) {
//            if (destination instanceof MainView) {
//                final MainView gui = (MainView) destination;
//                if (gui.isMa) {
//                    return;
//                }
//            }
//        }

        int locationX = location.x + dragX;
        int locationY = location.y + dragY;

        //  Mouse dragged events are not generated for every pixel the mouse
        //  is moved. Adjust the location to make sure we are still on a
        //  snap value.

        getBoundingSize(destination);


        //If the component is a MainView and it is maximized... lets restore

        while (locationX < bounds.x) {
            locationX += snapSize.width;
        }

        while (locationY < bounds.y) {
            locationY += snapSize.height;
        }

        while (locationX > bounds.width) {
            locationX -= snapSize.width;
        }

        while (locationY > bounds.height) {
            locationY -= snapSize.height;
        }


        //  Adjustments are finished, move the component
        destination.setLocation(locationX, locationY);
    }
 
Example 18
Source File: LazyMouse.java    From amodeus with GNU General Public License v2.0 4 votes vote down vote up
private boolean shortFromPressed(MouseEvent myMouseEvent) {
    Point myPointC = myMouseEvent.getPoint();
    Point myPointS = myMouseEvent.getLocationOnScreen();
    return Math.hypot(myPointC.x - myPressedC.x, myPointC.y - myPressedC.y) <= tolerance && //
            Math.hypot(myPointS.x - myPressedS.x, myPointS.y - myPressedS.y) <= tolerance;
}
 
Example 19
Source File: ComponentMover.java    From SikuliX1 with MIT License 2 votes vote down vote up
private void setupForDragging(MouseEvent e)

   {

      source.addMouseMotionListener( this );


      //  Determine the component that will ultimately be moved


      if (destinationComponent != null)

      {

         destination = destinationComponent;

      }

      else if (destinationClass == null)

      {

         destination = source;

      }

      else  //  forward events to destination component

      {

         destination = SwingUtilities.getAncestorOfClass(destinationClass, source);

      }


      pressed = e.getLocationOnScreen();

      if (destination instanceof Visual){
         location = ((Visual) destination).getActualLocation();
      }else{
         location = destination.getLocation();
      }


      if (changeCursor)

      {

         originalCursor = source.getCursor();

         source.setCursor( Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR) );

      }


      //  Making sure autoscrolls is false will allow for smoother dragging of

      //  individual components


      if (destination instanceof JComponent)

      {

         JComponent jc = (JComponent)destination;

         autoscrolls = jc.getAutoscrolls();

         jc.setAutoscrolls( false );

      }

   }
 
Example 20
Source File: ComponentMover.java    From SikuliNG with MIT License 2 votes vote down vote up
private void setupForDragging(MouseEvent e)

   {

      source.addMouseMotionListener( this );


      //  Determine the component that will ultimately be moved


      if (destinationComponent != null)

      {

         destination = destinationComponent;

      }

      else if (destinationClass == null)

      {

         destination = source;

      }

      else  //  forward events to destination component

      {

         destination = SwingUtilities.getAncestorOfClass(destinationClass, source);

      }


      pressed = e.getLocationOnScreen();

      if (destination instanceof Visual){
         location = ((Visual) destination).getActualLocation();
      }else{
         location = destination.getLocation();
      }


      if (changeCursor)

      {

         originalCursor = source.getCursor();

         source.setCursor( Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR) );

      }


      //  Making sure autoscrolls is false will allow for smoother dragging of

      //  individual components


      if (destination instanceof JComponent)

      {

         JComponent jc = (JComponent)destination;

         autoscrolls = jc.getAutoscrolls();

         jc.setAutoscrolls( false );

      }

   }