The LinearGradient class fills a shape
with a linear color gradient pattern. The user may specify two or
more gradient colors, and this Paint will provide an interpolation
between each color.
The application provides an array of Stops specifying how to distribute
the colors along the gradient. The Stop#offset variable must be
the range 0.0 to 1.0 and act like keyframes along the gradient.
The offsets mark where the gradient should be exactly a particular color.
If the proportional variable is set to true then the start and end points of the gradient should be specified relative to the unit square (0.0->1.0) and will be stretched across the shape. If the proportional variable is set to false, then the start and end points should be specified in the local coordinate system of the shape and the gradient will not be stretched at all.
The two filled rectangles in the example below will render the same. The one on the left uses proportional coordinates to specify the end points of the gradient. The one on the right uses absolute coordinates. Both of them fill the specified rectangle with a horizontal gradient that varies from black to red
// object bounding box relative (proportional = true)
Stop[] stops = new Stop[] { new Stop(0, Color.BLACK), new Stop(1, Color.RED)};
LinearGradient lg1 = new LinearGradient(0, 0, 1, 0, true, CycleMethod.NO_CYCLE, stops);
Rectangle r1 = new Rectangle(0, 0, 100, 100);
r1.setFill(lg1);
// user space relative (proportional: = false)
LinearGradient lg2 = new LinearGradient(125, 0, 225, 0, false, CycleMethod.NO_CYCLE, stops);
Rectangle r2 = new Rectangle(125, 0, 100, 100);
r2.setFill(lg2);
| Modifier and Type | Field and Description |
|---|---|
| private CycleMethod | |
| private double | |
| private double | |
| private int | hash
The cached hash code, used to improve performance in situations where we cache gradients, such as in the CSS routines. |
| private final boolean | |
| private Object | platformPaint
A cached reference to the platform paint, no point recomputing twice |
| private boolean | |
| private double | |
| private double | |
| private List |
| Access | Constructor and Description |
|---|---|
| public | LinearGradient(double
the X coordinate of the gradient axis start point startX, double the Y coordinate of the gradient axis start point startY, double the X coordinate of the gradient axis end point endX, double the Y coordinate of the gradient axis end point endY, boolean whether the coordinates are proportional
to the shape which this gradient fills proportional, CycleMethod cycle method applied to the gradient cycleMethod, Stop... the gradient's color specification stops)Creates a new instance of LinearGradient. |
| public | LinearGradient(double
the X coordinate of the gradient axis start point startX, double the Y coordinate of the gradient axis start point startY, double the X coordinate of the gradient axis end point endX, double the Y coordinate of the gradient axis end point endY, boolean whether the coordinates are proportional
to the shape which this gradient fills proportional, CycleMethod cycle method applied to the gradient cycleMethod, List<Stop> the gradient's color specification stops)Creates a new instance of LinearGradient. |
| private | LinearGradient(double startX, double startY, double endX, double endY, boolean proportional, CycleMethod cycleMethod, List<Stop> stops, int ignored)
Private constructor accepting a stop list that is already normalized. |
| Modifier and Type | Method and Description |
|---|---|
| pack-priv Object | |
| private boolean | |
| public boolean | Returns: true if this object is equal to the obj argument; false otherwise.the reference object with which to compare. obj)Overrides java. Indicates whether some other object is "equal to" this one. |
| public final CycleMethod | Returns: the cycle method applied to this linear gradientDefines which of the following cycle method is applied
to the |
| public final double | Returns: the X coordinate of the gradient axis end pointDefines the X coordinate of the gradient axis end point. |
| public final double | Returns: the Y coordinate of the gradient axis end pointDefines the Y coordinate of the gradient axis end point. |
| public final double | Returns: the X coordinate of the gradient axis start pointDefines the X coordinate of the gradient axis start point. |
| public final double | Returns: the Y coordinate of the gradient axis start pointDefines the Y coordinate of the gradient axis start point. |
| public final List | Returns: the list of stop valuesA sequence of 2 or more |
| public int | Returns: a hash code for thisLinearGradient object.Overrides java. Returns a hash code for this |
| public LinearGradient | Returns: the intermediate valuethe target value endValue, double the interpolation factor t)Implements javafx. Returns an intermediate value between the value of this |
| public Paint | interpolate(Paint
the target value endValue, double the interpolation factor t)Implements javafx. Returns an intermediate value between the value of this |
| public final boolean | isOpaque()
Implements abstract javafx. Gets whether this Paint is completely opaque. |
| public final boolean | Returns: if true start and end locations are proportional, otherwise absoluteIndicates whether start and end locations are proportional or absolute. |
| private boolean | isSame(double startX, double startY, double endX, double endY, boolean proportional, CycleMethod cycleMethod, List<Stop> stops)
|
| public String | Returns: a string representation of thisLinearGradient object.Overrides java. Returns a string representation of this |
| public static LinearGradient | Returns: aLinearGradient object holding the value represented
by the string argument.the string to convert value)Hides javafx. Creates a linear gradient value from a string representation. |
| cycleMethod | back to summary |
|---|---|
| private CycleMethod cycleMethod | |
| endX | back to summary |
|---|---|
| private double endX | |
| endY | back to summary |
|---|---|
| private double endY | |
| hash | back to summary |
|---|---|
| private int hash The cached hash code, used to improve performance in situations where we cache gradients, such as in the CSS routines. | |
| opaque | back to summary |
|---|---|
| private final boolean opaque | |
| platformPaint | back to summary |
|---|---|
| private Object platformPaint A cached reference to the platform paint, no point recomputing twice | |
| proportional | back to summary |
|---|---|
| private boolean proportional | |
| startX | back to summary |
|---|---|
| private double startX | |
| startY | back to summary |
|---|---|
| private double startY | |
| stops | back to summary |
|---|---|
| private List<Stop> stops | |
| LinearGradient | back to summary |
|---|---|
| public LinearGradient(double startX, double startY, double endX, double endY, boolean proportional, CycleMethod cycleMethod, Stop... stops) Creates a new instance of LinearGradient.
| |
| LinearGradient | back to summary |
|---|---|
| public LinearGradient(double startX, double startY, double endX, double endY, boolean proportional, CycleMethod cycleMethod, List<Stop> stops) Creates a new instance of LinearGradient.
| |
| LinearGradient | back to summary |
|---|---|
| private LinearGradient(double startX, double startY, double endX, double endY, boolean proportional, CycleMethod cycleMethod, List<Stop> stops, int ignored) Private constructor accepting a stop list that is already normalized.
This constructor is only called from the | |
| acc_getPlatformPaint | back to summary |
|---|---|
| pack-priv Object acc_getPlatformPaint() Implements abstract javafx.
| |
| determineOpacity | back to summary |
|---|---|
| private boolean determineOpacity() Iterate over all the stops. If any one of them has a transparent color, then we return false. If there are no stops, we return false. Otherwise, we return true. Note that this is called AFTER Stop.normalize, which ensures that we always have at least 2 stops.
| |
| equals | back to summary |
|---|---|
| public boolean equals(Object obj) Overrides java. Indicates whether some other object is "equal to" this one. | |
| getCycleMethod | back to summary |
|---|---|
| public final CycleMethod getCycleMethod() Defines which of the following cycle method is applied
to the
| |
| getEndX | back to summary |
|---|---|
| public final double getEndX() Defines the X coordinate of the gradient axis end point. If proportional is true (the default), this value specifies a point on a unit square that will be scaled to match the size of the shape that the gradient fills.
| |
| getEndY | back to summary |
|---|---|
| public final double getEndY() Defines the Y coordinate of the gradient axis end point. If proportional is true (the default), this value specifies a point on a unit square that will be scaled to match the size of the shape that the gradient fills.
| |
| getStartX | back to summary |
|---|---|
| public final double getStartX() Defines the X coordinate of the gradient axis start point. If proportional is true (the default), this value specifies a point on a unit square that will be scaled to match the size of the shape that the gradient fills.
| |
| getStartY | back to summary |
|---|---|
| public final double getStartY() Defines the Y coordinate of the gradient axis start point. If proportional is true (the default), this value specifies a point on a unit square that will be scaled to match the size of the shape that the gradient fills.
| |
| getStops | back to summary |
|---|---|
| public final List A sequence of 2 or more Each stop in the sequence must have an offset that is greater than the previous stop in the sequence. The list is unmodifiable and will throw
| |
| hashCode | back to summary |
|---|---|
| public int hashCode() Overrides java. Returns a hash code for this
| |
| interpolate | back to summary |
|---|---|
| public LinearGradient interpolate(LinearGradient endValue, double t) Implements javafx. Returns an intermediate value between the value of this
| |
| interpolate | back to summary |
|---|---|
| public Paint interpolate(Paint endValue, double t) Implements javafx. Doc from javafx. Returns an intermediate value between the value of this The returned value might not be a new instance; the implementation might also return one of the two existing instances if the intermediate value would be equal to one of the existing values. However, this is an optimization and applications should not assume any particular identity of the returned value.
| |
| isOpaque | back to summary |
|---|---|
| public final boolean isOpaque() Implements abstract javafx. Doc from javafx. Gets whether this Paint is completely opaque. An opaque paint is one that has no alpha component in any of its colors. It may be possible for a Paint to be opaque and yet return false, if it cannot be easily determined whether the paint is actually opaque. For example, the ImagePattern may not be able to cheaply determine its opacity.
| |
| isProportional | back to summary |
|---|---|
| public final boolean isProportional() Indicates whether start and end locations are proportional or absolute.
If this flag is true, the two end points are defined in a coordinate
space where coordinates in the range
| |
| isSame | back to summary |
|---|---|
| private boolean isSame(double startX, double startY, double endX, double endY, boolean proportional, CycleMethod cycleMethod, List<Stop> stops) | |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Returns a string representation of this | |
| valueOf | back to summary |
|---|---|
| public static LinearGradient valueOf(String value) Hides javafx. Creates a linear gradient value from a string representation. The format of the string representation is based on JavaFX CSS specification for linear gradient which is linear-gradient( [ [from <point> to <point>| [ to <side-or-corner>], ]? [ [ repeat | reflect ], ]? <color-stop>[, <color-stop>]+)where <side-or-corner> = [left | right] || [top | bottom] <point> = [ [ <length> <length> ] | [ <percentage> | <percentage> ] ] <color-stop> = [ <color> [ <percentage> | <length>]? ] Currently length can be only specified in px, the specification of unit can be omitted.
Format of color representation is the one used in
| |