[fix] restored autozoom behavior on figures -- particularly FinPointFigure
This commit is contained in:
parent
1eeef10a5f
commit
ae83846e4e
@ -106,12 +106,12 @@ public abstract class AbstractScaleFigure extends JPanel {
|
|||||||
* and the figures internal contents are centered according to the figure's origin.
|
* and the figures internal contents are centered according to the figure's origin.
|
||||||
*
|
*
|
||||||
* @param newScaleRequest the scale level
|
* @param newScaleRequest the scale level
|
||||||
* @param visibleBounds the visible bounds upon the Figure
|
* @param newVisibleBounds the visible bounds upon the Figure
|
||||||
*/
|
*/
|
||||||
public void scaleTo(final double newScaleRequest, final Dimension visibleBounds) {
|
public void scaleTo(final double newScaleRequest, final Dimension newVisibleBounds) {
|
||||||
if (MathUtil.equals(this.userScale, newScaleRequest, 0.01) &&
|
if (MathUtil.equals(this.userScale, newScaleRequest, 0.01) &&
|
||||||
(visibleBounds_px.width == visibleBounds.width) &&
|
(visibleBounds_px.width == newVisibleBounds.width) &&
|
||||||
(visibleBounds_px.height == visibleBounds.height) )
|
(visibleBounds_px.height == newVisibleBounds.height) )
|
||||||
{
|
{
|
||||||
return;}
|
return;}
|
||||||
if (Double.isInfinite(newScaleRequest) || Double.isNaN(newScaleRequest) || 0 > newScaleRequest) {
|
if (Double.isInfinite(newScaleRequest) || Double.isNaN(newScaleRequest) || 0 > newScaleRequest) {
|
||||||
@ -119,8 +119,10 @@ public abstract class AbstractScaleFigure extends JPanel {
|
|||||||
|
|
||||||
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;
|
||||||
|
updateCanvasOrigin();
|
||||||
|
|
||||||
this.visibleBounds_px = visibleBounds;
|
this.visibleBounds_px = newVisibleBounds;
|
||||||
|
updateCanvasSize();
|
||||||
|
|
||||||
this.fireChangeEvent();
|
this.fireChangeEvent();
|
||||||
}
|
}
|
||||||
@ -135,8 +137,6 @@ public abstract class AbstractScaleFigure extends JPanel {
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
updateSubjectDimensions();
|
updateSubjectDimensions();
|
||||||
updateCanvasSize();
|
|
||||||
updateCanvasOrigin();
|
|
||||||
|
|
||||||
final double width_scale = (visibleBounds.width - 2 * borderThickness_px.width) / (subjectBounds_m.getWidth() * baseScale);
|
final double width_scale = (visibleBounds.width - 2 * borderThickness_px.width) / (subjectBounds_m.getWidth() * baseScale);
|
||||||
final double height_scale = (visibleBounds.height - 2 * borderThickness_px.height) / (subjectBounds_m.getHeight() * baseScale);
|
final double height_scale = (visibleBounds.height - 2 * borderThickness_px.height) / (subjectBounds_m.getHeight() * baseScale);
|
||||||
|
@ -73,17 +73,7 @@ public class FinPointFigure extends AbstractScaleFigure {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Point getAutoZoomPoint(){
|
public Point getAutoZoomPoint(){
|
||||||
// from canvas top/left
|
return new Point( Math.max(0, (originLocation_px.x - borderThickness_px.width)), 0);
|
||||||
final Point zoomPointPx = new Point( Math.max(0, (originLocation_px.x - borderThickness_px.width)), 0);
|
|
||||||
|
|
||||||
// System.err.println("==>> FinPointFigure.getAutoZoomPoint ==>> " + finset.getName() );
|
|
||||||
// System.err.println(String.format(" ::scale(overall): %6.4f == %6.4f x %6.4f", scale, userScale, baseScale));
|
|
||||||
// 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(" ::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(" ::origin: @ %d, %d", originLocation_px.x, originLocation_px.y));
|
|
||||||
// System.err.println(String.format(" ::ZoomPoint: @ %d, %d", zoomPointPx.x, zoomPointPx.y));
|
|
||||||
|
|
||||||
return zoomPointPx;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -2,6 +2,7 @@ package net.sf.openrocket.gui.scalefigure;
|
|||||||
|
|
||||||
|
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
|
import java.awt.Component;
|
||||||
import java.awt.Dimension;
|
import java.awt.Dimension;
|
||||||
import java.awt.Font;
|
import java.awt.Font;
|
||||||
import java.awt.Graphics;
|
import java.awt.Graphics;
|
||||||
@ -11,6 +12,7 @@ import java.awt.Rectangle;
|
|||||||
import java.awt.RenderingHints;
|
import java.awt.RenderingHints;
|
||||||
import java.awt.event.ComponentAdapter;
|
import java.awt.event.ComponentAdapter;
|
||||||
import java.awt.event.ComponentEvent;
|
import java.awt.event.ComponentEvent;
|
||||||
|
import java.awt.event.ComponentListener;
|
||||||
import java.awt.event.MouseEvent;
|
import java.awt.event.MouseEvent;
|
||||||
import java.awt.event.MouseListener;
|
import java.awt.event.MouseListener;
|
||||||
import java.awt.event.MouseMotionListener;
|
import java.awt.event.MouseMotionListener;
|
||||||
@ -43,7 +45,7 @@ import net.sf.openrocket.util.MathUtil;
|
|||||||
*/
|
*/
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
public class ScaleScrollPane extends JScrollPane
|
public class ScaleScrollPane extends JScrollPane
|
||||||
implements MouseListener, MouseMotionListener {
|
implements ComponentListener, MouseListener, MouseMotionListener {
|
||||||
|
|
||||||
public static final int RULER_SIZE = 20;
|
public static final int RULER_SIZE = 20;
|
||||||
public static final int MINOR_TICKS = 3;
|
public static final int MINOR_TICKS = 3;
|
||||||
@ -106,9 +108,6 @@ public class ScaleScrollPane extends JScrollPane
|
|||||||
getVerticalScrollBar().setUnitIncrement(50);
|
getVerticalScrollBar().setUnitIncrement(50);
|
||||||
//getVerticalScrollBar().setBlockIncrement(viewport.getHeight()); // the default value is good
|
//getVerticalScrollBar().setBlockIncrement(viewport.getHeight()); // the default value is good
|
||||||
|
|
||||||
viewport.addMouseListener(this);
|
|
||||||
viewport.addMouseMotionListener(this);
|
|
||||||
|
|
||||||
figure.addChangeListener( e -> {
|
figure.addChangeListener( e -> {
|
||||||
horizontalRuler.updateSize();
|
horizontalRuler.updateSize();
|
||||||
verticalRuler.updateSize();
|
verticalRuler.updateSize();
|
||||||
@ -117,21 +116,11 @@ public class ScaleScrollPane extends JScrollPane
|
|||||||
figure.scaleTo(calculatedViewSize);
|
figure.scaleTo(calculatedViewSize);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
figure.addComponentListener(this);
|
||||||
|
|
||||||
viewport.addComponentListener(new ComponentAdapter() {
|
viewport.addMouseListener(this);
|
||||||
@Override
|
viewport.addMouseMotionListener(this);
|
||||||
public void componentResized(ComponentEvent e) {
|
viewport.addComponentListener(this);
|
||||||
if(fit) {
|
|
||||||
final Dimension calculatedViewSize = new Dimension(getWidth() - viewportMarginPx.width, getHeight() - viewportMarginPx.height);
|
|
||||||
figure.scaleTo(calculatedViewSize);
|
|
||||||
}
|
|
||||||
figure.updateFigure();
|
|
||||||
|
|
||||||
horizontalRuler.updateSize();
|
|
||||||
verticalRuler.updateSize();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public AbstractScaleFigure getFigure() {
|
public AbstractScaleFigure getFigure() {
|
||||||
@ -150,15 +139,10 @@ public class ScaleScrollPane extends JScrollPane
|
|||||||
*/
|
*/
|
||||||
public void setFitting(final boolean shouldFit) {
|
public void setFitting(final boolean shouldFit) {
|
||||||
this.fit = shouldFit;
|
this.fit = shouldFit;
|
||||||
|
|
||||||
if (shouldFit) {
|
if (shouldFit) {
|
||||||
validate();
|
final Dimension calculatedViewSize = new Dimension(getWidth() - viewportMarginPx.width, getHeight() - viewportMarginPx.height);
|
||||||
|
figure.scaleTo(calculatedViewSize);
|
||||||
Dimension view = viewport.getExtentSize();
|
|
||||||
figure.scaleTo(view);
|
|
||||||
|
|
||||||
final Point zoomPoint = figure.getAutoZoomPoint();
|
|
||||||
final Rectangle zoomRectangle = new Rectangle(zoomPoint.x, zoomPoint.y, (int)(view.getWidth()), (int)(view.getHeight()));
|
|
||||||
figure.scrollRectToVisible(zoomRectangle);
|
|
||||||
|
|
||||||
revalidate();
|
revalidate();
|
||||||
}
|
}
|
||||||
@ -260,6 +244,38 @@ public class ScaleScrollPane extends JScrollPane
|
|||||||
public void mouseMoved(MouseEvent e) {
|
public void mouseMoved(MouseEvent e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void componentResized(ComponentEvent e) {
|
||||||
|
if(fit) {
|
||||||
|
final Dimension calculatedViewSize = new Dimension(getWidth() - viewportMarginPx.width, getHeight() - viewportMarginPx.height);
|
||||||
|
figure.scaleTo(calculatedViewSize);
|
||||||
|
|
||||||
|
final Point zoomPoint = figure.getAutoZoomPoint();
|
||||||
|
final Rectangle zoomRectangle = new Rectangle(zoomPoint.x, zoomPoint.y, viewport.getWidth(), viewport.getHeight() );
|
||||||
|
figure.scrollRectToVisible(zoomRectangle);
|
||||||
|
|
||||||
|
revalidate();
|
||||||
|
}
|
||||||
|
// figure.updateFigure();
|
||||||
|
|
||||||
|
horizontalRuler.updateSize();
|
||||||
|
verticalRuler.updateSize();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void componentMoved(ComponentEvent e) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void componentShown(ComponentEvent e) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void componentHidden(ComponentEvent e) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//////////////// The view port rulers ////////////////
|
//////////////// The view port rulers ////////////////
|
||||||
|
Loading…
x
Reference in New Issue
Block a user