--- old/modules/graphics/src/test/java/com/sun/javafx/css/PaintTypeTest.java 2015-09-03 15:36:31.546343900 -0700 +++ /dev/null 2015-09-03 15:36:32.000000000 -0700 @@ -1,319 +0,0 @@ -/* - * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package com.sun.javafx.css; - -import javafx.css.ParsedValue; -import javafx.scene.paint.Color; -import javafx.scene.paint.CycleMethod; -import javafx.scene.paint.LinearGradient; -import javafx.scene.paint.Paint; -import javafx.scene.paint.RadialGradient; -import javafx.scene.paint.Stop; -import javafx.scene.text.Font; -import com.sun.javafx.css.converters.PaintConverter; -import com.sun.javafx.css.parser.CSSParser; -import com.sun.javafx.css.parser.StopConverter; -import org.junit.Test; -import static org.junit.Assert.assertEquals; - - -public class PaintTypeTest { - - public PaintTypeTest() { - } - - final Stop[] stops = new Stop[] { - new Stop(0.0f, Color.WHITE), - new Stop(1.0f, Color.BLACK) - }; - - final Paint[] paints = new Paint[] { - Color.rgb(0, 128, 255), - new LinearGradient(0.0f, 0.0f, 1.0f, 1.0f, true, CycleMethod.NO_CYCLE, stops), - new RadialGradient(225, 0.28, 1f, 1f, 5.0f, false, CycleMethod.NO_CYCLE, stops) - }; - - ParsedValue sizeVal(float value) { - return new ParsedValueImpl(new Size(value*100, SizeUnits.PERCENT), null); - } - - ParsedValue stopValue(Stop stop) { - ParsedValue offset = sizeVal((float)stop.getOffset()); - ParsedValue color = new ParsedValueImpl(stop.getColor(), null); - ParsedValue[] values = new ParsedValue[] { offset, color }; - return new ParsedValueImpl(values, StopConverter.getInstance()); - }; - - ParsedValue linearGradientValues(LinearGradient lg) { - ParsedValue[] values = new ParsedValue[7]; - int v = 0; - values[v++] = sizeVal((float) lg.getStartX()); - values[v++] = sizeVal((float) lg.getStartY()); - values[v++] = sizeVal((float) lg.getEndX()); - values[v++] = sizeVal((float) lg.getEndY()); - values[v++] = new ParsedValueImpl(lg.getCycleMethod(),null); - values[v++] = stopValue(stops[0]); - values[v++] = stopValue(stops[1]); - return new ParsedValueImpl(values, PaintConverter.LinearGradientConverter.getInstance()); - } - - ParsedValue radialGradientValues(RadialGradient rg) { - ParsedValue[] values = new ParsedValue[8]; - int v = 0; - values[v++] = new ParsedValueImpl(new Size(rg.getFocusAngle(), SizeUnits.PX), null); - values[v++] = new ParsedValueImpl(new Size(rg.getFocusDistance(), SizeUnits.PX), null); - values[v++] = sizeVal((float) rg.getCenterX()); - values[v++] = sizeVal((float) rg.getCenterY()); - values[v++] = new ParsedValueImpl(new Size(rg.getRadius(), SizeUnits.PX), null); - values[v++] = new ParsedValueImpl(rg.getCycleMethod(),null); - values[v++] = stopValue(stops[0]); - values[v++] = stopValue(stops[1]); - return new ParsedValueImpl(values, PaintConverter.RadialGradientConverter.getInstance()); - } - - final ParsedValue[] paintValues = new ParsedValue[] { - new ParsedValueImpl(paints[0], null), - linearGradientValues((LinearGradient)paints[1]), - radialGradientValues((RadialGradient)paints[2]) - }; - - /** - * Paint is layered (one value per layer). <paint> [, <paint>]*. - * In the convert function, the ParsedValue is a ParsedValue for each layer. - * That is, value.getValue() returns a ParsedValue[]. - */ - ParsedValue[],Paint[]> getValue(int nLayers) { - ParsedValue[] layers = new ParsedValue[nLayers]; - for (int l=0; l[],Paint[]>(layers, PaintConverter.SequenceConverter.getInstance()); - } - /** - * Test of convert method, of class PaintType. - */ - @Test - public void testConvert() { - //System.out.println("convert"); - int nValues = paints.length; - ParsedValue[],Paint[]> value = getValue(nValues); - Font font = null; - Paint[] result = value.convert(font); - assertEquals(nValues, result.length); - for(int r=0; r = radial-gradient( - // [ focus-angle , ]? - // [ focus-distance , ]? - // [ center , ]? - // radius , - // [ [ repeat | reflect ] ,]? - // [, ]+ ) - ParsedValue value = CSSParser.getInstance().parseExpr("-fx-background-color", - "radial-gradient(focus-angle 90deg, focus-distance 50%, radius 50, red, green, blue)"); - RadialGradient result = (RadialGradient)((Paint[])value.convert(null))[0]; - RadialGradient expected = new RadialGradient(90, .5, 0, 0, 50, - false, CycleMethod.NO_CYCLE, - new Stop(0, Color.RED), - new Stop(.5, Color.GREEN), - new Stop(1.0,Color.BLUE)); - assertEquals(expected,result); - - value = CSSParser.getInstance().parseExpr("-fx-background-color", - "radial-gradient(focus-angle 1.5708rad, focus-distance 50%, radius 50, red, green, blue)"); - result = (RadialGradient)((Paint[])value.convert(null))[0]; - assertEquals(expected,result); - - value = CSSParser.getInstance().parseExpr("-fx-background-color", - "radial-gradient(center 0% 10%, radius 50%, reflect, red, green, blue)"); - result = (RadialGradient)((Paint[])value.convert(null))[0]; - expected = new RadialGradient(0, 0, 0, .1, .5, - true, CycleMethod.REFLECT, - new Stop(0, Color.RED), - new Stop(.5, Color.GREEN), - new Stop(1.0,Color.BLUE)); - assertEquals(expected,result); - } - - @Test - public void testParseLinearGradient() { - - // = linear-gradient( - // [ [from to ] | [ to ] ] ,]? [ [ repeat | reflect ] ,]? - // [, ]+ - // ) - // - ParsedValue value = CSSParser.getInstance().parseExpr("-fx-background-color", - "linear-gradient(to top, red, green, blue)"); - LinearGradient result = (LinearGradient)((Paint[])value.convert(null))[0]; - LinearGradient expected = new LinearGradient(0, 1, 0, 0, - true, CycleMethod.NO_CYCLE, - new Stop(0, Color.RED), - new Stop(.5, Color.GREEN), - new Stop(1.0, Color.BLUE)); - assertEquals(expected,result); - - value = CSSParser.getInstance().parseExpr("-fx-background-color", - "linear-gradient(to bottom, red, green, blue)"); - result = (LinearGradient)((Paint[])value.convert(null))[0]; - expected = new LinearGradient(0, 0, 0, 1, - true, CycleMethod.NO_CYCLE, - new Stop(0, Color.RED), - new Stop(.5, Color.GREEN), - new Stop(1.0, Color.BLUE)); - assertEquals(expected,result); - - value = CSSParser.getInstance().parseExpr("-fx-background-color", - "linear-gradient(to left, red, green, blue)"); - result = (LinearGradient)((Paint[])value.convert(null))[0]; - expected = new LinearGradient(1, 0, 0, 0, - true, CycleMethod.NO_CYCLE, - new Stop(0, Color.RED), - new Stop(.5, Color.GREEN), - new Stop(1.0, Color.BLUE)); - assertEquals(expected,result); - - value = CSSParser.getInstance().parseExpr("-fx-background-color", - "linear-gradient(to right, red, green, blue)"); - result = (LinearGradient)((Paint[])value.convert(null))[0]; - expected = new LinearGradient(0, 0, 1, 0, - true, CycleMethod.NO_CYCLE, - new Stop(0, Color.RED), - new Stop(.5, Color.GREEN), - new Stop(1.0, Color.BLUE)); - assertEquals(expected,result); - - value = CSSParser.getInstance().parseExpr("-fx-background-color", - "linear-gradient(to bottom left, red, green, blue)"); - result = (LinearGradient)((Paint[])value.convert(null))[0]; - expected = new LinearGradient(1, 0, 0, 1, - true, CycleMethod.NO_CYCLE, - new Stop(0, Color.RED), - new Stop(.5, Color.GREEN), - new Stop(1.0, Color.BLUE)); - assertEquals(expected,result); - - value = CSSParser.getInstance().parseExpr("-fx-background-color", - "linear-gradient(to bottom right, red, green, blue)"); - result = (LinearGradient)((Paint[])value.convert(null))[0]; - expected = new LinearGradient(0, 0, 1, 1, - true, CycleMethod.NO_CYCLE, - new Stop(0, Color.RED), - new Stop(.5, Color.GREEN), - new Stop(1.0, Color.BLUE)); - assertEquals(expected,result); - - value = CSSParser.getInstance().parseExpr("-fx-background-color", - "linear-gradient(to top left, red, green, blue)"); - result = (LinearGradient)((Paint[])value.convert(null))[0]; - expected = new LinearGradient(1, 1, 0, 0, - true, CycleMethod.NO_CYCLE, - new Stop(0, Color.RED), - new Stop(.5, Color.GREEN), - new Stop(1.0, Color.BLUE)); - assertEquals(expected,result); - - value = CSSParser.getInstance().parseExpr("-fx-background-color", - "linear-gradient(to top right, red, green, blue)"); - result = (LinearGradient)((Paint[])value.convert(null))[0]; - expected = new LinearGradient(0, 1, 1, 0, - true, CycleMethod.NO_CYCLE, - new Stop(0, Color.RED), - new Stop(.5, Color.GREEN), - new Stop(1.0, Color.BLUE)); - assertEquals(expected,result); - - value = CSSParser.getInstance().parseExpr("-fx-background-color", - "linear-gradient(from 10% 10% to 90% 90%, reflect, red, green, blue)"); - result = (LinearGradient)((Paint[])value.convert(null))[0]; - expected = new LinearGradient(.1, .1, .9, .9, - true, CycleMethod.REFLECT, - new Stop(0, Color.RED), - new Stop(.5, Color.GREEN), - new Stop(1.0, Color.BLUE)); - assertEquals(expected,result); - } - -} --- /dev/null 2015-09-03 15:36:33.000000000 -0700 +++ new/modules/graphics/src/test/java/javafx/css/PaintTypeTest.java 2015-09-03 15:36:30.742297900 -0700 @@ -0,0 +1,318 @@ +/* + * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package javafx.css; + +import javafx.scene.paint.Color; +import javafx.scene.paint.CycleMethod; +import javafx.scene.paint.LinearGradient; +import javafx.scene.paint.Paint; +import javafx.scene.paint.RadialGradient; +import javafx.scene.paint.Stop; +import javafx.scene.text.Font; +import com.sun.javafx.css.ParsedValueImpl; +import javafx.css.converter.PaintConverter; +import javafx.css.converter.StopConverter; +import org.junit.Test; +import static org.junit.Assert.assertEquals; + + +public class PaintTypeTest { + + public PaintTypeTest() { + } + + final Stop[] stops = new Stop[] { + new Stop(0.0f, Color.WHITE), + new Stop(1.0f, Color.BLACK) + }; + + final Paint[] paints = new Paint[] { + Color.rgb(0, 128, 255), + new LinearGradient(0.0f, 0.0f, 1.0f, 1.0f, true, CycleMethod.NO_CYCLE, stops), + new RadialGradient(225, 0.28, 1f, 1f, 5.0f, false, CycleMethod.NO_CYCLE, stops) + }; + + ParsedValue sizeVal(float value) { + return new ParsedValueImpl(new Size(value*100, SizeUnits.PERCENT), null); + } + + ParsedValue stopValue(Stop stop) { + ParsedValue offset = sizeVal((float)stop.getOffset()); + ParsedValue color = new ParsedValueImpl(stop.getColor(), null); + ParsedValue[] values = new ParsedValue[] { offset, color }; + return new ParsedValueImpl(values, StopConverter.getInstance()); + }; + + ParsedValue linearGradientValues(LinearGradient lg) { + ParsedValue[] values = new ParsedValue[7]; + int v = 0; + values[v++] = sizeVal((float) lg.getStartX()); + values[v++] = sizeVal((float) lg.getStartY()); + values[v++] = sizeVal((float) lg.getEndX()); + values[v++] = sizeVal((float) lg.getEndY()); + values[v++] = new ParsedValueImpl(lg.getCycleMethod(),null); + values[v++] = stopValue(stops[0]); + values[v++] = stopValue(stops[1]); + return new ParsedValueImpl(values, PaintConverter.LinearGradientConverter.getInstance()); + } + + ParsedValue radialGradientValues(RadialGradient rg) { + ParsedValue[] values = new ParsedValue[8]; + int v = 0; + values[v++] = new ParsedValueImpl(new Size(rg.getFocusAngle(), SizeUnits.PX), null); + values[v++] = new ParsedValueImpl(new Size(rg.getFocusDistance(), SizeUnits.PX), null); + values[v++] = sizeVal((float) rg.getCenterX()); + values[v++] = sizeVal((float) rg.getCenterY()); + values[v++] = new ParsedValueImpl(new Size(rg.getRadius(), SizeUnits.PX), null); + values[v++] = new ParsedValueImpl(rg.getCycleMethod(),null); + values[v++] = stopValue(stops[0]); + values[v++] = stopValue(stops[1]); + return new ParsedValueImpl(values, PaintConverter.RadialGradientConverter.getInstance()); + } + + final ParsedValue[] paintValues = new ParsedValue[] { + new ParsedValueImpl(paints[0], null), + linearGradientValues((LinearGradient)paints[1]), + radialGradientValues((RadialGradient)paints[2]) + }; + + /** + * Paint is layered (one value per layer). <paint> [, <paint>]*. + * In the convert function, the ParsedValue is a ParsedValue for each layer. + * That is, value.getValue() returns a ParsedValue[]. + */ + ParsedValue[],Paint[]> getValue(int nLayers) { + ParsedValue[] layers = new ParsedValue[nLayers]; + for (int l=0; l[],Paint[]>(layers, PaintConverter.SequenceConverter.getInstance()); + } + /** + * Test of convert method, of class PaintType. + */ + @Test + public void testConvert() { + //System.out.println("convert"); + int nValues = paints.length; + ParsedValue[],Paint[]> value = getValue(nValues); + Font font = null; + Paint[] result = value.convert(font); + assertEquals(nValues, result.length); + for(int r=0; r = radial-gradient( + // [ focus-angle , ]? + // [ focus-distance , ]? + // [ center , ]? + // radius , + // [ [ repeat | reflect ] ,]? + // [, ]+ ) + ParsedValue value = new CssParser().parseExpr("-fx-background-color", + "radial-gradient(focus-angle 90deg, focus-distance 50%, radius 50, red, green, blue)"); + RadialGradient result = (RadialGradient)((Paint[])value.convert(null))[0]; + RadialGradient expected = new RadialGradient(90, .5, 0, 0, 50, + false, CycleMethod.NO_CYCLE, + new Stop(0, Color.RED), + new Stop(.5, Color.GREEN), + new Stop(1.0,Color.BLUE)); + assertEquals(expected,result); + + value = new CssParser().parseExpr("-fx-background-color", + "radial-gradient(focus-angle 1.5708rad, focus-distance 50%, radius 50, red, green, blue)"); + result = (RadialGradient)((Paint[])value.convert(null))[0]; + assertEquals(expected,result); + + value = new CssParser().parseExpr("-fx-background-color", + "radial-gradient(center 0% 10%, radius 50%, reflect, red, green, blue)"); + result = (RadialGradient)((Paint[])value.convert(null))[0]; + expected = new RadialGradient(0, 0, 0, .1, .5, + true, CycleMethod.REFLECT, + new Stop(0, Color.RED), + new Stop(.5, Color.GREEN), + new Stop(1.0,Color.BLUE)); + assertEquals(expected,result); + } + + @Test + public void testParseLinearGradient() { + + // = linear-gradient( + // [ [from to ] | [ to ] ] ,]? [ [ repeat | reflect ] ,]? + // [, ]+ + // ) + // + ParsedValue value = new CssParser().parseExpr("-fx-background-color", + "linear-gradient(to top, red, green, blue)"); + LinearGradient result = (LinearGradient)((Paint[])value.convert(null))[0]; + LinearGradient expected = new LinearGradient(0, 1, 0, 0, + true, CycleMethod.NO_CYCLE, + new Stop(0, Color.RED), + new Stop(.5, Color.GREEN), + new Stop(1.0, Color.BLUE)); + assertEquals(expected,result); + + value = new CssParser().parseExpr("-fx-background-color", + "linear-gradient(to bottom, red, green, blue)"); + result = (LinearGradient)((Paint[])value.convert(null))[0]; + expected = new LinearGradient(0, 0, 0, 1, + true, CycleMethod.NO_CYCLE, + new Stop(0, Color.RED), + new Stop(.5, Color.GREEN), + new Stop(1.0, Color.BLUE)); + assertEquals(expected,result); + + value = new CssParser().parseExpr("-fx-background-color", + "linear-gradient(to left, red, green, blue)"); + result = (LinearGradient)((Paint[])value.convert(null))[0]; + expected = new LinearGradient(1, 0, 0, 0, + true, CycleMethod.NO_CYCLE, + new Stop(0, Color.RED), + new Stop(.5, Color.GREEN), + new Stop(1.0, Color.BLUE)); + assertEquals(expected,result); + + value = new CssParser().parseExpr("-fx-background-color", + "linear-gradient(to right, red, green, blue)"); + result = (LinearGradient)((Paint[])value.convert(null))[0]; + expected = new LinearGradient(0, 0, 1, 0, + true, CycleMethod.NO_CYCLE, + new Stop(0, Color.RED), + new Stop(.5, Color.GREEN), + new Stop(1.0, Color.BLUE)); + assertEquals(expected,result); + + value = new CssParser().parseExpr("-fx-background-color", + "linear-gradient(to bottom left, red, green, blue)"); + result = (LinearGradient)((Paint[])value.convert(null))[0]; + expected = new LinearGradient(1, 0, 0, 1, + true, CycleMethod.NO_CYCLE, + new Stop(0, Color.RED), + new Stop(.5, Color.GREEN), + new Stop(1.0, Color.BLUE)); + assertEquals(expected,result); + + value = new CssParser().parseExpr("-fx-background-color", + "linear-gradient(to bottom right, red, green, blue)"); + result = (LinearGradient)((Paint[])value.convert(null))[0]; + expected = new LinearGradient(0, 0, 1, 1, + true, CycleMethod.NO_CYCLE, + new Stop(0, Color.RED), + new Stop(.5, Color.GREEN), + new Stop(1.0, Color.BLUE)); + assertEquals(expected,result); + + value = new CssParser().parseExpr("-fx-background-color", + "linear-gradient(to top left, red, green, blue)"); + result = (LinearGradient)((Paint[])value.convert(null))[0]; + expected = new LinearGradient(1, 1, 0, 0, + true, CycleMethod.NO_CYCLE, + new Stop(0, Color.RED), + new Stop(.5, Color.GREEN), + new Stop(1.0, Color.BLUE)); + assertEquals(expected,result); + + value = new CssParser().parseExpr("-fx-background-color", + "linear-gradient(to top right, red, green, blue)"); + result = (LinearGradient)((Paint[])value.convert(null))[0]; + expected = new LinearGradient(0, 1, 1, 0, + true, CycleMethod.NO_CYCLE, + new Stop(0, Color.RED), + new Stop(.5, Color.GREEN), + new Stop(1.0, Color.BLUE)); + assertEquals(expected,result); + + value = new CssParser().parseExpr("-fx-background-color", + "linear-gradient(from 10% 10% to 90% 90%, reflect, red, green, blue)"); + result = (LinearGradient)((Paint[])value.convert(null))[0]; + expected = new LinearGradient(.1, .1, .9, .9, + true, CycleMethod.REFLECT, + new Stop(0, Color.RED), + new Stop(.5, Color.GREEN), + new Stop(1.0, Color.BLUE)); + assertEquals(expected,result); + } + +}