/[classpath]/classpath/javax/print/attribute/ResolutionSyntax.java
ViewVC logotype

Diff of /classpath/javax/print/attribute/ResolutionSyntax.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.3.2.1 by gnu_andrew, Tue Aug 2 20:12:36 2005 UTC revision 1.3.2.2 by gnu_andrew, Sun Nov 27 21:00:37 2005 UTC
# Line 1  Line 1 
1  /* ResolutionSyntax.java --  /* ResolutionSyntax.java --
2     Copyright (C) 2003, 2004  Free Software Foundation, Inc.     Copyright (C) 2003, 2004, 2005  Free Software Foundation, Inc.
3    
4  This file is part of GNU Classpath.  This file is part of GNU Classpath.
5    
# Line 40  package javax.print.attribute; Line 40  package javax.print.attribute;
40  import java.io.Serializable;  import java.io.Serializable;
41    
42  /**  /**
43   * @author Michael Koch   * <code>ResolutionSyntax</code> is the abstract base class of all attribute
44     * classes which provide a resolution as value (e.g. printer resolution).
45     * <p>
46     * A <code>ResolutionSyntax</code> instance consists of two integer values
47     * describing the resolution in feed and cross feed direction. The units of
48     * the given values is determined by two defined constants:
49     * <ul>
50     * <li>DPCM - dots per centimeter</li>
51     * <li>DPI - dots per inch</li>
52     * </ul>
53     * </p>
54     * <p>
55     * A resolutions attribute is constructed by two values for the resolution and
56     * one of the two constants defining the actual units of the given values.
57     * </p>
58     * <p>
59     * There are different methods provided to return the resolution values in
60     * either of the both units and to compare if a resolution is less than or
61     * equal to a given other resolution attribute.
62     * </p>
63     * <p>
64     * <b>Internal storage:</b><br>
65     * The resolutions are stored internally as dots per 100 inches (dphi). The
66     * values of the provided constants for dots per inch (value 100) and dots
67     * per centimeter (value 254) are used as conversion factors to the internal
68     * storage units. To get the internal dphi values a multiplication of a given
69     * resolution value with its units constant value is needed. Retrieving the
70     * resolution for specific units is done by dividing the internal stored
71     * value through the units constant value. Clients are therefore able to
72     * provide their own resolution units by supplying other conversion factors.
73     * Subclasses of <code>ResolutionSyntax</code> have access to the internal
74     * resolution values through the protected methods
75     * {@link #getCrossFeedResolutionDphi()} and {@link #getFeedResolutionDphi()}.
76     * </p>
77     *
78     * @author Michael Koch (konqueror@gmx.de)
79   */   */
80  public abstract class ResolutionSyntax  public abstract class ResolutionSyntax
81    implements Cloneable, Serializable    implements Cloneable, Serializable
# Line 65  public abstract class ResolutionSyntax Line 100  public abstract class ResolutionSyntax
100     *     *
101     * @param crossFeedResolution the cross feed resolution     * @param crossFeedResolution the cross feed resolution
102     * @param feedResolution the feed resolution     * @param feedResolution the feed resolution
103     * @param units the unit to use     * @param units the unit to use (e.g. {@link #DPCM} or {@link #DPI})
104     *     *
105     * @exception IllegalArgumentException if preconditions fail     * @exception IllegalArgumentException if preconditions fail
106     */     */
# Line 82  public abstract class ResolutionSyntax Line 117  public abstract class ResolutionSyntax
117    }    }
118    
119    /**    /**
120     * Tests of obj is equal to this object.     * Tests if the given object is equal to this object.
121     *     *
122     * @param obj the object to test     * @param obj the object to test
123     *     *
124     * @return true if both objects are equal, false otherwise.     * @return <code>true</code> if both objects are equal,
125       * <code>false</code> otherwise.
126     */     */
127    public boolean equals(Object obj)    public boolean equals(Object obj)
128    {    {
# Line 100  public abstract class ResolutionSyntax Line 136  public abstract class ResolutionSyntax
136    }    }
137    
138    /**    /**
139     * Returns the cross feed resolution in units.     * Returns the cross feed resolution for the given units.
140     *     *
141     * @return the resolution     * @param units the unit to use (e.g. {@link #DPCM} or {@link #DPI})
142       * @return The resolution for the given units.
143     *     *
144     * @exception IllegalArgumentException if units < 1     * @exception IllegalArgumentException if units &lt; 1
145     */     */
146    public int getCrossFeedResolution(int units)    public int getCrossFeedResolution(int units)
147    {    {
148      if (units < 1)      if (units < 1)
149        throw new IllegalArgumentException("units may not be less then 1");        throw new IllegalArgumentException("units may not be less then 1");
150    
151      return (crossFeedResolution + units) / units;      return crossFeedResolution / units;
152    }    }
153    
154    /**    /**
155     * Returns the raw cross feed resolution in units.     * Returns the raw cross feed resolution in dots per 100 inches.
156     *     *
157     * @return the raw resolution     * @return The raw resolution.
158     */     */
159    protected int getCrossFeedResolutionDphi()    protected int getCrossFeedResolutionDphi()
160    {    {
# Line 125  public abstract class ResolutionSyntax Line 162  public abstract class ResolutionSyntax
162    }    }
163    
164    /**    /**
165     * Returns the feed resolution in units.     * Returns the feed resolution for the given units.
166     *     *
167     * @return the resolution     * @param units the unit to use (e.g. {@link #DPCM} or {@link #DPI})
168       * @return The resolution for the given units.
169     *     *
170     * @exception IllegalArgumentException if units < 1     * @exception IllegalArgumentException if units &lt; 1
171     */     */
172    public int getFeedResolution(int units)    public int getFeedResolution(int units)
173    {    {
174      if (units < 1)      if (units < 1)
175        throw new IllegalArgumentException("units may not be less then 1");        throw new IllegalArgumentException("units may not be less then 1");
176    
177      return (crossFeedResolution + units) / units;      return feedResolution / units;
178    }    }
179    
180    /**    /**
181     * Returns the raw feed resolution in units.     * Returns the raw feed resolution in dots per 100 inches.
182     *     *
183     * @return the raw resolution     * @return The raw resolution.
184     */     */
185    protected int getFeedResolutionDphi()    protected int getFeedResolutionDphi()
186    {    {
# Line 155  public abstract class ResolutionSyntax Line 193  public abstract class ResolutionSyntax
193     *     *
194     * @param units the units to use     * @param units the units to use
195     *     *
196     * @return the array with the resolutions     * @return The array with the resolutions.
197     */     */
198    public int[] getResolution(int units)    public int[] getResolution(int units)
199    {    {
# Line 168  public abstract class ResolutionSyntax Line 206  public abstract class ResolutionSyntax
206    /**    /**
207     * Returns the hashcode for this object.     * Returns the hashcode for this object.
208     *     *
209     * @return the hashcode     * @return The hashcode.
210     */     */
211    public int hashCode()    public int hashCode()
212    {    {
# Line 176  public abstract class ResolutionSyntax Line 214  public abstract class ResolutionSyntax
214    }    }
215    
216    /**    /**
217     * Checks of other is a lower or equal resolution.     * Checks if the given resolution attribute is a lower or equal
218       * to this resolution object.
219     *     *
220     * @param other the resolution to check against     * @param other the resolution to check against
221     *     *
222     * @return true if other describes a lower or equal resolution     * @return <code>true</code> if other resolution attribute describes
223       * a lower or equal resolution, <code>false</code> otherwise.
224     */     */
225    public boolean lessThanOrEquals(ResolutionSyntax other)    public boolean lessThanOrEquals(ResolutionSyntax other)
226    {    {
# Line 193  public abstract class ResolutionSyntax Line 233  public abstract class ResolutionSyntax
233    
234    /**    /**
235     * Returns the string representation for this object.     * Returns the string representation for this object.
236     *     * <p>
237     * @return the string representation     * The returned string is in the form "CxF dphi" with C standing
238       * for the cross feed and F for the feed direction resolution.
239       * Units used are dots per 100 inches (dphi).
240       * </p>
241       * @return The string representation.
242     */     */
243    public String toString()    public String toString()
244    {    {
# Line 203  public abstract class ResolutionSyntax Line 247  public abstract class ResolutionSyntax
247    
248    /**    /**
249     * Returns the string representation for this object.     * Returns the string representation for this object.
250     *     * <p>
251       * The returned string is in the form "CxF U" with C standing
252       * for the cross feed and F for the feed direction resolution.
253       * U denotes the units name if one is supplied.
254       * </p>
255       *
256     * @param units the units to use     * @param units the units to use
257     * @param unitsName the name of the units     * @param unitsName the name of the units. If <code>null</code>
258       * it is ommitted from the string representation.
259     *     *
260     * @return the string representation     * @return The string representation.
261     */     */
262    public String toString(int units, String unitsName)    public String toString(int units, String unitsName)
263    {    {
264        if (unitsName == null)
265          return getCrossFeedResolution(units) + "x" + getFeedResolution(units);
266        
267      return ("" + getCrossFeedResolution(units)      return ("" + getCrossFeedResolution(units)
268              + "x" + getFeedResolution(units)              + "x" + getFeedResolution(units)
269              + " " + unitsName);              + " " + unitsName);

Legend:
Removed from v.1.3.2.1  
changed lines
  Added in v.1.3.2.2

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26