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.parser;
27
28 import com.sun.javafx.css.Size;
29 import com.sun.javafx.css.SizeUnits;
30 import com.sun.javafx.css.StyleConverterImpl;
31 import javafx.css.ParsedValue;
32 import javafx.scene.text.Font;
33
34 /**
35 * A type that combines two Size values. The primary purpose of
36 * this type is to handle "convert(size1, size2)" expressions in CSS.
37 */
38 public final class DeriveSizeConverter extends StyleConverterImpl<ParsedValue<Size, Size>[], Size> {
39
40 // lazy, thread-safe instatiation
41 private static class Holder {
42 static final DeriveSizeConverter INSTANCE = new DeriveSizeConverter();
43 }
44
45 public static DeriveSizeConverter getInstance() {
46 return Holder.INSTANCE;
47 }
48
49 private DeriveSizeConverter() {
50 super();
51 }
52
53 @Override
54 public Size convert(ParsedValue<ParsedValue<Size, Size>[], Size> value, Font font) {
55 final ParsedValue<Size, Size>[] sizes = value.getValue();
56 final double px1 = sizes[0].convert(font).pixels(font);
57 final double px2 = sizes[1].convert(font).pixels(font);
58 return new Size(px1 + px2, SizeUnits.PX);
|
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.converter;
27
28 import javafx.css.Size;
29 import javafx.css.SizeUnits;
30 import javafx.css.StyleConverter;
31 import javafx.css.ParsedValue;
32 import javafx.scene.text.Font;
33
34 /**
35 * A type that combines two Size values. The primary purpose of
36 * this type is to handle "convert(size1, size2)" expressions in CSS.
37 */
38 public final class DeriveSizeConverter extends StyleConverter<ParsedValue<Size, Size>[], Size> {
39
40 // lazy, thread-safe instatiation
41 private static class Holder {
42 static final DeriveSizeConverter INSTANCE = new DeriveSizeConverter();
43 }
44
45 public static DeriveSizeConverter getInstance() {
46 return Holder.INSTANCE;
47 }
48
49 private DeriveSizeConverter() {
50 super();
51 }
52
53 @Override
54 public Size convert(ParsedValue<ParsedValue<Size, Size>[], Size> value, Font font) {
55 final ParsedValue<Size, Size>[] sizes = value.getValue();
56 final double px1 = sizes[0].convert(font).pixels(font);
57 final double px2 = sizes[1].convert(font).pixels(font);
58 return new Size(px1 + px2, SizeUnits.PX);
|