[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[cp-patches] FYI: javax/print/attribute/standard/MediaPrintableArea fixl
From: |
Wolfgang Baer |
Subject: |
[cp-patches] FYI: javax/print/attribute/standard/MediaPrintableArea fixlets and additions |
Date: |
Mon, 19 Dec 2005 12:17:51 +0100 |
User-agent: |
Debian Thunderbird 1.0.7 (X11/20051017) |
Hi,
this patch completes MediaPrintableArea.
Regards,
Wolfgang
2005-12-19 Wolfgang Baer <address@hidden>
* 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.
Index: javax/print/attribute/standard/MediaPrintableArea.java
===================================================================
RCS file:
/cvsroot/classpath/classpath/javax/print/attribute/standard/MediaPrintableArea.java,v
retrieving revision 1.2
diff -u -r1.2 MediaPrintableArea.java
--- javax/print/attribute/standard/MediaPrintableArea.java 2 Jul 2005
20:32:46 -0000 1.2
+++ javax/print/attribute/standard/MediaPrintableArea.java 19 Dec 2005
11:15:18 -0000
@@ -43,23 +43,71 @@
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 (address@hidden)
+ * @author Wolfgang Baer (address@hidden)
*/
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< 0 or y i< 0 or w i<= 0
* or h i<= 0 or units i< 1
@@ -69,14 +117,21 @@
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< 0 or y i< 0 or w i<= 0
* or h i<= 0 or units i< 1
@@ -86,16 +141,16 @@
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 @@
}
/**
- * 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 < 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 < 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 < 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 < 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 < 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) };
+ }
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [cp-patches] FYI: javax/print/attribute/standard/MediaPrintableArea fixlets and additions,
Wolfgang Baer <=