@Override public boolean isInImage(final IntCoords point) { final RealCoords dataCoords = panelToDataCoords(point); return getDisplay().getPlaneExtents().contains(dataCoords); }
@Override public Dimension getPreferredSize() { final Dimension drawViewSize = super.getPreferredSize(); if (drawViewSize.width > 0 && drawViewSize.height > 0) { // NB: Current preferred size is OK. return drawViewSize; } // NB: One or more figures in the drawing view are not initialized yet. // So we calculate the projected size manually. final RealRect imageBounds = getDisplay().getPlaneExtents(); final double zoomFactor = getDisplay().getCanvas().getZoomFactor(); final int x = (int) (imageBounds.width * zoomFactor); final int y = (int) (imageBounds.height * zoomFactor); // HACK: Add extra space to avoid unnecessary scroll bars. final int extra = 2; return new Dimension(x + extra, y + extra); } };
@Override public void panReset() { final RealRect extents = getDisplay().getPlaneExtents(); final double centerX = extents.x + extents.width / 2d; final double centerY = extents.y + extents.height / 2d; setPanCenter(new RealCoords(centerX, centerY)); }
/** Checks whether the given scale is out of bounds. */ private boolean scaleOutOfBounds(final double desiredScale) { if (desiredScale <= 0) { if (log != null) log.warn("**** BAD SCALE: " + desiredScale + " ****"); return true; } if (desiredScale > maxZoom) return true; // check if trying to zoom out too far if (desiredScale < getZoomFactor()) { // get boundaries of the plane in panel coordinates final RealRect planeExtents = getDisplay().getPlaneExtents(); final IntCoords nearCornerPanel = dataToPanelCoords(new RealCoords(planeExtents.x, planeExtents.y)); final IntCoords farCornerPanel = dataToPanelCoords(new RealCoords(planeExtents.x + planeExtents.width, planeExtents.y + planeExtents.height)); // if boundaries take up less than min allowed pixels in either dimension final int panelX = farCornerPanel.x - nearCornerPanel.x; final int panelY = farCornerPanel.y - nearCornerPanel.y; if (panelX < MIN_ALLOWED_VIEW_SIZE && panelY < MIN_ALLOWED_VIEW_SIZE) { return true; } } return false; }
private void maybeResizeWindow() { final Rectangle bounds = StaticSwingUtils.getWorkSpaceBounds(); final RealRect imageBounds = getDisplay().getPlaneExtents(); final ImageCanvas canvas = getDisplay().getCanvas(); final IntCoords topLeft = canvas.dataToPanelCoords(new RealCoords(imageBounds.x, imageBounds.y)); final IntCoords bottomRight = canvas.dataToPanelCoords(new RealCoords( imageBounds.x + imageBounds.width, imageBounds.y + imageBounds.height)); if (bottomRight.x - topLeft.x > bounds.width) return; if (bottomRight.y - topLeft.y > bounds.height) return; displayViewer.getWindow().pack(); }