Package org.jdesktop.swingx.painter
Class BusyPainter
- java.lang.Object
-
- org.jdesktop.beans.AbstractBean
-
- org.jdesktop.swingx.painter.AbstractPainter<java.lang.Object>
-
- org.jdesktop.swingx.painter.BusyPainter
-
- All Implemented Interfaces:
Painter<java.lang.Object>
@JavaBean public class BusyPainter extends AbstractPainter<java.lang.Object>
A specific painter that paints an "infinite progress" like animation.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
BusyPainter.Direction
Direction is used to set the initial direction in which the animation starts.-
Nested classes/interfaces inherited from class org.jdesktop.swingx.painter.AbstractPainter
AbstractPainter.Interpolation
-
-
Field Summary
Fields Modifier and Type Field Description private java.awt.Color
baseColor
private BusyPainter.Direction
direction
private int
frame
private java.awt.Color
highlightColor
private boolean
paintCentered
private int
points
private java.awt.Shape
pointShape
private int
trailLength
private java.awt.Shape
trajectory
-
Constructor Summary
Constructors Constructor Description BusyPainter()
Creates new busy painter initialized to the shape of circle and bounds size 26x26 points.BusyPainter(int height)
Creates new painter initialized to the shape of circle and bounds of square of specified height.BusyPainter(java.awt.Shape point, java.awt.Shape trajectory)
Initializes painter to the specified trajectory and and point shape.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private float
calcCube(float[] coords, java.awt.geom.Point2D.Float cp)
Claclulates length of the cubic segment.private java.awt.Color
calcFrameColor(int i)
Selects appropriate color for given frame based on the frame position and gradient difference.private float
calcLengthOfQuad(float[] coords, java.awt.geom.Point2D.Float cp)
Calculates length of the quadratic segmentprivate float
calcLine(float[] coords, java.awt.geom.Point2D.Float cp)
Calculates length of the linear segment.private java.awt.geom.Point2D.Float
calcPoint(float dist2go, java.awt.geom.Point2D.Float startPoint, float[] sgmt, int w, int h)
protected void
doPaint(java.awt.Graphics2D g, java.lang.Object t, int width, int height)
Subclasses must implement this method and perform custom painting operations here.private void
drawAt(java.awt.Graphics2D g, int i, java.awt.geom.Point2D.Float p, java.awt.geom.Point2D.Float c)
java.awt.Color
getBaseColor()
Gets base color.BusyPainter.Direction
getDirection()
Gets current direction of spinning.int
getFrame()
Gets current frame.java.awt.Color
getHighlightColor()
Gets highlight color.int
getPoints()
Gets total amount of distinct points in spinner.java.awt.Shape
getPointShape()
Gets shape of current point.protected static java.awt.Shape
getScaledDefaultPoint(int height)
protected static java.awt.Shape
getScaledDefaultTrajectory(int height)
int
getTrailLength()
Gets length of trail in number of points.java.awt.Shape
getTrajectory()
Gets current trajectory.private java.awt.geom.Point2D.Float
getXY(float t, float x1, float y1, float x2, float y2)
Calculates the XY point for a given t value.static java.awt.geom.Point2D.Float
getXY(float t, java.awt.geom.Point2D.Float begin, java.awt.geom.Point2D.Float ctrl, java.awt.geom.Point2D.Float end)
Calculates relative position of the point on the quad curve in time t<0,1>.protected void
init(java.awt.Shape point, java.awt.Shape trajectory, java.awt.Color baseColor, java.awt.Color highlightColor)
Initializes painter to provided shapes and default colors.boolean
isPaintCentered()
Gets value of centering hint.private void
paintRotatedCenteredShapeAtPoint(java.awt.geom.Point2D.Float p, java.awt.geom.Point2D.Float c, java.awt.Graphics2D g)
void
setBaseColor(java.awt.Color baseColor)
Sets new base color.void
setDirection(BusyPainter.Direction dir)
Sets new spinning direction.void
setFrame(int frame)
Sets current frame.void
setHighlightColor(java.awt.Color highlightColor)
Sets new highlight color.void
setPaintCentered(boolean paintCentered)
Centers shape in the area covered by the painter.void
setPoints(int points)
Sets total amount of points in spinner.void
setPointShape(java.awt.Shape pointShape)
Sets new point shape.void
setTrailLength(int trailLength)
Sets length of the trail in points.void
setTrajectory(java.awt.Shape trajectory)
Sets new trajectory.-
Methods inherited from class org.jdesktop.swingx.painter.AbstractPainter
clearCache, configureGraphics, getFilters, getInterpolation, isAntialiasing, isCacheable, isCacheCleared, isDirty, isInPaintContext, isVisible, paint, setAntialiasing, setCacheable, setDirty, setFilters, setInPaintContext, setInterpolation, setVisible, shouldUseCache, validate
-
Methods inherited from class org.jdesktop.beans.AbstractBean
addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, addVetoableChangeListener, clone, fireIndexedPropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, fireVetoableChange, getPropertyChangeListeners, getPropertyChangeListeners, getVetoableChangeListeners, getVetoableChangeListeners, hasPropertyChangeListeners, hasVetoableChangeListeners, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, removeVetoableChangeListener
-
-
-
-
Field Detail
-
frame
private int frame
-
points
private int points
-
baseColor
private java.awt.Color baseColor
-
highlightColor
private java.awt.Color highlightColor
-
trailLength
private int trailLength
-
pointShape
private java.awt.Shape pointShape
-
trajectory
private java.awt.Shape trajectory
-
direction
private BusyPainter.Direction direction
-
paintCentered
private boolean paintCentered
-
-
Constructor Detail
-
BusyPainter
public BusyPainter()
Creates new busy painter initialized to the shape of circle and bounds size 26x26 points.
-
BusyPainter
public BusyPainter(int height)
Creates new painter initialized to the shape of circle and bounds of square of specified height.- Parameters:
height
- Painter height.
-
BusyPainter
public BusyPainter(java.awt.Shape point, java.awt.Shape trajectory)
Initializes painter to the specified trajectory and and point shape. Bounds are dynamically calculated to so the specified trajectory fits in.- Parameters:
point
- Point shape.trajectory
- Trajectory shape.
-
-
Method Detail
-
getScaledDefaultTrajectory
protected static java.awt.Shape getScaledDefaultTrajectory(int height)
-
getScaledDefaultPoint
protected static java.awt.Shape getScaledDefaultPoint(int height)
-
init
protected void init(java.awt.Shape point, java.awt.Shape trajectory, java.awt.Color baseColor, java.awt.Color highlightColor)
Initializes painter to provided shapes and default colors.- Parameters:
point
- Point shape.trajectory
- Trajectory shape.
-
doPaint
protected void doPaint(java.awt.Graphics2D g, java.lang.Object t, int width, int height)
Description copied from class:AbstractPainter
Subclasses must implement this method and perform custom painting operations here.- Specified by:
doPaint
in classAbstractPainter<java.lang.Object>
- Parameters:
g
- The Graphics2D object in which to paint
-
isPaintCentered
public boolean isPaintCentered()
Gets value of centering hint. If true, shape will be positioned in the center of painted area.- Returns:
- Whether shape will be centered over painting area or not.
-
setPaintCentered
public void setPaintCentered(boolean paintCentered)
Centers shape in the area covered by the painter.- Parameters:
paintCentered
- Centering hint.
-
drawAt
private void drawAt(java.awt.Graphics2D g, int i, java.awt.geom.Point2D.Float p, java.awt.geom.Point2D.Float c)
-
paintRotatedCenteredShapeAtPoint
private void paintRotatedCenteredShapeAtPoint(java.awt.geom.Point2D.Float p, java.awt.geom.Point2D.Float c, java.awt.Graphics2D g)
-
calcPoint
private java.awt.geom.Point2D.Float calcPoint(float dist2go, java.awt.geom.Point2D.Float startPoint, float[] sgmt, int w, int h)
-
calcLine
private float calcLine(float[] coords, java.awt.geom.Point2D.Float cp)
Calculates length of the linear segment.- Parameters:
coords
- Segment coordinates.cp
- Start point.- Returns:
- Length of the segment.
-
calcCube
private float calcCube(float[] coords, java.awt.geom.Point2D.Float cp)
Claclulates length of the cubic segment.- Parameters:
coords
- Segment coordinates.cp
- Start point.- Returns:
- Length of the segment.
-
calcLengthOfQuad
private float calcLengthOfQuad(float[] coords, java.awt.geom.Point2D.Float cp)
Calculates length of the quadratic segment- Parameters:
coords
- Segment coordinatescp
- Start point.- Returns:
- Length of the segment.
-
getXY
private java.awt.geom.Point2D.Float getXY(float t, float x1, float y1, float x2, float y2)
Calculates the XY point for a given t value. The general spline equation is: x = b0*x0 + b1*x1 + b2*x2 + b3*x3 y = b0*y0 + b1*y1 + b2*y2 + b3*y3 where: b0 = (1-t)^3 b1 = 3 * t * (1-t)^2 b2 = 3 * t^2 * (1-t) b3 = t^3 We know that (x0,y0) == (0,0) and (x1,y1) == (1,1) for our splines, so this simplifies to: x = b1*x1 + b2*x2 + b3 y = b1*x1 + b2*x2 + b3- Parameters:
t
- parametric value for spline calculation
-
getXY
public static java.awt.geom.Point2D.Float getXY(float t, java.awt.geom.Point2D.Float begin, java.awt.geom.Point2D.Float ctrl, java.awt.geom.Point2D.Float end)
Calculates relative position of the point on the quad curve in time t<0,1>.- Parameters:
t
- distance on the curvectrl
- Control point in rel coordsend
- End point in rel coords- Returns:
- Solution of the quad equation for time T in non complex space in rel coords.
-
calcFrameColor
private java.awt.Color calcFrameColor(int i)
Selects appropriate color for given frame based on the frame position and gradient difference.- Parameters:
i
- Frame.- Returns:
- Frame color.
-
getFrame
public int getFrame()
Gets current frame.- Returns:
- Current frame.
-
setFrame
public void setFrame(int frame)
Sets current frame.- Parameters:
frame
- Current frame.
-
getBaseColor
public java.awt.Color getBaseColor()
Gets base color.- Returns:
- Base color.
-
setBaseColor
public void setBaseColor(java.awt.Color baseColor)
Sets new base color. Bound property.- Parameters:
baseColor
- Base color.
-
getHighlightColor
public java.awt.Color getHighlightColor()
Gets highlight color.- Returns:
- Current highlight color.
-
setHighlightColor
public void setHighlightColor(java.awt.Color highlightColor)
Sets new highlight color. Bound property.- Parameters:
highlightColor
- New highlight color.
-
getPoints
public int getPoints()
Gets total amount of distinct points in spinner.- Returns:
- Total amount of points.
-
setPoints
public void setPoints(int points)
Sets total amount of points in spinner. Bound property.- Parameters:
points
- Total amount of points.
-
getTrailLength
public int getTrailLength()
Gets length of trail in number of points.- Returns:
- Trail lenght.
-
setTrailLength
public void setTrailLength(int trailLength)
Sets length of the trail in points. Bound property.- Parameters:
trailLength
- Trail length in points.
-
getPointShape
public final java.awt.Shape getPointShape()
Gets shape of current point.- Returns:
- Shape of the point.
-
setPointShape
public final void setPointShape(java.awt.Shape pointShape)
Sets new point shape. Bound property.- Parameters:
pointShape
- new Shape.
-
getTrajectory
public final java.awt.Shape getTrajectory()
Gets current trajectory.- Returns:
- Current spinner trajectory .
-
setTrajectory
public final void setTrajectory(java.awt.Shape trajectory)
Sets new trajectory. Expected trajectory have to be closed shape. Bound property.- Parameters:
trajectory
- New trajectory.
-
getDirection
public BusyPainter.Direction getDirection()
Gets current direction of spinning.- Returns:
- Current spinning direction.
-
setDirection
public void setDirection(BusyPainter.Direction dir)
Sets new spinning direction.- Parameters:
dir
- Spinning direction.
-
-