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; }
12 public double toMillis(double d) { return d/FEET_PER_MM; }
13 public double toCentis(double d) { return d/(FEET_PER_MM*TEN); }
14 public double toMeters(double d) { return d/(FEET_PER_MM*TEN*TEN*TEN); }
15 public double toPoints(double d) { return (d * POINTS_PER_INCH * 12); }
16 public double convert(double d, PrintUnit u) { return u.toInches(d)/12; }
19 public double toInches(double d) { return d; }
20 public double toMillis(double d) { return d/INCHES_PER_MM; }
21 public double toCentis(double d) { return d/(INCHES_PER_MM*TEN); }
22 public double toMeters(double d) { return d/(INCHES_PER_MM*TEN*TEN*TEN); }
23 public double toPoints(double d) { return (d * POINTS_PER_INCH); }
24 public double convert(double d, PrintUnit u) { return u.toInches(d); }
27 public double toInches(double d) { return d * INCHES_PER_MM; }
28 public double toMillis(double d) { return d; }
29 public double toCentis(double d) { return d/TEN; }
30 public double toMeters(double d) { return d/(TEN*TEN*TEN); }
31 public double toPoints(double d) { return INCHES.toPoints(toInches(d)); }
32 public double convert(double d, PrintUnit u) { return u.toMillis(d); }
35 public double toInches(double d) { return d * INCHES_PER_MM * TEN; }
36 public double toMillis(double d) { return d * TEN; }
37 public double toCentis(double d) { return d; }
38 public double toMeters(double d) { return d/(TEN*TEN); }
39 public double toPoints(double d) { return INCHES.toPoints(toInches(d)); }
40 public double convert(double d, PrintUnit u) { return u.toCentis(d); }
43 public double toInches(double d) { return d * INCHES_PER_MM * TEN * TEN * TEN; }
44 public double toMillis(double d) { return d * TEN * TEN * TEN; }
45 public double toCentis(double d) { return d * TEN * TEN; }
46 public double toMeters(double d) { return d; }
47 public double toPoints(double d) { return INCHES.toPoints(toInches(d)); }
48 public double convert(double d, PrintUnit u) { return u.toMeters(d); }
51 public double toInches(double d) { return d/POINTS_PER_INCH; }
52 public double toMillis(double d) { return d/(POINTS_PER_INCH * INCHES_PER_MM); }
53 public double toCentis(double d) { return toMillis(d)/TEN; }
54 public double toMeters(double d) { return toMillis(d)/(TEN*TEN*TEN); }
55 public double toPoints(double d) { return d; }
56 public double convert(double d, PrintUnit u) { return u.toPoints(d); }
59 // Handy constants for conversion methods
60 public static final double INCHES_PER_MM = 0.0393700787d;
61 public static final double FEET_PER_MM = INCHES_PER_MM /12;
62 public static final double MM_PER_INCH = 1.0d/INCHES_PER_MM;
63 public static final long TEN = 10;
65 * PPI is Postscript Point and is a standard of 72. Java2D also uses this internally as a pixel-per-inch, so pixels
66 * and points are for the most part interchangeable (unless the defaults are changed), which makes translating
67 * between the screen and a print job easier.
69 * Not to be confused with Dots-Per-Inch, which is printer and print mode dependent.
71 public static final int POINTS_PER_INCH = 72;
73 // To maintain full signature compatibility with 1.5, and to improve the
74 // clarity of the generated javadoc (see 6287639: Abstract methods in
75 // enum classes should not be listed as abstract), method convert
76 // etc. are not declared abstract but otherwise act as abstract methods.
79 * Convert the given length in the given unit to this
80 * unit. Conversions from finer to coarser granularities
81 * truncate, so may lose precision.
83 * <p>For example, to convert 10 inches to point, use:
84 * <tt>PrintUnit.POINTS.convert(10L, PrintUnit.INCHES)</tt>
86 * @param sourceLength the length in the given <tt>sourceUnit</tt>
87 * @param sourceUnit the unit of the <tt>sourceDuration</tt> argument
89 * @return the converted length in this unit,
90 * or <tt>Long.MIN_VALUE</tt> if conversion would negatively
91 * overflow, or <tt>Long.MAX_VALUE</tt> if it would positively overflow.
93 public double convert(double sourceLength, PrintUnit sourceUnit) {
94 throw new AbstractMethodError();
98 * Equivalent to <tt>INCHES.convert(length, this)</tt>.
100 * @param length the length
102 * @return the converted length,
103 * or <tt>Long.MIN_VALUE</tt> if conversion would negatively
104 * overflow, or <tt>Long.MAX_VALUE</tt> if it would positively overflow.
107 public double toInches(double length) {
108 throw new AbstractMethodError();
112 * Equivalent to <tt>MILLIMETERS.convert(length, this)</tt>.
114 * @param length the length
116 * @return the converted length,
117 * or <tt>Long.MIN_VALUE</tt> if conversion would negatively
118 * overflow, or <tt>Long.MAX_VALUE</tt> if it would positively overflow.
121 public double toMillis(double length) {
122 throw new AbstractMethodError();
126 * Equivalent to <tt>CENTIMETERS.convert(length, this)</tt>.
128 * @param length the length
130 * @return the converted length,
131 * or <tt>Long.MIN_VALUE</tt> if conversion would negatively
132 * overflow, or <tt>Long.MAX_VALUE</tt> if it would positively overflow.
135 public double toCentis(double length) {
136 throw new AbstractMethodError();
140 * Equivalent to <tt>METERS.convert(length, this)</tt>.
142 * @param length the length
144 * @return the converted length,
145 * or <tt>Long.MIN_VALUE</tt> if conversion would negatively
146 * overflow, or <tt>Long.MAX_VALUE</tt> if it would positively overflow.
149 public double toMeters(double length) {
150 throw new AbstractMethodError();
154 * Equivalent to <tt>POINTS.convert(length, this)</tt>.
156 * @param length the length
158 * @return the converted length,
159 * or <tt>Long.MIN_VALUE</tt> if conversion would negatively
160 * overflow, or <tt>Long.MAX_VALUE</tt> if it would positively overflow.
163 public double toPoints(double length) {
164 throw new AbstractMethodError();