Ejemplo n.º 1
0
  protected Size calculateRectangleSize(MouseEvent e, Point fixedPoint, Rectangle rectangle) {
    Point mouseLoc = transformPoint(viewToWorld(), new Point(e.getX(), e.getY()));

    // the size of the rectangle is the difference between the X's and Y's
    return new Size(
        abs(fixedPoint.getCoordinate(X) - mouseLoc.getCoordinate(X)),
        abs(fixedPoint.getCoordinate(Y) - mouseLoc.getCoordinate(Y)));
  }
Ejemplo n.º 2
0
  protected Point calculateRectangleLocation(MouseEvent e, Point fixedPoint, Rectangle rectangle) {
    Point mouseLoc = transformPoint(viewToWorld(), new Point(e.getX(), e.getY()));

    // get the difference between the new point and the fixed point
    Size diff =
        new Size(
            mouseLoc.getCoordinate(X) - fixedPoint.getCoordinate(X),
            mouseLoc.getCoordinate(Y) - fixedPoint.getCoordinate(Y));

    // the center of the rectangle is located at the fixed point plus half the
    // difference to the new point

    return new Point(
        fixedPoint.getCoordinate(X) + diff.getLength(WIDTH) / 2,
        fixedPoint.getCoordinate(Y) + diff.getLength(HEIGHT) / 2);
  }