MediaSizepublic class MediaSize extends Size2DSyntax implements AttributeClass MediaSize is a two-dimensional size valued printing attribute class
that indicates the dimensions of the medium in a portrait orientation, with
the X dimension running along the bottom edge and the Y dimension running
along the left edge. Thus, the Y dimension must be greater than or equal to
the X dimension. Class MediaSize declares many standard media size
values, organized into nested classes for ISO, JIS, North American,
engineering, and other media.
MediaSize is not yet used to specify media. Its current role is
as a mapping for named media (see {@link MediaSizeName MediaSizeName}).
Clients can use the mapping method
MediaSize.getMediaSizeForName(MediaSizeName)
to find the physical dimensions of the MediaSizeName instances
enumerated in this API. This is useful for clients which need this
information to format & paginate printing.
|
Fields Summary |
---|
private static final long | serialVersionUID | private MediaSizeName | mediaName | private static HashMap | mediaMap | private static Vector | sizeVector |
Constructors Summary |
---|
public MediaSize(float x, float y, int units)Construct a new media size attribute from the given floating-point
values.
super (x, y, units);
if (x > y) {
throw new IllegalArgumentException("X dimension > Y dimension");
}
sizeVector.add(this);
| public MediaSize(int x, int y, int units)Construct a new media size attribute from the given integer values.
super (x, y, units);
if (x > y) {
throw new IllegalArgumentException("X dimension > Y dimension");
}
sizeVector.add(this);
| public MediaSize(float x, float y, int units, MediaSizeName media)Construct a new media size attribute from the given floating-point
values.
super (x, y, units);
if (x > y) {
throw new IllegalArgumentException("X dimension > Y dimension");
}
mediaName = media;
mediaMap.put(mediaName, this);
sizeVector.add(this);
| public MediaSize(int x, int y, int units, MediaSizeName media)Construct a new media size attribute from the given integer values.
super (x, y, units);
if (x > y) {
throw new IllegalArgumentException("X dimension > Y dimension");
}
mediaName = media;
mediaMap.put(mediaName, this);
sizeVector.add(this);
|
Methods Summary |
---|
public boolean | equals(java.lang.Object object)Returns whether this media size attribute is equivalent to the passed
in object.
To be equivalent, all of the following conditions must be true:
-
object is not null.
-
object is an instance of class MediaSize.
-
This media size attribute's X dimension is equal to
object 's X dimension.
-
This media size attribute's Y dimension is equal to
object 's Y dimension.
return (super.equals(object) && object instanceof MediaSize);
| public static javax.print.attribute.standard.MediaSizeName | findMedia(float x, float y, int units)The specified dimensions are used to locate a matching MediaSize
instance from amongst all the standard MediaSize instances.
If there is no exact match, the closest match is used.
The MediaSize is in turn used to locate the MediaSizeName object.
This method may return null if the closest matching MediaSize
has no corresponding Media instance.
This method is useful for clients which have only dimensions and
want to find a Media which corresponds to the dimensions.
MediaSize match = MediaSize.ISO.A4;
if (x <= 0.0f || y <= 0.0f || units < 1) {
throw new IllegalArgumentException("args must be +ve values");
}
double ls = x * x + y * y;
double tmp_ls;
float []dim;
float diffx = x;
float diffy = y;
for (int i=0; i < sizeVector.size() ; i++) {
MediaSize mediaSize = (MediaSize)sizeVector.elementAt(i);
dim = mediaSize.getSize(units);
if (x == dim[0] && y == dim[1]) {
match = mediaSize;
break;
} else {
diffx = x - dim[0];
diffy = y - dim[1];
tmp_ls = diffx * diffx + diffy * diffy;
if (tmp_ls < ls) {
ls = tmp_ls;
match = mediaSize;
}
}
}
return match.getMediaSizeName();
| public final java.lang.Class | getCategory()Get the printing attribute class which is to be used as the "category"
for this printing attribute value.
For class MediaSize and any vendor-defined subclasses, the category is
class MediaSize itself.
return MediaSize.class;
| public static javax.print.attribute.standard.MediaSize | getMediaSizeForName(javax.print.attribute.standard.MediaSizeName media)Get the MediaSize for the specified named media.
return (MediaSize)mediaMap.get(media);
| public javax.print.attribute.standard.MediaSizeName | getMediaSizeName()Get the media name, if any, for this size.
return mediaName;
| public final java.lang.String | getName()Get the name of the category of which this attribute value is an
instance.
For class MediaSize and any vendor-defined subclasses, the category
name is "media-size" .
return "media-size";
|
|