Class Viewport
- java.lang.Object
-
- org.locationtech.jtstest.testbuilder.ui.Viewport
-
- All Implemented Interfaces:
PointTransformation
public class Viewport extends java.lang.Object implements PointTransformation
Maintains the information associated with mapping the model view to the screen
-
-
Field Summary
Fields Modifier and Type Field Description private java.awt.geom.Point2D.DoubledestPtprivate static intINITIAL_ORIGIN_Xprivate static intINITIAL_ORIGIN_Yprivate static doubleINITIAL_SCALEprivate static intMIN_GRID_RESOLUTION_PIXELSprivate java.awt.geom.AffineTransformmodelToViewTransformprivate java.awt.geom.Point2DoriginInModelOrigin of view in model spaceprivate GeometryEditPanelpanelprivate static doubleROUND_ERROR_REMOVALprivate doublescaleThe scale is the factor which model distance is multiplied by to get view distanceprivate java.text.NumberFormatscaleFormatprivate PrecisionModelscalePMprivate java.awt.geom.Point2D.DoublesrcPtprivate EnvelopeviewEnvInModelprivate java.awt.DimensionviewSize
-
Constructor Summary
Constructors Constructor Description Viewport(GeometryEditPanel panel)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private EnvelopecomputeEnvelopeInModel()booleancontainsInModel(Coordinate p)PrecisionModelgetGridPrecisionModel()Gets a PrecisionModel corresponding to the grid size.doublegetGridSizeModel()private doublegetHeightInModel()doublegetHeightInView()java.awt.geom.Point2DgetLowerLeftCornerInModel()EnvelopegetModelEnv()java.awt.geom.AffineTransformgetModelToViewTransform()doublegetScale()java.text.NumberFormatgetScaleFormat()EnvelopegetViewEnv()private doublegetWidthInModel()doublegetWidthInView()intgridMagnitudeModel()Gets the magnitude (power of 10) for the basic grid size.booleanintersectsInModel(Envelope env)private voidsetOrigin(double viewOriginX, double viewOriginY)private voidsetScale(double scale)private voidsetScaleNoUpdate(double scale)private static doublesnapScale(double scaleRaw)Snaps scale to nearest multiple of 2, 5 or 10.private static doublesnapScaleTo_10_2_5(double scaleRaw)Not used - scaling to multiples of 10,5,2 is too coarse.private static doublesnapScaleToSingleDigitPrecision(double scaleRaw)doubletoModel(double viewDist)Converts a distance in the view to a distance in the model.java.awt.geom.Point2DtoModel(java.awt.geom.Point2D viewPt)CoordinatetoModelCoordinate(java.awt.geom.Point2D viewPt)doubletoView(double modelDist)Converts a distance in the model to a distance in the view.java.awt.geom.Point2DtoView(java.awt.geom.Point2D modelPt)java.awt.geom.Point2DtoView(java.awt.geom.Point2D modelPt, java.awt.geom.Point2D viewPt)java.awt.geom.Point2DtoView(Coordinate modelCoordinate)voidtransform(Coordinate modelCoordinate, java.awt.geom.Point2D point)Transforms aCoordinateinto a Java2DPoint.private voidupdate()voidupdate(java.awt.Dimension viewSize)private voidupdateModelToViewTransform()private voidviewUpdated()voidzoom(java.awt.geom.Point2D zoomPt, double zoomScale)Zoom to a point, ensuring that the zoom point remains in the same screen location.voidzoom(Envelope zoomEnv)voidzoomPan(double dx, double dy)voidzoomToInitialExtent()
-
-
-
Field Detail
-
INITIAL_SCALE
private static double INITIAL_SCALE
-
INITIAL_ORIGIN_X
private static int INITIAL_ORIGIN_X
-
INITIAL_ORIGIN_Y
private static int INITIAL_ORIGIN_Y
-
panel
private GeometryEditPanel panel
-
originInModel
private java.awt.geom.Point2D originInModel
Origin of view in model space
-
scale
private double scale
The scale is the factor which model distance is multiplied by to get view distance
-
scalePM
private PrecisionModel scalePM
-
scaleFormat
private java.text.NumberFormat scaleFormat
-
viewEnvInModel
private Envelope viewEnvInModel
-
modelToViewTransform
private java.awt.geom.AffineTransform modelToViewTransform
-
srcPt
private java.awt.geom.Point2D.Double srcPt
-
destPt
private java.awt.geom.Point2D.Double destPt
-
viewSize
private java.awt.Dimension viewSize
-
ROUND_ERROR_REMOVAL
private static final double ROUND_ERROR_REMOVAL
- See Also:
- Constant Field Values
-
MIN_GRID_RESOLUTION_PIXELS
private static final int MIN_GRID_RESOLUTION_PIXELS
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Viewport
public Viewport(GeometryEditPanel panel)
-
-
Method Detail
-
viewUpdated
private void viewUpdated()
-
getModelEnv
public Envelope getModelEnv()
-
getViewEnv
public Envelope getViewEnv()
-
getScale
public double getScale()
-
setScaleNoUpdate
private void setScaleNoUpdate(double scale)
-
setScale
private void setScale(double scale)
-
setOrigin
private void setOrigin(double viewOriginX, double viewOriginY)
-
getScaleFormat
public java.text.NumberFormat getScaleFormat()
-
snapScale
private static double snapScale(double scaleRaw)
Snaps scale to nearest multiple of 2, 5 or 10. This ensures that model coordinates entered via the geometry view don't carry more precision than the zoom level warrants.- Parameters:
scaleRaw-- Returns:
-
snapScaleToSingleDigitPrecision
private static double snapScaleToSingleDigitPrecision(double scaleRaw)
-
snapScaleTo_10_2_5
private static double snapScaleTo_10_2_5(double scaleRaw)
Not used - scaling to multiples of 10,5,2 is too coarse.- Parameters:
scaleRaw-- Returns:
-
intersectsInModel
public boolean intersectsInModel(Envelope env)
-
toModel
public java.awt.geom.Point2D toModel(java.awt.geom.Point2D viewPt)
-
toModelCoordinate
public Coordinate toModelCoordinate(java.awt.geom.Point2D viewPt)
-
transform
public void transform(Coordinate modelCoordinate, java.awt.geom.Point2D point)
Description copied from interface:PointTransformationTransforms aCoordinateinto a Java2DPoint.- Specified by:
transformin interfacePointTransformation- Parameters:
modelCoordinate- the source Coordinatepoint- the destination Point
-
toView
public java.awt.geom.Point2D toView(Coordinate modelCoordinate)
-
toView
public java.awt.geom.Point2D toView(java.awt.geom.Point2D modelPt)
-
toView
public java.awt.geom.Point2D toView(java.awt.geom.Point2D modelPt, java.awt.geom.Point2D viewPt)
-
toModel
public double toModel(double viewDist)
Converts a distance in the view to a distance in the model.- Parameters:
viewDist-- Returns:
- the model distance
-
toView
public double toView(double modelDist)
Converts a distance in the model to a distance in the view.- Parameters:
modelDist-- Returns:
- the view distance
-
update
public void update(java.awt.Dimension viewSize)
-
update
private void update()
-
updateModelToViewTransform
private void updateModelToViewTransform()
-
getModelToViewTransform
public java.awt.geom.AffineTransform getModelToViewTransform()
-
zoomToInitialExtent
public void zoomToInitialExtent()
-
zoom
public void zoom(Envelope zoomEnv)
-
zoomPan
public void zoomPan(double dx, double dy)
-
zoom
public void zoom(java.awt.geom.Point2D zoomPt, double zoomScale)Zoom to a point, ensuring that the zoom point remains in the same screen location.- Parameters:
zoomPt-zoomFactor-
-
getWidthInModel
private double getWidthInModel()
-
getHeightInModel
private double getHeightInModel()
-
getLowerLeftCornerInModel
public java.awt.geom.Point2D getLowerLeftCornerInModel()
-
getHeightInView
public double getHeightInView()
-
getWidthInView
public double getWidthInView()
-
computeEnvelopeInModel
private Envelope computeEnvelopeInModel()
-
containsInModel
public boolean containsInModel(Coordinate p)
-
gridMagnitudeModel
public int gridMagnitudeModel()
Gets the magnitude (power of 10) for the basic grid size.- Returns:
- the magnitude
-
getGridPrecisionModel
public PrecisionModel getGridPrecisionModel()
Gets a PrecisionModel corresponding to the grid size.- Returns:
- the precision model
-
getGridSizeModel
public double getGridSizeModel()
-
-