|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjavax.swing.plaf.ComponentUI
javax.swing.plaf.SliderUI
javax.swing.plaf.basic.BasicSliderUI
public class BasicSliderUI
BasicSliderUI.java This is the UI delegate in the Basic look and feel that paints JSliders.
The UI delegate keeps track of 6 rectangles that place the various parts of the JSlider inside the component.
The rectangles are organized as follows:
+-------------------------------------------------------+ <-- 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 |
BasicSliderUI.ActionScroller
This class is no longer used as of JDK1.3. |
class |
BasicSliderUI.ChangeHandler
Helper class that listens to the JSlider 's model for changes. |
class |
BasicSliderUI.ComponentHandler
Helper class that listens for resize events. |
class |
BasicSliderUI.FocusHandler
Helper class that listens for focus events. |
class |
BasicSliderUI.PropertyChangeHandler
Helper class that listens for changes to the properties of the JSlider . |
class |
BasicSliderUI.ScrollListener
Helper class that listens to our swing timer. |
class |
BasicSliderUI.TrackListener
Helper class that listens for mouse events. |
Field Summary | |
---|---|
protected ChangeListener |
changeListener
Listener for changes from the model. |
protected ComponentListener |
componentListener
Listener for component resizing. |
protected Rectangle |
contentRect
Rectangle describing content bounds. |
protected Insets |
focusInsets
The insets between the FocusRectangle and the ContentRectangle. |
protected FocusListener |
focusListener
Listener for focus handling. |
protected Rectangle |
focusRect
Rectangle describing focus bounds. |
protected Insets |
insetCache
The JSlider 's insets. |
protected Rectangle |
labelRect
Rectangle describing the label bounds. |
protected boolean |
leftToRightCache
Whether this slider is actually drawn left to right. |
static int |
MAX_SCROLL
FIXME: use this somewhere. |
static int |
MIN_SCROLL
FIXME: use this somewhere. |
static int |
NEGATIVE_SCROLL
A constant describing scrolling towards the minimum. |
static int |
POSITIVE_SCROLL
A constant describing scrolling towards the maximum. |
protected PropertyChangeListener |
propertyChangeListener
Listener for changes to the JSlider . |
protected BasicSliderUI.ScrollListener |
scrollListener
Listener for the scrollTimer. |
protected Timer |
scrollTimer
A timer that periodically moves the thumb. |
protected JSlider |
slider
A reference to the JSlider that this UI was created for. |
protected Rectangle |
thumbRect
Rectangle describing the thumb's bounds. |
protected Rectangle |
tickRect
Rectangle describing the tick bounds. |
protected int |
trackBuffer
The gap between the edges of the contentRect and trackRect. |
protected BasicSliderUI.TrackListener |
trackListener
Listener for mouse events. |
protected Rectangle |
trackRect
Rectangle describing the track bounds. |
Constructor Summary | |
---|---|
BasicSliderUI(JSlider b)
Creates a new Basic look and feel Slider UI. |
Method Summary | |
---|---|
protected void |
calculateContentRect()
Updates the contentRect field to an area inside the
focusRect . |
protected void |
calculateFocusRect()
This method calculates the size and position of the focusRect. |
protected void |
calculateGeometry()
This method calculates all the sizes of the rectangles by delegating to the helper methods calculateXXXRect. |
protected void |
calculateLabelRect()
Calculates the labelRect 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. |
protected void |
calculateThumbSize()
Sets the width and height of the thumbRect field, using the
dimensions returned by getThumbSize() . |
protected void |
calculateTickRect()
This method calculates the size and position of the tickRect. |
protected void |
calculateTrackBuffer()
Calculates the gap size between the edge of the contentRect
and the edge of the trackRect , storing the result in the
trackBuffer field. |
protected void |
calculateTrackRect()
Calculates the size and position of the trackRect. |
protected ChangeListener |
createChangeListener(JSlider slider)
Creates a new ChangeListener . |
protected ComponentListener |
createComponentListener(JSlider slider)
Creates a new ComponentListener . |
protected FocusListener |
createFocusListener(JSlider slider)
Creates a new FocusListener . |
protected PropertyChangeListener |
createPropertyChangeListener(JSlider slider)
Creates a new PropertyChangeListener . |
protected BasicSliderUI.ScrollListener |
createScrollListener(JSlider slider)
Creates a new BasicSliderUI.ScrollListener . |
protected BasicSliderUI.TrackListener |
createTrackListener(JSlider slider)
Creates a new BasicSliderUI.TrackListener . |
static ComponentUI |
createUI(JComponent b)
Factory method to create a BasicSliderUI for the given JComponent , which should be a JSlider . |
protected boolean |
drawInverted()
Returns true if the slider scale is to be drawn inverted,
and false if not. |
protected Color |
getFocusColor()
Gets the focus color to be used for this slider. |
protected int |
getHeightOfHighValueLabel()
Returns the height of the label whose key has the highest value, or 0 if there are no labels. |
protected int |
getHeightOfLowValueLabel()
Returns the height of the label whose key has the lowest value, or 0 if there are no labels. |
protected int |
getHeightOfTallestLabel()
This method returns the height of the tallest label in the slider's label table. |
protected Component |
getHighestValueLabel()
Returns the label whose key has the highest value. |
protected Color |
getHighlightColor()
Gets the highlight color to be used for this slider. |
protected Component |
getLowestValueLabel()
This method returns the label whose key has the lowest value. |
Dimension |
getMaximumSize(JComponent c)
This method returns the maximum size for this JSlider for this
look and feel. |
Dimension |
getMinimumHorizontalSize()
This method returns the minimum size when the slider is horizontally oriented. |
Dimension |
getMinimumSize(JComponent c)
This method returns the minimum size for this JSlider for this
look and feel. |
Dimension |
getMinimumVerticalSize()
This method returns the minimum size of the slider when it is vertically oriented. |
Dimension |
getPreferredHorizontalSize()
This method returns the preferred size when the slider is horizontally oriented. |
Dimension |
getPreferredSize(JComponent c)
This method returns the preferred size of the component. |
Dimension |
getPreferredVerticalSize()
This method returns the preferred size when the slider is vertically oriented. |
protected Color |
getShadowColor()
Gets the shadow color to be used for this slider. |
protected Dimension |
getThumbSize()
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. |
protected int |
getWidthOfHighValueLabel()
Returns the width of the label whose key has the highest value, or 0 if there are no labels. |
protected int |
getWidthOfLowValueLabel()
Returns the width of the label whose key has the lowest value, or 0 if there are no labels. |
protected int |
getWidthOfWidestLabel()
This method returns the width of the widest label in the slider's label table. |
protected void |
installDefaults(JSlider slider)
Initializes any default properties that this UI has from the defaults for the Basic look and feel. |
protected void |
installKeyboardActions(JSlider slider)
Installs any keyboard actions. |
protected void |
installListeners(JSlider slider)
Creates and registers all the listeners for this UI delegate. |
void |
installUI(JComponent c)
Installs and initializes all fields for this UI delegate. |
protected boolean |
isDragging()
Returns true if the user is dragging the slider. |
void |
paint(Graphics g,
JComponent c)
This method is used to paint the JSlider . |
void |
paintFocus(Graphics g)
This method is called during a repaint if the slider has focus. |
protected void |
paintHorizontalLabel(Graphics g,
int value,
Component label)
This method paints the label on the horizontal slider at the value specified. |
void |
paintLabels(Graphics g)
This method paints all the labels from the slider's label table. |
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. |
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. |
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. |
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. |
void |
paintThumb(Graphics g)
This method paints a thumb. |
void |
paintTicks(Graphics g)
This method is called during a repaint if the ticks are to be drawn. |
void |
paintTrack(Graphics g)
This method is called during a repaint if the track is to be drawn. |
protected void |
paintVerticalLabel(Graphics g,
int value,
Component label)
This method paints the label on the vertical slider at the value specified. |
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. |
void |
scrollByBlock(int direction)
Moves the thumb one block in the direction specified (a block is 1/10th of the slider range). |
void |
scrollByUnit(int direction)
Moves the thumb one unit in the specified direction. |
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. |
void |
setThumbLocation(int x,
int y)
This method sets the position of the thumbRect. |
protected void |
uninstallKeyboardActions(JSlider slider)
Uninstalls any keyboard actions. |
protected void |
uninstallListeners(JSlider slider)
Unregisters all the listeners that this UI delegate was using. |
void |
uninstallUI(JComponent c)
Performs the opposite of installUI. |
int |
valueForXPosition(int xPos)
This method returns the value in the slider's range given the x coordinate. |
int |
valueForYPosition(int yPos)
This method returns the value in the slider's range given the y coordinate. |
protected int |
xPositionForValue(int value)
Returns the x-coordinate (relative to the component) for the given slider value. |
protected int |
yPositionForValue(int value)
Returns the y-coordinate (relative to the component) for the given slider value. |
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 |
---|
protected ChangeListener changeListener
protected PropertyChangeListener propertyChangeListener
JSlider
.
protected BasicSliderUI.ScrollListener scrollListener
protected ComponentListener componentListener
protected FocusListener focusListener
protected BasicSliderUI.TrackListener trackListener
protected Insets focusInsets
protected Insets insetCache
JSlider
's insets.
protected Rectangle contentRect
protected Rectangle focusRect
protected Rectangle thumbRect
protected Rectangle tickRect
protected Rectangle labelRect
protected Rectangle trackRect
public static final int MAX_SCROLL
public static final int MIN_SCROLL
public static final int NEGATIVE_SCROLL
public static final int POSITIVE_SCROLL
protected int trackBuffer
protected boolean leftToRightCache
protected Timer scrollTimer
protected JSlider slider
JSlider
that this UI was created for.
Constructor Detail |
---|
public BasicSliderUI(JSlider b)
b
- The JSlider
that this UI was created for.Method Detail |
---|
protected boolean isDragging()
protected Color getShadowColor()
protected Color getHighlightColor()
protected Color getFocusColor()
public static ComponentUI createUI(JComponent b)
JComponent
, which should be a JSlider
.
b
- The JComponent
a UI is being created for.
JComponent
.public void installUI(JComponent c)
installUI
in class ComponentUI
c
- The JComponent
that is having this UI installed.ComponentUI.uninstallUI(javax.swing.JComponent)
,
JComponent.setUI(javax.swing.plaf.ComponentUI)
,
JComponent.updateUI()
public void uninstallUI(JComponent c)
uninstallUI
in class ComponentUI
c
- The JComponent
that is having this UI uninstalled.ComponentUI.installUI(javax.swing.JComponent)
,
JComponent.setUI(javax.swing.plaf.ComponentUI)
,
JComponent.updateUI()
protected void installDefaults(JSlider slider)
slider
- The JSlider
that is having this UI installed.protected BasicSliderUI.TrackListener createTrackListener(JSlider slider)
BasicSliderUI.TrackListener
.
slider
- The JSlider
that this BasicSliderUI.TrackListener
is
created for.
BasicSliderUI.TrackListener
.protected ChangeListener createChangeListener(JSlider slider)
ChangeListener
.
slider
- The JSlider
that this ChangeListener
is
created for.
ChangeListener
.protected ComponentListener createComponentListener(JSlider slider)
ComponentListener
.
slider
- The JSlider
that this ComponentListener
is
created for.
ComponentListener
.protected FocusListener createFocusListener(JSlider slider)
FocusListener
.
slider
- The JSlider
that this FocusListener
is
created for.
FocusListener
.protected BasicSliderUI.ScrollListener createScrollListener(JSlider slider)
BasicSliderUI.ScrollListener
.
slider
- The JSlider
that this BasicSliderUI.ScrollListener
is
created for.
BasicSliderUI.ScrollListener
.protected PropertyChangeListener createPropertyChangeListener(JSlider slider)
PropertyChangeListener
.
slider
- The JSlider
that this PropertyChangeListener
is created for.
PropertyChangeListener
.protected void installListeners(JSlider slider)
slider
- The JSlider
is having listeners installed.protected void uninstallListeners(JSlider slider)
slider
- The JSlider
that is having listeners removed.protected void installKeyboardActions(JSlider slider)
slider
- The JSlider
that is having keyboard actions
installed.protected void uninstallKeyboardActions(JSlider slider)
slider
- The JSlider
that is having keyboard actions
uninstalled.public Dimension getPreferredHorizontalSize()
public Dimension getPreferredVerticalSize()
public Dimension getMinimumHorizontalSize()
public Dimension getMinimumVerticalSize()
public Dimension getPreferredSize(JComponent c)
JComponent
a size.
getPreferredSize
in class ComponentUI
c
- The JComponent
to find the preferred size for.
public Dimension getMinimumSize(JComponent c)
JSlider
for this
look and feel. If it returns null, then it is up to the Layout Manager
to give the JComponent
a size.
getMinimumSize
in class ComponentUI
c
- The JComponent
to find the minimum size for.
public Dimension getMaximumSize(JComponent c)
JSlider
for this
look and feel.
getMaximumSize
in class ComponentUI
c
- The JComponent
to find a maximum size for.
protected void calculateGeometry()
protected void calculateFocusRect()
protected void calculateThumbSize()
thumbRect
field, using the
dimensions returned by getThumbSize()
.
protected void calculateContentRect()
contentRect
field to an area inside the
focusRect
. This method does not need to be called if the
orientation changes.
protected void calculateThumbLocation()
protected void calculateTrackBuffer()
contentRect
and the edge of the trackRect
, storing the result in the
trackBuffer
field. Sufficient space needs to be reserved
for the slider thumb and/or the labels at each end of the slider track.
protected Dimension getThumbSize()
11 x 20
for horizontal sliders, and 20 x 11
for
vertical sliders. Note that a new instance of Dimension
is
returned for every call to this method (this seems wasteful, but
Dimension
instances are not immutable, so this is probably
unavoidable).
protected void calculateTrackRect()
protected int getTickLength()
protected void calculateTickRect()
protected void calculateLabelRect()
labelRect
field, taking into account the
orientation of the slider.
protected int getWidthOfWidestLabel()
protected int getHeightOfTallestLabel()
protected int getWidthOfHighValueLabel()
getHighestValueLabel()
protected int getWidthOfLowValueLabel()
getLowestValueLabel()
protected int getHeightOfHighValueLabel()
protected int getHeightOfLowValueLabel()
protected boolean drawInverted()
true
if the slider scale is to be drawn inverted,
and false
if not.
true
if the slider is to be drawn inverted.protected Component getLowestValueLabel()
protected Component getHighestValueLabel()
null
if
no label table exists.public void paint(Graphics g, JComponent c)
JSlider
. It delegates all its
duties to the various paint methods like paintTicks(), paintTrack(),
paintThumb(), etc.
paint
in class ComponentUI
g
- The Graphics
object to paint with.c
- The JComponent
that is being painted.protected void recalculateIfInsetsChanged()
protected void recalculateIfOrientationChanged()
public void paintFocus(Graphics g)
g
- The Graphics
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---c
The 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.
g
- The Graphics
object to draw with.public void paintTicks(Graphics g)
g
- The Graphics
object to draw with.protected void paintMinorTickForHorizSlider(Graphics g, Rectangle tickBounds, int x)
g
- The Graphics
object to draw with.tickBounds
- The tickRect rectangle.x
- The x coordinate to draw the tick at.protected void paintMajorTickForHorizSlider(Graphics g, Rectangle tickBounds, int x)
g
- The Graphics
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)
g
- The Graphics
object to draw with.tickBounds
- The tickRect rectangle.y
- The y coordinate to draw the tick at.protected void paintMajorTickForVertSlider(Graphics g, Rectangle tickBounds, int y)
g
- The Graphics
object to draw with.tickBounds
- The tickRect rectangle.y
- The y coordinate to draw the tick at.public void paintLabels(Graphics g)
g
- The Graphics
object to draw with.protected void paintHorizontalLabel(Graphics g, int value, Component label)
g
- The Graphics
object to draw with.value
- The value to paint at.label
- The label to paint.protected void paintVerticalLabel(Graphics g, int value, Component label)
g
- The Graphics
object to draw with.value
- The value to paint at.label
- The label to paint.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-----d
In 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.
g
- The graphics object to paint withpublic void setThumbLocation(int x, int y)
x
- The new x position.y
- The new y position.public void scrollByBlock(int direction)
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)
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)
dir
- The direction to move in.protected int xPositionForValue(int value)
trackRect
field is
set up.
value
- the slider value.
protected int yPositionForValue(int value)
trackRect
field is
set up.
value
- the slider value.
public int valueForYPosition(int yPos)
yPos
- The y coordinate to calculate a value for.
public int valueForXPosition(int xPos)
xPos
- The x coordinate to calculate a value for.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |