public class Size
extends java.lang.Object
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.AVKey.PIXELS
, which indicates pixel units relative to the lower left corner of the
image, or AVKey.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.
Modifier and Type | Field and Description |
---|---|
static 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.
|
protected java.lang.String |
heightMode
Size mode for height.
|
protected double |
heightParam
Height size parameter.
|
protected java.lang.String |
heightUnits
Units of height.
|
static java.lang.String |
MAINTAIN_ASPECT_RATIO
Size mode to indicate that the content's aspect ratio must be maintained.
|
static java.lang.String |
NATIVE_DIMENSION
Size mode to indicate that the content's native dimension must be used.
|
protected java.lang.String |
widthMode
Size mode for width.
|
protected double |
widthParam
Width size parameter.
|
protected java.lang.String |
widthUnits
Units of width.
|
Constructor and 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.
|
Modifier and Type | Method and Description |
---|---|
java.awt.Dimension |
compute(int rectWidth,
int rectHeight,
int containerWidth,
int containerHeight)
Computes the width and height of a rectangle within a container rectangle.
|
protected double |
computeSize(double size,
java.lang.String units,
double containerDimension)
Compute a dimension taking into account the units of the dimension.
|
protected java.lang.String |
convertLegacyModeString(java.lang.String string)
Converts a legacy size mode
string ("NativeDimension", "MaintainAspectRatio", "ExplicitDimension"),
into one of the mode constants (NATIVE_DIMENSION , MAINTAIN_ASPECT_RATIO , or
EXPLICIT_DIMENSION ). |
boolean |
equals(java.lang.Object o) |
static Size |
fromFraction(double widthFraction,
double heightFraction)
Creates a new size from explicit fraction dimensions.
|
static Size |
fromPixels(int widthInPixels,
int heightInPixels)
Create a size from explicit pixel dimensions.
|
double |
getHeight()
Get the unscaled height.
|
java.lang.String |
getHeightMode()
Get the mode of the height dimension.
|
java.lang.String |
getHeightUnits()
Returns the units of the offset Y value.
|
void |
getRestorableState(RestorableSupport restorableSupport,
RestorableSupport.StateObject context)
Saves the size's current state in the specified
restorableSupport . |
double |
getWidth()
Get the unscaled width.
|
java.lang.String |
getWidthMode()
Get the mode of the width dimension.
|
java.lang.String |
getWidthUnits()
Returns the units of the offset X value.
|
int |
hashCode() |
void |
restoreState(RestorableSupport restorableSupport,
RestorableSupport.StateObject context)
Restores the state of any size parameters contained in the specified
RestorableSupport . |
void |
setHeight(java.lang.String mode,
double height,
java.lang.String units)
Set the height.
|
void |
setWidth(java.lang.String mode,
double width,
java.lang.String units)
Set the width.
|
public static final java.lang.String EXPLICIT_DIMENSION
protected java.lang.String heightMode
protected double heightParam
protected java.lang.String heightUnits
public static final java.lang.String MAINTAIN_ASPECT_RATIO
public static final java.lang.String NATIVE_DIMENSION
protected java.lang.String widthMode
protected double widthParam
protected java.lang.String widthUnits
public Size()
public Size(java.lang.String widthMode, double widthParam, java.lang.String widthUnits, java.lang.String heightMode, double heightParam, java.lang.String heightUnits)
widthMode
- Width mode, one of NATIVE_DIMENSION
, MAINTAIN_ASPECT_RATIO
, or EXPLICIT_DIMENSION
.widthParam
- The width (applies only to EXPLICIT_DIMENSION
mode).widthUnits
- Units of width
. Either AVKey.PIXELS
or AVKey.PIXELS
.heightMode
- height mode, one of NATIVE_DIMENSION
, MAINTAIN_ASPECT_RATIO
, or EXPLICIT_DIMENSION
.heightParam
- The height (applies only to EXPLICIT_DIMENSION
mode).heightUnits
- Units of height
. Either AVKey.PIXELS
or AVKey.PIXELS
.setWidth(String, double, String)
,
setHeight(String, double, String)
public java.awt.Dimension compute(int rectWidth, int rectHeight, int containerWidth, int containerHeight)
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.protected double computeSize(double size, java.lang.String units, double containerDimension)
size
- The size parameter.units
- One of AVKey.PIXELS
or AVKey.FRACTION
. If the units
value is
not one of the expected options, AVKey.PIXELS
is used as the default.containerDimension
- The viewport dimension.protected java.lang.String convertLegacyModeString(java.lang.String string)
string
("NativeDimension", "MaintainAspectRatio", "ExplicitDimension"),
into one of the mode constants (NATIVE_DIMENSION
, MAINTAIN_ASPECT_RATIO
, or
EXPLICIT_DIMENSION
). Returns the input string unmodified if the input does not match a legacy size
mode.string
- the legacy size mode String
to convert to a size mode.string
is not a legacy size mode.public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public static Size fromFraction(double widthFraction, double heightFraction)
widthFraction
- the size's width as a fraction of the containing rectangle.heightFraction
- the size's height as a fraction of the containing rectangle.public static Size fromPixels(int widthInPixels, int heightInPixels)
widthInPixels
- Width of rectangle in pixels.heightInPixels
- Height of rectangle in pixels.public double getHeight()
getHeightMode()
,
getHeightUnits()
public java.lang.String getHeightMode()
NATIVE_DIMENSION
, MAINTAIN_ASPECT_RATIO
, or EXPLICIT_DIMENSION
.public java.lang.String getHeightUnits()
setHeight(String, double, String)
for a description of the
recognized values.public void getRestorableState(RestorableSupport restorableSupport, RestorableSupport.StateObject context)
restorableSupport
. If context
is not
null
, the state is appended to it. Otherwise the state is added to the
RestorableSupport
root. This state can be restored later by calling restoreState(gov.nasa.worldwind.util.RestorableSupport, gov.nasa.worldwind.util.RestorableSupport.StateObject)
.restorableSupport
- the RestorableSupport
that receives the size's state.context
- the StateObject
the state is appended to, if not null
.java.lang.IllegalArgumentException
- if restorableSupport
is null
.public double getWidth()
getWidthMode()
,
getWidthUnits()
public java.lang.String getWidthMode()
NATIVE_DIMENSION
, MAINTAIN_ASPECT_RATIO
, or EXPLICIT_DIMENSION
.public java.lang.String getWidthUnits()
setWidth(String, double, String)
for a description of the
recognized values.public int hashCode()
hashCode
in class java.lang.Object
public void restoreState(RestorableSupport restorableSupport, RestorableSupport.StateObject context)
RestorableSupport
. If the
StateObject
is not null
it's searched for state values, otherwise the
RestorableSupport
root is searched.restorableSupport
- the RestorableSupport
that contains the size's state.context
- the StateObject
to search for state values, if not null
.java.lang.IllegalArgumentException
- if restorableSupport
is null
.public void setHeight(java.lang.String mode, double height, java.lang.String units)
mode
- Width mode, one of NATIVE_DIMENSION
, MAINTAIN_ASPECT_RATIO
, or EXPLICIT_DIMENSION
.height
- The width (applies only to EXPLICIT_DIMENSION
mode).units
- Units of width
. Either AVKey.PIXELS
or AVKey.FRACTION
.java.lang.IllegalArgumentException
- if mode
is null.public void setWidth(java.lang.String mode, double width, java.lang.String units)
mode
- Width mode, one of NATIVE_DIMENSION
, MAINTAIN_ASPECT_RATIO
, or EXPLICIT_DIMENSION
.width
- The width (applies only to EXPLICIT_DIMENSION
mode).units
- Units of width
. Either AVKey.PIXELS
or AVKey.PIXELS
.java.lang.IllegalArgumentException
- if mode
is null.