< prev index next >

src/java.desktop/share/classes/javax/swing/plaf/basic/BasicProgressBarUI.java

Print this page




 448             }
 449         }
 450         return amountFull;
 451     }
 452 
 453     /**
 454      * Delegates painting to one of two methods:
 455      * paintDeterminate or paintIndeterminate.
 456      */
 457     public void paint(Graphics g, JComponent c) {
 458         if (progressBar.isIndeterminate()) {
 459             paintIndeterminate(g, c);
 460         } else {
 461             paintDeterminate(g, c);
 462         }
 463     }
 464 
 465     /**
 466      * Stores the position and size of
 467      * the bouncing box that would be painted for the current animation index
 468      * in <code>r</code> and returns <code>r</code>.
 469      * Subclasses that add to the painting performed
 470      * in this class's implementation of <code>paintIndeterminate</code> --
 471      * to draw an outline around the bouncing box, for example --
 472      * can use this method to get the location of the bouncing
 473      * box that was just painted.
 474      * By overriding this method,
 475      * you have complete control over the size and position
 476      * of the bouncing box,
 477      * without having to reimplement <code>paintIndeterminate</code>.
 478      *
 479      * @param r  the Rectangle instance to be modified;
 480      *           may be <code>null</code>
 481      * @return   <code>null</code> if no box should be drawn;
 482      *           otherwise, returns the passed-in rectangle
 483      *           (if non-null)
 484      *           or a new rectangle
 485      *
 486      * @see #setAnimationIndex
 487      * @since 1.4
 488      */
 489     protected Rectangle getBox(Rectangle r) {
 490         int currentFrame = getAnimationIndex();
 491         int middleFrame = numFrames/2;
 492 
 493         if (sizeChanged() || delta == 0.0 || maxPosition == 0.0) {
 494             updateSizes();
 495         }
 496 
 497         r = getGenericBox(r);
 498 
 499         if (r == null) {
 500             return null;
 501         }


 570           // end of HORIZONTAL
 571 
 572         } else { //VERTICAL progress bar
 573             r.height = getBoxLength(componentInnards.height,
 574                                     componentInnards.width);
 575             if (r.height < 0) {
 576                 r = null;
 577             } else {
 578                 r.width = componentInnards.width;
 579                 r.x = componentInnards.x;
 580             }
 581         } // end of VERTICAL
 582 
 583         return r;
 584     }
 585 
 586     /**
 587      * Returns the length
 588      * of the "bouncing box" to be painted.
 589      * This method is invoked by the
 590      * default implementation of <code>paintIndeterminate</code>
 591      * to get the width (if the progress bar is horizontal)
 592      * or height (if vertical) of the box.
 593      * For example:
 594      * <blockquote>
 595      * <pre>
 596      *boxRect.width = getBoxLength(componentInnards.width,
 597      *                             componentInnards.height);
 598      * </pre>
 599      * </blockquote>
 600      *
 601      * @param availableLength  the amount of space available
 602      *                         for the bouncing box to move in;
 603      *                         for a horizontal progress bar,
 604      *                         for example,
 605      *                         this should be
 606      *                         the inside width of the progress bar
 607      *                         (the component width minus borders)
 608      * @param otherDimension   for a horizontal progress bar, this should be
 609      *                         the inside height of the progress bar; this
 610      *                         value might be used to constrain or determine
 611      *                         the return value
 612      *
 613      * @return the size of the box dimension being determined;
 614      *         must be no larger than <code>availableLength</code>
 615      *
 616      * @see javax.swing.SwingUtilities#calculateInnerArea
 617      * @since 1.5
 618      */
 619     protected int getBoxLength(int availableLength, int otherDimension) {
 620         return (int)Math.round(availableLength/6.0);
 621     }
 622 
 623     /**
 624      * All purpose paint method that should do the right thing for all
 625      * linear bouncing-box progress bars.
 626      * Override this if you are making another kind of
 627      * progress bar.
 628      *
 629      * @param g an instance of {@code Graphics}
 630      * @param c a component
 631      * @see #paintDeterminate
 632      *
 633      * @since 1.4
 634      */


 975 
 976     /**
 977      * Returns the number of frames for the complete animation loop
 978      * used by an indeterminate JProgessBar. The progress chunk will go
 979      * from one end to the other and back during the entire loop. This
 980      * visual behavior may be changed by subclasses in other Look and Feels.
 981      *
 982      * @return the number of frames
 983      * @since 1.6
 984      */
 985     protected final int getFrameCount() {
 986         return numFrames;
 987     }
 988 
 989     /**
 990      * Sets the index of the current animation frame
 991      * to the specified value and requests that the
 992      * progress bar be repainted.
 993      * Subclasses that don't use the default painting code
 994      * might need to override this method
 995      * to change the way that the <code>repaint</code> method
 996      * is invoked.
 997      *
 998      * @param newValue the new animation index; no checking
 999      *                 is performed on its value
1000      * @see #incrementAnimationIndex
1001      *
1002      * @since 1.4
1003      */
1004     protected void setAnimationIndex(int newValue) {
1005         if (animationIndex != newValue) {
1006             if (sizeChanged()) {
1007                 animationIndex = newValue;
1008                 maxPosition = 0;  //needs to be recalculated
1009                 delta = 0.0;      //needs to be recalculated
1010                 progressBar.repaint();
1011                 return;
1012             }
1013 
1014             //Get the previous box drawn.
1015             nextPaintRect = getBox(nextPaintRect);




 448             }
 449         }
 450         return amountFull;
 451     }
 452 
 453     /**
 454      * Delegates painting to one of two methods:
 455      * paintDeterminate or paintIndeterminate.
 456      */
 457     public void paint(Graphics g, JComponent c) {
 458         if (progressBar.isIndeterminate()) {
 459             paintIndeterminate(g, c);
 460         } else {
 461             paintDeterminate(g, c);
 462         }
 463     }
 464 
 465     /**
 466      * Stores the position and size of
 467      * the bouncing box that would be painted for the current animation index
 468      * in {@code r} and returns {@code r}.
 469      * Subclasses that add to the painting performed
 470      * in this class's implementation of {@code paintIndeterminate} --
 471      * to draw an outline around the bouncing box, for example --
 472      * can use this method to get the location of the bouncing
 473      * box that was just painted.
 474      * By overriding this method,
 475      * you have complete control over the size and position
 476      * of the bouncing box,
 477      * without having to reimplement {@code paintIndeterminate}.
 478      *
 479      * @param r  the Rectangle instance to be modified;
 480      *           may be {@code null}
 481      * @return   {@code null} if no box should be drawn;
 482      *           otherwise, returns the passed-in rectangle
 483      *           (if non-null)
 484      *           or a new rectangle
 485      *
 486      * @see #setAnimationIndex
 487      * @since 1.4
 488      */
 489     protected Rectangle getBox(Rectangle r) {
 490         int currentFrame = getAnimationIndex();
 491         int middleFrame = numFrames/2;
 492 
 493         if (sizeChanged() || delta == 0.0 || maxPosition == 0.0) {
 494             updateSizes();
 495         }
 496 
 497         r = getGenericBox(r);
 498 
 499         if (r == null) {
 500             return null;
 501         }


 570           // end of HORIZONTAL
 571 
 572         } else { //VERTICAL progress bar
 573             r.height = getBoxLength(componentInnards.height,
 574                                     componentInnards.width);
 575             if (r.height < 0) {
 576                 r = null;
 577             } else {
 578                 r.width = componentInnards.width;
 579                 r.x = componentInnards.x;
 580             }
 581         } // end of VERTICAL
 582 
 583         return r;
 584     }
 585 
 586     /**
 587      * Returns the length
 588      * of the "bouncing box" to be painted.
 589      * This method is invoked by the
 590      * default implementation of {@code paintIndeterminate}
 591      * to get the width (if the progress bar is horizontal)
 592      * or height (if vertical) of the box.
 593      * For example:
 594      * <blockquote>
 595      * <pre>
 596      *boxRect.width = getBoxLength(componentInnards.width,
 597      *                             componentInnards.height);
 598      * </pre>
 599      * </blockquote>
 600      *
 601      * @param availableLength  the amount of space available
 602      *                         for the bouncing box to move in;
 603      *                         for a horizontal progress bar,
 604      *                         for example,
 605      *                         this should be
 606      *                         the inside width of the progress bar
 607      *                         (the component width minus borders)
 608      * @param otherDimension   for a horizontal progress bar, this should be
 609      *                         the inside height of the progress bar; this
 610      *                         value might be used to constrain or determine
 611      *                         the return value
 612      *
 613      * @return the size of the box dimension being determined;
 614      *         must be no larger than {@code availableLength}
 615      *
 616      * @see javax.swing.SwingUtilities#calculateInnerArea
 617      * @since 1.5
 618      */
 619     protected int getBoxLength(int availableLength, int otherDimension) {
 620         return (int)Math.round(availableLength/6.0);
 621     }
 622 
 623     /**
 624      * All purpose paint method that should do the right thing for all
 625      * linear bouncing-box progress bars.
 626      * Override this if you are making another kind of
 627      * progress bar.
 628      *
 629      * @param g an instance of {@code Graphics}
 630      * @param c a component
 631      * @see #paintDeterminate
 632      *
 633      * @since 1.4
 634      */


 975 
 976     /**
 977      * Returns the number of frames for the complete animation loop
 978      * used by an indeterminate JProgessBar. The progress chunk will go
 979      * from one end to the other and back during the entire loop. This
 980      * visual behavior may be changed by subclasses in other Look and Feels.
 981      *
 982      * @return the number of frames
 983      * @since 1.6
 984      */
 985     protected final int getFrameCount() {
 986         return numFrames;
 987     }
 988 
 989     /**
 990      * Sets the index of the current animation frame
 991      * to the specified value and requests that the
 992      * progress bar be repainted.
 993      * Subclasses that don't use the default painting code
 994      * might need to override this method
 995      * to change the way that the {@code repaint} method
 996      * is invoked.
 997      *
 998      * @param newValue the new animation index; no checking
 999      *                 is performed on its value
1000      * @see #incrementAnimationIndex
1001      *
1002      * @since 1.4
1003      */
1004     protected void setAnimationIndex(int newValue) {
1005         if (animationIndex != newValue) {
1006             if (sizeChanged()) {
1007                 animationIndex = newValue;
1008                 maxPosition = 0;  //needs to be recalculated
1009                 delta = 0.0;      //needs to be recalculated
1010                 progressBar.repaint();
1011                 return;
1012             }
1013 
1014             //Get the previous box drawn.
1015             nextPaintRect = getBox(nextPaintRect);


< prev index next >