modules/graphics/src/main/java/com/sun/javafx/scene/layout/region/BorderImageWidthConverter.java

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


  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.scene.layout.BorderWidths;
  29 import javafx.scene.text.Font;
  30 import javafx.css.ParsedValue;
  31 import com.sun.javafx.css.Size;
  32 import com.sun.javafx.css.SizeUnits;
  33 import com.sun.javafx.css.StyleConverterImpl;
  34 
  35 /**
  36  * User: richardbair
  37  * Date: 8/10/12
  38  * Time: 8:07 PM
  39  */
  40 public class BorderImageWidthConverter extends StyleConverterImpl<ParsedValue[], BorderWidths> {
  41     private static final BorderImageWidthConverter CONVERTER_INSTANCE = new BorderImageWidthConverter();
  42 
  43     public static BorderImageWidthConverter getInstance() {
  44         return CONVERTER_INSTANCE;
  45     }
  46 
  47     private BorderImageWidthConverter() { }
  48 
  49     @Override
  50     public BorderWidths convert(ParsedValue<ParsedValue[], BorderWidths> value, Font font) {
  51         ParsedValue[] sides = value.getValue();
  52         assert sides.length == 4;
  53 
  54         double top = 1, right = 1, bottom = 1, left = 1;
  55         boolean topPercent = false, rightPercent = false, bottomPercent = false, leftPercent = false;
  56         ParsedValue val = sides[0];
  57         if ("auto".equals(val.getValue())) {
  58             top = BorderWidths.AUTO;
  59         } else {
  60             Size size = (Size)val.convert(font);




  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.scene.layout.BorderWidths;
  29 import javafx.scene.text.Font;
  30 import javafx.css.ParsedValue;
  31 import javafx.css.Size;
  32 import javafx.css.SizeUnits;
  33 import javafx.css.StyleConverter;
  34 
  35 /**
  36  * User: richardbair
  37  * Date: 8/10/12
  38  * Time: 8:07 PM
  39  */
  40 public class BorderImageWidthConverter extends StyleConverter<ParsedValue[], BorderWidths> {
  41     private static final BorderImageWidthConverter CONVERTER_INSTANCE = new BorderImageWidthConverter();
  42 
  43     public static BorderImageWidthConverter getInstance() {
  44         return CONVERTER_INSTANCE;
  45     }
  46 
  47     private BorderImageWidthConverter() { }
  48 
  49     @Override
  50     public BorderWidths convert(ParsedValue<ParsedValue[], BorderWidths> value, Font font) {
  51         ParsedValue[] sides = value.getValue();
  52         assert sides.length == 4;
  53 
  54         double top = 1, right = 1, bottom = 1, left = 1;
  55         boolean topPercent = false, rightPercent = false, bottomPercent = false, leftPercent = false;
  56         ParsedValue val = sides[0];
  57         if ("auto".equals(val.getValue())) {
  58             top = BorderWidths.AUTO;
  59         } else {
  60             Size size = (Size)val.convert(font);