- java.lang.Object
- 
- javax.swing.plaf.ComponentUI
- 
- javax.swing.plaf.ProgressBarUI
- 
- javax.swing.plaf.basic.BasicProgressBarUI
 
 
 
- 
- Direct Known Subclasses:
- MetalProgressBarUI,- SynthProgressBarUI
 
 public class BasicProgressBarUI extends ProgressBarUI A Basic L&F implementation of ProgressBarUI.
- 
- 
Nested Class SummaryNested Classes Modifier and Type Class Description classBasicProgressBarUI.ChangeHandlerThis class should be treated as a "protected" inner class.
 - 
Field SummaryFields Modifier and Type Field Description protected RectangleboxRectUsed to hold the location and size of the bouncing box (returned by getBox) to be painted.protected ChangeListenerchangeListenerThe instance ofChangeListener.protected JProgressBarprogressBarThe instance ofJProgressBar.
 - 
Constructor SummaryConstructors Constructor Description BasicProgressBarUI()
 - 
Method SummaryAll Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static ComponentUIcreateUI(JComponent x)Returns a new instance ofBasicProgressBarUI.protected intgetAmountFull(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 intgetAnimationIndex()Gets the index of the current animation frame.intgetBaseline(JComponent c, int width, int height)Returns the baseline.Component.BaselineResizeBehaviorgetBaselineResizeBehavior(JComponent c)Returns an enum indicating how the baseline of the component changes as the size changes.protected RectanglegetBox(Rectangle r)Stores the position and size of the bouncing box that would be painted for the current animation index inrand returnsr.protected intgetBoxLength(int availableLength, int otherDimension)Returns the length of the "bouncing box" to be painted.protected intgetCellLength()Returns the width (if HORIZONTAL) or height (if VERTICAL) of each of the individual cells/units to be rendered in the progress bar.protected intgetCellSpacing()Returns the spacing between each of the cells/units in the progress bar.protected intgetFrameCount()Returns the number of frames for the complete animation loop used by an indeterminate JProgessBar.DimensiongetMinimumSize(JComponent c)The Minimum size for this component is 10.protected DimensiongetPreferredInnerHorizontal()Returns preferred size of the horizontalJProgressBar.protected DimensiongetPreferredInnerVertical()Returns preferred size of the verticalJProgressBar.protected ColorgetSelectionBackground()The "selectionBackground" is the color of the text when it is painted over an unfilled area of the progress bar.protected ColorgetSelectionForeground()The "selectionForeground" is the color of the text when it is painted over a filled area of the progress bar.protected PointgetStringPlacement(Graphics g, String progressString, int x, int y, int width, int height)Designate the place where the progress string will be painted.protected voidincrementAnimationIndex()Sets the index of the current animation frame, to the next valid value, which results in the progress bar being repainted.protected voidinstallDefaults()Installs default properties.protected voidinstallListeners()Registers listeners.voidpaint(Graphics g, JComponent c)Delegates painting to one of two methods: paintDeterminate or paintIndeterminate.protected voidpaintDeterminate(Graphics g, JComponent c)All purpose paint method that should do the right thing for almost all linear, determinate progress bars.protected voidpaintIndeterminate(Graphics g, JComponent c)All purpose paint method that should do the right thing for all linear bouncing-box progress bars.protected voidpaintString(Graphics g, int x, int y, int width, int height, int amountFull, Insets b)Paints the progress string.protected voidsetAnimationIndex(int newValue)Sets the index of the current animation frame to the specified value and requests that the progress bar be repainted.protected voidsetCellLength(int cellLen)Sets the cell length.protected voidsetCellSpacing(int cellSpace)Sets the cell spacing.protected voidstartAnimationTimer()Starts the animation thread, creating and initializing it if necessary.protected voidstopAnimationTimer()Stops the animation thread.protected voiduninstallDefaults()Unintalls default properties.protected voiduninstallListeners()Removes all listeners installed by this object.- 
Methods declared in class javax.swing.plaf.ComponentUIcontains, getAccessibleChild, getAccessibleChildrenCount, getMaximumSize, getPreferredSize, installUI, uninstallUI, update
 
- 
 
- 
- 
- 
Field Detail- 
progressBarprotected JProgressBar progressBar The instance ofJProgressBar.
 - 
changeListenerprotected ChangeListener changeListener The instance ofChangeListener.
 - 
boxRectprotected Rectangle boxRect Used to hold the location and size of the bouncing box (returned by getBox) to be painted.- Since:
- 1.5
 
 
- 
 - 
Method Detail- 
createUIpublic static ComponentUI createUI(JComponent x) Returns a new instance ofBasicProgressBarUI.- Parameters:
- x- a component
- Returns:
- a new instance of BasicProgressBarUI
 
 - 
installDefaultsprotected void installDefaults() Installs default properties.
 - 
uninstallDefaultsprotected void uninstallDefaults() Unintalls default properties.
 - 
installListenersprotected void installListeners() Registers listeners.
 - 
startAnimationTimerprotected 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()
 
 - 
stopAnimationTimerprotected 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:
- startAnimationTimer()
 
 - 
uninstallListenersprotected void uninstallListeners() Removes all listeners installed by this object.
 - 
getBaselinepublic int getBaseline(JComponent c, int width, int height) Returns the baseline.- Overrides:
- getBaselinein class- ComponentUI
- Parameters:
- c-- JComponentbaseline is being requested for
- width- the width to get the baseline for
- height- the height to get the baseline for
- Returns:
- baseline or a value < 0 indicating there is no reasonable baseline
- Throws:
- NullPointerException- if- cis- null
- IllegalArgumentException- if width or height is < 0
- Since:
- 1.6
- See Also:
- JComponent.getBaseline(int, int)
 
 - 
getBaselineResizeBehaviorpublic Component.BaselineResizeBehavior getBaselineResizeBehavior(JComponent c) Returns an enum indicating how the baseline of the component changes as the size changes.- Overrides:
- getBaselineResizeBehaviorin class- ComponentUI
- Parameters:
- c-- JComponentto return baseline resize behavior for
- Returns:
- an enum indicating how the baseline changes as the component size changes
- Throws:
- NullPointerException- if- cis- null
- Since:
- 1.6
- See Also:
- JComponent.getBaseline(int, int)
 
 - 
getPreferredInnerHorizontalprotected Dimension getPreferredInnerHorizontal() Returns preferred size of the horizontalJProgressBar.- Returns:
- preferred size of the horizontal JProgressBar
 
 - 
getPreferredInnerVerticalprotected Dimension getPreferredInnerVertical() Returns preferred size of the verticalJProgressBar.- Returns:
- preferred size of the vertical JProgressBar
 
 - 
getSelectionForegroundprotected Color 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
 
 - 
getSelectionBackgroundprotected Color 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
 
 - 
getCellLengthprotected 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(int),- JProgressBar.isStringPainted()
 
 - 
setCellLengthprotected void setCellLength(int cellLen) Sets the cell length.- Parameters:
- cellLen- a new cell length
 
 - 
getCellSpacingprotected 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(int),- JProgressBar.isStringPainted()
 
 - 
setCellSpacingprotected void setCellSpacing(int cellSpace) Sets the cell spacing.- Parameters:
- cellSpace- a new cell spacing
 
 - 
getAmountFullprotected 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. 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- insets
- width- a width
- height- a height
- Returns:
- the amount of the progress bar that should be filled
 
 - 
paintpublic void paint(Graphics g, JComponent c) Delegates painting to one of two methods: paintDeterminate or paintIndeterminate.- Overrides:
- paintin class- ComponentUI
- Parameters:
- g- the- Graphicscontext in which to paint
- c- 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:
- ComponentUI.update(java.awt.Graphics, javax.swing.JComponent)
 
 - 
getBoxprotected Rectangle getBox(Rectangle r) Stores the position and size of the bouncing box that would be painted for the current animation index inrand 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 be- null
- Returns:
- nullif no box should be drawn; otherwise, returns the passed-in rectangle (if non-null) or a new rectangle
- Since:
- 1.4
- See Also:
- setAnimationIndex(int)
 
 - 
getBoxLengthprotected int getBoxLength(int availableLength, int otherDimension)Returns the length of the "bouncing box" to be painted. This method is invoked by the default implementation ofpaintIndeterminateto get the width (if the progress bar is horizontal) or height (if vertical) of the box. For example:boxRect.width = getBoxLength(componentInnards.width, componentInnards.height);- Parameters:
- availableLength- the amount of space available for the bouncing box to move in; for a horizontal progress bar, for example, this should be the inside width of the progress bar (the component width minus borders)
- otherDimension- for a horizontal progress bar, this should be the inside height of the progress bar; this value might be used to constrain or determine the return value
- Returns:
- the size of the box dimension being determined;
         must be no larger than availableLength
- Since:
- 1.5
- See Also:
- SwingUtilities.calculateInnerArea(javax.swing.JComponent, java.awt.Rectangle)
 
 - 
paintIndeterminateprotected void paintIndeterminate(Graphics g, JComponent c) All purpose paint method that should do the right thing for all linear bouncing-box progress bars. Override this if you are making another kind of progress bar.- Parameters:
- g- an instance of- Graphics
- c- a component
- Since:
- 1.4
- See Also:
- paintDeterminate(java.awt.Graphics, javax.swing.JComponent)
 
 - 
paintDeterminateprotected void paintDeterminate(Graphics g, JComponent c) All purpose paint method that should do the right thing for almost all linear, determinate progress bars. By setting a few values in the defaults table, things should work just fine to paint your progress bar. Naturally, override this if you are making a circular or semi-circular progress bar.- Parameters:
- g- an instance of- Graphics
- c- a component
- Since:
- 1.4
- See Also:
- paintIndeterminate(java.awt.Graphics, javax.swing.JComponent)
 
 - 
paintStringprotected void paintString(Graphics g, int x, int y, int width, int height, int amountFull, Insets b) Paints the progress string.- Parameters:
- g- an instance of- Graphics
- x- X location of bounding box
- y- Y location of bounding box
- width- width of bounding box
- height- height of bounding box
- amountFull- size of the fill region, either width or height depending upon orientation.
- b- Insets of the progress bar.
 
 - 
getStringPlacementprotected Point getStringPlacement(Graphics g, String progressString, int x, int y, int width, int height) Designate the place where the progress string will be painted. This implementation places it at the center of the progress bar (in both x and y). Override this if you want to right, left, top, or bottom align the progress string or if you need to nudge it around for any reason.- Parameters:
- g- an instance of- Graphics
- progressString- a text
- x- an X coordinate
- y- an Y coordinate
- width- a width
- height- a height
- Returns:
- the place where the progress string will be painted
 
 - 
getMinimumSizepublic Dimension getMinimumSize(JComponent c) The Minimum size for this component is 10. The rationale here is that there should be at least one pixel per 10 percent.- Overrides:
- getMinimumSizein class- ComponentUI
- Parameters:
- c- the component whose minimum size is being queried; this argument is often ignored, but might be used if the UI object is stateless and shared by multiple components
- Returns:
- a Dimensionobject ornull
- See Also:
- JComponent.getMinimumSize(),- LayoutManager.minimumLayoutSize(java.awt.Container),- ComponentUI.getPreferredSize(javax.swing.JComponent)
 
 - 
getAnimationIndexprotected int getAnimationIndex() Gets the index of the current animation frame.- Returns:
- the index of the current animation frame
- Since:
- 1.4
 
 - 
getFrameCountprotected final int getFrameCount() Returns the number of frames for the complete animation loop used by an indeterminate JProgessBar. The progress chunk will go from one end to the other and back during the entire loop. This visual behavior may be changed by subclasses in other Look and Feels.- Returns:
- the number of frames
- Since:
- 1.6
 
 - 
setAnimationIndexprotected void setAnimationIndex(int newValue) Sets the index of the current animation frame to the specified value and requests that the progress bar be repainted. Subclasses that don't use the default painting code might need to override this method to change the way that therepaintmethod is invoked.- Parameters:
- newValue- the new animation index; no checking is performed on its value
- Since:
- 1.4
- See Also:
- incrementAnimationIndex()
 
 - 
incrementAnimationIndexprotected void incrementAnimationIndex() Sets the index of the current animation frame, to the next valid value, which results in the progress bar being repainted. The next valid value is, by default, the current animation index plus one. If the new value would be too large, this method sets the index to 0. Subclasses might need to override this method to ensure that the index does not go over the number of frames needed for the particular progress bar instance. This method is invoked by the default animation thread every X milliseconds, where X is specified by the "ProgressBar.repaintInterval" UI default.- Since:
- 1.4
- See Also:
- setAnimationIndex(int)
 
 
- 
 
-