modules/graphics/src/test/java/javafx/css/PaintTypeTest.java
Print this page
rev 9240 : 8076423: JEP 253: Prepare JavaFX UI Controls & CSS APIs for Modularization
*** 21,43 ****
* 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 {
--- 21,42 ----
* 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 {
*** 163,173 ****
setup();
for (int i=0; i<css.length; i++) {
Stylesheet stylesheet =
! CSSParser.getInstance().parse("* { -fx-border-color: " + css[i] + "; }");
ParsedValue value = TypeTest.getValueFor(stylesheet, "-fx-border-color");
Paint[][] paints = (Paint[][])value.convert(Font.getDefault());
--- 162,172 ----
setup();
for (int i=0; i<css.length; i++) {
Stylesheet stylesheet =
! new CssParser().parse("* { -fx-border-color: " + css[i] + "; }");
ParsedValue value = TypeTest.getValueFor(stylesheet, "-fx-border-color");
Paint[][] paints = (Paint[][])value.convert(Font.getDefault());
*** 189,214 ****
// [ focus-distance <percentage>, ]?
// [ center <point>, ]?
// radius <length>,
// [ [ repeat | reflect ] ,]?
// <color-stop>[, <color-stop>]+ )
! 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),
--- 188,213 ----
// [ focus-distance <percentage>, ]?
// [ center <point>, ]?
// radius <length>,
// [ [ repeat | reflect ] ,]?
// <color-stop>[, <color-stop>]+ )
! 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),
*** 223,313 ****
// <linear-gradient> = linear-gradient(
// [ [from <point> to <point>] | [ to <side-or-corner> ] ] ,]? [ [ repeat | reflect ] ,]?
// <color-stop>[, <color-stop>]+
// )
//
! 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),
--- 222,312 ----
// <linear-gradient> = linear-gradient(
// [ [from <point> to <point>] | [ to <side-or-corner> ] ] ,]? [ [ repeat | reflect ] ,]?
// <color-stop>[, <color-stop>]+
// )
//
! 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),