Class RMGradientFill
- java.lang.Object
-
- com.inductiveautomation.rm.base.RMListenerList
-
- com.inductiveautomation.rm.base.RMObject
-
- com.inductiveautomation.rm.graphics.RMFill
-
- com.inductiveautomation.rm.graphics.RMGradientFill
-
- All Implemented Interfaces:
Archivable
,RMPropertyChanger
,java.lang.Cloneable
- Direct Known Subclasses:
RMRadialGradientFill
public class RMGradientFill extends RMFill
This class represents a fill that draws a linear gradient between an arbitrary list of colors.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
RMGradientFill.ColorStop
Simple static class to represent a stop (they're immutable).
-
Constructor Summary
Constructors Constructor Description RMGradientFill()
Creates an uninitialized gradient fill.RMGradientFill(RMColor aColor1, RMColor aColor2, float aRotation)
Creates a gradient fill from the given start color to the given end color with the given roll.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description RMGradientFill
clone()
Standard clone implementation.RMGradientFill
deriveGradient(boolean isRadial)
Returns a new gradient which is a copy of this gradient but of a different type.RMGradientFill
deriveGradient(float aRoll)
Returns a new gradient which is a copy of this gradient but with a different roll value.boolean
equals(java.lang.Object anObj)
Standard equals implementation.java.lang.Object
fromXML(RXArchiver anArchiver, RXElement anElement)
XML unarchival.RMColor
getColor()
Returns the color associated with this fill.RMGradientFill.ColorStop
getColorStop(int anIndex)
Returns the individual color stop at given index.int
getColorStopCount()
Returns the number of color stops in the gradientjava.util.List<RMGradientFill.ColorStop>
getColorStops()
Returns the list of color stops.void
getGradientAxis(RMRect aRect, java.awt.geom.Point2D p1, java.awt.geom.Point2D p2)
Returns the 2 points, in the shape's coordinate system, which define the gradient.void
getGradientAxis(RMShape aShape, RMPath aPath, java.awt.geom.Point2D p1, java.awt.geom.Point2D p2)
Returns the 2 points, in the shape's coordinate system, which define the gradient.java.awt.geom.Rectangle2D
getGradientBounds(java.awt.Shape aShape)
Returns the gradient bounds for a given shape which is the bounds required to encompass the entire shape in the coordinates of the gradient rotation (effectively the bounds of the shape rotated by opposite gradient rotation).java.awt.Paint
getPaint(float startx, float starty, float endx, float endy)
Returns a java.awt.Paint instance to draw this gradient.float
getRoll()
Returns the gradient's rotation.RMColor
getStopColor(int index)
Returns the color of the stop at the given index.float
getStopPosition(int index)
Returns the position (in the range {0-1}) for the given stop index.boolean
hasAlpha()
Returns true if any of the colors in the gradient have alphaint
insertColorStop(RMColor aColor, float position)
Adds a new color stop at the given position.boolean
isRadial()
Returns whether gradient is radial.void
paint(RMShapePainter aPntr, RMShape aShape)
Render this fill in a shape painter.void
removeColorStop(int index)
Removes the stop at the given index.void
reverseColors()
Reverse the order of the color stopsvoid
setColor(RMColor aColor)
Sets color of first stop.void
setColorStop(int index, RMColor aColor, float position)
Sets the color & position of the stop at the given index.protected void
setRoll(float aRoll)
Sets the gradient's rotation.void
setStops(java.util.List<RMGradientFill.ColorStop> newStops)
Resets all the stops from the new list.java.lang.String
toString()
Standard to string implementation.RXElement
toXML(RXArchiver anArchiver)
XML archival.-
Methods inherited from class com.inductiveautomation.rm.graphics.RMFill
deriveFill, getBounds, getName, readAttributes
-
Methods inherited from class com.inductiveautomation.rm.base.RMObject
addPropertyChangeListener, animUpdate, firePropertyChange, firePropertyChange, firePropertyChange, getPCEvent, removePropertyChangeListener, sendPropertyChange
-
Methods inherited from class com.inductiveautomation.rm.base.RMListenerList
addListener, getListener, getListenerCount, getListenerCount, getListenerList, getListeners, hasListeners, removeListener
-
-
-
-
Method Detail
-
getColorStopCount
public int getColorStopCount()
Returns the number of color stops in the gradient
-
getColorStop
public RMGradientFill.ColorStop getColorStop(int anIndex)
Returns the individual color stop at given index.
-
getColorStops
public java.util.List<RMGradientFill.ColorStop> getColorStops()
Returns the list of color stops.
-
setColorStop
public void setColorStop(int index, RMColor aColor, float position)
Sets the color & position of the stop at the given index.
-
removeColorStop
public void removeColorStop(int index)
Removes the stop at the given index.
-
setStops
public void setStops(java.util.List<RMGradientFill.ColorStop> newStops)
Resets all the stops from the new list.
-
insertColorStop
public int insertColorStop(RMColor aColor, float position)
Adds a new color stop at the given position. Returns the index of the new stop.
-
reverseColors
public void reverseColors()
Reverse the order of the color stops
-
getRoll
public float getRoll()
Returns the gradient's rotation.
-
setRoll
protected void setRoll(float aRoll)
Sets the gradient's rotation.
-
isRadial
public boolean isRadial()
Returns whether gradient is radial.
-
deriveGradient
public RMGradientFill deriveGradient(float aRoll)
Returns a new gradient which is a copy of this gradient but with a different roll value.
-
deriveGradient
public RMGradientFill deriveGradient(boolean isRadial)
Returns a new gradient which is a copy of this gradient but of a different type.
-
getGradientBounds
public java.awt.geom.Rectangle2D getGradientBounds(java.awt.Shape aShape)
Returns the gradient bounds for a given shape which is the bounds required to encompass the entire shape in the coordinates of the gradient rotation (effectively the bounds of the shape rotated by opposite gradient rotation). The gradient should be defined in these bounds so that rendered shapes completely utilizes the color range.
-
getGradientAxis
public void getGradientAxis(RMShape aShape, RMPath aPath, java.awt.geom.Point2D p1, java.awt.geom.Point2D p2)
Returns the 2 points, in the shape's coordinate system, which define the gradient.
-
getGradientAxis
public void getGradientAxis(RMRect aRect, java.awt.geom.Point2D p1, java.awt.geom.Point2D p2)
Returns the 2 points, in the shape's coordinate system, which define the gradient.
-
getColor
public RMColor getColor()
Returns the color associated with this fill.
-
setColor
public void setColor(RMColor aColor)
Sets color of first stop.
-
getStopColor
public RMColor getStopColor(int index)
Returns the color of the stop at the given index.
-
getStopPosition
public float getStopPosition(int index)
Returns the position (in the range {0-1}) for the given stop index.
-
hasAlpha
public boolean hasAlpha()
Returns true if any of the colors in the gradient have alpha
-
getPaint
public java.awt.Paint getPaint(float startx, float starty, float endx, float endy)
Returns a java.awt.Paint instance to draw this gradient.
-
paint
public void paint(RMShapePainter aPntr, RMShape aShape)
Render this fill in a shape painter.
-
equals
public boolean equals(java.lang.Object anObj)
Standard equals implementation.
-
clone
public RMGradientFill clone()
Standard clone implementation.
-
toXML
public RXElement toXML(RXArchiver anArchiver)
XML archival.- Specified by:
toXML
in interfaceArchivable
- Overrides:
toXML
in classRMFill
-
fromXML
public java.lang.Object fromXML(RXArchiver anArchiver, RXElement anElement)
XML unarchival.- Specified by:
fromXML
in interfaceArchivable
- Overrides:
fromXML
in classRMFill
-
-