/* * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. * * * * * * * * * * * * * * * * * * * * */ package com.sun.javafx.scene.layout.region; import java.util.ArrayList; import java.util.Collections; import java.util.List; import javafx.scene.layout.BorderStrokeStyle; import javafx.scene.shape.StrokeLineCap; import javafx.scene.shape.StrokeLineJoin; import javafx.scene.shape.StrokeType; import javafx.scene.text.Font; import javafx.css.ParsedValue; import com.sun.javafx.css.ParsedValueImpl; import com.sun.javafx.css.Size; import com.sun.javafx.css.StyleConverterImpl; /** */ public class BorderStyleConverter extends StyleConverterImpl { // private static final ParsedValue[],Double[]> DASHED = // new ParsedValue[],Double[]>( // new ParsedValue[] { // new ParsedValue(new Size(5.0f, SizeUnits.PX), null), // new ParsedValue(new Size(3.0f, SizeUnits.PX), null) // }, SizeConverter.SequenceConverter.getInstance()); // // private static final ParsedValue[],Double[]> DOTTED = // new ParsedValue[],Double[]>( // new ParsedValue[]{ // new ParsedValue(new Size(1.0f, SizeUnits.PX), null), // new ParsedValue(new Size(3.0f, SizeUnits.PX), null) // }, SizeConverter.SequenceConverter.getInstance()); // // private static final ParsedValue[],Double[]> SOLID = // new ParsedValue[],Double[]>( // new ParsedValue[]{ // /* empty array */ // }, SizeConverter.SequenceConverter.getInstance()); public static final ParsedValueImpl NONE = new ParsedValueImpl(null, null); public static final ParsedValueImpl HIDDEN = new ParsedValueImpl(null, null); public static final ParsedValueImpl DOTTED = new ParsedValueImpl(null, null); public static final ParsedValueImpl DASHED = new ParsedValueImpl(null, null); public static final ParsedValueImpl SOLID = new ParsedValueImpl(null, null); /** * Convert a sequence of values to a BorderStyle. */ private static final BorderStyleConverter BORDER_STYLE_CONVERTER = new BorderStyleConverter(); public static BorderStyleConverter getInstance() { return BORDER_STYLE_CONVERTER; } // Prevent instantiation private BorderStyleConverter() { } @Override public BorderStrokeStyle convert(ParsedValue value, Font font) { final ParsedValue[] values = value.getValue(); // The first value may be some named style, such as DOTTED, DASHED, SOLID, or NONE. // However even if named, there might be additional style information such as the // round cap to use, etc. But most of the time, people will only define the name and // nothing more. So we special case this so that if you use "solid" in CSS and that // is all, then we map it to BorderStrokeStyle.SOLID and quite early. Object v = values[0]; final boolean onlyNamed = values[1] == null && values[2] == null && values[3] == null && values[4] == null && values[5] == null; if (NONE == v) return BorderStrokeStyle.NONE; if (DOTTED == v && onlyNamed) { return BorderStrokeStyle.DOTTED; } else if (DASHED == v && onlyNamed) { return BorderStrokeStyle.DASHED; } else if (SOLID == v && onlyNamed) { return BorderStrokeStyle.SOLID; } // We have some custom specified value ParsedValue[] dash_vals = ((ParsedValue[],Number[]>)values[0]).getValue(); final List dashes; if (dash_vals == null) { if (DOTTED == v) { dashes = BorderStrokeStyle.DOTTED.getDashArray(); } else if (DASHED == v) { dashes = BorderStrokeStyle.DASHED.getDashArray(); } else if (SOLID == v) { dashes = BorderStrokeStyle.SOLID.getDashArray(); } else { dashes = Collections.emptyList(); } } else { dashes = new ArrayList(dash_vals.length); for(int dash=0; dash