Package gov.nasa.worldwind.render
Class Offset
- java.lang.Object
-
- gov.nasa.worldwind.render.Offset
-
public class Offset extends java.lang.ObjectDefines the relationship of an image, label or other screen-space item relative to another screen-space item. An offset contains an X coordinate, a Y coordinate, and for each of these a separate "units" string indicating the coordinate units.Recognized "units" values are
AVKey.PIXELS, which indicates pixel units relative to the lower left corner of the screen-space item,AVKey.FRACTION, which indicates that the units are fractions of the screen-space item's width and height, relative to its lower left corner, andAVKey.INSET_PIXELS, which indicates units of pixels but with origin at the screen-space item's upper right.This class implements the functionality of a KML Offset.
-
-
Field Summary
Fields Modifier and Type Field Description static OffsetBOTTOM_CENTERstatic OffsetCENTERstatic OffsetLEFT_CENTERstatic OffsetRIGHT_CENTERstatic OffsetTOP_CENTERprotected java.lang.Doublexprotected java.lang.StringxUnitsprotected java.lang.Doubleyprotected java.lang.StringyUnits
-
Constructor Summary
Constructors Constructor Description Offset(java.lang.Double x, java.lang.Double y, java.lang.String xUnits, java.lang.String yUnits)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.awt.geom.Point2D.DoublecomputeOffset(double width, double height, java.lang.Double xScale, java.lang.Double yScale)Computes the X and Y offset specified by this offset applied to a specified rectangle.booleanequals(java.lang.Object o)static OffsetfromFraction(double xFraction, double yFraction)Creates a new offset from explicit fraction coordinates.voidgetRestorableState(RestorableSupport restorableSupport, RestorableSupport.StateObject context)Saves the offset's current state in the specifiedrestorableSupport.java.lang.DoublegetX()Returns the hot spot's X coordinate.java.lang.StringgetXUnits()Returns the units of the offset X value.java.lang.DoublegetY()Returns the hot spot's Y coordinate.java.lang.StringgetYUnits()Returns the units of the offset Y value.inthashCode()voidrestoreState(RestorableSupport restorableSupport, RestorableSupport.StateObject context)Restores the state of any offset parameters contained in the specifiedRestorableSupport.voidsetX(java.lang.Double x)Specifies the hot spot's X coordinate, in units specified bysetXUnits(String).voidsetXUnits(java.lang.String units)Specifies the units of the offset X value.voidsetY(java.lang.Double y)Specifies the hot spot's Y coordinate, in units specified bysetYUnits(String).voidsetYUnits(java.lang.String units)Specifies the units of the offset Y value.
-
-
-
Field Detail
-
CENTER
public static final Offset CENTER
-
BOTTOM_CENTER
public static final Offset BOTTOM_CENTER
-
TOP_CENTER
public static final Offset TOP_CENTER
-
LEFT_CENTER
public static final Offset LEFT_CENTER
-
RIGHT_CENTER
public static final Offset RIGHT_CENTER
-
x
protected java.lang.Double x
-
y
protected java.lang.Double y
-
xUnits
protected java.lang.String xUnits
-
yUnits
protected java.lang.String yUnits
-
-
Method Detail
-
fromFraction
public static Offset fromFraction(double xFraction, double yFraction)
Creates a new offset from explicit fraction coordinates.- Parameters:
xFraction- the offset's X coordinate as a fraction of the containing rectangle.yFraction- the offset's Y coordinate as a fraction of the containing rectangle.- Returns:
- a new offset with the specified X and Y coordinates.
-
getX
public java.lang.Double getX()
Returns the hot spot's X coordinate. SeesetXUnits(String)for a description of the hot spot.- Returns:
- the hot spot's X coordinate.
-
setX
public void setX(java.lang.Double x)
Specifies the hot spot's X coordinate, in units specified bysetXUnits(String).- Parameters:
x- the hot spot's X coordinate. May be null, in which case 0 is used during rendering.
-
getY
public java.lang.Double getY()
Returns the hot spot's Y coordinate. SeesetYUnits(String)for a description of the hot spot.- Returns:
- the hot spot's Y coordinate.
-
setY
public void setY(java.lang.Double y)
Specifies the hot spot's Y coordinate, in units specified bysetYUnits(String).- Parameters:
y- the hot spot's Y coordinate. May be null, in which case 0 is used during rendering.
-
getXUnits
public java.lang.String getXUnits()
Returns the units of the offset X value. SeesetXUnits(String)for a description of the recognized values.- Returns:
- the units of the offset X value, or null.
-
setXUnits
public void setXUnits(java.lang.String units)
Specifies the units of the offset X value. Recognized values areAVKey.PIXELS, which indicates pixel units relative to the lower left corner of the placemark image,AVKey.FRACTION, which indicates the units are fractions of the placemark image width and height, andAVKey.INSET_PIXELS, which indicates units of pixels but with origin in the upper left.- Parameters:
units- the units of the offset X value. If null,AVKey.PIXELSis used during rendering.
-
getYUnits
public java.lang.String getYUnits()
Returns the units of the offset Y value. SeesetYUnits(String)for a description of the recognized values.- Returns:
- the units of the offset Y value, or null.
-
setYUnits
public void setYUnits(java.lang.String units)
Specifies the units of the offset Y value. Recognized values areAVKey.PIXELS, which indicates pixel units relative to the lower left corner of the placemark image,AVKey.FRACTION, which indicates the units are fractions of the placemark image width and height, andAVKey.INSET_PIXELS, which indicates units of pixels but with origin in the upper left.- Parameters:
units- the units of the offset Y value. If null,AVKey.PIXELSis used during rendering.
-
computeOffset
public java.awt.geom.Point2D.Double computeOffset(double width, double height, java.lang.Double xScale, java.lang.Double yScale)Computes the X and Y offset specified by this offset applied to a specified rectangle.- Parameters:
width- the rectangle width.height- the rectangle height.xScale- an optional scale to apply to the X coordinate of the offset. May be null.yScale- an optional scale to apply to the Y coordinate of the offset. May be null.- Returns:
- the result of applying this offset to the specified rectangle and incorporating the optional scales.
-
getRestorableState
public void getRestorableState(RestorableSupport restorableSupport, RestorableSupport.StateObject context)
Saves the offset's current state in the specifiedrestorableSupport. Ifcontextis notnull, the state is appended to it. Otherwise the state is added to theRestorableSupportroot. This state can be restored later by callingrestoreState(gov.nasa.worldwind.util.RestorableSupport, gov.nasa.worldwind.util.RestorableSupport.StateObject).- Parameters:
restorableSupport- theRestorableSupportthat receives the offset's state.context- theStateObjectthe state is appended to, if notnull.- Throws:
java.lang.IllegalArgumentException- ifrestorableSupportisnull.
-
restoreState
public void restoreState(RestorableSupport restorableSupport, RestorableSupport.StateObject context)
Restores the state of any offset parameters contained in the specifiedRestorableSupport. If theStateObjectis notnullit's searched for state values, otherwise theRestorableSupportroot is searched.- Parameters:
restorableSupport- theRestorableSupportthat contains the offset's state.context- theStateObjectto search for state values, if notnull.- Throws:
java.lang.IllegalArgumentException- ifrestorableSupportisnull.
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
-