public class Size extends Object
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 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 String |
heightMode
Size mode for height.
|
protected double |
heightParam
Height size parameter.
|
protected String |
heightUnits
Units of height.
|
static String |
MAINTAIN_ASPECT_RATIO
Size mode to indicate that the content's aspect ratio must be maintained.
|
static String |
NATIVE_DIMENSION
Size mode to indicate that the content's native dimension must be used.
|
protected String |
widthMode
Size mode for width.
|
protected double |
widthParam
Width size parameter.
|
protected String |
widthUnits
Units of width.
|
| Constructor and Description |
|---|
Size()
Create a Size object that will preserve native dimensions.
|
Size(String widthMode,
double widthParam,
String widthUnits,
String heightMode,
double heightParam,
String heightUnits)
Create a Size with specified dimensions.
|
| Modifier and Type | Method and Description |
|---|---|
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,
String units,
double containerDimension)
Compute a dimension taking into account the units of the dimension.
|
protected String |
convertLegacyModeString(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(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.
|
String |
getHeightMode()
Get the mode of the height dimension.
|
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.
|
String |
getWidthMode()
Get the mode of the width dimension.
|
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(String mode,
double height,
String units)
Set the height.
|
void |
setWidth(String mode,
double width,
String units)
Set the width.
|
public static final String EXPLICIT_DIMENSION
protected String heightMode
protected double heightParam
protected String heightUnits
public static final String MAINTAIN_ASPECT_RATIO
public static final String NATIVE_DIMENSION
protected String widthMode
protected double widthParam
protected String widthUnits
public Size()
public Size(String widthMode, double widthParam, String widthUnits, String heightMode, double heightParam, 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 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,
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 String convertLegacyModeString(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 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 String getHeightMode()
NATIVE_DIMENSION, MAINTAIN_ASPECT_RATIO, or EXPLICIT_DIMENSION.public 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.IllegalArgumentException - if restorableSupport is null.public double getWidth()
getWidthMode(),
getWidthUnits()public String getWidthMode()
NATIVE_DIMENSION, MAINTAIN_ASPECT_RATIO, or EXPLICIT_DIMENSION.public String getWidthUnits()
setWidth(String, double, String) for a description of the
recognized values.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.IllegalArgumentException - if restorableSupport is null.public void setHeight(String mode, double height, 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.IllegalArgumentException - if mode is null.public void setWidth(String mode, double width, 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.IllegalArgumentException - if mode is null.