Point p = e.getPoint();
// Backup the current crop, so we can back out changes if it turns
// out they exceed the underlay constraint.
CropBounds oldCrop = crop;
if ((dragStart != null) &&
((Math.abs(dragStart.x - p.x) < MinDragDistance) ||
(Math.abs(dragStart.y - p.y) < MinDragDistance))) {
return;
}
if (dragStart != null) {
if (! underlayRect.contains(p)) {
return;
}
double x = Math.min(p.x, dragStart.x);
double y = Math.min(p.y, dragStart.y);
double w = Math.abs(p.x - dragStart.x);
double h = Math.abs(p.y - dragStart.y);
Rectangle2D rect = new Rectangle2D.Double(x, y, w, h);
CropBounds newCrop = new CropBounds(rect);
setCrop(newCrop);
if (isOnNorth(p)) {
adjustingNorth = true;
}
else {
adjustingSouth = true;
}
if (isOnWest(p)) {
adjustingWest = true;
}
else {
adjustingEast = true;
}
dragStart = null;
}
else if (isMoving) {
int dx = p.x - moveMouseStart.x;
int dy = p.y - moveMouseStart.y;
Point2D.Double center = new Point2D.Double(
moveCenterStart.getX() + dx,
moveCenterStart.getY() + dy
);
double width = crop.getWidth();
double height = crop.getHeight();
double angle = crop.getAngle();
CropBounds newCrop = new CropBounds(center, width, height, angle);
newCrop = UnderlayConstraints.translateToUnderlay(newCrop, underlayRect);
if (newCrop != null) {
setCrop(newCrop);
}
}
else if (isRotating) {
Point2D center = crop.getCenter();
Line2D start = new Line2D.Double(center, rotateMouseStart);
Line2D end = new Line2D.Double(center, p);
double startAngle = Math.atan2(
start.getY2() - start.getY1(), start.getX2() - start.getX1()
);
double endAngle = Math.atan2(
end.getY2() - end.getY1(), end.getX2() - end.getX1()
);
double angle = rotateAngleStart + endAngle - startAngle;
CropBounds newCrop = new CropBounds(crop, angle);
updateRotateConstraints();
newCrop = UnderlayConstraints.sizeToUnderlay(
newCrop, underlayRect, rotateWidthLimit, rotateHeightLimit
);
if (newCrop != null) {