1 7 8 9 package javax.print.attribute; 10 11 import java.io.Serializable ; 12 13 68 public abstract class ResolutionSyntax implements Serializable , Cloneable { 69 70 private static final long serialVersionUID = 2706743076526672017L; 71 72 76 private int crossFeedResolution; 77 78 82 private int feedResolution; 83 84 88 public static final int DPI = 100; 89 90 94 public static final int DPCM = 254; 95 96 97 112 public ResolutionSyntax(int crossFeedResolution, int feedResolution, 113 int units) { 114 115 if (crossFeedResolution < 1) { 116 throw new IllegalArgumentException ("crossFeedResolution is < 1"); 117 } 118 if (feedResolution < 1) { 119 throw new IllegalArgumentException ("feedResolution is < 1"); 120 } 121 if (units < 1) { 122 throw new IllegalArgumentException ("units is < 1"); 123 } 124 125 this.crossFeedResolution = crossFeedResolution * units; 126 this.feedResolution = feedResolution * units; 127 } 128 129 144 private static int convertFromDphi(int dphi, int units) { 145 if (units < 1) { 146 throw new IllegalArgumentException (": units is < 1"); 147 } 148 int round = units / 2; 149 return (dphi + round) / units; 150 } 151 152 166 public int[] getResolution(int units) { 167 return new int[] { getCrossFeedResolution(units), 168 getFeedResolution(units) 169 }; 170 } 171 172 185 public int getCrossFeedResolution(int units) { 186 return convertFromDphi (crossFeedResolution, units); 187 } 188 189 202 public int getFeedResolution(int units) { 203 return convertFromDphi (feedResolution, units); 204 } 205 206 225 public String toString(int units, String unitsName) { 226 StringBuffer result = new StringBuffer (); 227 result.append(getCrossFeedResolution (units)); 228 result.append('x'); 229 result.append(getFeedResolution (units)); 230 if (unitsName != null) { 231 result.append (' '); 232 result.append (unitsName); 233 } 234 return result.toString(); 235 } 236 237 238 259 public boolean lessThanOrEquals(ResolutionSyntax other) { 260 return (this.crossFeedResolution <= other.crossFeedResolution && 261 this.feedResolution <= other.feedResolution); 262 } 263 264 265 286 public boolean equals(Object object) { 287 288 return(object != null && 289 object instanceof ResolutionSyntax && 290 this.crossFeedResolution == 291 ((ResolutionSyntax ) object).crossFeedResolution && 292 this.feedResolution == 293 ((ResolutionSyntax ) object).feedResolution); 294 } 295 296 299 public int hashCode() { 300 return(((crossFeedResolution & 0x0000FFFF)) | 301 ((feedResolution & 0x0000FFFF) << 16)); 302 } 303 304 310 public String toString() { 311 StringBuffer result = new StringBuffer (); 312 result.append(crossFeedResolution); 313 result.append('x'); 314 result.append(feedResolution); 315 result.append(" dphi"); 316 return result.toString(); 317 } 318 319 320 326 protected int getCrossFeedResolutionDphi() { 327 return crossFeedResolution; 328 } 329 330 336 protected int getFeedResolutionDphi() { 337 return feedResolution; 338 } 339 340 } 341 | Popular Tags |