Package gov.nasa.worldwind.render
Class Size
- java.lang.Object
-
- gov.nasa.worldwind.render.Size
-
public class Size extends java.lang.ObjectDefines the dimensions of an image, label or other screen-space item relative to a container (for example, the viewport). A size contains a width, a height, a width size mode, a height size mode, and for each of these a "units" string indicating the coordinate units.The possible size modes are:
-
NATIVE_DIMENSION- Maintain the native dimensions. -
MAINTAIN_ASPECT_RATIO- Maintain the aspect ratio of the image when one dimension is specified and the other is not. -
EXPLICIT_DIMENSION- Use an explicit dimension. This dimension may be either an absolute pixel value, or a fraction of the container.
Recognized units are
AVKey.PIXELS, which indicates pixel units relative to the lower left corner of the image, orAVKey.FRACTION, which indicates the units are fractions of the image width and height.Examples:
Width mode Height mode Width (Units) Height (Units) Result -------------------------------------------------------------------------------------------------------------------- Native Native N/A N/A Keep native dimensions Aspect ratio Explicit N/A 100 (pix) Scale image so that height is 100 pixels, but maintain aspect ratio Explicit Aspect ratio 0.5 (fraction) N/A Make the width half of the container, and scale height to maintain aspect ratio Explicit Native 1.0 (fraction) N/A Stretch the image to fill the width of the container, but do not scale the height.This class implements the functionality of a KML size. -
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringEXPLICIT_DIMENSIONSize mode to indicate that the size parameter indicates an explicit dimension measured either in pixels, or as a fraction of the container.protected java.lang.StringheightModeSize mode for height.protected doubleheightParamHeight size parameter.protected java.lang.StringheightUnitsUnits of height.static java.lang.StringMAINTAIN_ASPECT_RATIOSize mode to indicate that the content's aspect ratio must be maintained.static java.lang.StringNATIVE_DIMENSIONSize mode to indicate that the content's native dimension must be used.protected java.lang.StringwidthModeSize mode for width.protected doublewidthParamWidth size parameter.protected java.lang.StringwidthUnitsUnits of width.
-
Constructor Summary
Constructors Constructor Description Size()Create a Size object that will preserve native dimensions.Size(java.lang.String widthMode, double widthParam, java.lang.String widthUnits, java.lang.String heightMode, double heightParam, java.lang.String heightUnits)Create a Size with specified dimensions.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.awt.Dimensioncompute(int rectWidth, int rectHeight, int containerWidth, int containerHeight)Computes the width and height of a rectangle within a container rectangle.protected doublecomputeSize(double size, java.lang.String units, double containerDimension)Compute a dimension taking into account the units of the dimension.protected java.lang.StringconvertLegacyModeString(java.lang.String string)Converts a legacy size modestring("NativeDimension", "MaintainAspectRatio", "ExplicitDimension"), into one of the mode constants (NATIVE_DIMENSION,MAINTAIN_ASPECT_RATIO, orEXPLICIT_DIMENSION).booleanequals(java.lang.Object o)static SizefromFraction(double widthFraction, double heightFraction)Creates a new size from explicit fraction dimensions.static SizefromPixels(int widthInPixels, int heightInPixels)Create a size from explicit pixel dimensions.doublegetHeight()Get the unscaled height.java.lang.StringgetHeightMode()Get the mode of the height dimension.java.lang.StringgetHeightUnits()Returns the units of the offset Y value.voidgetRestorableState(RestorableSupport restorableSupport, RestorableSupport.StateObject context)Saves the size's current state in the specifiedrestorableSupport.doublegetWidth()Get the unscaled width.java.lang.StringgetWidthMode()Get the mode of the width dimension.java.lang.StringgetWidthUnits()Returns the units of the offset X value.inthashCode()voidrestoreState(RestorableSupport restorableSupport, RestorableSupport.StateObject context)Restores the state of any size parameters contained in the specifiedRestorableSupport.voidsetHeight(java.lang.String mode, double height, java.lang.String units)Set the height.voidsetWidth(java.lang.String mode, double width, java.lang.String units)Set the width.
-
-
-
Field Detail
-
NATIVE_DIMENSION
public static final java.lang.String NATIVE_DIMENSION
Size mode to indicate that the content's native dimension must be used.- See Also:
- Constant Field Values
-
MAINTAIN_ASPECT_RATIO
public static final java.lang.String MAINTAIN_ASPECT_RATIO
Size mode to indicate that the content's aspect ratio must be maintained.- See Also:
- Constant Field Values
-
EXPLICIT_DIMENSION
public static final java.lang.String EXPLICIT_DIMENSION
Size mode to indicate that the size parameter indicates an explicit dimension measured either in pixels, or as a fraction of the container.- See Also:
- Constant Field Values
-
widthMode
protected java.lang.String widthMode
-
widthUnits
protected java.lang.String widthUnits
Units of width.
-
widthParam
protected double widthParam
Width size parameter.
-
heightMode
protected java.lang.String heightMode
-
heightUnits
protected java.lang.String heightUnits
Units of height.
-
heightParam
protected double heightParam
Height size parameter.
-
-
Constructor Detail
-
Size
public Size()
Create a Size object that will preserve native dimensions.
-
Size
public Size(java.lang.String widthMode, double widthParam, java.lang.String widthUnits, java.lang.String heightMode, double heightParam, java.lang.String heightUnits)Create a Size with specified dimensions.- Parameters:
widthMode- Width mode, one ofNATIVE_DIMENSION,MAINTAIN_ASPECT_RATIO, orEXPLICIT_DIMENSION.widthParam- The width (applies only toEXPLICIT_DIMENSIONmode).widthUnits- Units ofwidth. EitherAVKey.PIXELSorAVKey.PIXELS.heightMode- height mode, one ofNATIVE_DIMENSION,MAINTAIN_ASPECT_RATIO, orEXPLICIT_DIMENSION.heightParam- The height (applies only toEXPLICIT_DIMENSIONmode).heightUnits- Units ofheight. EitherAVKey.PIXELSorAVKey.PIXELS.- See Also:
setWidth(String, double, String),setHeight(String, double, String)
-
-
Method Detail
-
fromPixels
public static Size fromPixels(int widthInPixels, int heightInPixels)
Create a size from explicit pixel dimensions.- Parameters:
widthInPixels- Width of rectangle in pixels.heightInPixels- Height of rectangle in pixels.- Returns:
- New size object.
-
fromFraction
public static Size fromFraction(double widthFraction, double heightFraction)
Creates a new size from explicit fraction dimensions.- Parameters:
widthFraction- the size's width as a fraction of the containing rectangle.heightFraction- the size's height as a fraction of the containing rectangle.- Returns:
- a new size with the specified width and height.
-
setWidth
public void setWidth(java.lang.String mode, double width, java.lang.String units)Set the width.- Parameters:
mode- Width mode, one ofNATIVE_DIMENSION,MAINTAIN_ASPECT_RATIO, orEXPLICIT_DIMENSION.width- The width (applies only toEXPLICIT_DIMENSIONmode).units- Units ofwidth. EitherAVKey.PIXELSorAVKey.PIXELS.- Throws:
java.lang.IllegalArgumentException- ifmodeis null.
-
setHeight
public void setHeight(java.lang.String mode, double height, java.lang.String units)Set the height.- Parameters:
mode- Width mode, one ofNATIVE_DIMENSION,MAINTAIN_ASPECT_RATIO, orEXPLICIT_DIMENSION.height- The width (applies only toEXPLICIT_DIMENSIONmode).units- Units ofwidth. EitherAVKey.PIXELSorAVKey.FRACTION.- Throws:
java.lang.IllegalArgumentException- ifmodeis null.
-
getWidthUnits
public java.lang.String getWidthUnits()
Returns the units of the offset X value. SeesetWidth(String, double, String)for a description of the recognized values.- Returns:
- the units of the offset X value, or null.
-
getHeightUnits
public java.lang.String getHeightUnits()
Returns the units of the offset Y value. SeesetHeight(String, double, String)for a description of the recognized values.- Returns:
- the units of the offset Y value, or null.
-
getWidthMode
public java.lang.String getWidthMode()
Get the mode of the width dimension.- Returns:
- Width mode, one of
NATIVE_DIMENSION,MAINTAIN_ASPECT_RATIO, orEXPLICIT_DIMENSION.
-
getHeightMode
public java.lang.String getHeightMode()
Get the mode of the height dimension.- Returns:
- Height mode, one of
NATIVE_DIMENSION,MAINTAIN_ASPECT_RATIO, orEXPLICIT_DIMENSION.
-
getWidth
public double getWidth()
Get the unscaled width.- Returns:
- Unscaled width. The units of this value depend on the current height units.
- See Also:
getWidthMode(),getWidthUnits()
-
getHeight
public double getHeight()
Get the unscaled height.- Returns:
- Unscaled height. The units of this value depend on the current height units.
- See Also:
getHeightMode(),getHeightUnits()
-
compute
public java.awt.Dimension compute(int rectWidth, int rectHeight, int containerWidth, int containerHeight)Computes the width and height of a rectangle within a container rectangle.- Parameters:
rectWidth- The width of the rectangle to size.rectHeight- The height of the rectangle to size.containerWidth- The width of the container.containerHeight- The height of the container.- Returns:
- The desired image dimensions.
-
computeSize
protected double computeSize(double size, java.lang.String units, double containerDimension)Compute a dimension taking into account the units of the dimension.- Parameters:
size- The size parameter.units- One ofAVKey.PIXELSorAVKey.FRACTION. If theunitsvalue is not one of the expected options,AVKey.PIXELSis used as the default.containerDimension- The viewport dimension.- Returns:
- Size in pixels
-
getRestorableState
public void getRestorableState(RestorableSupport restorableSupport, RestorableSupport.StateObject context)
Saves the size'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 size'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 size parameters contained in the specifiedRestorableSupport. If theStateObjectis notnullit's searched for state values, otherwise theRestorableSupportroot is searched.- Parameters:
restorableSupport- theRestorableSupportthat contains the size's state.context- theStateObjectto search for state values, if notnull.- Throws:
java.lang.IllegalArgumentException- ifrestorableSupportisnull.
-
convertLegacyModeString
protected java.lang.String convertLegacyModeString(java.lang.String string)
Converts a legacy size modestring("NativeDimension", "MaintainAspectRatio", "ExplicitDimension"), into one of the mode constants (NATIVE_DIMENSION,MAINTAIN_ASPECT_RATIO, orEXPLICIT_DIMENSION). Returns the input string unmodified if the input does not match a legacy size mode.- Parameters:
string- the legacy size modeStringto convert to a size mode.- Returns:
- a size mode constant, or the input string if
stringis not a legacy size mode.
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
-