Copyright 2012-02-25 Werner Randelshofer

ch.randelshofer.gui.plaf
Class ImageSliderUI

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.ImageSliderUI
All Implemented Interfaces:
PlafConstants

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

A Java L&F implementation of SliderUI.

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.


Nested Class Summary
protected  class ImageSliderUI.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
           
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
ImageSliderUI()
           
 
Method Summary
protected  void calculateContentRect()
          The content rectangle is inside the focus rectangle of the component.
protected  void calculateFocusRect()
          The focus rectangle is inside the border insets of the component.
protected  void calculateThumbLocation()
           
protected  void calculateTrackBuffer()
          The distance that the track is from the side of the control.
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()
           
 int getTickLength()
          Gets the height of the tick area for horizontal sliders and the width of the tick area for vertical sliders.
protected  int getTrackLength()
          Returns the longer dimension of the slide bar.
protected  int getTrackWidth()
          Returns the shorter dimension of the track.
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)
           
protected  void paintMajorTickForHorizSlider(java.awt.Graphics g, java.awt.Rectangle tickBounds, int x)
           
protected  void paintMajorTickForVertSlider(java.awt.Graphics g, java.awt.Rectangle tickBounds, int y)
           
protected  void paintMinorTickForHorizSlider(java.awt.Graphics g, java.awt.Rectangle tickBounds, int x)
           
protected  void paintMinorTickForVertSlider(java.awt.Graphics g, java.awt.Rectangle tickBounds, int y)
           
 void paintThumb(java.awt.Graphics g)
           
 void paintTrack(java.awt.Graphics g)
           
protected  void recalculateIfInsetsChanged()
          Recalculates the geometry, if the insets of the slider have changed.
protected  void scrollDueToClickInTrack(int dir)
           
 int valueForXPosition(int xPos)
          Returns a value give an x position.
protected  int xPositionForValue(int value)
           
 
Methods inherited from class javax.swing.plaf.basic.BasicSliderUI
calculateGeometry, calculateLabelRect, calculateThumbSize, calculateTickRect, createChangeListener, createComponentListener, createFocusListener, createScrollListener, createTrackListener, drawInverted, getBaseline, getBaselineResizeBehavior, getFocusColor, getHeightOfHighValueLabel, getHeightOfLowValueLabel, getHeightOfTallestLabel, getHighestValue, getHighestValueLabel, getHighlightColor, getLowestValue, getLowestValueLabel, getMaximumSize, getMinimumHorizontalSize, getMinimumVerticalSize, getPreferredHorizontalSize, getPreferredVerticalSize, getShadowColor, getWidthOfHighValueLabel, getWidthOfLowValueLabel, getWidthOfWidestLabel, installKeyboardActions, installListeners, isDragging, labelsHaveSameBaselines, paintHorizontalLabel, paintLabels, paintTicks, paintVerticalLabel, recalculateIfOrientationChanged, scrollByBlock, scrollByUnit, setThumbLocation, uninstallKeyboardActions, uninstallListeners, uninstallUI, valueForYPosition, 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

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

ImageSliderUI

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

recalculateIfInsetsChanged

protected void recalculateIfInsetsChanged()
Recalculates the geometry, if the insets of the slider have changed.

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

calculateFocusRect

protected void calculateFocusRect()
The focus rectangle is inside the border insets of the component.

Prerequisites: The insetCache variable must have been updated before this method can be called. Otherwise the result is undefined.

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

calculateContentRect

protected void calculateContentRect()
The content rectangle is inside the focus rectangle of the component.

Prerequisites: calculateFocusRect must have been called before this method can be called. Otherwise the result is undefined.

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

calculateTrackBuffer

protected void calculateTrackBuffer()
The distance that the track is from the side of the control.

Prerequisites: calculateContentRect must have been called before this method can be called. Otherwise the result is undefined.

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

calculateTrackRect

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

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

calculateThumbLocation

protected void calculateThumbLocation()
Overrides:
calculateThumbLocation in class javax.swing.plaf.basic.BasicSliderUI

getTickLength

public 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.

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

getTrackWidth

protected int getTrackWidth()
Returns the shorter dimension of the track.


xPositionForValue

protected int xPositionForValue(int value)
Overrides:
xPositionForValue in class javax.swing.plaf.basic.BasicSliderUI

valueForXPosition

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.

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

getTrackLength

protected int getTrackLength()
Returns the longer dimension of the slide bar. (The slide bar is only the part that runs directly under the thumb)


getThumbOverhang

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


scrollDueToClickInTrack

protected void scrollDueToClickInTrack(int dir)
Overrides:
scrollDueToClickInTrack in class javax.swing.plaf.basic.BasicSliderUI

paintMinorTickForHorizSlider

protected void paintMinorTickForHorizSlider(java.awt.Graphics g,
                                            java.awt.Rectangle tickBounds,
                                            int x)
Overrides:
paintMinorTickForHorizSlider in class javax.swing.plaf.basic.BasicSliderUI

paintMajorTickForHorizSlider

protected void paintMajorTickForHorizSlider(java.awt.Graphics g,
                                            java.awt.Rectangle tickBounds,
                                            int x)
Overrides:
paintMajorTickForHorizSlider in class javax.swing.plaf.basic.BasicSliderUI

paintMinorTickForVertSlider

protected void paintMinorTickForVertSlider(java.awt.Graphics g,
                                           java.awt.Rectangle tickBounds,
                                           int y)
Overrides:
paintMinorTickForVertSlider in class javax.swing.plaf.basic.BasicSliderUI

paintMajorTickForVertSlider

protected void paintMajorTickForVertSlider(java.awt.Graphics g,
                                           java.awt.Rectangle tickBounds,
                                           int y)
Overrides:
paintMajorTickForVertSlider in class javax.swing.plaf.basic.BasicSliderUI

Copyright 2012-02-25 Werner Randelshofer