public abstract class MultiThumbSlider extends JComponent
JSlider, except there are
at least two thumbs. A JSlider is designed to modify
one number within a certain range of values. By contrast a MultiThumbSlider
actually modifies a table of data. Each thumb in a MultiThumbSlider
should be thought of as a key, and it maps to an abstract value. In the case
of the GradientSlider: each value is a java.awt.Color.
Other subclasses could come along that map to other abstract objects. (For example,
a VolumeSlider might map each thumb to a specific volume level. This
type of widget would let the user control fading in/out of an audio track.)
The slider graphically represents the domain from zero to one, so each thumb is always positioned within that domain. If the user drags a thumb outside this domain: that thumb disappears.
There is always a selected thumb in each slider when this slider has the keyboard focus. The user can press the tab key (or shift-tab) to transfer focus to different thumbs. Also the arrow keys can be used to control the selected thumb.
The user can click and drag any thumb to a new location. If a thumb is dragged
so it is less than zero or greater than one: then that thumb is removed. If the user
clicks between two existing thumbs: a new thumb is created if autoAdd is
set to true. (If autoAdd is set to false: nothing happens.)
There are unimplemented methods in this class: doDoubleClick() and
doPopup(). The UI will invoke these methods as needed; this gives the
user a chance to edit the values represented at a particular point.
Also using the keyboard:
Toolkit.getDefaultTookit().getMenuShortcutKeyMask(). On Mac this is META, and on Windows
this is CONTROL.) Likewise on a vertical slider the up/down arrow keys can be used to add
thumbs.
doPopup().
This should invoke a JPopupMenu that is keyboard accessible, so the user should be
able to navigate this component without a mouse. Likewise on a vertical slider the right
arrow key should do the same.
doDoubleClick().
Because thumbs can be abstractly inserted, this values each thumb represents should be
tween-able. That is, if there is a value at zero and a value at one, the call
getValue(.5f) must return a value that is halfway between those values.
Also note that although the thumbs must always be between zero and one: the minimum and maximum thumbs do not have to be zero and one. The user can adjust them so the minimum thumb is, say, .2f, and the maximum thumb is .5f.
JComponent.AccessibleJComponentContainer.AccessibleAWTContainerComponent.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy| Modifier and Type | Field and Description |
|---|---|
static String |
ADJUST_PROPERTY
The property that is changed when
setValueIsAdjusting(b) is called. |
(package private) boolean |
adjusting
Whether the UI is currently adjusting values.
|
(package private) boolean |
autoAdd
Whether thumbs are automatically added when the user clicks
in a space with no existing thumbs
|
(package private) boolean |
blocked
Whether this slider is blocked, no more colors can be added by user.
|
(package private) List |
changeListeners
ChangeListeners registered with this slider.
|
static int |
HORIZONTAL
The orientation constant for a horizontal slider.
|
(package private) boolean |
inverted
Whether this slider is inverted or not.
|
static String |
INVERTED_PROPERTY
The property that is changed when
setInverted(b) is called. |
(package private) int |
orientation
Whether this slider is HORIZONTAL or VERTICAL.
|
static String |
ORIENTATION_PROPERTY
The property that is changed when
setOrientation(i) is called. |
static String |
PAINT_TICKS_PROPERTY
The property that is changed when
setPaintTicks(b) is called. |
(package private) boolean |
paintTicks
Whether tickmarks should be painted on this slider.
|
static String |
SELECTED_THUMB_PROPERTY
The property that is changed when
setSelectedThumb() is called. |
private static long |
serialVersionUID |
protected float[] |
thumbPositions
The positions of the thumbs
|
(package private) Object[] |
values
The values for each thumb
|
static String |
VALUES_PROPERTY
The property that is changed when
setValues() is called. |
static int |
VERTICAL
The orientation constant for a vertical slider.
|
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOWaccessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENTABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH| Constructor and Description |
|---|
MultiThumbSlider(int orientation,
float[] thumbPositions,
Object[] values)
Creates a new MultiThumbSlider.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addChangeListener(ChangeListener l)
This listener will be notified when the colors/positions of
this slider are modified.
|
int |
addThumb(float pos)
This inserts a thumb at a position indicated.
|
boolean |
doDoubleClick(int x,
int y)
An optional method subclasses can override to react to the user's
double-click.
|
boolean |
doPopup(int x,
int y)
An optional method subclasses can override to react to the user's
request for a contextual menu.
|
protected void |
fireChangeListeners()
Invokes all the ChangeListeners.
|
int |
getOrientation()
The orientation of this slider.
|
int |
getSelectedThumb()
Returns the selected thumb index, or -1 if this component doesn't have
the keyboard focus.
|
int |
getSelectedThumb(boolean ignoreIfUnfocused)
Returns the currently selected thumb index.
|
int |
getThumbCount()
The number of thumbs in this slider.
|
float[] |
getThumbPositions()
The thumb positions for this slider.
|
abstract Object |
getValue(float pos)
This returns a value at a certain position on this slider.
|
Object[] |
getValues()
The values for thumbs for this slider.
|
boolean |
isAutoAdding()
Whether thumbs are automatically added when the
user clicks in a space that doesn't already have a thumb.
|
boolean |
isBlocked()
Returns true if the slider is blocked.
|
boolean |
isInverted()
Whether this slider is inverted or not.
|
boolean |
isPaintTicks()
Tells if tick marks are to be painted.
|
boolean |
isValueAdjusting()
true if the user is current modifying this component. |
void |
removeChangeListener(ChangeListener l)
Removes a
ChangeListener from this slider. |
void |
removeThumb(int thumbIndex)
Removes a specific thumb
|
void |
setAutoAdding(boolean b)
Controls whether thumbs are automatically added when the
user clicks in a space that doesn't already have a thumb.
|
void |
setBlocked(boolean blocked)
Enable/Disable adding new colors by user
|
void |
setInverted(boolean b)
Assigns whether this slider is inverted or not.
|
void |
setOrientation(int i)
Reassign the orientation of this slider.
|
void |
setPaintTicks(boolean b)
Turns on/off the painted tick marks for this slider.
|
void |
setSelectedThumb(int index)
Assigns the currently selected thumb.
|
void |
setValueIsAdjusting(boolean b)
This is used to notify other objects when the user is in the process
of adjusting values in this slider.
|
void |
setValues(float[] thumbPositions,
Object[] values)
This assigns new positions/values for the thumbs in this slider.
|
private static String |
toString(float[] f) |
void |
transferFocus()
Depending on which thumb is selected, this may shift the focus
to the next available thumb, or it may shift the focus to the
next focusable
JComponent. |
private void |
transferFocus(boolean forward)
Shifts the focus forward or backward.
|
void |
transferFocusBackward()
Depending on which thumb is selected, this may shift the focus
to the previous available thumb, or it may shift the focus to the
previous focusable
JComponent. |
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, paramString, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update, updateUIadd, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTreeaction, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAccessibleContext, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocusUpCycleprivate static final long serialVersionUID
public static final String SELECTED_THUMB_PROPERTY
setSelectedThumb() is called.public static final String INVERTED_PROPERTY
setInverted(b) is called.public static final String ORIENTATION_PROPERTY
setOrientation(i) is called.public static final String VALUES_PROPERTY
setValues() is called.
Note this is used when either the positions or the values are updated, because
they need to be updated at the same time to maintain an exact one-to-one
ratio.public static final String ADJUST_PROPERTY
setValueIsAdjusting(b) is called.public static final String PAINT_TICKS_PROPERTY
setPaintTicks(b) is called.protected float[] thumbPositions
Object[] values
boolean autoAdd
boolean adjusting
int orientation
boolean inverted
boolean paintTicks
boolean blocked
List changeListeners
public static final int HORIZONTAL
public static final int VERTICAL
public MultiThumbSlider(int orientation,
float[] thumbPositions,
Object[] values)
orientation - must be HORIZONTAL or VERTICALthumbPositions - an array of values from zero to one.values - an array of values, each value corresponds to a value in thumbPositions.public void addChangeListener(ChangeListener l)
Note you can also listen to these events by listening to
the VALUES_PROPERTY, but this mechanism is provided
as a convenience to resemble the JSlider model.
l - the ChangeListener to add.public void removeChangeListener(ChangeListener l)
ChangeListener from this slider.l - the ChangeListener to remove.protected void fireChangeListeners()
public void transferFocus()
JComponent.transferFocus in class Componentprivate void transferFocus(boolean forward)
super.transferFocus() to let the
next JComponent receive the focus.forward - whether we're shifting forward or backwardpublic void transferFocusBackward()
JComponent.transferFocusBackward in class Componentpublic abstract Object getValue(float pos)
Subclasses implementing this method should note that
this method cannot return null. If the pos argument
is outside the domain of thumbs, then a value still needs to be
returned.
pos - a position between zero and onepospublic void removeThumb(int thumbIndex)
thumbIndex - the thumb index to remove.public boolean doDoubleClick(int x,
int y)
Note this method will be called with arguments (-1,-1) if the space bar or return key is pressed.
By default this method does nothing, and returns false
Note the (x,y) information passed to this method is only provided so subclasses can position components (such as a JPopupMenu). It can be assumed for a double-click event that the user has selected a thumb (since one click will click/create a thumb) and intends to edit the currently selected thumb.
x - the x-value of the mouse click locationy - the y-value of the mouse click locationtrue if this event was consumed, or acted upon.
false if this is unimplemented.public boolean doPopup(int x,
int y)
By default this method does nothing, and returns false
x - the x-value of the mouse click locationy - the y-value of the mouse click locationtrue if this event was consumed, or acted upon.
false if this is unimplemented.public boolean isPaintTicks()
public void setPaintTicks(boolean b)
This triggers a PropertyChangeEvent for
PAINT_TICKS_PROPERTY.
b - whether tick marks should be paintedpublic boolean isBlocked()
public void setBlocked(boolean blocked)
blocked - whether the user can add new colorspublic int addThumb(float pos)
This method relies on the abstract getValue(float) to
determine what value to put at the new thumb location.
pos - the new thumb positionpublic void setValueIsAdjusting(boolean b)
A listener may not want to act on certain changes until this property
is false if it is expensive to process certain changes.
This triggers a PropertyChangeEvent for
ADJUST_PROPERTY.
b - valuepublic boolean isValueAdjusting()
true if the user is current modifying this component.adjusting propertypublic float[] getThumbPositions()
There is a one-to-one correspondence between this array and the
getValues() array.
This array is always sorted in ascending order.
public Object[] getValues()
There is a one-to-one correspondence between this array and the
getThumbPositions() array.
private static String toString(float[] f)
f - an array of floatspublic void setValues(float[] thumbPositions,
Object[] values)
This triggers a PropertyChangeEvent for
VALUES_PROPERTY, and possibly for the
SELECTED_THUMB_PROPERTY if that had to be adjusted, too.
thumbPositions - an array of the new position of each thumbvalues - an array of the value associated with each thumbIllegalArgumentException - if the size of the arrays are different,
or if the thumbPositions array is not sorted in ascending order.public int getThumbCount()
public void setSelectedThumb(int index)
A slider should always have a selected thumb if it has the keyboard focus, though, so be careful when you modify this.
This triggers a PropertyChangeEvent for
SELECTED_THUMB_PROPERTY.
index - the new selected thumbpublic int getSelectedThumb()
public int getSelectedThumb(boolean ignoreIfUnfocused)
Note this might be -1, indicating that there is no selected thumb.
It is recommend you use the getSelectedThumb() method
most of the time. This method is made public so UI's can provide
a better user experience as this component gains and loses focus.
ignoreIfUnfocused - if this component doesn't have focus and this
is true, then this returns -1. If this is false
then this returns the internal value used to store the selected index, but
the user may not realize this thumb is "selected".public void setAutoAdding(boolean b)
b - whether auto adding is active or notpublic boolean isAutoAdding()
public int getOrientation()
public void setOrientation(int i)
i - must be HORIZONTAL or VERTICALpublic boolean isInverted()
public void setInverted(boolean b)
This triggers a PropertyChangeEvent for
INVERTED_PROPERTY.
b - valueCopyright © 2007–2017 Gephi Consortium. All rights reserved.