java.lang.Object
javax.swing.plaf.ComponentUI
javax.swing.plaf.ProgressBarUI
javax.swing.plaf.basic.BasicProgressBarUI
- Direct Known Subclasses:
MetalProgressBarUI
,SynthProgressBarUI
A Basic L&F implementation of ProgressBarUI.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclass
This class should be treated as a "protected" inner class. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Rectangle
Used to hold the location and size of the bouncing box (returned by getBox) to be painted.protected ChangeListener
The instance ofChangeListener
.protected JProgressBar
The instance ofJProgressBar
. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic ComponentUI
Returns a new instance ofBasicProgressBarUI
.protected int
getAmountFull
(Insets b, int width, int height) This determines the amount of the progress bar that should be filled based on the percent done gathered from the model.protected int
Gets the index of the current animation frame.int
getBaseline
(JComponent c, int width, int height) Returns the baseline.Returns an enum indicating how the baseline of the component changes as the size changes.protected Rectangle
Stores the position and size of the bouncing box that would be painted for the current animation index inr
and returnsr
.protected int
getBoxLength
(int availableLength, int otherDimension) Returns the length of the "bouncing box" to be painted.protected int
Returns the width (if HORIZONTAL) or height (if VERTICAL) of each of the individual cells/units to be rendered in the progress bar.protected int
Returns the spacing between each of the cells/units in the progress bar.protected final int
Returns the number of frames for the complete animation loop used by an indeterminate JProgessBar.The Minimum size for this component is 10.protected Dimension
Returns preferred size of the horizontalJProgressBar
.protected Dimension
Returns preferred size of the verticalJProgressBar
.protected Color
The "selectionBackground" is the color of the text when it is painted over an unfilled area of the progress bar.protected Color
The "selectionForeground" is the color of the text when it is painted over a filled area of the progress bar.protected Point
getStringPlacement
(Graphics g, String progressString, int x, int y, int width, int height) Designate the place where the progress string will be painted.protected void
Sets the index of the current animation frame, to the next valid value, which results in the progress bar being repainted.protected void
Installs default properties.protected void
Registers listeners.void
paint
(Graphics g, JComponent c) Delegates painting to one of two methods: paintDeterminate or paintIndeterminate.protected void
All purpose paint method that should do the right thing for almost all linear, determinate progress bars.protected void
All purpose paint method that should do the right thing for all linear bouncing-box progress bars.protected void
paintString
(Graphics g, int x, int y, int width, int height, int amountFull, Insets b) Paints the progress string.protected void
setAnimationIndex
(int newValue) Sets the index of the current animation frame to the specified value and requests that the progress bar be repainted.protected void
setCellLength
(int cellLen) Sets the cell length.protected void
setCellSpacing
(int cellSpace) Sets the cell spacing.protected void
Starts the animation thread, creating and initializing it if necessary.protected void
Stops the animation thread.protected void
Unintalls default properties.protected void
Removes all listeners installed by this object.Methods declared in class javax.swing.plaf.ComponentUI
contains, getAccessibleChild, getAccessibleChildrenCount, getMaximumSize, getPreferredSize, installUI, uninstallUI, update
-
Field Details
-
progressBar
The instance ofJProgressBar
. -
changeListener
The instance ofChangeListener
. -
boxRect
Used to hold the location and size of the bouncing box (returned by getBox) to be painted.- Since:
- 1.5
-
-
Constructor Details
-
BasicProgressBarUI
public BasicProgressBarUI()Constructs aBasicProgressBarUI
.
-
-
Method Details
-
createUI
Returns a new instance ofBasicProgressBarUI
.- Parameters:
x
- a component- Returns:
- a new instance of
BasicProgressBarUI
-
installDefaults
protected void installDefaults()Installs default properties. -
uninstallDefaults
protected void uninstallDefaults()Unintalls default properties. -
installListeners
protected void installListeners()Registers listeners. -
startAnimationTimer
protected void startAnimationTimer()Starts the animation thread, creating and initializing it if necessary. This method is invoked when an indeterminate progress bar should start animating. Reasons for this may include:- The progress bar is determinate and becomes displayable
- The progress bar is displayable and becomes determinate
- The progress bar is displayable and determinate and this UI is installed
- Since:
- 1.4
- See Also:
-
stopAnimationTimer
protected void stopAnimationTimer()Stops the animation thread. This method is invoked when the indeterminate animation should be stopped. Reasons for this may include:- The progress bar changes to determinate
- The progress bar is no longer part of a displayable hierarchy
- This UI in uninstalled
- Since:
- 1.4
- See Also:
-
uninstallListeners
protected void uninstallListeners()Removes all listeners installed by this object. -
getBaseline
Returns the baseline.- Overrides:
getBaseline
in classComponentUI
- Parameters:
c
-JComponent
baseline is being requested forwidth
- the width to get the baseline forheight
- the height to get the baseline for- Returns:
- baseline or a value < 0 indicating there is no reasonable baseline
- Throws:
NullPointerException
- ifc
isnull
IllegalArgumentException
- if width or height is < 0- Since:
- 1.6
- See Also:
-
getBaselineResizeBehavior
Returns an enum indicating how the baseline of the component changes as the size changes.- Overrides:
getBaselineResizeBehavior
in classComponentUI
- Parameters:
c
-JComponent
to return baseline resize behavior for- Returns:
- an enum indicating how the baseline changes as the component size changes
- Throws:
NullPointerException
- ifc
isnull
- Since:
- 1.6
- See Also:
-
getPreferredInnerHorizontal
Returns preferred size of the horizontalJProgressBar
.- Returns:
- preferred size of the horizontal
JProgressBar
-
getPreferredInnerVertical
Returns preferred size of the verticalJProgressBar
.- Returns:
- preferred size of the vertical
JProgressBar
-
getSelectionForeground
The "selectionForeground" is the color of the text when it is painted over a filled area of the progress bar.- Returns:
- the color of the selected foreground
-
getSelectionBackground
The "selectionBackground" is the color of the text when it is painted over an unfilled area of the progress bar.- Returns:
- the color of the selected background
-
getCellLength
protected int getCellLength()Returns the width (if HORIZONTAL) or height (if VERTICAL) of each of the individual cells/units to be rendered in the progress bar. However, for text rendering simplification and aesthetic considerations, this function will return 1 when the progress string is being rendered.- Returns:
- the value representing the spacing between cells
- See Also:
-
setCellLength
protected void setCellLength(int cellLen) Sets the cell length.- Parameters:
cellLen
- a new cell length
-
getCellSpacing
protected int getCellSpacing()Returns the spacing between each of the cells/units in the progress bar. However, for text rendering simplification and aesthetic considerations, this function will return 0 when the progress string is being rendered.- Returns:
- the value representing the spacing between cells
- See Also:
-
setCellSpacing
protected void setCellSpacing(int cellSpace) Sets the cell spacing.- Parameters:
cellSpace
- a new cell spacing
-
getAmountFull
This determines the amount of the progress bar that should be filled based on the percent done gathered from the model. This is a common operation so it was abstracted out. It assumes that your progress bar is linear. That is, if you are making a circular progress indicator, you will want to override this method.- Parameters:
b
- insetswidth
- a widthheight
- a height- Returns:
- the amount of the progress bar that should be filled
-
paint
Delegates painting to one of two methods: paintDeterminate or paintIndeterminate.- Overrides:
paint
in classComponentUI
- Parameters:
g
- theGraphics
context in which to paintc
- the component being painted; this argument is often ignored, but might be used if the UI object is stateless and shared by multiple components- See Also:
-
getBox
Stores the position and size of the bouncing box that would be painted for the current animation index inr
and returnsr
. Subclasses that add to the painting performed in this class's implementation ofpaintIndeterminate
-- to draw an outline around the bouncing box, for example -- can use this method to get the location of the bouncing box that was just painted. By overriding this method, you have complete control over the size and position of the bouncing box, without having to reimplementpaintIndeterminate
.- Parameters:
r
- the Rectangle instance to be modified; may benull
- Returns:
null
if no box should be drawn; otherwise, returns the passed-in rectangle (if non-null) or a new rectangle- Since:
- 1.4
- See Also:
-