Package com.bric.multislider
Class MultiThumbSliderUI<T>
- java.lang.Object
-
- javax.swing.plaf.ComponentUI
-
- com.bric.multislider.MultiThumbSliderUI<T>
-
- Type Parameters:
T
- the type
- All Implemented Interfaces:
MouseListener
,MouseMotionListener
,EventListener
- Direct Known Subclasses:
DefaultMultiThumbSliderUI
public abstract class MultiThumbSliderUI<T> extends ComponentUI implements MouseListener, MouseMotionListener
This is the abstract UI forMultiThumbSliders
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) class
MultiThumbSliderUI.State
This records the positions/values of each thumb.static class
MultiThumbSliderUI.Thumb
A thumb shape.
-
Field Summary
Fields Modifier and Type Field Description (package private) Runnable
animatingRunnable
(package private) Thread
animatingThread
(package private) ComponentListener
compListener
(package private) int
DEPTH
The height of a horizontal slider -- or width of a vertical slider.(package private) FocusListener
focusListener
(package private) float
indication
The overall indication of the thumbs.(package private) KeyListener
keyListener
(package private) int
MAX_LENGTH
The maximum width returned bygetMaximumSize()
.(package private) int
MIN_LENGTH
The minimum width returned bygetMinimumSize()
.protected boolean
mouseInside
protected boolean
mouseIsDown
(package private) int
PREF_LENGTH
The maximum width returned bygetPreferredSize()
.(package private) PropertyChangeListener
propertyListener
protected MultiThumbSlider<T>
slider
static String
THUMB_SHAPE_PROPERTY
The Swing client property associated with a Thumb.protected float[]
thumbIndications
A float from zero to one, indicating whether that thumb should be highlighted or not.(package private) int[]
thumbPositions
The pixel position of the thumbs.(package private) PropertyChangeListener
thumbShapeListener
protected Rectangle
trackRect
The rectangle the track should be painted in.
-
Constructor Summary
Constructors Constructor Description MultiThumbSliderUI(MultiThumbSlider<T> slider)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected boolean
addThumb(int index1, int index2)
This will try to add a thumb between index1 and index2.protected void
calculateGeometry()
protected Rectangle
calculateTrackRect()
Dimension
getMaximumSize(JComponent s)
Dimension
getMinimumSize(JComponent s)
protected abstract int
getPreferredComponentDepth()
Return the typical height of a horizontally oriented slider, or the width of the vertically oriented slider.Dimension
getPreferredSize(JComponent s)
static <K> K
getProperty(JComponent jc, String propertyName, K defaultValue)
This retrieves a property.MultiThumbSliderUI.Thumb
getThumb(int thumbIndex)
Return the Thumb option used to render a specific thumb.Point2D
getThumbCenter(float position)
Calculate the thumb center based on a fractional positionPoint2D
getThumbCenter(int thumbIndex)
Calculate the thumb centerShape
getThumbShape(int thumbIndex)
Create the shape used to render a specific thumb.Shape
getThumbShape(int thumbIndex, Point2D center)
Create the shape used to render a specific thumb.protected Dimension
getThumbSize(int thumbIndex)
void
installUI(JComponent slider)
void
mouseClicked(MouseEvent e)
void
mouseDragged(MouseEvent e)
void
mouseEntered(MouseEvent e)
void
mouseExited(MouseEvent e)
void
mouseMoved(MouseEvent e)
void
mousePressed(MouseEvent e)
void
mouseReleased(MouseEvent e)
void
paint(Graphics g, JComponent slider2)
protected abstract void
paintFocus(Graphics2D g)
protected abstract void
paintThumbs(Graphics2D g)
protected abstract void
paintTrack(Graphics2D g)
void
uninstallUI(JComponent slider)
protected void
updateIndication()
protected boolean
validatePositions(MultiThumbSliderUI.State state)
Makes sure the thumbs are in the right order.-
Methods inherited from class javax.swing.plaf.ComponentUI
contains, createUI, getAccessibleChild, getAccessibleChildrenCount, getBaseline, getBaselineResizeBehavior, update
-
-
-
-
Field Detail
-
THUMB_SHAPE_PROPERTY
public static final String THUMB_SHAPE_PROPERTY
The Swing client property associated with a Thumb.- See Also:
MultiThumbSliderUI.Thumb
-
thumbShapeListener
PropertyChangeListener thumbShapeListener
-
slider
protected MultiThumbSlider<T> slider
-
MAX_LENGTH
int MAX_LENGTH
The maximum width returned bygetMaximumSize()
. (or if the slider is vertical, this is the maximum height.)
-
MIN_LENGTH
int MIN_LENGTH
The minimum width returned bygetMinimumSize()
. (or if the slider is vertical, this is the minimum height.)
-
PREF_LENGTH
int PREF_LENGTH
The maximum width returned bygetPreferredSize()
. (or if the slider is vertical, this is the preferred height.)
-
DEPTH
int DEPTH
The height of a horizontal slider -- or width of a vertical slider.
-
thumbPositions
int[] thumbPositions
The pixel position of the thumbs. This may be x or y coordinates, depending on whether this slider is horizontal or vertical
-
thumbIndications
protected float[] thumbIndications
A float from zero to one, indicating whether that thumb should be highlighted or not.
-
indication
float indication
The overall indication of the thumbs. At one they should be opaque, at zero they should be transparent.
-
trackRect
protected Rectangle trackRect
The rectangle the track should be painted in.
-
animatingThread
Thread animatingThread
-
animatingRunnable
Runnable animatingRunnable
-
mouseInside
protected boolean mouseInside
-
mouseIsDown
protected boolean mouseIsDown
-
focusListener
FocusListener focusListener
-
keyListener
KeyListener keyListener
-
propertyListener
PropertyChangeListener propertyListener
-
compListener
ComponentListener compListener
-
-
Constructor Detail
-
MultiThumbSliderUI
public MultiThumbSliderUI(MultiThumbSlider<T> slider)
-
-
Method Detail
-
getMaximumSize
public Dimension getMaximumSize(JComponent s)
- Overrides:
getMaximumSize
in classComponentUI
-
getMinimumSize
public Dimension getMinimumSize(JComponent s)
- Overrides:
getMinimumSize
in classComponentUI
-
getPreferredSize
public Dimension getPreferredSize(JComponent s)
- Overrides:
getPreferredSize
in classComponentUI
-
getPreferredComponentDepth
protected abstract int getPreferredComponentDepth()
Return the typical height of a horizontally oriented slider, or the width of the vertically oriented slider.- Returns:
- the typical height of a horizontally oriented slider, or the width of the vertically oriented slider.
-
mousePressed
public void mousePressed(MouseEvent e)
- Specified by:
mousePressed
in interfaceMouseListener
-
mouseEntered
public void mouseEntered(MouseEvent e)
- Specified by:
mouseEntered
in interfaceMouseListener
-
mouseExited
public void mouseExited(MouseEvent e)
- Specified by:
mouseExited
in interfaceMouseListener
-
mouseClicked
public void mouseClicked(MouseEvent e)
- Specified by:
mouseClicked
in interfaceMouseListener
-
mouseMoved
public void mouseMoved(MouseEvent e)
- Specified by:
mouseMoved
in interfaceMouseMotionListener
-
getThumbSize
protected Dimension getThumbSize(int thumbIndex)
-
getThumbShape
public Shape getThumbShape(int thumbIndex)
Create the shape used to render a specific thumb.- Parameters:
thumbIndex
- the index of the thumb to render.- Returns:
- the shape used to render a specific thumb.
- See Also:
getThumbCenter(int)
,getThumb(int)
-
getThumbShape
public Shape getThumbShape(int thumbIndex, Point2D center)
Create the shape used to render a specific thumb.- Parameters:
thumbIndex
- the index of the thumb to render.center
- an optional center to focus the thumb around. If this is null then the current (real) center is used, but this can be supplied manually to consider possible shapes and visual size constraints based on the current collision policy.- Returns:
- the shape used to render a specific thumb.
- See Also:
getThumbCenter(int)
,getThumb(int)
-
getThumbCenter
public Point2D getThumbCenter(int thumbIndex)
Calculate the thumb center- Parameters:
thumbIndex
- the index of the thumb to consult.- Returns:
- the center of a given thumb
-
getThumbCenter
public Point2D getThumbCenter(float position)
Calculate the thumb center based on a fractional position- Parameters:
position
- a value from [0,1]- Returns:
- the center of a potential thumbnail for this position.
-
getThumb
public MultiThumbSliderUI.Thumb getThumb(int thumbIndex)
Return the Thumb option used to render a specific thumb. The default implementation here consults the client property MultiThumbSliderUI.THUMB_SHAPE_PROPERTY, and returns Circle by default.- Parameters:
thumbIndex
- the index of the thumb to render.- Returns:
- the Thumb option used to render a specific thumb.
-
mouseDragged
public void mouseDragged(MouseEvent e)
- Specified by:
mouseDragged
in interfaceMouseMotionListener
-
mouseReleased
public void mouseReleased(MouseEvent e)
- Specified by:
mouseReleased
in interfaceMouseListener
-
getProperty
public static <K> K getProperty(JComponent jc, String propertyName, K defaultValue)
This retrieves a property. If the component has this property manually set (by callingcomponent.putClientProperty()
), then that value will be returned. Otherwise this method refers toUIManager.get()
. If that value is missing, this returnsdefaultValue
- Parameters:
jc
- componentpropertyName
- the property namedefaultValue
- if no other value is found, this is returned- Returns:
- the property value
-
validatePositions
protected boolean validatePositions(MultiThumbSliderUI.State state)
Makes sure the thumbs are in the right order.- Parameters:
state
- state- Returns:
- true if the thumbs are valid. False if there are two thumbs with the same value (this is not allowed)
-
addThumb
protected boolean addThumb(int index1, int index2)
This will try to add a thumb between index1 and index2.This method will not add a thumb if there is already a very small distance between these two endpoints
- Parameters:
index1
- low valueindex2
- high value- Returns:
- true if a new thumb was added
-
updateIndication
protected void updateIndication()
-
calculateGeometry
protected void calculateGeometry()
-
calculateTrackRect
protected Rectangle calculateTrackRect()
-
installUI
public void installUI(JComponent slider)
- Overrides:
installUI
in classComponentUI
-
paint
public void paint(Graphics g, JComponent slider2)
- Overrides:
paint
in classComponentUI
-
paintTrack
protected abstract void paintTrack(Graphics2D g)
-
paintFocus
protected abstract void paintFocus(Graphics2D g)
-
paintThumbs
protected abstract void paintThumbs(Graphics2D g)
-
uninstallUI
public void uninstallUI(JComponent slider)
- Overrides:
uninstallUI
in classComponentUI
-
-