CubeTwister 2.0alpha142 2012-02-11

ch.randelshofer.gui.plaf
Class CustomSliderUI

java.lang.Object
  extended by javax.swing.plaf.ComponentUI
      extended by javax.swing.plaf.SliderUI
          extended by javax.swing.plaf.basic.BasicSliderUI
              extended by ch.randelshofer.gui.plaf.CustomSliderUI
All Implemented Interfaces:
PlafConstants

public class CustomSliderUI
extends javax.swing.plaf.basic.BasicSliderUI
implements PlafConstants

CustomSliderUI draws a BackdropBorder in the background of the slider, and draws an Icon as the slider thumb. This allows for easy visual customization of sliders.

Usage:

 JSlider s = new JSlider();
 s.setUI((SliderUI) CustomSliderUI.createUI(b));
 s.setBorder(new BackdropBorder(....));
 s.putClientProperty(CustomSliderUI.THUMB_ICON_CLIENT_PROPERTY, new Icon(....));
 

XXX This class has been implemented for horizontal sliders whithout labels only.

FIXME The thumb can be dragged too far to the left and to the right.

Version:
2.0 2006-09-24 Rewritten.
1.0 2001-10-16 Created.
Author:
Werner Randelshofer

Nested Class Summary
protected  class CustomSliderUI.MetalPropertyListener
           
 
Nested classes/interfaces inherited from class javax.swing.plaf.basic.BasicSliderUI
javax.swing.plaf.basic.BasicSliderUI.ActionScroller, javax.swing.plaf.basic.BasicSliderUI.ChangeHandler, javax.swing.plaf.basic.BasicSliderUI.ComponentHandler, javax.swing.plaf.basic.BasicSliderUI.FocusHandler, javax.swing.plaf.basic.BasicSliderUI.PropertyChangeHandler, javax.swing.plaf.basic.BasicSliderUI.ScrollListener, javax.swing.plaf.basic.BasicSliderUI.TrackListener
 
Field Summary
protected static java.awt.Color darkShadowColor
           
protected  boolean filledSlider
           
protected static java.awt.Color highlightColor
           
protected static javax.swing.Icon horizThumbIcon
           
protected static java.awt.Color shadowColor
           
protected  java.lang.String SLIDER_FILL
           
static java.lang.String THUMB_ICON_CLIENT_PROPERTY
           
protected static java.awt.Color thumbColor
           
protected  int TICK_BUFFER
           
protected static int tickLength
           
protected static int trackWidth
           
protected static javax.swing.Icon vertThumbIcon
           
 
Fields inherited from class javax.swing.plaf.basic.BasicSliderUI
changeListener, componentListener, contentRect, focusInsets, focusListener, focusRect, insetCache, labelRect, leftToRightCache, MAX_SCROLL, MIN_SCROLL, NEGATIVE_SCROLL, POSITIVE_SCROLL, propertyChangeListener, scrollListener, scrollTimer, slider, thumbRect, tickRect, trackBuffer, trackListener, trackRect
 
Fields inherited from interface ch.randelshofer.gui.plaf.PlafConstants
ALL, CENTER, EAST, NONE, PROP_BEVEL, WEST
 
Constructor Summary
CustomSliderUI()
           
 
Method Summary
protected  void calculateTrackRect()
          The track rect is the area, where the track is painted.
protected  java.beans.PropertyChangeListener createPropertyChangeListener(javax.swing.JSlider slider)
           
static javax.swing.plaf.ComponentUI createUI(javax.swing.JComponent c)
           
 java.awt.Dimension getMinimumSize(javax.swing.JComponent c)
          Gets the minimal size for the component.
 java.awt.Dimension getPreferredSize(javax.swing.JComponent c)
          Gets the preferred size for the component.
protected  java.lang.String getPropertyPrefix()
           
protected  java.awt.Dimension getRequiredSize(javax.swing.JComponent c, int trackLength)
          Helper method for computing the size of the component.
protected  int getThumbOverhang()
          Returns the amount that the thumb goes past the slide bar.
protected  java.awt.Dimension getThumbSize()
           
protected  int getTrackWidth()
           
protected  void installDefaults(javax.swing.JSlider c)
           
 void installUI(javax.swing.JComponent c)
           
 void paint(java.awt.Graphics g, javax.swing.JComponent c)
           
 void paintFocus(java.awt.Graphics g)
           
 void paintThumb(java.awt.Graphics g)
           
 void paintTrack(java.awt.Graphics g)
           
 
Methods inherited from class javax.swing.plaf.basic.BasicSliderUI
calculateContentRect, calculateFocusRect, calculateGeometry, calculateLabelRect, calculateThumbLocation, calculateThumbSize, calculateTickRect, calculateTrackBuffer, createChangeListener, createComponentListener, createFocusListener, createScrollListener, createTrackListener, drawInverted, getBaseline, getBaselineResizeBehavior, getFocusColor, getHeightOfHighValueLabel, getHeightOfLowValueLabel, getHeightOfTallestLabel, getHighestValue, getHighestValueLabel, getHighlightColor, getLowestValue, getLowestValueLabel, getMaximumSize, getMinimumHorizontalSize, getMinimumVerticalSize, getPreferredHorizontalSize, getPreferredVerticalSize, getShadowColor, getTickLength, getWidthOfHighValueLabel, getWidthOfLowValueLabel, getWidthOfWidestLabel, installKeyboardActions, installListeners, isDragging, labelsHaveSameBaselines, paintHorizontalLabel, paintLabels, paintMajorTickForHorizSlider, paintMajorTickForVertSlider, paintMinorTickForHorizSlider, paintMinorTickForVertSlider, paintTicks, paintVerticalLabel, recalculateIfInsetsChanged, recalculateIfOrientationChanged, scrollByBlock, scrollByUnit, scrollDueToClickInTrack, setThumbLocation, uninstallKeyboardActions, uninstallListeners, uninstallUI, valueForXPosition, valueForYPosition, xPositionForValue, yPositionForValue, yPositionForValue
 
Methods inherited from class javax.swing.plaf.ComponentUI
contains, getAccessibleChild, getAccessibleChildrenCount, update
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

THUMB_ICON_CLIENT_PROPERTY

public static final java.lang.String THUMB_ICON_CLIENT_PROPERTY
See Also:
Constant Field Values

TICK_BUFFER

protected final int TICK_BUFFER
See Also:
Constant Field Values

filledSlider

protected boolean filledSlider

thumbColor

protected static java.awt.Color thumbColor

highlightColor

protected static java.awt.Color highlightColor

shadowColor

protected static java.awt.Color shadowColor

darkShadowColor

protected static java.awt.Color darkShadowColor

trackWidth

protected static int trackWidth

tickLength

protected static int tickLength

horizThumbIcon

protected static javax.swing.Icon horizThumbIcon

vertThumbIcon

protected static javax.swing.Icon vertThumbIcon

SLIDER_FILL

protected final java.lang.String SLIDER_FILL
See Also:
Constant Field Values
Constructor Detail

CustomSliderUI

public CustomSliderUI()
Method Detail

createUI

public static javax.swing.plaf.ComponentUI createUI(javax.swing.JComponent c)

getPropertyPrefix

protected java.lang.String getPropertyPrefix()

installUI

public void installUI(javax.swing.JComponent c)
Overrides:
installUI in class javax.swing.plaf.basic.BasicSliderUI

installDefaults

protected void installDefaults(javax.swing.JSlider c)
Overrides:
installDefaults in class javax.swing.plaf.basic.BasicSliderUI

createPropertyChangeListener

protected java.beans.PropertyChangeListener createPropertyChangeListener(javax.swing.JSlider slider)
Overrides:
createPropertyChangeListener in class javax.swing.plaf.basic.BasicSliderUI

paint

public void paint(java.awt.Graphics g,
                  javax.swing.JComponent c)
Overrides:
paint in class javax.swing.plaf.basic.BasicSliderUI

paintThumb

public void paintThumb(java.awt.Graphics g)
Overrides:
paintThumb in class javax.swing.plaf.basic.BasicSliderUI

paintTrack

public void paintTrack(java.awt.Graphics g)
Overrides:
paintTrack in class javax.swing.plaf.basic.BasicSliderUI

paintFocus

public void paintFocus(java.awt.Graphics g)
Overrides:
paintFocus in class javax.swing.plaf.basic.BasicSliderUI

getThumbSize

protected java.awt.Dimension getThumbSize()
Overrides:
getThumbSize in class javax.swing.plaf.basic.BasicSliderUI

getPreferredSize

public java.awt.Dimension getPreferredSize(javax.swing.JComponent c)
Gets the preferred size for the component.

Overrides:
getPreferredSize in class javax.swing.plaf.basic.BasicSliderUI

getMinimumSize

public java.awt.Dimension getMinimumSize(javax.swing.JComponent c)
Gets the minimal size for the component.

Overrides:
getMinimumSize in class javax.swing.plaf.basic.BasicSliderUI

getRequiredSize

protected java.awt.Dimension getRequiredSize(javax.swing.JComponent c,
                                             int trackLength)
Helper method for computing the size of the component.

Parameters:
c - The JSlider.
trackLength - The amount of pixels, we want to be able to move the slider thumb.

calculateTrackRect

protected void calculateTrackRect()
The track rect is the area, where the track is painted.

Overrides:
calculateTrackRect in class javax.swing.plaf.basic.BasicSliderUI

getTrackWidth

protected int getTrackWidth()

getThumbOverhang

protected int getThumbOverhang()
Returns the amount that the thumb goes past the slide bar.


(c) Werner Randelshofer.
All rights reserved.