1 /* 2 * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 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.scene.layout.region; 27 28 import javafx.css.ParsedValue; 29 import com.sun.javafx.css.StyleConverterImpl; 30 import com.sun.javafx.css.Size; 31 import javafx.scene.layout.BorderWidths; 32 import javafx.scene.text.Font; 33 34 /** 35 * User: richardbair 36 * Date: 8/10/12 37 * Time: 8:27 PM 38 */ 39 public class BorderImageWidthsSequenceConverter extends StyleConverterImpl<ParsedValue<ParsedValue[], BorderWidths>[], BorderWidths[]> { 40 private static final BorderImageWidthsSequenceConverter CONVERTER = 41 new BorderImageWidthsSequenceConverter(); 42 43 public static BorderImageWidthsSequenceConverter getInstance() { 44 return CONVERTER; 45 } 46 47 @Override 48 public BorderWidths[] convert(ParsedValue<ParsedValue<ParsedValue[], BorderWidths>[], BorderWidths[]> value, Font font) { 49 // For 'border-image-slice: 10% fill, 20% 30%', the value arg will be 50 // ParsedValue { values: [ 51 // ParsedValue { values: [ ParsedValue {parsed: 10%}, ParsedValue {parsed: fill}] } , 52 // ParsedValue { values: [ ParsedValue {parsed: 20%}, ParsedValue {parsed: 30%}] } 53 // ]} 54 // 55 // For 'border-image-slice: 10% fill', the value arg will be 56 // ParsedValue { values: [ ParsedValue {parsed: 10%}, ParsedValue {parsed: fill}] } 57 // 58 // For 'border-image-slice: 10%', the value arg will be 59 // ParsedValue {parsed: 10%} 60 // 61 // where the sizes are actually Size objects. 62 // 63 // If the value arg contains multiple layers, unwind the nested 64 // values by one level. 65 ParsedValue<ParsedValue[], BorderWidths>[] layers = value.getValue(); 66 BorderWidths[] widths = new BorderWidths[layers.length]; 67 for (int l = 0; l < layers.length; l++) { 68 widths[l] = BorderImageWidthConverter.getInstance().convert(layers[l], font); 69 } 70 return widths; 71 } 72 73 @Override 74 public String toString() { 75 return "BorderImageWidthsSequenceConverter"; 76 } 77 }