public class

BasicSliderUI

extends SliderUI
java.lang.Object
   ↳ javax.swing.plaf.ComponentUI
     ↳ javax.swing.plaf.SliderUI
       ↳ javax.swing.plaf.basic.BasicSliderUI
Known Direct Subclasses

Class Overview

A Basic L&F implementation of SliderUI.

Summary

Nested Classes
class BasicSliderUI.ActionScroller As of Java 2 platform v1.3 this undocumented class is no longer used. 
class BasicSliderUI.ChangeHandler Data model listener. 
class BasicSliderUI.ComponentHandler Listener for resizing events. 
class BasicSliderUI.FocusHandler Focus-change listener. 
class BasicSliderUI.PropertyChangeHandler  
class BasicSliderUI.ScrollListener Scroll-event listener. 
class BasicSliderUI.TrackListener Track mouse movements. 
Constants
int MAX_SCROLL
int MIN_SCROLL
int NEGATIVE_SCROLL
int POSITIVE_SCROLL
Fields
protected ChangeListener changeListener
protected ComponentListener componentListener
protected Rectangle contentRect
protected Insets focusInsets
protected FocusListener focusListener
protected Rectangle focusRect
protected Insets insetCache
protected Rectangle labelRect
protected boolean leftToRightCache
protected PropertyChangeListener propertyChangeListener
protected BasicSliderUI.ScrollListener scrollListener
protected Timer scrollTimer
protected JSlider slider
protected Rectangle thumbRect
protected Rectangle tickRect
protected int trackBuffer
protected BasicSliderUI.TrackListener trackListener
protected Rectangle trackRect
Public Constructors
BasicSliderUI(JSlider b)
Public Methods
static ComponentUI createUI(JComponent b)
int getBaseline(JComponent c, int width, int height)
Returns the baseline.
Component.BaselineResizeBehavior getBaselineResizeBehavior(JComponent c)
Returns an enum indicating how the baseline of the component changes as the size changes.
Dimension getMaximumSize(JComponent c)
Returns the specified component's maximum size appropriate for the look and feel.
Dimension getMinimumHorizontalSize()
Dimension getMinimumSize(JComponent c)
Returns the specified component's minimum size appropriate for the look and feel.
Dimension getMinimumVerticalSize()
Dimension getPreferredHorizontalSize()
Dimension getPreferredSize(JComponent c)
Returns the specified component's preferred size appropriate for the look and feel.
Dimension getPreferredVerticalSize()
void installUI(JComponent c)
Configures the specified component appropriate for the look and feel.
void paint(Graphics g, JComponent c)
Paints the specified component appropriate for the look and feel.
void paintFocus(Graphics g)
void paintLabels(Graphics g)
void paintThumb(Graphics g)
void paintTicks(Graphics g)
void paintTrack(Graphics g)
void scrollByBlock(int direction)
void scrollByUnit(int direction)
void setThumbLocation(int x, int y)
void uninstallUI(JComponent c)
Reverses configuration which was done on the specified component during installUI.
int valueForXPosition(int xPos)
Returns a value give an x position.
int valueForYPosition(int yPos)
Returns a value give a y position.
Protected Methods
void calculateContentRect()
void calculateFocusRect()
void calculateGeometry()
void calculateLabelRect()
void calculateThumbLocation()
void calculateThumbSize()
void calculateTickRect()
void calculateTrackBuffer()
void calculateTrackRect()
ChangeListener createChangeListener(JSlider slider)
ComponentListener createComponentListener(JSlider slider)
FocusListener createFocusListener(JSlider slider)
PropertyChangeListener createPropertyChangeListener(JSlider slider)
BasicSliderUI.ScrollListener createScrollListener(JSlider slider)
BasicSliderUI.TrackListener createTrackListener(JSlider slider)
boolean drawInverted()
Color getFocusColor()
int getHeightOfHighValueLabel()
int getHeightOfLowValueLabel()
int getHeightOfTallestLabel()
Integer getHighestValue()
Returns the biggest value that has an entry in the label table.
Component getHighestValueLabel()
Returns the label that corresponds to the lowest slider value in the label table.
Color getHighlightColor()
Integer getLowestValue()
Returns the smallest value that has an entry in the label table.
Component getLowestValueLabel()
Returns the label that corresponds to the highest slider value in the label table.
Color getShadowColor()
Dimension getThumbSize()
int getTickLength()
Gets the height of the tick area for horizontal sliders and the width of the tick area for vertical sliders.
int getWidthOfHighValueLabel()
int getWidthOfLowValueLabel()
int getWidthOfWidestLabel()
void installDefaults(JSlider slider)
void installKeyboardActions(JSlider slider)
void installListeners(JSlider slider)
boolean isDragging()
Returns true if the user is dragging the slider.
boolean labelsHaveSameBaselines()
Returns true if all the labels from the label table have the same baseline.
void paintHorizontalLabel(Graphics g, int value, Component label)
Called for every label in the label table.
void paintMajorTickForHorizSlider(Graphics g, Rectangle tickBounds, int x)
void paintMajorTickForVertSlider(Graphics g, Rectangle tickBounds, int y)
void paintMinorTickForHorizSlider(Graphics g, Rectangle tickBounds, int x)
void paintMinorTickForVertSlider(Graphics g, Rectangle tickBounds, int y)
void paintVerticalLabel(Graphics g, int value, Component label)
Called for every label in the label table.
void recalculateIfInsetsChanged()
void recalculateIfOrientationChanged()
void scrollDueToClickInTrack(int dir)
This function is called when a mousePressed was detected in the track, not in the thumb.
void uninstallKeyboardActions(JSlider slider)
void uninstallListeners(JSlider slider)
int xPositionForValue(int value)
int yPositionForValue(int value, int trackY, int trackHeight)
Returns the y location for the specified value.
int yPositionForValue(int value)
[Expand]
Inherited Methods
From class javax.swing.plaf.ComponentUI
From class java.lang.Object

Constants

public static final int MAX_SCROLL

Constant Value: 2 (0x00000002)

public static final int MIN_SCROLL

Constant Value: -2 (0xfffffffe)

public static final int NEGATIVE_SCROLL

Constant Value: -1 (0xffffffff)

public static final int POSITIVE_SCROLL

Constant Value: 1 (0x00000001)

Fields

protected ChangeListener changeListener

protected ComponentListener componentListener

protected Rectangle contentRect

protected Insets focusInsets

protected FocusListener focusListener

protected Rectangle focusRect

protected Insets insetCache

protected Rectangle labelRect

protected boolean leftToRightCache

protected PropertyChangeListener propertyChangeListener

protected BasicSliderUI.ScrollListener scrollListener

protected Timer scrollTimer

protected JSlider slider

protected Rectangle thumbRect

protected Rectangle tickRect

protected int trackBuffer

protected BasicSliderUI.TrackListener trackListener

protected Rectangle trackRect

Public Constructors

public BasicSliderUI (JSlider b)

Public Methods

public static ComponentUI createUI (JComponent b)

public int getBaseline (JComponent c, int width, int height)

Returns the baseline.

Parameters
c JComponent baseline is being requested for
width the width to get the baseline for
height the height to get the baseline for
Returns
  • baseline or a value < 0 indicating there is no reasonable baseline

public Component.BaselineResizeBehavior getBaselineResizeBehavior (JComponent c)

Returns an enum indicating how the baseline of the component changes as the size changes.

Parameters
c JComponent to return baseline resize behavior for
Returns
  • an enum indicating how the baseline changes as the component size changes

public Dimension getMaximumSize (JComponent c)

Returns the specified component's maximum size appropriate for the look and feel. If null is returned, the maximum size will be calculated by the component's layout manager instead (this is the preferred approach for any component with a specific layout manager installed). The default implementation of this method invokes getPreferredSize and returns that value.

Parameters
c the component whose maximum size is being queried; this argument is often ignored, but might be used if the UI object is stateless and shared by multiple components
Returns
  • a Dimension object or null

public Dimension getMinimumHorizontalSize ()

public Dimension getMinimumSize (JComponent c)

Returns the specified component's minimum size appropriate for the look and feel. If null is returned, the minimum size will be calculated by the component's layout manager instead (this is the preferred approach for any component with a specific layout manager installed). The default implementation of this method invokes getPreferredSize and returns that value.

Parameters
c the component whose minimum size is being queried; this argument is often ignored, but might be used if the UI object is stateless and shared by multiple components
Returns
  • a Dimension object or null

public Dimension getMinimumVerticalSize ()

public Dimension getPreferredHorizontalSize ()

public Dimension getPreferredSize (JComponent c)

Returns the specified component's preferred size appropriate for the look and feel. If null is returned, the preferred size will be calculated by the component's layout manager instead (this is the preferred approach for any component with a specific layout manager installed). The default implementation of this method returns null.

Parameters
c the component whose preferred size is being queried; this argument is often ignored, but might be used if the UI object is stateless and shared by multiple components

public Dimension getPreferredVerticalSize ()

public void installUI (JComponent c)

Configures the specified component appropriate for the look and feel. This method is invoked when the ComponentUI instance is being installed as the UI delegate on the specified component. This method should completely configure the component for the look and feel, including the following:

  1. Install any default property values for color, fonts, borders, icons, opacity, etc. on the component. Whenever possible, property values initialized by the client program should not be overridden.
  2. Install a LayoutManager on the component if necessary.
  3. Create/add any required sub-components to the component.
  4. Create/install event listeners on the component.
  5. Create/install a PropertyChangeListener on the component in order to detect and respond to component property changes appropriately.
  6. Install keyboard UI (mnemonics, traversal, etc.) on the component.
  7. Initialize any appropriate instance data.

Parameters
c the component where this UI delegate is being installed

public void paint (Graphics g, JComponent c)

Paints the specified component appropriate for the look and feel. This method is invoked from the ComponentUI.update method when the specified component is being painted. Subclasses should override this method and use the specified Graphics object to render the content of the component.

Parameters
g the Graphics context in which to paint
c the component being painted; this argument is often ignored, but might be used if the UI object is stateless and shared by multiple components

public void paintFocus (Graphics g)

public void paintLabels (Graphics g)

public void paintThumb (Graphics g)

public void paintTicks (Graphics g)

public void paintTrack (Graphics g)

public void scrollByBlock (int direction)

public void scrollByUnit (int direction)

public void setThumbLocation (int x, int y)

public void uninstallUI (JComponent c)

Reverses configuration which was done on the specified component during installUI. This method is invoked when this UIComponent instance is being removed as the UI delegate for the specified component. This method should undo the configuration performed in installUI, being careful to leave the JComponent instance in a clean state (no extraneous listeners, look-and-feel-specific property objects, etc.). This should include the following:

  1. Remove any UI-set borders from the component.
  2. Remove any UI-set layout managers on the component.
  3. Remove any UI-added sub-components from the component.
  4. Remove any UI-added event/property listeners from the component.
  5. Remove any UI-installed keyboard UI from the component.
  6. Nullify any allocated instance data objects to allow for GC.

Parameters
c the component from which this UI delegate is being removed; this argument is often ignored, but might be used if the UI object is stateless and shared by multiple components

public int valueForXPosition (int xPos)

Returns a value give an x position. If xPos is past the track at the left or the right it will set the value to the min or max of the slider, depending if the slider is inverted or not.

public int valueForYPosition (int yPos)

Returns a value give a y position. If yPos is past the track at the top or the bottom it will set the value to the min or max of the slider, depending if the slider is inverted or not.

Protected Methods

protected void calculateContentRect ()

protected void calculateFocusRect ()

protected void calculateGeometry ()

protected void calculateLabelRect ()

protected void calculateThumbLocation ()

protected void calculateThumbSize ()

protected void calculateTickRect ()

protected void calculateTrackBuffer ()

protected void calculateTrackRect ()

protected ChangeListener createChangeListener (JSlider slider)

protected ComponentListener createComponentListener (JSlider slider)

protected FocusListener createFocusListener (JSlider slider)

protected PropertyChangeListener createPropertyChangeListener (JSlider slider)

protected BasicSliderUI.ScrollListener createScrollListener (JSlider slider)

protected BasicSliderUI.TrackListener createTrackListener (JSlider slider)

protected boolean drawInverted ()

protected Color getFocusColor ()

protected int getHeightOfHighValueLabel ()

protected int getHeightOfLowValueLabel ()

protected int getHeightOfTallestLabel ()

protected Integer 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.

protected Component getHighestValueLabel ()

Returns the label that corresponds to the lowest slider value in the label table.

protected Color getHighlightColor ()

protected Integer 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.

protected Component getLowestValueLabel ()

Returns the label that corresponds to the highest slider value in the label table.

protected Color getShadowColor ()

protected Dimension getThumbSize ()

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().

protected int getWidthOfHighValueLabel ()

protected int getWidthOfLowValueLabel ()

protected int getWidthOfWidestLabel ()

protected void installDefaults (JSlider slider)

protected void installKeyboardActions (JSlider slider)

protected void installListeners (JSlider slider)

protected boolean isDragging ()

Returns true if the user is dragging the slider.

Returns
  • true if the user is dragging the slider

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

protected void paintHorizontalLabel (Graphics g, int value, Component label)

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.

protected void paintMajorTickForHorizSlider (Graphics g, Rectangle tickBounds, int x)

protected void paintMajorTickForVertSlider (Graphics g, Rectangle tickBounds, int y)

protected void paintMinorTickForHorizSlider (Graphics g, Rectangle tickBounds, int x)

protected void paintMinorTickForVertSlider (Graphics g, Rectangle tickBounds, int y)

protected void paintVerticalLabel (Graphics g, int value, Component label)

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.

protected void recalculateIfInsetsChanged ()

protected void recalculateIfOrientationChanged ()

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.

protected void uninstallKeyboardActions (JSlider slider)

protected void uninstallListeners (JSlider slider)

protected int xPositionForValue (int value)

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 if trackHeight is negative undefined results may occur.

Parameters
value the slider value to get the location for
trackY y-origin of the track
trackHeight the height of the track

protected int yPositionForValue (int value)