List of usage examples for org.jfree.util ShapeUtilities getPointInRectangle
public static Point2D getPointInRectangle(double x, double y, final Rectangle2D area)
From source file:de.hs.mannheim.modUro.controller.diagram.fx.interaction.ZoomHandlerFX.java
/** * Handles a mouse pressed event by recording the initial mouse pointer * location.//w ww. ja v a 2 s .c o m * * @param canvas the JavaFX canvas (<code>null</code> not permitted). * @param e the mouse event (<code>null</code> not permitted). */ @Override public void handleMousePressed(ChartCanvas canvas, MouseEvent e) { Point2D pt = new Point2D.Double(e.getX(), e.getY()); Rectangle2D dataArea = canvas.findDataArea(pt); if (dataArea != null) { this.startPoint = ShapeUtilities.getPointInRectangle(e.getX(), e.getY(), dataArea); } else { this.startPoint = null; canvas.clearLiveHandler(); } }
From source file:gda.plots.SimplePlot.java
/** * Recalculates the rectangle which should be magnified. * /* w w w . j a va 2 s . c o m*/ * @param e * the MouseEvent which triggered the recalculation */ private void recalculateMagnifyRectangle(MouseEvent e) { if (magnifyWidth == 0 || magnifyHeight == 0) return; Rectangle2D scaledDataArea = getScreenDataArea(); double widthToUse; double heightToUse; double xToUse; double yToUse; // If magnifyWidth is positive then e.getX() is // the end of the rectangle so the start is (e.getX() - magnifyWidth ). // If magnifyWidth is negative then e.getX() is the start of a // rectangle with the opposite sign width. Similarly for y. if (magnifyWidth > 0) { xToUse = e.getX() - magnifyWidth; widthToUse = magnifyWidth; } else { xToUse = e.getX(); widthToUse = -1.0 * magnifyWidth; } if (magnifyHeight > 0) { yToUse = e.getY() - magnifyHeight; heightToUse = magnifyHeight; } else { yToUse = e.getY(); heightToUse = -1.0 * magnifyHeight; } // xToUse and yToUse now specify the top left of the rectangle. In order // to keep the magnified rectangle inside the data area the start point // must be inside a rectangle which is the scaledDataArea reduced in // width // and height by the width and height of the magnifyRectangle. Point2D revisedStartPoint = ShapeUtilities.getPointInRectangle(xToUse, yToUse, new Rectangle2D.Double(scaledDataArea.getMinX(), scaledDataArea.getMinY(), scaledDataArea.getWidth() - magnifyWidth, scaledDataArea.getHeight() - magnifyHeight)); magnifyRectangle = new Rectangle2D.Double(revisedStartPoint.getX(), revisedStartPoint.getY(), widthToUse, heightToUse); }