javax.swing.plaf.basic

Class BasicProgressBarUI

public class BasicProgressBarUI extends ProgressBarUI

The Basic Look and Feel UI delegate for the JProgressBar.
Nested Class Summary
classBasicProgressBarUI.ChangeHandler
A helper class that listens for ChangeEvents from the progressBar's model.
Field Summary
protected RectangleboxRect
Holds the value of the bouncing box that is returned by {@link #getBox}.
protected ChangeListenerchangeListener
The Listener for the model.
protected JProgressBarprogressBar
The progressBar for this UI.
Constructor Summary
BasicProgressBarUI()
Creates a new BasicProgressBarUI object.
Method Summary
static ComponentUIcreateUI(JComponent x)
Creates a new BasicProgressBarUI for the component.
protected intgetAmountFull(Insets b, int width, int height)
This method returns the length of the bar (from the minimum) in pixels (or units that the Graphics object draws in) based on the progressBar's getPercentComplete() value.
protected intgetAnimationIndex()
The current animation index.
protected RectanglegetBox(Rectangle r)
This method returns the size and position of the bouncing box for the current animation index.
protected intgetCellLength()
This method returns the length of the cells.
protected intgetCellSpacing()
This method returns the spacing between cells.
DimensiongetMaximumSize(JComponent c)
This method returns the maximum size of the JComponent.
DimensiongetMinimumSize(JComponent c)
This method returns the minimum size of the JComponent.
protected DimensiongetPreferredInnerHorizontal()
This method returns the preferred size of the inner rectangle (the bounds without the insets) if the progressBar is horizontal.
protected DimensiongetPreferredInnerVertical()
This method returns the preferred size of the inner rectangle (the bounds without insets) if the progressBar is vertical.
DimensiongetPreferredSize(JComponent c)
This method returns the preferred size of the given JComponent.
protected ColorgetSelectionBackground()
This method returns the Color that the text is shown in when the bar is not over the text.
protected ColorgetSelectionForeground()
This method returns the Color that the text is shown in when the bar is over the text.
protected PointgetStringPlacement(Graphics g, String progressString, int x, int y, int width, int height)
This method returns the point (the top left of the bounding box) where the text should be painted.
protected voidincrementAnimationIndex()
This method increments the animation index.
protected voidinstallDefaults()
This method changes the settings for the progressBar to the defaults provided by the current Look and Feel.
protected voidinstallListeners()
This method registers listeners to all the components that this UI delegate needs to listen to.
voidinstallUI(JComponent c)
This method installs the UI for the given JComponent.
voidpaint(Graphics g, JComponent c)
This method paints the progressBar.
protected voidpaintDeterminate(Graphics g, JComponent c)
This method is called if the painting to be done is for a determinate progressBar.
protected voidpaintIndeterminate(Graphics g, JComponent c)
This method is called if the painting to be done is for an indeterminate progressBar.
protected voidpaintString(Graphics g, int x, int y, int width, int height, int amountFull, Insets b)
This method paints the string for the progressBar.
protected voidsetAnimationIndex(int newValue)
This method sets the current animation index.
protected voidsetCellLength(int cellLen)
This method sets the cell length.
protected voidsetCellSpacing(int cellSpace)
This method sets the cell spacing.
protected voidstartAnimationTimer()
This method starts the animation timer.
protected voidstopAnimationTimer()
This method stops the animation timer.
protected voiduninstallDefaults()
The method uninstalls any defaults that were set by the current Look and Feel.
protected voiduninstallListeners()
This method unregisters listeners to all the components that were listened to.
voiduninstallUI(JComponent c)
This method removes the UI for the given JComponent.

Field Detail

boxRect

protected Rectangle boxRect
Holds the value of the bouncing box that is returned by {@link #getBox}.

Since: 1.5

changeListener

protected ChangeListener changeListener
The Listener for the model.

progressBar

protected JProgressBar progressBar
The progressBar for this UI.

Constructor Detail

BasicProgressBarUI

public BasicProgressBarUI()
Creates a new BasicProgressBarUI object.

Method Detail

createUI

public static ComponentUI createUI(JComponent x)
Creates a new BasicProgressBarUI for the component.

Parameters: x The JComponent to create the UI for.

Returns: A new BasicProgressBarUI.

getAmountFull

protected int getAmountFull(Insets b, int width, int height)
This method returns the length of the bar (from the minimum) in pixels (or units that the Graphics object draws in) based on the progressBar's getPercentComplete() value.

Parameters: b The insets of the progressBar. width The width of the progressBar. height The height of the progressBar.

Returns: The length of the bar that should be painted in pixels.

getAnimationIndex

protected int getAnimationIndex()
The current animation index.

Returns: The current animation index.

getBox

protected Rectangle getBox(Rectangle r)
This method returns the size and position of the bouncing box for the current animation index. It stores the values in the given rectangle and returns it. It returns null if no box should be drawn.

Parameters: r The bouncing box rectangle.

Returns: The bouncing box rectangle.

getCellLength

protected int getCellLength()
This method returns the length of the cells.

Returns: The cell length.

getCellSpacing

protected int getCellSpacing()
This method returns the spacing between cells.

Returns: The cell gap.

getMaximumSize

public Dimension getMaximumSize(JComponent c)
This method returns the maximum size of the JComponent. If it returns null, it is up to the LayoutManager to give it a size.

Parameters: c The component to find a maximum size for.

Returns: The maximum size.

getMinimumSize

public Dimension getMinimumSize(JComponent c)
This method returns the minimum size of the JComponent. If it returns null, it is up to the LayoutManager to give it a size.

Parameters: c The component to find a minimum size for.

Returns: The minimum size.

getPreferredInnerHorizontal

protected Dimension getPreferredInnerHorizontal()
This method returns the preferred size of the inner rectangle (the bounds without the insets) if the progressBar is horizontal.

Returns: The preferred size of the progressBar minus insets if it's horizontal.

getPreferredInnerVertical

protected Dimension getPreferredInnerVertical()
This method returns the preferred size of the inner rectangle (the bounds without insets) if the progressBar is vertical.

Returns: The preferred size of the progressBar minus insets if it's vertical.

getPreferredSize

public Dimension getPreferredSize(JComponent c)
This method returns the preferred size of the given JComponent. If it returns null, then it is up to the LayoutManager to give it a size.

Parameters: c The component to find the preferred size for.

Returns: The preferred size of the component.

getSelectionBackground

protected Color getSelectionBackground()
This method returns the Color that the text is shown in when the bar is not over the text.

Returns: The color of the text when the bar is not over it.

getSelectionForeground

protected Color getSelectionForeground()
This method returns the Color that the text is shown in when the bar is over the text.

Returns: The color of the text when the bar is over it.

getStringPlacement

protected Point getStringPlacement(Graphics g, String progressString, int x, int y, int width, int height)
This method returns the point (the top left of the bounding box) where the text should be painted.

Parameters: g The Graphics object to measure FontMetrics with. progressString The string to paint. x The x coordinate of the overall bounds box. y The y coordinate of the overall bounds box. width The width of the overall bounds box. height The height of the overall bounds box.

Returns: The top left of the bounding box where text should be painted.

incrementAnimationIndex

protected void incrementAnimationIndex()
This method increments the animation index.

installDefaults

protected void installDefaults()
This method changes the settings for the progressBar to the defaults provided by the current Look and Feel.

installListeners

protected void installListeners()
This method registers listeners to all the components that this UI delegate needs to listen to.

installUI

public void installUI(JComponent c)
This method installs the UI for the given JComponent. This includes setting up defaults and listeners as well as initializing any values or objects that the UI may need.

Parameters: c The JComponent that is having this UI installed.

paint

public void paint(Graphics g, JComponent c)
This method paints the progressBar. It delegates its responsibilities to paintDeterminate and paintIndeterminate.

Parameters: g The Graphics object to paint with. c The JComponent to paint.

paintDeterminate

protected void paintDeterminate(Graphics g, JComponent c)
This method is called if the painting to be done is for a determinate progressBar.

Parameters: g The Graphics object to paint with. c The JComponent to paint.

paintIndeterminate

protected void paintIndeterminate(Graphics g, JComponent c)
This method is called if the painting to be done is for an indeterminate progressBar.

Parameters: g The Graphics object to paint with. c The JComponent to paint.

paintString

protected void paintString(Graphics g, int x, int y, int width, int height, int amountFull, Insets b)
This method paints the string for the progressBar.

Parameters: g The Graphics object to paint with. x The x coordinate of the progressBar. y The y coordinate of the progressBar. width The width of the progressBar. height The height of the progressBar. amountFull The amount of the progressBar that has its bar filled. b The insets of the progressBar.

setAnimationIndex

protected void setAnimationIndex(int newValue)
This method sets the current animation index. If the index is greater than the number of frames, it resets to 0.

Parameters: newValue The new animation index.

setCellLength

protected void setCellLength(int cellLen)
This method sets the cell length.

Parameters: cellLen The cell length.

setCellSpacing

protected void setCellSpacing(int cellSpace)
This method sets the cell spacing.

Parameters: cellSpace The cell spacing.

startAnimationTimer

protected void startAnimationTimer()
This method starts the animation timer. It is called when the propertyChangeListener detects that the progressBar has changed to indeterminate mode.

Since: 1.4

stopAnimationTimer

protected void stopAnimationTimer()
This method stops the animation timer. It is called when the propertyChangeListener detects that the progressBar has changed to determinate mode.

Since: 1.4

uninstallDefaults

protected void uninstallDefaults()
The method uninstalls any defaults that were set by the current Look and Feel.

uninstallListeners

protected void uninstallListeners()
This method unregisters listeners to all the components that were listened to.

uninstallUI

public void uninstallUI(JComponent c)
This method removes the UI for the given JComponent. This includes removing any listeners or defaults that the installUI may have set up.

Parameters: c The JComponent that is having this UI uninstalled.