6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package com.sun.javafx.css;
27
28 import javafx.scene.text.Font;
29
30 /**
31 * Represents a size specified in a particular unit, such as 14px or 0.2em.
32 */
33 final public class Size {
34
35 final private double value;
36 final private SizeUnits units;
37 public Size(double value, SizeUnits units) {
38 this.value = value;
39 this.units = (units != null) ? units : SizeUnits.PX;
40 }
41
42 /** */
43 public double getValue() {
44 return value;
45 }
46
47 /** */
48 public SizeUnits getUnits() {
49 return units;
50 }
51
52 /**
53 * Return whether or not this Size is an absolute value or a relative value.
54 */
55 public boolean isAbsolute() {
56 return units.isAbsolute();
57 }
58
59 /** Convert this size into Points units, a Point is 1/72 of a inch */
60 public double points(Font font) {
61 return points(1.0, font);
62 }
63
64 /**
65 * Convert this size into points
66 *
67 * @param multiplier The multiplier for PERCENTAGE sizes
68 * @param font The font for EM sizes
69 */
70 public double points(double multiplier, Font font) {
71 return units.points(value, multiplier, font);
72 }
73
74 /**
75 * Convert this size into pixels
76 *
77 * @param multiplier The multiplier for PERCENTAGE sizes
78 * @param font The font for EM sizes
79 */
80 public double pixels(double multiplier, Font font) {
81 return units.pixels(value, multiplier, font);
82 }
83
84 /**
85 * If size is not an absolute size, return the product of font size in pixels
86 * and value. Otherwise, return the absolute value.
87 */
88 public double pixels(Font font) {
89 return pixels(1.0f, font);
90 }
91
92 /**
93 * If size is not an absolute size, return the product of multiplier
94 * and value. Otherwise, return the absolute value.
95 */
96 public double pixels(double multiplier) {
97 return pixels(multiplier, null);
98 }
99
100 /**
101 * A convenience method for calling <code>pixels(1)</code>
102 */
103 public double pixels() {
104 return pixels(1.0f, null);
105 }
106
107 @Override public String toString() {
108 return Double.toString(value) + units.toString();
109 }
110
111 @Override public int hashCode() {
112 long bits = 17L;
113 bits = 37L * bits + Double.doubleToLongBits(value);
114 bits = 37L * bits + units.hashCode();
115 return (int) (bits ^ (bits >> 32));
116 }
|
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package javafx.css;
27
28 import javafx.scene.text.Font;
29
30
31 /**
32 * Represents a size specified in a particular unit, such as 14px or 0.2em.
33 *
34 * @since 9
35 */
36 final public class Size {
37
38 final private double value;
39 final private SizeUnits units;
40 public Size(double value, SizeUnits units) {
41 this.value = value;
42 this.units = (units != null) ? units : SizeUnits.PX;
43 }
44
45 /** */
46 public double getValue() {
47 return value;
48 }
49
50 /** */
51 public SizeUnits getUnits() {
52 return units;
53 }
54
55 /**
56 * Return whether or not this Size is an absolute value or a relative value.
57 */
58 public boolean isAbsolute() {
59 return units.isAbsolute();
60 }
61
62 /** Convert this size into Points units, a Point is 1/72 of a inch */
63 double points(Font font) {
64 return points(1.0, font);
65 }
66
67 /**
68 * Convert this size into points
69 *
70 * @param multiplier The multiplier for PERCENTAGE sizes
71 * @param font The font for EM sizes
72 */
73 double points(double multiplier, Font font) {
74 return units.points(value, multiplier, font);
75 }
76
77 /**
78 * Convert this size into pixels
79 *
80 * @param multiplier The multiplier for PERCENTAGE sizes
81 * @param font The font for EM sizes
82 */
83 public double pixels(double multiplier, Font font) {
84 return units.pixels(value, multiplier, font);
85 }
86
87 /**
88 * If size is not an absolute size, return the product of font size in pixels
89 * and value. Otherwise, return the absolute value.
90 */
91 public double pixels(Font font) {
92 return pixels(1.0f, font);
93 }
94
95 /**
96 * If size is not an absolute size, return the product of multiplier
97 * and value. Otherwise, return the absolute value.
98 */
99 double pixels(double multiplier) {
100 return pixels(multiplier, null);
101 }
102
103 /**
104 * A convenience method for calling <code>pixels(1)</code>
105 */
106 public double pixels() {
107 return pixels(1.0f, null);
108 }
109
110 @Override public String toString() {
111 return Double.toString(value) + units.toString();
112 }
113
114 @Override public int hashCode() {
115 long bits = 17L;
116 bits = 37L * bits + Double.doubleToLongBits(value);
117 bits = 37L * bits + units.hashCode();
118 return (int) (bits ^ (bits >> 32));
119 }
|