Dimension target = new Dimension(dx, dy);
Dimension target; int sameOrientation = (Math.abs(dx) - Math.abs(dy)) * (imageRect.width - imageRect.height); if (sameOrientation > 0) { target = new Dimension(dx, dy); } else { target = new Dimension(dy, dx); }
		public void mouseDragged(MouseEvent e) {			if (imageRect == null) {				return;			}			Point2D p = validate(e.getPoint());			int modifiers = e.getModifiersEx();			double px = p.getX();			double py = p.getY();			if ((modifiers & InputEvent.SHIFT_DOWN_MASK) == InputEvent.SHIFT_DOWN_MASK) {				// constrain to a square				double dx = px - start.getX();				double dy = py - start.getY();				if (Math.abs(dx) < Math.abs(dy)) {					py = start.getY() + (dy*dx > 0?dx:-dx);				} else {					px = start.getX() + (dx*dy > 0?dy:-dy);				}				p.setLocation(px, py);			} else if ((modifiers & InputEvent.CTRL_DOWN_MASK) == InputEvent.CTRL_DOWN_MASK) {				// constrain to same aspect ratio				int dx = (int) (px - start.getX());				int dy = (int) (py - start.getY());				Dimension target = new Dimension(dx, dy);				Dimension d = ImageUtils.getSizeKeepRatio(imageRect.getSize(),						target, false);				p.setLocation(start.getX() + d.width, start.getY() + d.height);			}			centerMode = (modifiers & InputEvent.ALT_DOWN_MASK) == InputEvent.ALT_DOWN_MASK;			end = validate(p);			updateRect();		}