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 for
MultiThumbSliders-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) classThis records the positions/values of each thumb.static enumA thumb shape. -
Field Summary
FieldsModifier and TypeFieldDescription(package private) Runnable(package private) Thread(package private) ComponentListener(package private) intThe height of a horizontal slider -- or width of a vertical slider.(package private) FocusListener(package private) floatThe overall indication of the thumbs.(package private) KeyListener(package private) intThe maximum width returned bygetMaximumSize().(package private) intThe minimum width returned bygetMinimumSize().protected booleanprotected boolean(package private) intThe maximum width returned bygetPreferredSize().(package private) PropertyChangeListenerprotected MultiThumbSlider<T>static final StringThe Swing client property associated with a Thumb.protected float[]A float from zero to one, indicating whether that thumb should be highlighted or not.(package private) int[]The pixel position of the thumbs.(package private) PropertyChangeListenerprotected RectangleThe rectangle the track should be painted in. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected booleanaddThumb(int index1, int index2) This will try to add a thumb between index1 and index2.protected voidprotected Rectangleprotected abstract intReturn the typical height of a horizontally oriented slider, or the width of the vertically oriented slider.static <K> KgetProperty(JComponent jc, String propertyName, K defaultValue) This retrieves a property.getThumb(int thumbIndex) Return the Thumb option used to render a specific thumb.getThumbCenter(float position) Calculate the thumb center based on a fractional positiongetThumbCenter(int thumbIndex) Calculate the thumb centergetThumbShape(int thumbIndex) Create the shape used to render a specific thumb.getThumbShape(int thumbIndex, Point2D center) Create the shape used to render a specific thumb.protected DimensiongetThumbSize(int thumbIndex) voidinstallUI(JComponent slider) voidvoidvoidvoidvoidvoidvoidvoidpaint(Graphics g, JComponent slider2) protected abstract voidprotected abstract voidprotected abstract voidvoiduninstallUI(JComponent slider) protected voidprotected booleanvalidatePositions(MultiThumbSliderUi<T>.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 Details
-
THUMB_SHAPE_PROPERTY
The Swing client property associated with a Thumb.- See Also:
-
thumbShapeListener
PropertyChangeListener thumbShapeListener -
slider
-
MAX_LENGTH
int MAX_LENGTHThe maximum width returned bygetMaximumSize(). (or if the slider is vertical, this is the maximum height.) -
MIN_LENGTH
int MIN_LENGTHThe minimum width returned bygetMinimumSize(). (or if the slider is vertical, this is the minimum height.) -
PREF_LENGTH
int PREF_LENGTHThe maximum width returned bygetPreferredSize(). (or if the slider is vertical, this is the preferred height.) -
DEPTH
int DEPTHThe height of a horizontal slider -- or width of a vertical slider. -
thumbPositions
int[] thumbPositionsThe pixel position of the thumbs. This may be x or y coordinates, depending on whether this slider is horizontal or vertical -
thumbIndications
protected float[] thumbIndicationsA float from zero to one, indicating whether that thumb should be highlighted or not. -
indication
float indicationThe overall indication of the thumbs. At one they should be opaque, at zero they should be transparent. -
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 Details
-
MultiThumbSliderUi
-
-
Method Details
-
getMaximumSize
- Overrides:
getMaximumSizein classComponentUI
-
getMinimumSize
- Overrides:
getMinimumSizein classComponentUI
-
getPreferredSize
- Overrides:
getPreferredSizein 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
- Specified by:
mousePressedin interfaceMouseListener
-
mouseEntered
- Specified by:
mouseEnteredin interfaceMouseListener
-
mouseExited
- Specified by:
mouseExitedin interfaceMouseListener
-
mouseClicked
- Specified by:
mouseClickedin interfaceMouseListener
-
mouseMoved
- Specified by:
mouseMovedin interfaceMouseMotionListener
-
getThumbSize
-
getThumbShape
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:
-
getThumbShape
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
Calculate the thumb center- Parameters:
thumbIndex- the index of the thumb to consult.- Returns:
- the center of a given thumb
-
getThumbCenter
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
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
- Specified by:
mouseDraggedin interfaceMouseMotionListener
-
mouseReleased
- Specified by:
mouseReleasedin interfaceMouseListener
-
getProperty
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
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
-
installUI
- Overrides:
installUIin classComponentUI
-
paint
- Overrides:
paintin classComponentUI
-
paintTrack
-
paintFocus
-
paintThumbs
-
uninstallUI
- Overrides:
uninstallUIin classComponentUI
-