summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWolfgang Baer <WBaer@gmx.de>2005-12-19 11:18:47 +0000
committerWolfgang Baer <WBaer@gmx.de>2005-12-19 11:18:47 +0000
commitb7e3091850a9bcdff8c0a42748d4f595359a55b9 (patch)
treec8e325723b60996559490c734f4ef2c4e3cedf06
parent8ee72e9cdba8819a684144f6d44633c7cd9feac4 (diff)
downloadclasspath-b7e3091850a9bcdff8c0a42748d4f595359a55b9.tar.gz
2005-12-19 Wolfgang Baer <WBaer@gmx.de>
* javax/print/attribute/standard/MediaPrintableArea.java: Added and updated javadocs to class and methods. (x): Use int as type. (y): Likewise. (width): Likewise. (height): Likewise. (MediaPrintableArea): Convert values to micrometers. (MediaPrintableArea): Likewise. (getX): Convert return value into choosen units. (getY): Convert return value into choosen units. (getWidth): Convert return value into choosen units. (getHeight): Convert return value into choosen units. (equals): New overridden method. (toString): Likewise. (hashCode): Likewise. (toString): New method. (getPrintableArea): Likewise.
-rw-r--r--ChangeLog20
-rw-r--r--javax/print/attribute/standard/MediaPrintableArea.java215
2 files changed, 210 insertions, 25 deletions
diff --git a/ChangeLog b/ChangeLog
index 42b1b559a..aa1f16d62 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,25 @@
2005-12-19 Wolfgang Baer <WBaer@gmx.de>
+ * javax/print/attribute/standard/MediaPrintableArea.java:
+ Added and updated javadocs to class and methods.
+ (x): Use int as type.
+ (y): Likewise.
+ (width): Likewise.
+ (height): Likewise.
+ (MediaPrintableArea): Convert values to micrometers.
+ (MediaPrintableArea): Likewise.
+ (getX): Convert return value into choosen units.
+ (getY): Convert return value into choosen units.
+ (getWidth): Convert return value into choosen units.
+ (getHeight): Convert return value into choosen units.
+ (equals): New overridden method.
+ (toString): Likewise.
+ (hashCode): Likewise.
+ (toString): New method.
+ (getPrintableArea): Likewise.
+
+2005-12-19 Wolfgang Baer <WBaer@gmx.de>
+
* javax/print/attribute/standard/Media.java (equals):
Reimplemented to allow future subclasses to behave correctly.
diff --git a/javax/print/attribute/standard/MediaPrintableArea.java b/javax/print/attribute/standard/MediaPrintableArea.java
index c7cf8d3a9..9a1342cb4 100644
--- a/javax/print/attribute/standard/MediaPrintableArea.java
+++ b/javax/print/attribute/standard/MediaPrintableArea.java
@@ -43,23 +43,71 @@ import javax.print.attribute.PrintJobAttribute;
import javax.print.attribute.PrintRequestAttribute;
/**
+ * The <code>MediaPrintableArea</code> attribute specifies the area
+ * of a media sheet which is available for printing.
+ * <p>
+ * Due to hardware limitation its not possible with most printers to use the
+ * whole area of a media sheet for printing. This attribute defines the area
+ * for printing through the values of the upper left corner position (x,y)
+ * on the sheet and the available width and height of the area. The units of
+ * the values are determined by two defined constants:
+ * <ul>
+ * <li>INCH - defines an inch</li>
+ * <li>MM - defines a millimeter</li>
+ * </ul>
+ * </p>
+ * <p>
+ * <b>Internal storage:</b><br>
+ * The values of x, y, width and height are stored internally in micrometers.
+ * The values of the provided constants for inch (value 25400) and millimeters
+ * (value 1000) are used as conversion factors to the internal storage units.
+ * To get the internal micrometers values a multiplication of a given
+ * size value with its units constant value is done. Retrieving the size value
+ * for specific units is done by dividing the internal stored value by the
+ * units constant value.
+ * </p>
+ * <p>
+ * <b>IPP Compatibility:</b> MediaPrintableArea is not an IPP 1.1 attribute.
+ * </p>
+ *
* @author Michael Koch (konqueror@gmx.de)
+ * @author Wolfgang Baer (WBaer@gmx.de)
*/
public final class MediaPrintableArea
implements DocAttribute, PrintJobAttribute, PrintRequestAttribute
{
private static final long serialVersionUID = -1597171464050795793L;
+ /**
+ * Constant for the units of inches.
+ * The actual value is the conversion factor to micrometers.
+ */
public static final int INCH = 25400;
+
+ /**
+ * Constant for the units of millimeters.
+ * The actual value is the conversion factor to micrometers.
+ */
public static final int MM = 1000;
- private float x;
- private float y;
- private float width;
- private float height;
+ /** x in micrometers. */
+ private int x;
+ /** y in micrometers. */
+ private int y;
+ /** width in micrometers. */
+ private int width;
+ /** height in micrometers. */
+ private int height;
/**
- * Creates a new <code>MediaPrintableArea</code> object.
+ * Creates a new <code>MediaPrintableArea</code> object with the given
+ * float values for the given units.
+ *
+ * @param x start of the printable area on the sheet in x direction.
+ * @param y start of the printable area on the sheet in y direction.
+ * @param w the width of the printable area.
+ * @param h the height of the printable area.
+ * @param units the units of the given values.
*
* @throws IllegalArgumentException if x i&lt; 0 or y i&lt; 0 or w i&lt;= 0
* or h i&lt;= 0 or units i&lt; 1
@@ -69,14 +117,21 @@ public final class MediaPrintableArea
if (x < 0.0f || y < 0.0f || w <= 0.0f || h <= 0.0f)
throw new IllegalArgumentException();
- this.x = x;
- this.y = y;
- this.width = w;
- this.height = h;
+ this.x = (int) (x * units + 0.5f);
+ this.y = (int) (y * units + 0.5f);
+ this.width = (int) (w * units + 0.5f);
+ this.height = (int) (h * units + 0.5f);
}
/**
- * Creates a new <code>MediaPrintableArea</code> object.
+ * Creates a new <code>MediaPrintableArea</code> object with the given
+ * int values for the given units.
+ *
+ * @param x start of the printable area on the sheet in x direction.
+ * @param y start of the printable area on the sheet in y direction.
+ * @param w the width of the printable area.
+ * @param h the height of the printable area.
+ * @param units the units of the given values.
*
* @throws IllegalArgumentException if x i&lt; 0 or y i&lt; 0 or w i&lt;= 0
* or h i&lt;= 0 or units i&lt; 1
@@ -86,16 +141,16 @@ public final class MediaPrintableArea
if (x < 0 || y < 0 || w <= 0 || h <= 0)
throw new IllegalArgumentException();
- this.x = x;
- this.y = y;
- this.width = w;
- this.height = h;
+ this.x = x * units;
+ this.y = y * units;
+ this.width = w * units;
+ this.height = h * units;
}
/**
* Returns category of this class.
*
- * @return the class <code>MediaPrintableArea</code> itself
+ * @return The class <code>MediaPrintableArea</code> itself.
*/
public Class getCategory()
{
@@ -103,44 +158,154 @@ public final class MediaPrintableArea
}
/**
- * Returns name of this class.
+ * Returns the name of this attribute.
*
- * @return the string "media-printable-area"
+ * @return The name "media-printable-area".
*/
public String getName()
{
return "media-printable-area";
}
+ /**
+ * Returns the height of the printable area for the given units.
+ *
+ * @param units the units conversion factor.
+ * @return The height.
+ *
+ * @throws IllegalArgumentException if <code>units</code> is &lt; 1
+ */
public float getHeight(int units)
{
if (units < 1)
- throw new IllegalArgumentException();
+ throw new IllegalArgumentException("units may not be less than 1");
- return height * units;
+ return height / ((float)units);
}
+ /**
+ * Returns the width of the printable area for the given units.
+ *
+ * @param units the units conversion factor.
+ * @return The width.
+ *
+ * @throws IllegalArgumentException if <code>units</code> is &lt; 1
+ */
public float getWidth(int units)
{
if (units < 1)
- throw new IllegalArgumentException();
+ throw new IllegalArgumentException("units may not be less than 1");
- return width * units;
+ return width / ((float)units);
}
+ /**
+ * Returns the position in x direction of the printable area
+ * for the given units.
+ *
+ * @param units the units conversion factor.
+ * @return The position in x direction.
+ *
+ * @throws IllegalArgumentException if <code>units</code> is &lt; 1
+ */
public float getX(int units)
{
if (units < 1)
- throw new IllegalArgumentException();
+ throw new IllegalArgumentException("units may not be less than 1");
- return x * units;
+ return x / ((float)units);
}
+ /**
+ * Returns the position in y direction of the printable area
+ * for the given units.
+ *
+ * @param units the units conversion factor.
+ * @return The position in y direction.
+ *
+ * @throws IllegalArgumentException if <code>units</code> is &lt; 1
+ */
public float getY(int units)
{
if (units < 1)
- throw new IllegalArgumentException();
+ throw new IllegalArgumentException("units may not be less than 1");
- return y * units;
+ return y / ((float)units);
}
+
+ /**
+ * Tests if the given object is equal to this object.
+ *
+ * @param obj the object to test
+ *
+ * @return <code>true</code> if both objects are equal, <code>false</code> otherwise.
+ */
+ public boolean equals(Object obj)
+ {
+ if (! (obj instanceof MediaPrintableArea))
+ return false;
+
+ MediaPrintableArea tmp = (MediaPrintableArea) obj;
+
+ return (x == tmp.getX(1) && y == tmp.getY(1)
+ && width == tmp.getWidth(1) && height == tmp.getHeight(1));
+ }
+
+ /**
+ * Returns the string representation for this object in units of millimeters..
+ * <p>
+ * The returned string is in the form "(x,y)->(width,height)mm".
+ * </p>
+ * @return The string representation in millimeters.
+ */
+ public String toString()
+ {
+ return toString(MM, "mm");
+ }
+
+ /**
+ * Returns the hashcode for this object.
+ *
+ * @return The hashcode.
+ */
+ public int hashCode()
+ {
+ return x ^ y + width ^ height;
+ }
+
+ /**
+ * Returns the string representation for this object in units of millimeters..
+ * <p>
+ * The returned string is in the form "(x,y)->(width,height)unitsName".
+ * </p>
+ * @param units the units to use for conversion.
+ * @param unitsName the name of the used units, appended to the resulting
+ * string if not <code>null</code>.
+ * @return The string representation in millimeters.
+ *
+ * @throws IllegalArgumentException if <code>units</code> is &lt; 1
+ */
+ public String toString(int units, String unitsName)
+ {
+ if (units < 1)
+ throw new IllegalArgumentException("units may not be less than 1");
+
+ String tmp = "(" + getX(units) + "," + getY(units) + ")->("
+ + getWidth(units) + "," + getHeight(units) + ")";
+
+ return unitsName == null ? tmp : tmp + unitsName;
+ }
+
+ /**
+ * Returns the printable area as an float[] with 4 values
+ * (order x, y, width, height) in the given units.
+ *
+ * @param units the units to use.
+ * @return The printable area as float array.
+ */
+ public float[] getPrintableArea(int units)
+ {
+ return new float[] { getX(units), getY(units),
+ getWidth(units), getHeight(units) };
+ }
}