javax.swing.plaf.basic

Class BasicScrollBarUI

Implemented Interfaces:
LayoutManager, SwingConstants
Known Direct Subclasses:
MetalScrollBarUI

public class BasicScrollBarUI
extends ScrollBarUI
implements LayoutManager, SwingConstants

The Basic Look and Feel UI delegate for JScrollBar.

Nested Class Summary

protected class
BasicScrollBarUI.ArrowButtonListener
A helper class that listens to the two JButtons on each end of the JScrollBar.
protected class
BasicScrollBarUI.ModelListener
A helper class that listens to the ScrollBar's model for ChangeEvents.
class
BasicScrollBarUI.PropertyChangeHandler
A helper class that listens to the ScrollBar's properties.
protected class
BasicScrollBarUI.ScrollListener
A helper class that listens for events from the timer that is used to move the thumb.
protected class
BasicScrollBarUI.TrackListener
Helper class that listens for movement on the track.

Field Summary

protected static int
DECREASE_HIGHLIGHT
Indicates that the decrease highlight should be painted.
protected static int
INCREASE_HIGHLIGHT
Indicates that the increase highlight should be painted.
protected static int
NO_HIGHLIGHT
Indicates that no highlight should be painted.
protected BasicScrollBarUI.ArrowButtonListener
buttonListener
The listener that listens to the JButtons.
protected JButton
decrButton
The JButton that decrements the scrollbar's value.
protected JButton
incrButton
The JButton that increments the scrollbar's value.
protected boolean
isDragging
FIXME: Use this for something (presumably mouseDragged)
protected Dimension
maximumThumbSize
The dimensions of the maximum thumb size.
protected Dimension
minimumThumbSize
The dimensions of the minimum thumb size.
protected BasicScrollBarUI.ModelListener
modelListener
The listener that listens to the model.
protected PropertyChangeListener
propertyChangeListener
The listener that listens to the scrollbar for property changes.
protected BasicScrollBarUI.ScrollListener
scrollListener
The listener that listens to the timer.
protected Timer
scrollTimer
The timer used to move the thumb when the mouse is held.
protected JScrollBar
scrollbar
The scrollbar this UI is acting for.
protected Color
thumbColor
The color of the thumb.
protected Color
thumbDarkShadowColor
The outer shadow of the thumb.
protected Color
thumbHighlightColor
The top and left edge color for the thumb.
protected Color
thumbLightShadowColor
The outer light shadow for the thumb.
protected Rectangle
thumbRect
The size and position of the thumb.
protected Color
trackColor
The color of the track.
protected int
trackHighlight
The current highlight status.
protected Color
trackHighlightColor
The color that is used when the mouse press occurs in the track.
protected BasicScrollBarUI.TrackListener
trackListener
The listener that listens for MouseEvents on the track.
protected Rectangle
trackRect
The size and position of the track.

Fields inherited from interface javax.swing.SwingConstants

BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST

Method Summary

void
addLayoutComponent(String name, Component child)
This method adds a component to the layout.
protected void
configureScrollBarColors()
This method configures the scrollbar's colors.
protected BasicScrollBarUI.ArrowButtonListener
createArrowButtonListener()
This method creates an ArrowButtonListener.
protected JButton
createDecreaseButton(int orientation)
This method creates a new JButton with the appropriate icon for the orientation.
protected JButton
createIncreaseButton(int orientation)
This method creates a new JButton with the appropriate icon for the orientation.
protected BasicScrollBarUI.ModelListener
createModelListener()
This method creates a new ModelListener.
protected PropertyChangeListener
createPropertyChangeListener()
This method creates a new PropertyChangeListener.
protected BasicScrollBarUI.ScrollListener
createScrollListener()
This method creates a new ScrollListener.
protected BasicScrollBarUI.TrackListener
createTrackListener()
This method creates a new TrackListener.
static ComponentUI
createUI(JComponent c)
This method returns a new BasicScrollBarUI.
Dimension
getMaximumSize(JComponent c)
This method returns the maximum size for this JComponent.
protected Dimension
getMaximumThumbSize()
This method returns the maximum thumb size.
Dimension
getMinimumSize(JComponent c)
This method returns the minimum size for this JComponent.
protected Dimension
getMinimumThumbSize()
This method returns the minimum thumb size.
Dimension
getPreferredSize(JComponent c)
This method returns a cached value of the preferredSize.
boolean
getSupportsAbsolutePositioning()
Indicates whether the user can position the thumb with a mouse click (i.e. middle button).
protected Rectangle
getThumbBounds()
This method returns the thumb's bounds based on the current value of the scrollbar.
protected Rectangle
getTrackBounds()
This method calculates the bounds of the track.
protected void
installComponents()
This method installs any addition Components that are a part of or related to this scrollbar.
protected void
installDefaults()
This method installs the defaults for the scrollbar specified by the Basic Look and Feel.
protected void
installKeyboardActions()
Installs the input map from the look and feel defaults, and a corresponding action map.
protected void
installListeners()
This method installs any listeners for the scrollbar.
void
installUI(JComponent c)
This method installs the UI for the component.
boolean
isThumbRollover()
Returns true if the mouse is over the thumb.
void
layoutContainer(Container scrollbarContainer)
This method lays out the scrollbar.
protected void
layoutHScrollbar(JScrollBar sb)
This method lays out the scrollbar horizontally.
protected void
layoutVScrollbar(JScrollBar sb)
This method lays out the scrollbar vertically.
Dimension
minimumLayoutSize(Container scrollbarContainer)
This method returns the minimum size required for the layout.
void
paint(Graphics g, JComponent c)
This method is called when the component is painted.
protected void
paintDecreaseHighlight(Graphics g)
This method is called when repainting and the mouse is pressed in the track.
protected void
paintIncreaseHighlight(Graphics g)
This method is called when repainting and the mouse is pressed in the track.
protected void
paintThumb(Graphics g, JComponent c, Rectangle thumbBounds)
This method paints the thumb.
protected void
paintTrack(Graphics g, JComponent c, Rectangle trackBounds)
This method paints the track.
Dimension
preferredLayoutSize(Container scrollbarContainer)
This method returns the preferred size for the layout.
void
removeLayoutComponent(Component child)
This method removes a child component from the layout.
protected void
scrollByBlock(int direction)
The method scrolls the thumb by a block in the direction specified.
protected void
scrollByUnit(int direction)
The method scrolls the thumb by a unit in the direction specified.
protected void
setThumbBounds(int x, int y, int width, int height)
This method sets the thumb's bounds.
protected void
setThumbRollover(boolean active)
Set thumbRollover to active.
protected void
uninstallComponents()
This method uninstalls any components that are a part of or related to this scrollbar.
protected void
uninstallDefaults()
This method uninstalls any defaults that this scrollbar acquired from the Basic Look and Feel defaults.
protected void
uninstallKeyboardActions()
Uninstalls the input map and action map installed by installKeyboardActions().
protected void
uninstallListeners()
This method uninstalls any listeners that were registered during install.
void
uninstallUI(JComponent c)
This method uninstalls the UI.

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

Field Details

DECREASE_HIGHLIGHT

protected static final int DECREASE_HIGHLIGHT
Indicates that the decrease highlight should be painted.
Field Value:
1

INCREASE_HIGHLIGHT

protected static final int INCREASE_HIGHLIGHT
Indicates that the increase highlight should be painted.
Field Value:
2

NO_HIGHLIGHT

protected static final int NO_HIGHLIGHT
Indicates that no highlight should be painted.
Field Value:
0

buttonListener

protected BasicScrollBarUI.ArrowButtonListener buttonListener
The listener that listens to the JButtons.

decrButton

protected JButton decrButton
The JButton that decrements the scrollbar's value.

incrButton

protected JButton incrButton
The JButton that increments the scrollbar's value.

isDragging

protected boolean isDragging
FIXME: Use this for something (presumably mouseDragged)

maximumThumbSize

protected Dimension maximumThumbSize
The dimensions of the maximum thumb size.

minimumThumbSize

protected Dimension minimumThumbSize
The dimensions of the minimum thumb size.

modelListener

protected BasicScrollBarUI.ModelListener modelListener
The listener that listens to the model.

propertyChangeListener

protected PropertyChangeListener propertyChangeListener
The listener that listens to the scrollbar for property changes.

scrollListener

protected BasicScrollBarUI.ScrollListener scrollListener
The listener that listens to the timer.

scrollTimer

protected Timer scrollTimer
The timer used to move the thumb when the mouse is held.

scrollbar

protected JScrollBar scrollbar
The scrollbar this UI is acting for.

thumbColor

protected Color thumbColor
The color of the thumb.

thumbDarkShadowColor

protected Color thumbDarkShadowColor
The outer shadow of the thumb.

thumbHighlightColor

protected Color thumbHighlightColor
The top and left edge color for the thumb.

thumbLightShadowColor

protected Color thumbLightShadowColor
The outer light shadow for the thumb.

thumbRect

protected Rectangle thumbRect
The size and position of the thumb.

trackColor

protected Color trackColor
The color of the track.

trackHighlight

protected int trackHighlight
The current highlight status.

trackHighlightColor

protected Color trackHighlightColor
The color that is used when the mouse press occurs in the track.

trackListener

protected BasicScrollBarUI.TrackListener trackListener
The listener that listens for MouseEvents on the track.

trackRect

protected Rectangle trackRect
The size and position of the track.

Method Details

addLayoutComponent

public void addLayoutComponent(String name,
                               Component child)
This method adds a component to the layout.
Specified by:
addLayoutComponent in interface LayoutManager
Parameters:
name - The name to associate with the component that is added.
child - The Component to add.

configureScrollBarColors

protected void configureScrollBarColors()
This method configures the scrollbar's colors. This can be done by looking up the standard colors from the Look and Feel defaults.

createArrowButtonListener

protected BasicScrollBarUI.ArrowButtonListener createArrowButtonListener()
This method creates an ArrowButtonListener.
Returns:
A new ArrowButtonListener.

createDecreaseButton

protected JButton createDecreaseButton(int orientation)
This method creates a new JButton with the appropriate icon for the orientation.
Parameters:
orientation - The orientation this JButton uses.
Returns:
The decrease JButton.

createIncreaseButton

protected JButton createIncreaseButton(int orientation)
This method creates a new JButton with the appropriate icon for the orientation.
Parameters:
orientation - The orientation this JButton uses.
Returns:
The increase JButton.

createModelListener

protected BasicScrollBarUI.ModelListener createModelListener()
This method creates a new ModelListener.
Returns:
A new ModelListener.

createPropertyChangeListener

protected PropertyChangeListener createPropertyChangeListener()
This method creates a new PropertyChangeListener.
Returns:
A new PropertyChangeListener.

createScrollListener

protected BasicScrollBarUI.ScrollListener createScrollListener()
This method creates a new ScrollListener.
Returns:
A new ScrollListener.

createTrackListener

protected BasicScrollBarUI.TrackListener createTrackListener()
This method creates a new TrackListener.
Returns:
A new TrackListener.

createUI

public static ComponentUI createUI(JComponent c)
This method returns a new BasicScrollBarUI.
Overrides:
createUI in interface ComponentUI
Parameters:
c - The JComponent to create a UI for.
Returns:
A new BasicScrollBarUI.

getMaximumSize

public Dimension getMaximumSize(JComponent c)
This method returns the maximum size for this JComponent.
Overrides:
getMaximumSize in interface ComponentUI
Parameters:
c - The JComponent to measure the maximum size for.
Returns:
The maximum size for the component.

getMaximumThumbSize

protected Dimension getMaximumThumbSize()
This method returns the maximum thumb size.
Returns:
The maximum thumb size.

getMinimumSize

public Dimension getMinimumSize(JComponent c)
This method returns the minimum size for this JComponent.
Overrides:
getMinimumSize in interface ComponentUI
Parameters:
c - The JComponent to measure the minimum size for.
Returns:
The minimum size for the component.

getMinimumThumbSize

protected Dimension getMinimumThumbSize()
This method returns the minimum thumb size.
Returns:
The minimum thumb size.

getPreferredSize

public Dimension getPreferredSize(JComponent c)
This method returns a cached value of the preferredSize. The only restrictions are: If the scrollbar is horizontal, the height should be the maximum of the height of the JButtons and the minimum width of the thumb. For vertical scrollbars, the calculation is similar (swap width for height and vice versa).
Overrides:
getPreferredSize in interface ComponentUI
Parameters:
c - The JComponent to measure.
Returns:
The preferredSize.

getSupportsAbsolutePositioning

public boolean getSupportsAbsolutePositioning()
Indicates whether the user can position the thumb with a mouse click (i.e. middle button).
Returns:
true if the user can position the thumb with a mouse click.
Since:
1.5

getThumbBounds

protected Rectangle getThumbBounds()
This method returns the thumb's bounds based on the current value of the scrollbar. This method updates the cached value and returns that.
Returns:
The thumb bounds.

getTrackBounds

protected Rectangle getTrackBounds()
This method calculates the bounds of the track. This method updates the cached value and returns it.
Returns:
The track's bounds.

installComponents

protected void installComponents()
This method installs any addition Components that are a part of or related to this scrollbar.

installDefaults

protected void installDefaults()
This method installs the defaults for the scrollbar specified by the Basic Look and Feel.

installKeyboardActions

protected void installKeyboardActions()
Installs the input map from the look and feel defaults, and a corresponding action map. Note the the keyboard bindings will only work when the JScrollBar component has the focus, which is rare.

installListeners

protected void installListeners()
This method installs any listeners for the scrollbar. This method also installs listeners for things such as the JButtons and the timer.

installUI

public void installUI(JComponent c)
This method installs the UI for the component. This can include setting up listeners, defaults, and components. This also includes initializing any data objects.
Overrides:
installUI in interface ComponentUI
Parameters:
c - The JComponent to install.

isThumbRollover

public boolean isThumbRollover()
Returns true if the mouse is over the thumb.
Returns:
true if the mouse is over the thumb.
Since:
1.5

layoutContainer

public void layoutContainer(Container scrollbarContainer)
This method lays out the scrollbar.
Specified by:
layoutContainer in interface LayoutManager
Parameters:
scrollbarContainer - The Container to layout.

layoutHScrollbar

protected void layoutHScrollbar(JScrollBar sb)
This method lays out the scrollbar horizontally.
Parameters:
sb - The JScrollBar to layout.

layoutVScrollbar

protected void layoutVScrollbar(JScrollBar sb)
This method lays out the scrollbar vertically.
Parameters:
sb - The JScrollBar to layout.

minimumLayoutSize

public Dimension minimumLayoutSize(Container scrollbarContainer)
This method returns the minimum size required for the layout.
Specified by:
minimumLayoutSize in interface LayoutManager
Parameters:
scrollbarContainer - The Container that is laid out.
Returns:
The minimum size.

paint

public void paint(Graphics g,
                  JComponent c)
This method is called when the component is painted.
Overrides:
paint in interface ComponentUI
Parameters:
g - The Graphics object to paint with.
c - The JComponent to paint.

paintDecreaseHighlight

protected void paintDecreaseHighlight(Graphics g)
This method is called when repainting and the mouse is pressed in the track. It paints the track below the thumb with the trackHighlight color.
Parameters:
g - The Graphics object to paint with.

paintIncreaseHighlight

protected void paintIncreaseHighlight(Graphics g)
This method is called when repainting and the mouse is pressed in the track. It paints the track above the thumb with the trackHighlight color.
Parameters:
g - The Graphics objet to paint with.

paintThumb

protected void paintThumb(Graphics g,
                          JComponent c,
                          Rectangle thumbBounds)
This method paints the thumb.
Parameters:
g - The Graphics object to paint with.
c - The Component that is being painted.
thumbBounds - The thumb bounds.

paintTrack

protected void paintTrack(Graphics g,
                          JComponent c,
                          Rectangle trackBounds)
This method paints the track.
Parameters:
g - The Graphics object to paint with.
c - The JComponent being painted.
trackBounds - The track's bounds.

preferredLayoutSize

public Dimension preferredLayoutSize(Container scrollbarContainer)
This method returns the preferred size for the layout.
Specified by:
preferredLayoutSize in interface LayoutManager
Parameters:
scrollbarContainer - The Container to find a size for.
Returns:
The preferred size for the layout.

removeLayoutComponent

public void removeLayoutComponent(Component child)
This method removes a child component from the layout.
Specified by:
removeLayoutComponent in interface LayoutManager
Parameters:
child - The child to remove.

scrollByBlock

protected void scrollByBlock(int direction)
The method scrolls the thumb by a block in the direction specified.
Parameters:
direction - The direction to scroll.

scrollByUnit

protected void scrollByUnit(int direction)
The method scrolls the thumb by a unit in the direction specified.
Parameters:
direction - The direction to scroll.

setThumbBounds

protected void setThumbBounds(int x,
                              int y,
                              int width,
                              int height)
This method sets the thumb's bounds.
Parameters:
x - The X position of the thumb.
y - The Y position of the thumb.
width - The width of the thumb.
height - The height of the thumb.

setThumbRollover

protected void setThumbRollover(boolean active)
Set thumbRollover to active. This indicates whether or not the mouse is over the thumb.
Parameters:
active - - true if the mouse is over the thumb.
Since:
1.5

uninstallComponents

protected void uninstallComponents()
This method uninstalls any components that are a part of or related to this scrollbar.

uninstallDefaults

protected void uninstallDefaults()
This method uninstalls any defaults that this scrollbar acquired from the Basic Look and Feel defaults.

uninstallKeyboardActions

protected void uninstallKeyboardActions()
Uninstalls the input map and action map installed by installKeyboardActions().

uninstallListeners

protected void uninstallListeners()
This method uninstalls any listeners that were registered during install.

uninstallUI

public void uninstallUI(JComponent c)
This method uninstalls the UI. This includes removing any defaults, listeners, and components that this UI may have initialized. It also nulls any instance data.
Overrides:
uninstallUI in interface ComponentUI
Parameters:
c - The Component to uninstall for.

BasicScrollBarUI.java -- Copyright (C) 2004, 2005, 2006, Free Software Foundation, Inc. This file is part of GNU Classpath. GNU Classpath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. GNU Classpath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Linking this library statically or dynamically with other modules is making a combined work based on this library. Thus, the terms and conditions of the GNU General Public License cover the whole combination. As a special exception, the copyright holders of this library give you permission to link this library with independent modules to produce an executable, regardless of the license terms of these independent modules, and to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each linked independent module, the terms and conditions of the license of that module. An independent module is a module which is not derived from or based on this library. If you modify this library, you may extend this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version.