modules/graphics/src/main/java/javafx/scene/layout/BorderConverter.java

Print this page
rev 9240 : 8076423: JEP 253: Prepare JavaFX UI Controls & CSS APIs for Modularization


   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.scene.layout;
  27 
  28 import com.sun.javafx.css.StyleConverterImpl;
  29 import com.sun.javafx.css.StyleManager;
  30 import com.sun.javafx.scene.layout.region.BorderImageSlices;
  31 import com.sun.javafx.scene.layout.region.Margins;
  32 import com.sun.javafx.scene.layout.region.RepeatStruct;
  33 import java.util.Map;
  34 import javafx.css.CssMetaData;
  35 import javafx.css.ParsedValue;
  36 import javafx.css.Styleable;

  37 import javafx.geometry.Insets;
  38 import javafx.scene.image.Image;
  39 import javafx.scene.paint.Color;
  40 import javafx.scene.paint.Paint;
  41 
  42 /**
  43  */
  44 class BorderConverter extends StyleConverterImpl<ParsedValue[], Border> {
  45 
  46     private static final BorderConverter BORDER_IMAGE_CONVERTER =
  47             new BorderConverter();
  48 
  49     public static BorderConverter getInstance() {
  50         return BORDER_IMAGE_CONVERTER;
  51     }
  52 
  53     // Disallow instantiation
  54     private BorderConverter() { }
  55 
  56     @Override
  57     public Border convert(Map<CssMetaData<? extends Styleable, ?>, Object> convertedValues) {
  58         final Paint[][] strokeFills = (Paint[][])convertedValues.get(Border.BORDER_COLOR);
  59         final BorderStrokeStyle[][] strokeStyles = (BorderStrokeStyle[][]) convertedValues.get(Border.BORDER_STYLE);
  60         final String[] imageUrls = (String[]) convertedValues.get(Border.BORDER_IMAGE_SOURCE);
  61         //
  62         // In W3C CSS, border colors and border images are not layered. In javafx, they are. We've taken the position
  63         // that there is one layer per -fx-border-color or -fx-border-image-source. This is consistent with
  64         // background-image (see http://www.w3.org/TR/css3-background/#layering). But, in a browser, you can have a




   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.scene.layout;
  27 

  28 import com.sun.javafx.css.StyleManager;
  29 import com.sun.javafx.scene.layout.region.BorderImageSlices;
  30 import com.sun.javafx.scene.layout.region.Margins;
  31 import com.sun.javafx.scene.layout.region.RepeatStruct;
  32 import java.util.Map;
  33 import javafx.css.CssMetaData;
  34 import javafx.css.ParsedValue;
  35 import javafx.css.Styleable;
  36 import javafx.css.StyleConverter;
  37 import javafx.geometry.Insets;
  38 import javafx.scene.image.Image;
  39 import javafx.scene.paint.Color;
  40 import javafx.scene.paint.Paint;
  41 
  42 /**
  43  */
  44 class BorderConverter extends StyleConverter<ParsedValue[], Border> {
  45 
  46     private static final BorderConverter BORDER_IMAGE_CONVERTER =
  47             new BorderConverter();
  48 
  49     public static BorderConverter getInstance() {
  50         return BORDER_IMAGE_CONVERTER;
  51     }
  52 
  53     // Disallow instantiation
  54     private BorderConverter() { }
  55 
  56     @Override
  57     public Border convert(Map<CssMetaData<? extends Styleable, ?>, Object> convertedValues) {
  58         final Paint[][] strokeFills = (Paint[][])convertedValues.get(Border.BORDER_COLOR);
  59         final BorderStrokeStyle[][] strokeStyles = (BorderStrokeStyle[][]) convertedValues.get(Border.BORDER_STYLE);
  60         final String[] imageUrls = (String[]) convertedValues.get(Border.BORDER_IMAGE_SOURCE);
  61         //
  62         // In W3C CSS, border colors and border images are not layered. In javafx, they are. We've taken the position
  63         // that there is one layer per -fx-border-color or -fx-border-image-source. This is consistent with
  64         // background-image (see http://www.w3.org/TR/css3-background/#layering). But, in a browser, you can have a