public class MediaSpec extends Object
width: 1100pxheight: 850pxdevice-width: 1920pxdevice-height: 1200pxcolor: 8color-index: 0monochrome: 0resolution: 96dpiscan: progressivegrid: 0| Modifier and Type | Class and Description |
|---|---|
static class |
MediaSpec.Feature
Known media query features based on the specification
|
| Modifier and Type | Field and Description |
|---|---|
protected int |
color
Color depth (bits per color) or 0 for no colors
|
protected int |
colorIndex
Number of entries in the color lookup table or 0 when no indexed colors are used
|
protected float |
deviceHeight
Oputput device height in pixels
|
protected float |
deviceWidth
Output device width in pixels
|
static float |
dpi
CSS3 uses a fixed value of 96DPI for computing the lengths
|
static float |
em
the values of 'em' used for computing the pixel lengths
|
static float |
ex
the values of 'em' used for computing the pixel lengths
|
protected static Map<String,MediaSpec.Feature> |
featureMap |
protected int |
grid
1 for a grid device, 0 for bitmap device
|
protected float |
height
Output area height in pixels
|
protected int |
monochrome
Bits per pixel of a monochrome frame buffer or 0 when the device is not monochrome
|
protected float |
resolution
Resolution in DPI
|
protected boolean |
scanInterlace
Indicates interlaced scanning for "tv" media types
|
protected String |
type
Media type name (e.g.
|
protected float |
width
Output area width in pixels
|
| Constructor and Description |
|---|
MediaSpec(String type)
Creates a new media specification with the given media type and default values of the features.
|
| Modifier and Type | Method and Description |
|---|---|
protected Float |
dpiResolution(TermResolution spec)
Converts a resolution from a CSS length to 'dpi'.
|
float |
getAspectRatio()
Obtains the aspect ratio of the display area defined as width / height.
|
int |
getColor()
Obtains the number of bits per color component of the output device.
|
int |
getColorIndex()
Obtains the number of entries in the color lookup table of the output device.
|
float |
getDeviceAspectRation()
Obtains the aspect ratio of the device defined as deviceWidth / deviceHeight.
|
float |
getDeviceHeight()
Obtains the height of the rendering surface of the output device.
|
float |
getDeviceWidth()
Obtains the width of the rendering surface of the output device.
|
protected String |
getExpressionIdentifier(MediaExpression e)
Obtains the identifier specified by the given media query expression.
|
protected Integer |
getExpressionInteger(MediaExpression e)
Obtains the integer specified by the given media query expression.
|
protected Float |
getExpressionLengthPx(MediaExpression e)
Obtains the length specified by the given media query expression.
|
protected Float |
getExpressionRatio(MediaExpression e)
Obtains the ratio specified by the given media query expression.
|
protected Float |
getExpressionResolution(MediaExpression e)
Obtains the resolution specified by the given media query expression.
|
protected MediaSpec.Feature |
getFeatureByName(String name)
Obtains the feature based on its name.
|
int |
getGrid()
Checks whether the output device is grid or bitmap.
|
float |
getHeight()
Obtains the height of the display area.
|
int |
getMonochrome()
Obtains the number of bits per pixel in a monochrome frame buffer.
|
float |
getResolution()
Sets the resolution of the output device, i.e. the density of the pixels.
|
String |
getType()
Obtains the media type of this specification.
|
float |
getWidth()
Obtains the width of the display area.
|
boolean |
isPortrait()
Checks whether the display area orientation is portrait or landscape.
|
boolean |
isScanInterlace()
Checks if the device is using the interlaced or progressive scanning (for "tv" media only).
|
protected void |
loadDefaults()
Loads some reasonable defaults that correspond to a normal desktop configuration.
|
boolean |
matches(MediaExpression e)
Checks if this media specification matches a given media query expression.
|
boolean |
matches(MediaQuery q)
Checks if this media specification matches a given media query.
|
boolean |
matchesEmpty()
Checks whether the media specification matches an empty or missing media query, i.e. whether the
media or import rules with no media queries should be accepted with this media specification.
|
boolean |
matchesOneOf(List<MediaQuery> queries)
Checks whether this media specification matches to at least one of the given media queries.
|
protected Float |
pxLength(TermLength spec)
Converts a length from a CSS length to 'px'.
|
void |
setColor(int color)
Sets the number of bits per color component of the output device.
|
void |
setColorIndex(int colorIndex)
Sets the number of entries in the color lookup table of the output device.
|
void |
setDeviceDimensions(float deviceWidth,
float deviceHeight)
Sets the width of the rendering surface of the output device.
|
void |
setDeviceHeight(float deviceHeight)
Sets the height of the rendering surface of the output device.
|
void |
setDeviceWidth(float deviceWidth)
Sets the width of the rendering surface of the output device.
|
void |
setDimensions(float width,
float height)
Sets the width and height height of the display area.
|
void |
setGrid(int grid)
Sets whether the output device is grid or bitmap.
|
void |
setHeight(float height)
Sets the height of the display area.
|
void |
setMonochrome(int monochrome)
Sets the number of bits per pixel in a monochrome frame buffer.
|
void |
setResolution(float resolution)
Obtains the resolution of the output device, i.e. the density of the pixels.
|
void |
setScanInterlace(boolean scanInterlace)
Sets the device scanning process (for "tv" media only).
|
void |
setWidth(float width)
Sets the width of the display area.
|
String |
toString() |
protected boolean |
valueMatches(Float required,
float current,
boolean min,
boolean max)
Checks whether a value coresponds to the given criteria.
|
protected boolean |
valueMatches(Integer required,
int current,
boolean min,
boolean max)
Checks whether a value coresponds to the given criteria.
|
public static final float em
public static final float ex
public static final float dpi
protected static Map<String,MediaSpec.Feature> featureMap
protected String type
protected float width
protected float height
protected float deviceWidth
protected float deviceHeight
protected int color
protected int colorIndex
protected int monochrome
protected float resolution
protected boolean scanInterlace
protected int grid
public MediaSpec(String type)
type - The media type (e.g. "screen")public String getType()
public float getWidth()
public void setWidth(float width)
width - The width in pixels.public float getHeight()
public void setHeight(float height)
height - The height in pixels.public void setDimensions(float width,
float height)
width - The width in pixels.height - The height in pixels.public float getDeviceWidth()
public void setDeviceWidth(float deviceWidth)
deviceWidth - the width in pixels.public float getDeviceHeight()
public void setDeviceHeight(float deviceHeight)
deviceHeight - the height in pixels.public void setDeviceDimensions(float deviceWidth,
float deviceHeight)
deviceWidth - the width in pixels.deviceHeight - the height in pixels.public int getColor()
public void setColor(int color)
color - The number of bits or 0 if the device is not a color device.public int getColorIndex()
public void setColorIndex(int colorIndex)
colorIndex - The number of lookup table entries or 0 if the device does not use a color lookup table.public int getMonochrome()
public void setMonochrome(int monochrome)
monochrome - The number of bits per pixel or 0 if the device is not a monochrome device.public float getResolution()
public void setResolution(float resolution)
resolution - The resolution in DPI.public boolean isScanInterlace()
true if the device is using the interlaced scanning, false for progressive scanning.public void setScanInterlace(boolean scanInterlace)
scanInterlace - true if the device is using the interlaced scanning, false for progressive scanning.public int getGrid()
public void setGrid(int grid)
grid - If the output device is grid-based (e.g., a "tty" terminal, or a phone display with only one fixed font), the value will be 1. Otherwise, the value will be 0.public float getAspectRatio()
public float getDeviceAspectRation()
public boolean isPortrait()
true when the value of the height media feature is greater than or equal to the value
of the width media feature.public boolean matches(MediaQuery q)
q - The media querytrue when this media specification matches the given media query.public boolean matches(MediaExpression e)
e - The media query expressiontrue when this media specification matches the given expression.public boolean matchesOneOf(List<MediaQuery> queries)
queries - The list of media queries to be matched.true when at least one query matches, false when no query matches.public boolean matchesEmpty()
true when this media specification matches an empty media queryprotected MediaSpec.Feature getFeatureByName(String name)
name - The name of the featurenull if the name is unknownprotected boolean valueMatches(Float required, float current, boolean min, boolean max)
current - the actual media valuerequired - the required value or null for invalid requirementmin - true when the required value is the minimal onemax - true when the required value is the maximal onetrue when the value matches the criteria.protected boolean valueMatches(Integer required, int current, boolean min, boolean max)
required - the required valuecurrent - the tested value or null for invalid valuemin - true when the required value is the minimal onemax - true when the required value is the maximal onetrue when the value matches the criteria.protected Float getExpressionLengthPx(MediaExpression e)
e - The media query expression specifying a length.null when the value cannot be converted to length.protected Float getExpressionResolution(MediaExpression e)
e - The media query expression specifying a resolution.null when the value cannot be converted to resolution.protected Float getExpressionRatio(MediaExpression e)
e - The media query expression specifying a ratio.null when the value cannot be converted to ratio.protected Integer getExpressionInteger(MediaExpression e)
e - The media query expression specifying an integer.null when the value cannot be converted to integer.protected String getExpressionIdentifier(MediaExpression e)
e - The media query expression specifying an identifier.null when the value cannot be converted to an identifier.protected Float pxLength(TermLength spec)
spec - the CSS length specificationnull when the unit is invalidprotected Float dpiResolution(TermResolution spec)
spec - the CSS resolution specificationnull when the unit is invalidprotected void loadDefaults()
Copyright © 2019. All rights reserved.