java.lang.Object
javax.swing.plaf.ComponentUI
javax.swing.plaf.SliderUI
javax.swing.plaf.basic.BasicSliderUI
- Direct Known Subclasses:
MetalSliderUI,SynthSliderUI
public class BasicSliderUI extends SliderUI
A Basic L&F implementation of SliderUI.
-
Nested Class Summary
Nested Classes Modifier and Type Class Description classBasicSliderUI.ActionScrollerAs of Java 2 platform v1.3 this undocumented class is no longer used.classBasicSliderUI.ChangeHandlerData model listener.classBasicSliderUI.ComponentHandlerListener for resizing events.classBasicSliderUI.FocusHandlerFocus-change listener.classBasicSliderUI.PropertyChangeHandlerA property change handler.classBasicSliderUI.ScrollListenerScroll-event listener.classBasicSliderUI.TrackListenerTrack mouse movements. -
Field Summary
Fields Modifier and Type Field Description protected ChangeListenerchangeListenerChange listenerprotected ComponentListenercomponentListenerComponent listenerprotected RectanglecontentRectContent rectangleprotected InsetsfocusInsetsFocus insetsprotected FocusListenerfocusListenerFocus listenerprotected RectanglefocusRectFocus rectangleprotected InsetsinsetCacheInset cacheprotected RectanglelabelRectLabel rectangleprotected booleanleftToRightCacheLeft-to-right cachestatic intMAX_SCROLLMaximum scrollstatic intMIN_SCROLLMinimum scrollstatic intNEGATIVE_SCROLLNegative scrollstatic intPOSITIVE_SCROLLPositive scrollprotected PropertyChangeListenerpropertyChangeListenerProperty chane listenerprotected BasicSliderUI.ScrollListenerscrollListenerScroll listenerprotected TimerscrollTimerScroll timerprotected JSlidersliderSliderprotected RectanglethumbRectThumb rectangleprotected RectangletickRectTick rectangleprotected inttrackBufferThe distance that the track is from the side of the controlprotected BasicSliderUI.TrackListenertrackListenerTrack listenerprotected RectangletrackRectTrack rectangle -
Constructor Summary
Constructors Constructor Description BasicSliderUI(JSlider b)Constructs aBasicSliderUI. -
Method Summary
Modifier and Type Method Description protected voidcalculateContentRect()Calculates the content rectangle.protected voidcalculateFocusRect()Calculates the focus rectangle.protected voidcalculateGeometry()Calculates the geometry.protected voidcalculateLabelRect()Calculates the label rectangle.protected voidcalculateThumbLocation()Calculates the thumb location.protected voidcalculateThumbSize()Calculates the thumb size rectangle.protected voidcalculateTickRect()Calculates the tick rectangle.protected voidcalculateTrackBuffer()Calculates the track buffer.protected voidcalculateTrackRect()Calculates the track rectangle.protected ChangeListenercreateChangeListener(JSlider slider)Creates a change listener.protected ComponentListenercreateComponentListener(JSlider slider)Creates a composite listener.protected FocusListenercreateFocusListener(JSlider slider)Creates a focus listener.protected PropertyChangeListenercreatePropertyChangeListener(JSlider slider)Creates a property change listener.protected BasicSliderUI.ScrollListenercreateScrollListener(JSlider slider)Creates a scroll listener.protected BasicSliderUI.TrackListenercreateTrackListener(JSlider slider)Creates a track listener.static ComponentUIcreateUI(JComponent b)Creates a UI.protected booleandrawInverted()Draws inverted.intgetBaseline(JComponent c, int width, int height)Returns the baseline.Component.BaselineResizeBehaviorgetBaselineResizeBehavior(JComponent c)Returns an enum indicating how the baseline of the component changes as the size changes.protected ColorgetFocusColor()Returns the focus color.protected intgetHeightOfHighValueLabel()Returns the height of the highest value label.protected intgetHeightOfLowValueLabel()Returns the height of the lowest value label.protected intgetHeightOfTallestLabel()Returns the height of the tallest label.protected IntegergetHighestValue()Returns the biggest value that has an entry in the label table.protected ComponentgetHighestValueLabel()Returns the label that corresponds to the lowest slider value in the label table.protected ColorgetHighlightColor()Returns the highlight color.protected IntegergetLowestValue()Returns the smallest value that has an entry in the label table.protected ComponentgetLowestValueLabel()Returns the label that corresponds to the highest slider value in the label table.DimensiongetMaximumSize(JComponent c)Returns the maximum size.DimensiongetMinimumHorizontalSize()Returns the minimum horizontal size.DimensiongetMinimumSize(JComponent c)Returns the minimum size.DimensiongetMinimumVerticalSize()Returns the minimum vertical size.DimensiongetPreferredHorizontalSize()Returns the preferred horizontal size.DimensiongetPreferredSize(JComponent c)Returns the preferred size.DimensiongetPreferredVerticalSize()Returns the preferred vertical size.protected ColorgetShadowColor()Returns the shadow color.protected DimensiongetThumbSize()Returns the thumb size.protected intgetTickLength()Gets the height of the tick area for horizontal sliders and the width of the tick area for vertical sliders.protected intgetWidthOfHighValueLabel()Returns the width of the highest value label.protected intgetWidthOfLowValueLabel()Returns the width of the lowest value label.protected intgetWidthOfWidestLabel()Returns the width of the widest label.protected voidinstallDefaults(JSlider slider)Installs the defaults.protected voidinstallKeyboardActions(JSlider slider)Installs keyboard actions.protected voidinstallListeners(JSlider slider)Installs listeners.voidinstallUI(JComponent c)Installs a UI.protected booleanisDragging()Returns true if the user is dragging the slider.protected booleanlabelsHaveSameBaselines()Returns true if all the labels from the label table have the same baseline.voidpaintFocus(Graphics g)Paints focus.protected voidpaintHorizontalLabel(Graphics g, int value, Component label)Called for every label in the label table.voidpaintLabels(Graphics g)Paints the labels.protected voidpaintMajorTickForHorizSlider(Graphics g, Rectangle tickBounds, int x)Paints major tick for horizontal slider.protected voidpaintMajorTickForVertSlider(Graphics g, Rectangle tickBounds, int y)Paints major tick for vertical slider.protected voidpaintMinorTickForHorizSlider(Graphics g, Rectangle tickBounds, int x)Paints minor tick for horizontal slider.protected voidpaintMinorTickForVertSlider(Graphics g, Rectangle tickBounds, int y)Paints minor tick for vertical slider.voidpaintThumb(Graphics g)Paints the thumb.voidpaintTicks(Graphics g)Paints ticks.voidpaintTrack(Graphics g)Paints track.protected voidpaintVerticalLabel(Graphics g, int value, Component label)Called for every label in the label table.protected voidrecalculateIfInsetsChanged()Recalculates if the insets have changed.protected voidrecalculateIfOrientationChanged()Recalculates if the orientation has changed.voidscrollByBlock(int direction)Scrolls by block.voidscrollByUnit(int direction)Scrolls by unit.protected voidscrollDueToClickInTrack(int dir)This function is called when a mousePressed was detected in the track, not in the thumb.voidsetThumbLocation(int x, int y)Sets the thumb location.protected voiduninstallDefaults(JSlider slider)Uninstalls the defaults.protected voiduninstallKeyboardActions(JSlider slider)Uninstalls keyboard actions.protected voiduninstallListeners(JSlider slider)Uninstalls listeners.voiduninstallUI(JComponent c)Uninstalls a UI.intvalueForXPosition(int xPos)Returns the value at the x position.intvalueForYPosition(int yPos)Returns the value at the y position.protected intxPositionForValue(int value)Returns the x position for a value.protected intyPositionForValue(int value)Returns the y position for a value.protected intyPositionForValue(int value, int trackY, int trackHeight)Returns the y location for the specified value.Methods declared in class javax.swing.plaf.ComponentUI
contains, getAccessibleChild, getAccessibleChildrenCount, paint, update
-
Field Details
-
POSITIVE_SCROLL
public static final int POSITIVE_SCROLLPositive scroll- See Also:
- Constant Field Values
-
NEGATIVE_SCROLL
public static final int NEGATIVE_SCROLLNegative scroll- See Also:
- Constant Field Values
-
MIN_SCROLL
public static final int MIN_SCROLLMinimum scroll- See Also:
- Constant Field Values
-
MAX_SCROLL
public static final int MAX_SCROLLMaximum scroll- See Also:
- Constant Field Values
-
scrollTimer
Scroll timer -
slider
Slider -
focusInsets
Focus insets -
insetCache
Inset cache -
leftToRightCache
protected boolean leftToRightCacheLeft-to-right cache -
focusRect
Focus rectangle -
contentRect
Content rectangle -
labelRect
Label rectangle -
tickRect
Tick rectangle -
trackRect
Track rectangle -
thumbRect
Thumb rectangle -
trackBuffer
protected int trackBufferThe distance that the track is from the side of the control -
trackListener
Track listener -
changeListener
Change listener -
componentListener
Component listener -
focusListener
Focus listener -
scrollListener
Scroll listener -
propertyChangeListener
Property chane listener
-
-
Constructor Details
-
BasicSliderUI
Constructs aBasicSliderUI.- Parameters:
b- a slider
-
-
Method Details
-
getShadowColor
Returns the shadow color.- Returns:
- the shadow color
-
getHighlightColor
Returns the highlight color.- Returns:
- the highlight color
-
getFocusColor
Returns the focus color.- Returns:
- the focus color
-
isDragging
protected boolean isDragging()Returns true if the user is dragging the slider.- Returns:
- true if the user is dragging the slider
- Since:
- 1.5
-
createUI
Creates a UI.- Parameters:
b- a component- Returns:
- a UI
-
installUI
Installs a UI.- Overrides:
installUIin classComponentUI- Parameters:
c- a component- See Also:
ComponentUI.uninstallUI(javax.swing.JComponent),JComponent.setUI(javax.swing.plaf.ComponentUI),JComponent.updateUI()
-
uninstallUI
Uninstalls a UI.- Overrides:
uninstallUIin classComponentUI- Parameters:
c- a component- See Also:
ComponentUI.installUI(javax.swing.JComponent),JComponent.updateUI()
-
installDefaults
Installs the defaults.- Parameters:
slider- a slider
-
uninstallDefaults
Uninstalls the defaults.- Parameters:
slider- a slider
-
createTrackListener
Creates a track listener.- Parameters:
slider- a slider- Returns:
- a track listener
-
createChangeListener
Creates a change listener.- Parameters:
slider- a slider- Returns:
- a change listener
-
createComponentListener
Creates a composite listener.- Parameters:
slider- a slider- Returns:
- a composite listener
-
createFocusListener
Creates a focus listener.- Parameters:
slider- a slider- Returns:
- a focus listener
-
createScrollListener
Creates a scroll listener.- Parameters:
slider- a slider- Returns:
- a scroll listener
-
createPropertyChangeListener
Creates a property change listener.- Parameters:
slider- a slider- Returns:
- a property change listener
-
installListeners
Installs listeners.- Parameters:
slider- a slider
-
uninstallListeners
Uninstalls listeners.- Parameters:
slider- a slider
-
installKeyboardActions
Installs keyboard actions.- Parameters:
slider- a slider
-
uninstallKeyboardActions
Uninstalls keyboard actions.- Parameters:
slider- a slider
-
getBaseline
Returns the baseline.- Overrides:
getBaselinein classComponentUI- Parameters:
c-JComponentbaseline is being requested forwidth- the width to get the baseline forheight- the height to get the baseline for- Returns:
- baseline or a value < 0 indicating there is no reasonable baseline
- Throws:
NullPointerException- ifcisnullIllegalArgumentException- if width or height is < 0- Since:
- 1.6
- See Also:
JComponent.getBaseline(int, int)
-
getBaselineResizeBehavior
Returns an enum indicating how the baseline of the component changes as the size changes.- Overrides:
getBaselineResizeBehaviorin classComponentUI- Parameters:
c-JComponentto return baseline resize behavior for- Returns:
- an enum indicating how the baseline changes as the component size changes
- Throws:
NullPointerException- ifcisnull- Since:
- 1.6
- See Also:
JComponent.getBaseline(int, int)
-
labelsHaveSameBaselines
protected boolean labelsHaveSameBaselines()Returns true if all the labels from the label table have the same baseline.- Returns:
- true if all the labels from the label table have the same baseline
- Since:
- 1.6
-
getPreferredHorizontalSize
Returns the preferred horizontal size.- Returns:
- the preferred horizontal size
-
getPreferredVerticalSize
Returns the preferred vertical size.- Returns:
- the preferred vertical size
-
getMinimumHorizontalSize
Returns the minimum horizontal size.- Returns:
- the minimum horizontal size
-
getMinimumVerticalSize
Returns the minimum vertical size.- Returns:
- the minimum vertical size
-
getPreferredSize
Returns the preferred size.- Overrides:
getPreferredSizein classComponentUI- Parameters:
c- a component- Returns:
- the preferred size
- See Also:
JComponent.getPreferredSize(),LayoutManager.preferredLayoutSize(java.awt.Container)
-
getMinimumSize
Returns the minimum size.- Overrides:
getMinimumSizein classComponentUI- Parameters:
c- a component- Returns:
- the minimum size
- See Also:
JComponent.getMinimumSize(),LayoutManager.minimumLayoutSize(java.awt.Container),ComponentUI.getPreferredSize(javax.swing.JComponent)
-
getMaximumSize
Returns the maximum size.- Overrides:
getMaximumSizein classComponentUI- Parameters:
c- a component- Returns:
- the maximum size
- See Also:
JComponent.getMaximumSize(),LayoutManager2.maximumLayoutSize(java.awt.Container)
-
calculateGeometry
protected void calculateGeometry()Calculates the geometry. -
calculateFocusRect
protected void calculateFocusRect()Calculates the focus rectangle. -
calculateThumbSize
protected void calculateThumbSize()Calculates the thumb size rectangle. -
calculateContentRect
protected void calculateContentRect()Calculates the content rectangle. -
calculateThumbLocation
protected void calculateThumbLocation()Calculates the thumb location. -
calculateTrackBuffer
protected void calculateTrackBuffer()Calculates the track buffer. -
calculateTrackRect
protected void calculateTrackRect()Calculates the track rectangle. -
getTickLength
protected int getTickLength()Gets the height of the tick area for horizontal sliders and the width of the tick area for vertical sliders. BasicSliderUI uses the returned value to determine the tick area rectangle. If you want to give your ticks some room, make this larger than you need and paint your ticks away from the sides in paintTicks().- Returns:
- an integer representing the height of the tick area for horizontal sliders, and the width of the tick area for the vertical sliders
-
calculateTickRect
protected void calculateTickRect()Calculates the tick rectangle. -
calculateLabelRect
protected void calculateLabelRect()Calculates the label rectangle. -
getThumbSize
Returns the thumb size.- Returns:
- the thumb size
-
getWidthOfWidestLabel
protected int getWidthOfWidestLabel()Returns the width of the widest label.- Returns:
- the width of the widest label
-
getHeightOfTallestLabel
protected int getHeightOfTallestLabel()Returns the height of the tallest label.- Returns:
- the height of the tallest label
-
getWidthOfHighValueLabel
protected int getWidthOfHighValueLabel()Returns the width of the highest value label.- Returns:
- the width of the highest value label
-
getWidthOfLowValueLabel
protected int getWidthOfLowValueLabel()Returns the width of the lowest value label.- Returns:
- the width of the lowest value label
-
getHeightOfHighValueLabel
protected int getHeightOfHighValueLabel()Returns the height of the highest value label.- Returns:
- the height of the highest value label
-
getHeightOfLowValueLabel
protected int getHeightOfLowValueLabel()Returns the height of the lowest value label.- Returns:
- the height of the lowest value label
-
drawInverted
protected boolean drawInverted()Draws inverted.- Returns:
- the inverted-ness
-
getHighestValue
Returns the biggest value that has an entry in the label table.- Returns:
- biggest value that has an entry in the label table, or null.
- Since:
- 1.6
-
getLowestValue
Returns the smallest value that has an entry in the label table.- Returns:
- smallest value that has an entry in the label table, or null.
- Since:
- 1.6
-
getLowestValueLabel
Returns the label that corresponds to the highest slider value in the label table.- Returns:
- the label that corresponds to the highest slider value in the label table
- See Also:
JSlider.setLabelTable(java.util.Dictionary)
-
getHighestValueLabel
Returns the label that corresponds to the lowest slider value in the label table.- Returns:
- the label that corresponds to the lowest slider value in the label table
- See Also:
JSlider.setLabelTable(java.util.Dictionary)
-
recalculateIfInsetsChanged
protected void recalculateIfInsetsChanged()Recalculates if the insets have changed. -
recalculateIfOrientationChanged
protected void recalculateIfOrientationChanged()Recalculates if the orientation has changed. -
paintFocus
Paints focus.- Parameters:
g- the graphics
-
paintTrack
Paints track.- Parameters:
g- the graphics
-
paintTicks
Paints ticks.- Parameters:
g- the graphics
-
paintMinorTickForHorizSlider
Paints minor tick for horizontal slider.- Parameters:
g- the graphicstickBounds- the tick boundsx- the x coordinate
-
paintMajorTickForHorizSlider
Paints major tick for horizontal slider.- Parameters:
g- the graphicstickBounds- the tick boundsx- the x coordinate
-
paintMinorTickForVertSlider
Paints minor tick for vertical slider.- Parameters:
g- the graphicstickBounds- the tick boundsy- the y coordinate
-
paintMajorTickForVertSlider
Paints major tick for vertical slider.- Parameters:
g- the graphicstickBounds- the tick boundsy- the y coordinate
-
paintLabels
Paints the labels.- Parameters:
g- the graphics
-
paintHorizontalLabel
Called for every label in the label table. Used to draw the labels for horizontal sliders. The graphics have been translated to labelRect.y already.- Parameters:
g- the graphics context in which to paintvalue- the value of the sliderlabel- the component label in the label table that needs to be painted- See Also:
JSlider.setLabelTable(java.util.Dictionary)
-
paintVerticalLabel
Called for every label in the label table. Used to draw the labels for vertical sliders. The graphics have been translated to labelRect.x already.- Parameters:
g- the graphics context in which to paintvalue- the value of the sliderlabel- the component label in the label table that needs to be painted- See Also:
JSlider.setLabelTable(java.util.Dictionary)
-
paintThumb
Paints the thumb.- Parameters:
g- the graphics
-
setThumbLocation
public void setThumbLocation(int x, int y)Sets the thumb location.- Parameters:
x- the x coordinatey- the y coordinate
-
scrollByBlock
public void scrollByBlock(int direction)Scrolls by block.- Parameters:
direction- the direction
-
scrollByUnit
public void scrollByUnit(int direction)Scrolls by unit.- Parameters:
direction- the direction
-
scrollDueToClickInTrack
protected void scrollDueToClickInTrack(int dir)This function is called when a mousePressed was detected in the track, not in the thumb. The default behavior is to scroll by block. You can override this method to stop it from scrolling or to add additional behavior.- Parameters:
dir- the direction and number of blocks to scroll
-
xPositionForValue
protected int xPositionForValue(int value)Returns the x position for a value.- Parameters:
value- the value- Returns:
- the x position for a value
-
yPositionForValue
protected int yPositionForValue(int value)Returns the y position for a value.- Parameters:
value- the value- Returns:
- the y position for a value
-
yPositionForValue
protected int yPositionForValue(int value, int trackY, int trackHeight)Returns the y location for the specified value. No checking is done on the arguments. In particular iftrackHeightis negative undefined results may occur.- Parameters:
value- the slider value to get the location fortrackY- y-origin of the tracktrackHeight- the height of the track- Returns:
- the y location for the specified value of the slider
- Since:
- 1.6
-
valueForYPosition
public int valueForYPosition(int yPos)Returns the value at the y position. IfyPosis beyond the track at the bottom or the top, this method sets the value to either the minimum or maximum value of the slider, depending on if the slider is inverted or not.- Parameters:
yPos- the location of the slider along the y axis- Returns:
- the value at the y position
-
valueForXPosition
public int valueForXPosition(int xPos)Returns the value at the x position. IfxPosis beyond the track at the left or the right, this method sets the value to either the minimum or maximum value of the slider, depending on if the slider is inverted or not.- Parameters:
xPos- the location of the slider along the x axis- Returns:
- the value of the x position
-