4 package net.sf.openrocket.gui.print;
7 * Utilities for print units.
9 public enum PrintUnit {
11 public double toInches(double d) { return d; }
12 public double toMillis(double d) { return d/INCHES_PER_MM; }
13 public double toCentis(double d) { return d/(INCHES_PER_MM*TEN); }
14 public double toMeters(double d) { return d/(INCHES_PER_MM*TEN*TEN*TEN); }
15 public long toPoints(double d) { return (long)(d * POINTS_PER_INCH); }
16 public double convert(double d, PrintUnit u) { return u.toInches(d); }
19 public double toInches(double d) { return d * INCHES_PER_MM; }
20 public double toMillis(double d) { return d; }
21 public double toCentis(double d) { return d/TEN; }
22 public double toMeters(double d) { return d/(TEN*TEN*TEN); }
23 public long toPoints(double d) { return INCHES.toPoints(toInches(d)); }
24 public double convert(double d, PrintUnit u) { return u.toMillis(d); }
27 public double toInches(double d) { return d * INCHES_PER_MM * TEN; }
28 public double toMillis(double d) { return d * TEN; }
29 public double toCentis(double d) { return d; }
30 public double toMeters(double d) { return d/(TEN*TEN); }
31 public long toPoints(double d) { return INCHES.toPoints(toInches(d)); }
32 public double convert(double d, PrintUnit u) { return u.toCentis(d); }
35 public double toInches(double d) { return d * INCHES_PER_MM * TEN * TEN * TEN; }
36 public double toMillis(double d) { return d * TEN * TEN * TEN; }
37 public double toCentis(double d) { return d * TEN * TEN; }
38 public double toMeters(double d) { return d; }
39 public long toPoints(double d) { return INCHES.toPoints(toInches(d)); }
40 public double convert(double d, PrintUnit u) { return u.toMeters(d); }
43 public double toInches(double d) { return d/POINTS_PER_INCH; }
44 public double toMillis(double d) { return d/(POINTS_PER_INCH * INCHES_PER_MM); }
45 public double toCentis(double d) { return toMillis(d)/TEN; }
46 public double toMeters(double d) { return toMillis(d)/(TEN*TEN*TEN); }
47 public long toPoints(double d) { return (long)d; }
48 public double convert(double d, PrintUnit u) { return u.toPoints(d); }
51 // Handy constants for conversion methods
52 public static final double INCHES_PER_MM = 0.0393700787d;
53 public static final double MM_PER_INCH = 1.0d/INCHES_PER_MM;
54 public static final long TEN = 10;
56 * PPI is Postscript Point and is a standard of 72. Java2D also uses this internally as a pixel-per-inch, so pixels
57 * and points are for the most part interchangeable (unless the defaults are changed), which makes translating
58 * between the screen and a print job easier.
60 * Not to be confused with Dots-Per-Inch, which is printer and print mode dependent.
62 public static final int POINTS_PER_INCH = 72;
64 // To maintain full signature compatibility with 1.5, and to improve the
65 // clarity of the generated javadoc (see 6287639: Abstract methods in
66 // enum classes should not be listed as abstract), method convert
67 // etc. are not declared abstract but otherwise act as abstract methods.
70 * Convert the given length in the given unit to this
71 * unit. Conversions from finer to coarser granularities
72 * truncate, so may lose precision.
74 * <p>For example, to convert 10 inches to point, use:
75 * <tt>PrintUnit.POINTS.convert(10L, PrintUnit.INCHES)</tt>
77 * @param sourceLength the length in the given <tt>sourceUnit</tt>
78 * @param sourceUnit the unit of the <tt>sourceDuration</tt> argument
80 * @return the converted length in this unit,
81 * or <tt>Long.MIN_VALUE</tt> if conversion would negatively
82 * overflow, or <tt>Long.MAX_VALUE</tt> if it would positively overflow.
84 public double convert(double sourceLength, PrintUnit sourceUnit) {
85 throw new AbstractMethodError();
89 * Equivalent to <tt>INCHES.convert(length, this)</tt>.
91 * @param length the length
93 * @return the converted length,
94 * or <tt>Long.MIN_VALUE</tt> if conversion would negatively
95 * overflow, or <tt>Long.MAX_VALUE</tt> if it would positively overflow.
98 public double toInches(double length) {
99 throw new AbstractMethodError();
103 * Equivalent to <tt>MILLIMETERS.convert(length, this)</tt>.
105 * @param length the length
107 * @return the converted length,
108 * or <tt>Long.MIN_VALUE</tt> if conversion would negatively
109 * overflow, or <tt>Long.MAX_VALUE</tt> if it would positively overflow.
112 public double toMillis(double length) {
113 throw new AbstractMethodError();
117 * Equivalent to <tt>CENTIMETERS.convert(length, this)</tt>.
119 * @param length the length
121 * @return the converted length,
122 * or <tt>Long.MIN_VALUE</tt> if conversion would negatively
123 * overflow, or <tt>Long.MAX_VALUE</tt> if it would positively overflow.
126 public double toCentis(double length) {
127 throw new AbstractMethodError();
131 * Equivalent to <tt>METERS.convert(length, this)</tt>.
133 * @param length the length
135 * @return the converted length,
136 * or <tt>Long.MIN_VALUE</tt> if conversion would negatively
137 * overflow, or <tt>Long.MAX_VALUE</tt> if it would positively overflow.
140 public double toMeters(double length) {
141 throw new AbstractMethodError();
145 * Equivalent to <tt>POINTS.convert(length, this)</tt>.
147 * @param length the length
149 * @return the converted length,
150 * or <tt>Long.MIN_VALUE</tt> if conversion would negatively
151 * overflow, or <tt>Long.MAX_VALUE</tt> if it would positively overflow.
154 public long toPoints(double length) {
155 throw new AbstractMethodError();