Prev Class | Next Class | Frames | No Frames |
Summary: Nested | Field | Method | Constr | Detail: Nested | Field | Method | Constr |
java.lang.Object
javax.swing.plaf.ComponentUI
javax.swing.plaf.SliderUI
javax.swing.plaf.basic.BasicSliderUI
public class BasicSliderUI
extends SliderUI
+-------------------------------------------------------+ <-- focusRect | | | +==+-------------------+==+--------------------+==+<------ contentRect | | | | |<---thumbRect | | | | | | TRACK | | |<--------- trackRect | | +-------------------+==+--------------------+ | | | | | | | | | | | TICKS GO HERE |<-------- tickRect | | | | | | | +==+-------------------------------------------+==+ | | | | | | | | | | | |<----- labelRect | | | LABELS GO HERE | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |The space between the contentRect and the focusRect are the FocusInsets. The space between the focusRect and the component bounds is the insetCache which are the component's insets. The top of the thumb is the top of the contentRect. The trackRect has to be as tall as the thumb. The trackRect and tickRect do not start from the left edge of the focusRect. They are trackBuffer away from each side of the focusRect. This is so that the thumb has room to move. The labelRect does start right against the contentRect's left and right edges and it gets all remaining space.
Nested Class Summary | |
class |
|
class |
|
class |
|
class |
|
class |
|
class |
|
class |
|
Field Summary | |
static int |
|
static int |
|
static int |
|
static int |
|
protected ChangeListener |
|
protected ComponentListener |
|
protected Rectangle |
|
protected Insets |
|
protected FocusListener |
|
protected Rectangle |
|
protected Insets |
|
protected Rectangle |
|
protected boolean |
|
protected PropertyChangeListener |
|
protected BasicSliderUI.ScrollListener |
|
protected Timer |
|
protected JSlider | |
protected Rectangle |
|
protected Rectangle |
|
protected int |
|
protected BasicSliderUI.TrackListener |
|
protected Rectangle |
|
Constructor Summary | |
|
Method Summary | |
protected void |
|
protected void |
|
protected void |
|
protected void |
|
protected void |
|
protected void |
|
protected void |
|
protected void |
|
protected void |
|
protected ChangeListener |
|
protected ComponentListener |
|
protected FocusListener |
|
protected PropertyChangeListener |
|
protected BasicSliderUI.ScrollListener |
|
protected BasicSliderUI.TrackListener |
|
static ComponentUI |
|
protected boolean |
|
protected Color |
|
protected int |
|
protected int |
|
protected int |
|
protected Component |
|
protected Color |
|
protected Component |
|
Dimension |
|
Dimension |
|
Dimension |
|
Dimension |
|
Dimension |
|
Dimension |
|
Dimension |
|
protected Color |
|
protected Dimension |
|
protected int |
|
protected int |
|
protected int |
|
protected int |
|
protected void |
|
protected void |
|
protected void |
|
void |
|
protected boolean |
|
void |
|
void |
|
protected void |
|
void |
|
protected void |
|
protected void |
|
protected void |
|
protected void |
|
void |
|
void |
|
void |
|
protected void |
|
protected void |
|
protected void |
|
void |
|
void |
|
protected void |
|
void |
|
protected void |
|
protected void |
|
void |
|
int |
|
int |
|
protected int |
|
protected int |
|
Methods inherited from class javax.swing.plaf.ComponentUI | |
contains , createUI , getAccessibleChild , getAccessibleChildrenCount , getMaximumSize , getMinimumSize , getPreferredSize , installUI , paint , uninstallUI , update |
Methods inherited from class java.lang.Object | |
clone , equals , extends Object> getClass , finalize , hashCode , notify , notifyAll , toString , wait , wait , wait |
public static final int NEGATIVE_SCROLL
A constant describing scrolling towards the minimum.
- Field Value:
- -1
public static final int POSITIVE_SCROLL
A constant describing scrolling towards the maximum.
- Field Value:
- 1
protected Insets focusInsets
The insets between the FocusRectangle and the ContentRectangle.
protected boolean leftToRightCache
Whether this slider is actually drawn left to right.
protected PropertyChangeListener propertyChangeListener
Listener for changes to theJSlider
.
public BasicSliderUI(JSlider b)
Creates a new Basic look and feel Slider UI.
- Parameters:
b
- TheJSlider
that this UI was created for.
protected void calculateContentRect()
Updates thecontentRect
field to an area inside thefocusRect
. This method does not need to be called if the orientation changes.
protected void calculateFocusRect()
This method calculates the size and position of the focusRect. This method does not need to be called if the orientation changes.
protected void calculateGeometry()
This method calculates all the sizes of the rectangles by delegating to the helper methods calculateXXXRect.
protected void calculateLabelRect()
Calculates thelabelRect
field, taking into account the orientation of the slider.
protected void calculateThumbLocation()
Calculates the position of the thumbRect based on the current value of the slider. It must take into account the orientation of the slider.
protected void calculateThumbSize()
Sets the width and height of thethumbRect
field, using the dimensions returned bygetThumbSize()
.
protected void calculateTickRect()
This method calculates the size and position of the tickRect. It must take into account the orientation of the slider.
protected void calculateTrackBuffer()
Calculates the gap size between the edge of thecontentRect
and the edge of thetrackRect
, storing the result in thetrackBuffer
field. Sufficient space needs to be reserved for the slider thumb and/or the labels at each end of the slider track.
protected void calculateTrackRect()
Calculates the size and position of the trackRect. It must take into account the orientation of the slider.
protected ChangeListener createChangeListener(JSlider slider)
Creates a newChangeListener
.
- Parameters:
slider
- TheJSlider
that thisChangeListener
is created for.
- Returns:
- A new
ChangeListener
.
protected ComponentListener createComponentListener(JSlider slider)
Creates a newComponentListener
.
- Parameters:
slider
- TheJSlider
that thisComponentListener
is created for.
- Returns:
- A new
ComponentListener
.
protected FocusListener createFocusListener(JSlider slider)
Creates a newFocusListener
.
- Parameters:
slider
- TheJSlider
that thisFocusListener
is created for.
- Returns:
- A new
FocusListener
.
protected PropertyChangeListener createPropertyChangeListener(JSlider slider)
Creates a newPropertyChangeListener
.
- Parameters:
slider
- TheJSlider
that thisPropertyChangeListener
is created for.
- Returns:
- A new
PropertyChangeListener
.
protected BasicSliderUI.ScrollListener createScrollListener(JSlider slider)
Creates a newBasicSliderUI.ScrollListener
.
- Parameters:
slider
- TheJSlider
that thisBasicSliderUI.ScrollListener
is created for.
- Returns:
- A new
BasicSliderUI.ScrollListener
.
protected BasicSliderUI.TrackListener createTrackListener(JSlider slider)
Creates a newBasicSliderUI.TrackListener
.
- Parameters:
slider
- TheJSlider
that thisBasicSliderUI.TrackListener
is created for.
- Returns:
- A new
BasicSliderUI.TrackListener
.
public static ComponentUI createUI(JComponent b)
Factory method to create a BasicSliderUI for the givenJComponent
, which should be aJSlider
.
- Overrides:
- createUI in interface ComponentUI
- Parameters:
b
- TheJComponent
a UI is being created for.
- Returns:
- A BasicSliderUI for the
JComponent
.
protected boolean drawInverted()
Returnstrue
if the slider scale is to be drawn inverted, andfalse
if not.
- Returns:
true
if the slider is to be drawn inverted.
protected Color getFocusColor()
Gets the focus color to be used for this slider. The focus color is the color used for drawing the focus rectangle when the component gains focus.
- Returns:
- The focus color.
protected int getHeightOfHighValueLabel()
Returns the height of the label whose key has the highest value, or 0 if there are no labels.
- Returns:
- The height of the high value label or 0 if no label table exists.
protected int getHeightOfLowValueLabel()
Returns the height of the label whose key has the lowest value, or 0 if there are no labels.
- Returns:
- The height of the low value label or 0 if no label table exists.
protected int getHeightOfTallestLabel()
This method returns the height of the tallest label in the slider's label table.
- Returns:
- The height of the tallest label or 0 if no label table exists.
protected Component getHighestValueLabel()
Returns the label whose key has the highest value.
- Returns:
- The label whose key has the highest value or
null
if no label table exists.
protected Color getHighlightColor()
Gets the highlight color to be used for this slider. The highlight color is the color used for drawing the bottom and right edges of the track.
- Returns:
- The highlight color.
protected Component getLowestValueLabel()
This method returns the label whose key has the lowest value.
- Returns:
- The low value label or null if no label table exists.
public Dimension getMaximumSize(JComponent c)
This method returns the maximum size for thisJSlider
for this look and feel.
- Overrides:
- getMaximumSize in interface ComponentUI
- Parameters:
c
- TheJComponent
to find a maximum size for.
- Returns:
- The dimensions of the maximum size.
public Dimension getMinimumHorizontalSize()
This method returns the minimum size when the slider is horizontally oriented.
- Returns:
- The dimensions of the minimum horizontal size.
public Dimension getMinimumSize(JComponent c)
This method returns the minimum size for thisJSlider
for this look and feel. If it returns null, then it is up to the Layout Manager to give theJComponent
a size.
- Overrides:
- getMinimumSize in interface ComponentUI
- Parameters:
c
- TheJComponent
to find the minimum size for.
- Returns:
- The dimensions of the minimum size.
public Dimension getMinimumVerticalSize()
This method returns the minimum size of the slider when it is vertically oriented.
- Returns:
- The dimensions of the minimum vertical size.
public Dimension getPreferredHorizontalSize()
This method returns the preferred size when the slider is horizontally oriented.
- Returns:
- The dimensions of the preferred horizontal size.
public Dimension getPreferredSize(JComponent c)
This method returns the preferred size of the component. If it returns null, then it is up to the Layout Manager to give theJComponent
a size.
- Overrides:
- getPreferredSize in interface ComponentUI
- Parameters:
c
- TheJComponent
to find the preferred size for.
- Returns:
- The dimensions of the preferred size.
public Dimension getPreferredVerticalSize()
This method returns the preferred size when the slider is vertically oriented.
- Returns:
- The dimensions of the preferred vertical size.
protected Color getShadowColor()
Gets the shadow color to be used for this slider. The shadow color is the color used for drawing the top and left edges of the track.
- Returns:
- The shadow color.
protected Dimension getThumbSize()
Returns the size of the slider's thumb. The size is hard coded to11 x 20
for horizontal sliders, and20 x 11
for vertical sliders. Note that a new instance ofDimension
is returned for every call to this method (this seems wasteful, butDimension
instances are not immutable, so this is probably unavoidable).
- Returns:
- The size of the slider's thumb.
protected int getTickLength()
This method returns the height of the tick area box if the slider is horizontal and the width of the tick area box is the slider is vertical. It not necessarily how long the ticks will be. If a gap between the edge of tick box and the actual tick is desired, then that will need to be handled in the tick painting methods.
- Returns:
- The height (or width if the slider is vertical) of the tick rectangle.
protected int getWidthOfHighValueLabel()
Returns the width of the label whose key has the highest value, or 0 if there are no labels.
- Returns:
- The width of the label whose key has the highest value.
- See Also:
getHighestValueLabel()
protected int getWidthOfLowValueLabel()
Returns the width of the label whose key has the lowest value, or 0 if there are no labels.
- Returns:
- The width of the label whose key has the lowest value.
- See Also:
getLowestValueLabel()
protected int getWidthOfWidestLabel()
This method returns the width of the widest label in the slider's label table.
- Returns:
- The width of the widest label or 0 if no label table exists.
protected void installDefaults(JSlider slider)
Initializes any default properties that this UI has from the defaults for the Basic look and feel.
- Parameters:
slider
- TheJSlider
that is having this UI installed.
protected void installKeyboardActions(JSlider slider)
Installs any keyboard actions. The list of keys that need to be bound are listed in Basic look and feel's defaults.
- Parameters:
slider
- TheJSlider
that is having keyboard actions installed.
protected void installListeners(JSlider slider)
Creates and registers all the listeners for this UI delegate. This includes creating the ScrollListener and registering it to the timer.
- Parameters:
slider
- TheJSlider
is having listeners installed.
public void installUI(JComponent c)
Installs and initializes all fields for this UI delegate. Any properties of the UI that need to be initialized and/or set to defaults will be done now. It will also install any listeners necessary.
- Overrides:
- installUI in interface ComponentUI
- Parameters:
c
- TheJComponent
that is having this UI installed.
protected boolean isDragging()
Returns true if the user is dragging the slider.
- Returns:
- true if the slider is being dragged.
- Since:
- 1.5
public void paint(Graphics g, JComponent c)
This method is used to paint theJSlider
. It delegates all its duties to the various paint methods like paintTicks(), paintTrack(), paintThumb(), etc.
- Overrides:
- paint in interface ComponentUI
- Parameters:
g
- TheGraphics
object to paint with.c
- TheJComponent
that is being painted.
public void paintFocus(Graphics g)
This method is called during a repaint if the slider has focus. It draws an outline of the focusRect using the color returned by getFocusColor().
- Parameters:
g
- TheGraphics
object to draw with.
protected void paintHorizontalLabel(Graphics g, int value, Component label)
This method paints the label on the horizontal slider at the value specified. The value is not a coordinate. It is a value within the range of the slider. If the value is not within the range of the slider, this method will do nothing. This method should not paint outside the boundaries of the labelRect.
- Parameters:
g
- TheGraphics
object to draw with.value
- The value to paint at.label
- The label to paint.
public void paintLabels(Graphics g)
This method paints all the labels from the slider's label table. This method must make sure that the label table is not null before painting the labels. Each entry in the label table is a (integer, component) pair. Every label is painted at the value of the integer.
- Parameters:
g
- TheGraphics
object to draw with.
protected void paintMajorTickForHorizSlider(Graphics g, Rectangle tickBounds, int x)
This method paints a major tick for a horizontal slider at the given x value. x represents the x coordinate to paint at.
- Parameters:
g
- TheGraphics
object to draw with.tickBounds
- The tickRect rectangle.x
- The x coordinate to draw the tick at.
protected void paintMajorTickForVertSlider(Graphics g, Rectangle tickBounds, int y)
This method paints a major tick for a vertical slider at the given y value. y represents the y coordinate to paint at.
- Parameters:
g
- TheGraphics
object to draw with.tickBounds
- The tickRect rectangle.y
- The y coordinate to draw the tick at.
protected void paintMinorTickForHorizSlider(Graphics g, Rectangle tickBounds, int x)
This method paints a minor tick for a horizontal slider at the given x value. x represents the x coordinate to paint at.
- Parameters:
g
- TheGraphics
object to draw with.tickBounds
- The tickRect rectangle.x
- The x coordinate to draw the tick at.
protected void paintMinorTickForVertSlider(Graphics g, Rectangle tickBounds, int y)
This method paints a minor tick for a vertical slider at the given y value. y represents the y coordinate to paint at.
- Parameters:
g
- TheGraphics
object to draw with.tickBounds
- The tickRect rectangle.y
- The y coordinate to draw the tick at.
public void paintThumb(Graphics g)
This method paints a thumb. There are two types of thumb:Vertical Horizontal a---b a-----b | | | \ e c | c \ / | / d e-----dIn the case of vertical thumbs, we highlight the path b-a-e-d and shadow the path b-c-d. In the case of horizontal thumbs, we highlight the path c-b-a-e and shadow the path c-d-e. In both cases we fill the path a-b-c-d-e before shadows and highlights are drawn.
- Parameters:
g
- The graphics object to paint with
public void paintTicks(Graphics g)
This method is called during a repaint if the ticks are to be drawn. This method must still verify that the majorTickSpacing and minorTickSpacing are greater than zero before drawing the ticks.
- Parameters:
g
- TheGraphics
object to draw with.
public void paintTrack(Graphics g)
This method is called during a repaint if the track is to be drawn. It draws a 3D rectangle to represent the track. The track is not the size of the trackRect. The top and left edges of the track should be outlined with the shadow color. The bottom and right edges should be outlined with the highlight color.a---d | | | | a------------------------d | | | | | | b------------------------c | | | | b---cThe b-a-d path needs to be drawn with the shadow color and the b-c-d path needs to be drawn with the highlight color.
- Parameters:
g
- TheGraphics
object to draw with.
protected void paintVerticalLabel(Graphics g, int value, Component label)
This method paints the label on the vertical slider at the value specified. The value is not a coordinate. It is a value within the range of the slider. If the value is not within the range of the slider, this method will do nothing. This method should not paint outside the boundaries of the labelRect.
- Parameters:
g
- TheGraphics
object to draw with.value
- The value to paint at.label
- The label to paint.
protected void recalculateIfInsetsChanged()
This method recalculates any rectangles that need to be recalculated after the insets of the component have changed.
protected void recalculateIfOrientationChanged()
This method recalculates any rectangles that need to be recalculated after the orientation of the slider changes.
public void scrollByBlock(int direction)
Moves the thumb one block in the direction specified (a block is 1/10th of the slider range). If the slider snaps to ticks, this method is responsible for snapping it to a tick after the thumb has been moved.
- Parameters:
direction
- the direction (positive values increment the thumb position by one block, zero/negative values decrement the thumb position by one block).
public void scrollByUnit(int direction)
Moves the thumb one unit in the specified direction. If the slider snaps to ticks, this method is responsible for snapping it to a tick after the thumb has been moved.
- Parameters:
direction
- the direction (positive values increment the thumb position by one, zero/negative values decrement the thumb position by one).
protected void scrollDueToClickInTrack(int dir)
This method is called when there has been a click in the track and the thumb needs to be scrolled on regular intervals. This method is only responsible for starting the timer and not for stopping it.
- Parameters:
dir
- The direction to move in.
public void setThumbLocation(int x, int y)
This method sets the position of the thumbRect.
- Parameters:
x
- The new x position.y
- The new y position.
protected void uninstallKeyboardActions(JSlider slider)
Uninstalls any keyboard actions. The list of keys used are listed in Basic look and feel's defaults.
- Parameters:
slider
- TheJSlider
that is having keyboard actions uninstalled.
protected void uninstallListeners(JSlider slider)
Unregisters all the listeners that this UI delegate was using. In addition, it will also null any listeners that it was using.
- Parameters:
slider
- TheJSlider
that is having listeners removed.
public void uninstallUI(JComponent c)
Performs the opposite of installUI. Any properties or resources that need to be cleaned up will be done now. It will also uninstall any listeners it has. In addition, any properties of this UI will be nulled.
- Overrides:
- uninstallUI in interface ComponentUI
- Parameters:
c
- TheJComponent
that is having this UI uninstalled.
public int valueForXPosition(int xPos)
This method returns the value in the slider's range given the x coordinate. If the value is out of range, it will return the closest legal value.
- Parameters:
xPos
- The x coordinate to calculate a value for.
- Returns:
- The value for the x coordinate.
public int valueForYPosition(int yPos)
This method returns the value in the slider's range given the y coordinate. If the value is out of range, it will return the closest legal value.
- Parameters:
yPos
- The y coordinate to calculate a value for.
- Returns:
- The value for the y coordinate.
protected int xPositionForValue(int value)
Returns the x-coordinate (relative to the component) for the given slider value. This method assumes that thetrackRect
field is set up.
- Parameters:
value
- the slider value.
- Returns:
- The x-coordinate.
protected int yPositionForValue(int value)
Returns the y-coordinate (relative to the component) for the given slider value. This method assumes that thetrackRect
field is set up.
- Parameters:
value
- the slider value.
- Returns:
- The y-coordinate.