133 throw new IllegalArgumentException("crossFeedResolution is < 1"); 134 } 135 if (feedResolution < 1) { 136 throw new IllegalArgumentException("feedResolution is < 1"); 137 } 138 if (units < 1) { 139 throw new IllegalArgumentException("units is < 1"); 140 } 141 142 this.crossFeedResolution = crossFeedResolution * units; 143 this.feedResolution = feedResolution * units; 144 } 145 146 /** 147 * Convert a value from dphi to some other units. The result is rounded to 148 * the nearest integer. 149 * 150 * @param dphi 151 * Value (dphi) to convert. 152 * @param units 153 * Unit conversion factor, e.g. {@link #DPI <CODE>DPI</CODE>} or 154 * {@link #DPCM <CODE>DPCM</CODE>}. 155 * 156 * @return The value of <CODE>dphi</CODE> converted to the desired units. 157 * 158 * @exception IllegalArgumentException 159 * (unchecked exception) Thrown if <CODE>units</CODE> < 1. 160 */ 161 private static int convertFromDphi(int dphi, int units) { 162 if (units < 1) { 163 throw new IllegalArgumentException(": units is < 1"); 164 } 165 int round = units / 2; 166 return (dphi + round) / units; 167 } 168 169 /** 170 * Get this resolution attribute's resolution values in the given units. 171 * The values are rounded to the nearest integer. 172 * 173 * @param units 174 * Unit conversion factor, e.g. {@link #DPI DPI} or 175 * {@link #DPCM DPCM}. 176 * 177 * @return A two-element array with the cross feed direction resolution 178 * at index 0 and the feed direction resolution at index 1. 179 * 205 206 /** 207 * Returns this resolution attribute's feed direction resolution in the 208 * given units. The value is rounded to the nearest integer. 209 * 210 * @param units 211 * Unit conversion factor, e.g. {@link #DPI DPI} or {@link 212 * #DPCM DPCM}. 213 * 214 * @return Feed direction resolution. 215 * 216 * @exception IllegalArgumentException 217 * (unchecked exception) Thrown if {@code units < 1}. 218 */ 219 public int getFeedResolution(int units) { 220 return convertFromDphi (feedResolution, units); 221 } 222 223 /** 224 * Returns a string version of this resolution attribute in the given units. 225 * The string takes the form <CODE>"<I>C</I>x<I>F</I> <I>U</I>"</CODE>, 226 * where <I>C</I> is the cross feed direction resolution, <I>F</I> is the 227 * feed direction resolution, and <I>U</I> is the units name. The values are 228 * rounded to the nearest integer. 229 * 230 * @param units 231 * Unit conversion factor, e.g. {@link #DPI CODE>DPI} or {@link 232 * #DPCM DPCM}. 233 * @param unitsName 234 * Units name string, e.g. <CODE>"dpi"</CODE> or <CODE>"dpcm"</CODE>. If 235 * null, no units name is appended to the result. 236 * 237 * @return String version of this resolution attribute. 238 * 239 * @exception IllegalArgumentException 240 * (unchecked exception) Thrown if {@code units < 1}. 241 */ 242 public String toString(int units, String unitsName) { 243 StringBuilder result = new StringBuilder(); 244 result.append(getCrossFeedResolution (units)); 245 result.append('x'); 246 result.append(getFeedResolution (units)); 247 if (unitsName != null) { 248 result.append (' '); 249 result.append (unitsName); 250 } 251 return result.toString(); 252 } 253 254 255 /** 256 * Determine whether this resolution attribute's value is less than or 257 * equal to the given resolution attribute's value. This is true if all 258 * of the following conditions are true: 259 * <UL> 260 * <LI> 261 * This attribute's cross feed direction resolution is less than or equal to 262 * the <CODE>other</CODE> attribute's cross feed direction resolution. 263 * <LI> 264 * This attribute's feed direction resolution is less than or equal to the 265 * <CODE>other</CODE> attribute's feed direction resolution. 266 * </UL> 267 * 268 * @param other Resolution attribute to compare with. 269 * 270 * @return True if this resolution attribute is less than or equal to the 271 * <CODE>other</CODE> resolution attribute, false otherwise. 272 * 273 * @exception NullPointerException 274 * (unchecked exception) Thrown if <CODE>other</CODE> is null. 275 */ 276 public boolean lessThanOrEquals(ResolutionSyntax other) { 277 return (this.crossFeedResolution <= other.crossFeedResolution && 278 this.feedResolution <= other.feedResolution); 279 } 280 281 282 /** 283 * Returns whether this resolution attribute is equivalent to the passed in 284 * object. To be equivalent, all of the following conditions must be true: 285 * <OL TYPE=1> 286 * <LI> 287 * <CODE>object</CODE> is not null. 288 * <LI> 289 * <CODE>object</CODE> is an instance of class ResolutionSyntax. 290 * <LI> 291 * This attribute's cross feed direction resolution is equal to 292 * <CODE>object</CODE>'s cross feed direction resolution. 293 * <LI> 294 * This attribute's feed direction resolution is equal to 295 * <CODE>object</CODE>'s feed direction resolution. 296 * </OL> 297 * 298 * @param object Object to compare to. 299 * 300 * @return True if <CODE>object</CODE> is equivalent to this resolution 301 * attribute, false otherwise. 302 */ 303 public boolean equals(Object object) { 304 305 return(object != null && 306 object instanceof ResolutionSyntax && 307 this.crossFeedResolution == 308 ((ResolutionSyntax) object).crossFeedResolution && 309 this.feedResolution == 310 ((ResolutionSyntax) object).feedResolution); 311 } 312 313 /** 314 * Returns a hash code value for this resolution attribute. 315 */ 316 public int hashCode() { 317 return(((crossFeedResolution & 0x0000FFFF)) | 318 ((feedResolution & 0x0000FFFF) << 16)); 319 } 320 321 /** 322 * Returns a string version of this resolution attribute. The string takes 323 * the form <CODE>"<I>C</I>x<I>F</I> dphi"</CODE>, where <I>C</I> is the 324 * cross feed direction resolution and <I>F</I> is the feed direction 325 * resolution. The values are reported in the internal units of dphi. 326 */ 327 public String toString() { 328 StringBuilder result = new StringBuilder(); 329 result.append(crossFeedResolution); 330 result.append('x'); 331 result.append(feedResolution); 332 result.append(" dphi"); 333 return result.toString(); 334 } 335 336 337 /** 338 * Returns this resolution attribute's cross feed direction resolution in 339 * units of dphi. (For use in a subclass.) 340 * 341 * @return Cross feed direction resolution. 342 */ 343 protected int getCrossFeedResolutionDphi() { | 133 throw new IllegalArgumentException("crossFeedResolution is < 1"); 134 } 135 if (feedResolution < 1) { 136 throw new IllegalArgumentException("feedResolution is < 1"); 137 } 138 if (units < 1) { 139 throw new IllegalArgumentException("units is < 1"); 140 } 141 142 this.crossFeedResolution = crossFeedResolution * units; 143 this.feedResolution = feedResolution * units; 144 } 145 146 /** 147 * Convert a value from dphi to some other units. The result is rounded to 148 * the nearest integer. 149 * 150 * @param dphi 151 * Value (dphi) to convert. 152 * @param units 153 * Unit conversion factor, e.g. {@link #DPI DPI} or 154 * {@link #DPCM DPCM}. 155 * 156 * @return The value of {@code dphi} converted to the desired units. 157 * 158 * @exception IllegalArgumentException 159 * (unchecked exception) Thrown if {@code units} < 1. 160 */ 161 private static int convertFromDphi(int dphi, int units) { 162 if (units < 1) { 163 throw new IllegalArgumentException(": units is < 1"); 164 } 165 int round = units / 2; 166 return (dphi + round) / units; 167 } 168 169 /** 170 * Get this resolution attribute's resolution values in the given units. 171 * The values are rounded to the nearest integer. 172 * 173 * @param units 174 * Unit conversion factor, e.g. {@link #DPI DPI} or 175 * {@link #DPCM DPCM}. 176 * 177 * @return A two-element array with the cross feed direction resolution 178 * at index 0 and the feed direction resolution at index 1. 179 * 205 206 /** 207 * Returns this resolution attribute's feed direction resolution in the 208 * given units. The value is rounded to the nearest integer. 209 * 210 * @param units 211 * Unit conversion factor, e.g. {@link #DPI DPI} or {@link 212 * #DPCM DPCM}. 213 * 214 * @return Feed direction resolution. 215 * 216 * @exception IllegalArgumentException 217 * (unchecked exception) Thrown if {@code units < 1}. 218 */ 219 public int getFeedResolution(int units) { 220 return convertFromDphi (feedResolution, units); 221 } 222 223 /** 224 * Returns a string version of this resolution attribute in the given units. 225 * The string takes the form <code>"<I>C</I>x<I>F</I> <I>U</I>"</code>, 226 * where <I>C</I> is the cross feed direction resolution, <I>F</I> is the 227 * feed direction resolution, and <I>U</I> is the units name. The values are 228 * rounded to the nearest integer. 229 * 230 * @param units 231 * Unit conversion factor, e.g. {@link #DPI CODE>DPI} or {@link 232 * #DPCM DPCM}. 233 * @param unitsName 234 * Units name string, e.g. {@code "dpi"} or {@code "dpcm"}. If 235 * null, no units name is appended to the result. 236 * 237 * @return String version of this resolution attribute. 238 * 239 * @exception IllegalArgumentException 240 * (unchecked exception) Thrown if {@code units < 1}. 241 */ 242 public String toString(int units, String unitsName) { 243 StringBuilder result = new StringBuilder(); 244 result.append(getCrossFeedResolution (units)); 245 result.append('x'); 246 result.append(getFeedResolution (units)); 247 if (unitsName != null) { 248 result.append (' '); 249 result.append (unitsName); 250 } 251 return result.toString(); 252 } 253 254 255 /** 256 * Determine whether this resolution attribute's value is less than or 257 * equal to the given resolution attribute's value. This is true if all 258 * of the following conditions are true: 259 * <UL> 260 * <LI> 261 * This attribute's cross feed direction resolution is less than or equal to 262 * the {@code other} attribute's cross feed direction resolution. 263 * <LI> 264 * This attribute's feed direction resolution is less than or equal to the 265 * {@code other} attribute's feed direction resolution. 266 * </UL> 267 * 268 * @param other Resolution attribute to compare with. 269 * 270 * @return True if this resolution attribute is less than or equal to the 271 * {@code other} resolution attribute, false otherwise. 272 * 273 * @exception NullPointerException 274 * (unchecked exception) Thrown if {@code other} is null. 275 */ 276 public boolean lessThanOrEquals(ResolutionSyntax other) { 277 return (this.crossFeedResolution <= other.crossFeedResolution && 278 this.feedResolution <= other.feedResolution); 279 } 280 281 282 /** 283 * Returns whether this resolution attribute is equivalent to the passed in 284 * object. To be equivalent, all of the following conditions must be true: 285 * <OL TYPE=1> 286 * <LI> 287 * {@code object} is not null. 288 * <LI> 289 * {@code object} is an instance of class ResolutionSyntax. 290 * <LI> 291 * This attribute's cross feed direction resolution is equal to 292 * {@code object}'s cross feed direction resolution. 293 * <LI> 294 * This attribute's feed direction resolution is equal to 295 * {@code object}'s feed direction resolution. 296 * </OL> 297 * 298 * @param object Object to compare to. 299 * 300 * @return True if {@code object} is equivalent to this resolution 301 * attribute, false otherwise. 302 */ 303 public boolean equals(Object object) { 304 305 return(object != null && 306 object instanceof ResolutionSyntax && 307 this.crossFeedResolution == 308 ((ResolutionSyntax) object).crossFeedResolution && 309 this.feedResolution == 310 ((ResolutionSyntax) object).feedResolution); 311 } 312 313 /** 314 * Returns a hash code value for this resolution attribute. 315 */ 316 public int hashCode() { 317 return(((crossFeedResolution & 0x0000FFFF)) | 318 ((feedResolution & 0x0000FFFF) << 16)); 319 } 320 321 /** 322 * Returns a string version of this resolution attribute. The string takes 323 * the form <code>"<I>C</I>x<I>F</I> dphi"</code>, where <I>C</I> is the 324 * cross feed direction resolution and <I>F</I> is the feed direction 325 * resolution. The values are reported in the internal units of dphi. 326 */ 327 public String toString() { 328 StringBuilder result = new StringBuilder(); 329 result.append(crossFeedResolution); 330 result.append('x'); 331 result.append(feedResolution); 332 result.append(" dphi"); 333 return result.toString(); 334 } 335 336 337 /** 338 * Returns this resolution attribute's cross feed direction resolution in 339 * units of dphi. (For use in a subclass.) 340 * 341 * @return Cross feed direction resolution. 342 */ 343 protected int getCrossFeedResolutionDphi() { |