[fix] fixes remaining FinPointFigure auto-zoom-bounds behavior
This commit is contained in:
parent
5696ad910b
commit
724f42a096
@ -33,14 +33,14 @@ public abstract class AbstractScaleFigure extends JPanel {
|
|||||||
// Number of pixels to leave at edges when fitting figure
|
// Number of pixels to leave at edges when fitting figure
|
||||||
private static final int DEFAULT_BORDER_PIXELS_WIDTH = 30;
|
private static final int DEFAULT_BORDER_PIXELS_WIDTH = 30;
|
||||||
private static final int DEFAULT_BORDER_PIXELS_HEIGHT = 20;
|
private static final int DEFAULT_BORDER_PIXELS_HEIGHT = 20;
|
||||||
|
|
||||||
// constant factor that scales screen real-estate to rocket-space
|
|
||||||
private final double baseScale;
|
|
||||||
private double userScale = 1.0;
|
|
||||||
protected double scale = -1;
|
|
||||||
|
|
||||||
protected static final Dimension borderThickness_px = new Dimension(DEFAULT_BORDER_PIXELS_WIDTH, DEFAULT_BORDER_PIXELS_HEIGHT);
|
protected static final Dimension borderThickness_px = new Dimension(DEFAULT_BORDER_PIXELS_WIDTH, DEFAULT_BORDER_PIXELS_HEIGHT);
|
||||||
// pixel offset from the the subject's origin to the canvas's upper-left-corner.
|
|
||||||
|
// constant factor that scales screen real-estate to rocket-space
|
||||||
|
protected final double baseScale;
|
||||||
|
protected double userScale = 1.0;
|
||||||
|
protected double scale = -1;
|
||||||
|
|
||||||
|
// pixel offset from the the subject's origin to the canvas's upper-left-corner.
|
||||||
protected Point originLocation_px = new Point(0,0);
|
protected Point originLocation_px = new Point(0,0);
|
||||||
|
|
||||||
// size of the visible region
|
// size of the visible region
|
||||||
@ -109,10 +109,15 @@ public abstract class AbstractScaleFigure extends JPanel {
|
|||||||
* @param visibleBounds the visible bounds upon the Figure
|
* @param visibleBounds the visible bounds upon the Figure
|
||||||
*/
|
*/
|
||||||
public void scaleTo(final double newScaleRequest, final Dimension visibleBounds) {
|
public void scaleTo(final double newScaleRequest, final Dimension visibleBounds) {
|
||||||
if (MathUtil.equals(this.userScale, newScaleRequest, 0.01)){
|
// System.err.println(String.format(" ::scaleTo: %6.4f ==>> %6.4f, %d x %d", userScale, newScaleRequest, visibleBounds.width, visibleBounds.height));
|
||||||
|
if (MathUtil.equals(this.userScale, newScaleRequest, 0.01) &&
|
||||||
|
(visibleBounds_px.width == visibleBounds.width) &&
|
||||||
|
(visibleBounds_px.height == visibleBounds.height) )
|
||||||
|
{
|
||||||
return;}
|
return;}
|
||||||
if (Double.isInfinite(newScaleRequest) || Double.isNaN(newScaleRequest) || 0 > newScaleRequest) {
|
if (Double.isInfinite(newScaleRequest) || Double.isNaN(newScaleRequest) || 0 > newScaleRequest) {
|
||||||
return;}
|
return;}
|
||||||
|
// System.err.println(String.format(" => continue"));
|
||||||
|
|
||||||
this.userScale = MathUtil.clamp( newScaleRequest, MINIMUM_ZOOM, MAXIMUM_ZOOM);
|
this.userScale = MathUtil.clamp( newScaleRequest, MINIMUM_ZOOM, MAXIMUM_ZOOM);
|
||||||
this.scale = baseScale * userScale;
|
this.scale = baseScale * userScale;
|
||||||
@ -128,22 +133,19 @@ public abstract class AbstractScaleFigure extends JPanel {
|
|||||||
* @param visibleBounds the visible bounds to scale this figure to.
|
* @param visibleBounds the visible bounds to scale this figure to.
|
||||||
*/
|
*/
|
||||||
public void scaleTo(Dimension visibleBounds) {
|
public void scaleTo(Dimension visibleBounds) {
|
||||||
if( 0 == visibleBounds.getWidth() || 0 == visibleBounds.getHeight())
|
// System.err.println(String.format(" ::scaleTo: %d x %d", visibleBounds.width, visibleBounds.height));
|
||||||
|
if( 0 >= visibleBounds.getWidth() || 0 >= visibleBounds.getHeight())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
updateSubjectDimensions();
|
updateSubjectDimensions();
|
||||||
|
updateCanvasSize();
|
||||||
|
updateCanvasOrigin();
|
||||||
|
|
||||||
// dimensions within the viewable area, which are available to draw
|
final double width_scale = (visibleBounds.width) / ((subjectBounds_m.getWidth() * baseScale) + 2 * borderThickness_px.width);
|
||||||
final int drawable_width_px = visibleBounds.width - 2 * borderThickness_px.width;
|
final double height_scale = (visibleBounds.height) / ((subjectBounds_m.getHeight() * baseScale) + 2 * borderThickness_px.height);
|
||||||
final int drawable_height_px = visibleBounds.height - 2 * borderThickness_px.height;
|
final double newScale = Math.min(height_scale, width_scale);
|
||||||
|
|
||||||
if(( 0 < drawable_width_px ) && ( 0 < drawable_height_px)) {
|
scaleTo(newScale, visibleBounds);
|
||||||
final double width_scale = (drawable_width_px) / ( subjectBounds_m.getWidth() * baseScale);
|
|
||||||
final double height_scale = (drawable_height_px) / ( subjectBounds_m.getHeight() * baseScale);
|
|
||||||
final double minScale = Math.min(height_scale, width_scale);
|
|
||||||
|
|
||||||
scaleTo(minScale, visibleBounds);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -73,18 +73,15 @@ public class FinPointFigure extends AbstractScaleFigure {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Point getAutoZoomPoint(){
|
public Point getAutoZoomPoint(){
|
||||||
final int finFrontLocationPx = originLocation_px.x + (int)(subjectBounds_m.getX()*scale);
|
|
||||||
|
|
||||||
// from canvas top/left
|
// from canvas top/left
|
||||||
final Point zoomPointPx = new Point( Math.max(0, originLocation_px.x + (int)(subjectBounds_m.getX()*scale)),
|
final Point zoomPointPx = new Point( Math.max(0, (originLocation_px.x - borderThickness_px.width)), 0);
|
||||||
0 );
|
|
||||||
|
|
||||||
System.err.println("==>> FinPointFigure.getAutoZoomPoint ==>> " + finset.getName() );
|
// System.err.println("==>> FinPointFigure.getAutoZoomPoint ==>> " + finset.getName() );
|
||||||
System.err.println(String.format(" ::ContentBounds: %6.4f, %6.4f", contentBounds_m.getX(), contentBounds_m.getY()));
|
// System.err.println(String.format(" ::scale(overall): %6.4f == %6.4f x %6.4f", scale, userScale, baseScale));
|
||||||
System.err.println(String.format(" ::SubjectBounds: %6.4f, %6.4f", subjectBounds_m.getX(), subjectBounds_m.getY()));
|
// System.err.println(String.format(" ::ContentBounds(px): @ %d, %d [ %d x %d ]", (int)(contentBounds_m.getX()*scale), (int)(contentBounds_m.getY()*scale), (int)(contentBounds_m.getWidth()*scale), (int)(contentBounds_m.getHeight()*scale)));
|
||||||
// System.err.println(String.format(" ::finRootOffset: %d, %d", finFrontOffsetPx, finBottomOffsetPx));
|
// System.err.println(String.format(" ::SubjectBounds(px): @ %d, %d [ %d x %d ]", (int)(subjectBounds_m.getX()*scale), (int)(subjectBounds_m.getY()*scale), (int)(subjectBounds_m.getWidth()*scale), (int)(subjectBounds_m.getHeight()*scale)));
|
||||||
// System.err.println(String.format(" ::finRootLocation: %d, %d", finFrontLocationPx, 0));
|
// System.err.println(String.format(" ::origin: @ %d, %d", originLocation_px.x, originLocation_px.y));
|
||||||
System.err.println(String.format(" ::ZoomPoint: %d, %d", zoomPointPx.x, zoomPointPx.y));
|
// System.err.println(String.format(" ::ZoomPoint: @ %d, %d", zoomPointPx.x, zoomPointPx.y));
|
||||||
|
|
||||||
return zoomPointPx;
|
return zoomPointPx;
|
||||||
}
|
}
|
||||||
@ -401,12 +398,12 @@ public class FinPointFigure extends AbstractScaleFigure {
|
|||||||
// this is non-intuitive: it's an offset _from_ the origin(0,0) _to_ the lower-left of the content --
|
// this is non-intuitive: it's an offset _from_ the origin(0,0) _to_ the lower-left of the content --
|
||||||
// because the canvas is drawn from that lower-left corner of the content, and the fin-front
|
// because the canvas is drawn from that lower-left corner of the content, and the fin-front
|
||||||
// is fixed-- by definition-- to the origin.
|
// is fixed-- by definition-- to the origin.
|
||||||
final int finFrontPx = (int)(contentBounds_m.getX()*scale);
|
final int finFrontPx = -(int)(contentBounds_m.getX()*scale); // pixels from left-border to fin-front
|
||||||
final int contentHeightPx = (int)(contentBounds_m.getHeight()*scale);
|
final int contentHeightPx = (int)(contentBounds_m.getHeight()*scale);
|
||||||
|
|
||||||
originLocation_px.x = borderThickness_px.width - finFrontPx;
|
originLocation_px.x = borderThickness_px.width + finFrontPx;
|
||||||
|
|
||||||
if( visibleBounds_px.height > (contentHeightPx + 2*borderThickness_px.height)) {
|
if( visibleBounds_px.height > (contentHeightPx + 2*borderThickness_px.height)){
|
||||||
originLocation_px.y = getHeight() - mountHeightPx - borderThickness_px.height;
|
originLocation_px.y = getHeight() - mountHeightPx - borderThickness_px.height;
|
||||||
}else {
|
}else {
|
||||||
originLocation_px.y = borderThickness_px.height + finHeightPx;
|
originLocation_px.y = borderThickness_px.height + finHeightPx;
|
||||||
|
@ -159,11 +159,11 @@ public class ScaleScrollPane extends JScrollPane
|
|||||||
figure.scaleTo(view);
|
figure.scaleTo(view);
|
||||||
|
|
||||||
final Point zoomPoint = figure.getAutoZoomPoint();
|
final Point zoomPoint = figure.getAutoZoomPoint();
|
||||||
|
final Rectangle zoomRectangle = new Rectangle(zoomPoint.x, zoomPoint.y, (int)(view.getWidth()), (int)(view.getHeight()));
|
||||||
|
// System.err.println(String.format("::zoom: @ %d, %d [ %d x %d ]", zoomRectangle.x, zoomRectangle.y, zoomRectangle.width, zoomRectangle.height));
|
||||||
|
figure.scrollRectToVisible(zoomRectangle);
|
||||||
|
|
||||||
viewport.scrollRectToVisible( new Rectangle(
|
figure.invalidate();
|
||||||
zoomPoint.x, zoomPoint.y, (int)(view.getWidth()), (int)(view.getHeight())));
|
|
||||||
|
|
||||||
this.firePropertyChange( USER_SCALE_PROPERTY, 1.0, figure.getUserScale());
|
|
||||||
revalidate();
|
revalidate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -177,13 +177,13 @@ public class ScaleScrollPane extends JScrollPane
|
|||||||
if( MathUtil.equals(newScale, figure.getUserScale(), 0.01)){
|
if( MathUtil.equals(newScale, figure.getUserScale(), 0.01)){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// if explicitly setting a zoom level, turn off fitting
|
// if explicitly setting a zoom level, turn off fitting
|
||||||
this.fit = false;
|
this.fit = false;
|
||||||
Dimension view = viewport.getExtentSize();
|
Dimension view = viewport.getExtentSize();
|
||||||
figure.scaleTo(newScale, view);
|
figure.scaleTo(newScale, view);
|
||||||
|
|
||||||
revalidate();
|
revalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -244,7 +244,7 @@ public class ScaleScrollPane extends JScrollPane
|
|||||||
|
|
||||||
dragStartX = e.getX();
|
dragStartX = e.getX();
|
||||||
dragStartY = e.getY();
|
dragStartY = e.getY();
|
||||||
|
|
||||||
viewport.scrollRectToVisible(dragRectangle);
|
viewport.scrollRectToVisible(dragRectangle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user