< prev index next >

src/java.desktop/share/classes/javax/swing/plaf/metal/MetalProgressBarUI.java

Print this page




  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package javax.swing.plaf.metal;
  27 
  28 import javax.swing.*;
  29 import javax.swing.plaf.*;
  30 import javax.swing.plaf.basic.*;
  31 import java.awt.*;
  32 
  33 /**
  34  * The Metal implementation of ProgressBarUI.
  35  * <p>
  36  * <strong>Warning:</strong>
  37  * Serialized objects of this class will not be compatible with
  38  * future Swing releases. The current serialization support is
  39  * appropriate for short term storage or RMI between applications running
  40  * the same version of Swing.  As of 1.4, support for long term storage
  41  * of all JavaBeans&trade;
  42  * has been added to the <code>java.beans</code> package.
  43  * Please see {@link java.beans.XMLEncoder}.
  44  *
  45  * @author Michael C. Albers
  46  */
  47 @SuppressWarnings("serial") // Same-version serialization only
  48 public class MetalProgressBarUI extends BasicProgressBarUI {
  49 
  50     private Rectangle innards;
  51     private Rectangle box;
  52 
  53     /**
  54      * Constructs an instance of {@code MetalProgressBarUI}.
  55      *
  56      * @param c a component
  57      * @return an instance of {@code MetalProgressBarUI}
  58      */
  59     public static ComponentUI createUI(JComponent c) {
  60         return new MetalProgressBarUI();
  61     }
  62 
  63     /**
  64      * Draws a bit of special highlighting on the progress bar.
  65      * The core painting is deferred to the BasicProgressBar's
  66      * <code>paintDeterminate</code> method.
  67      * @since 1.4
  68      */
  69     public void paintDeterminate(Graphics g, JComponent c) {
  70         super.paintDeterminate(g,c);
  71 
  72         if (!(g instanceof Graphics2D)) {
  73             return;
  74         }
  75 
  76         if (progressBar.isBorderPainted()) {
  77             Insets b = progressBar.getInsets(); // area for border
  78             int barRectWidth = progressBar.getWidth() - (b.left + b.right);
  79             int barRectHeight = progressBar.getHeight() - (b.top + b.bottom);
  80             int amountFull = getAmountFull(b, barRectWidth, barRectHeight);
  81             boolean isLeftToRight = MetalUtils.isLeftToRight(c);
  82             int startX, startY, endX, endY;
  83 
  84             // The progress bar border is painted according to a light source.
  85             // This light source is stationary and does not change when the
  86             // component orientation changes.


 126                     g2.setColor(MetalLookAndFeel.getPrimaryControlDarkShadow());
 127                     g2.drawLine(startX, endY,
 128                             startX, endY - amountFull + 1);
 129                 }
 130                 // Draw a line across the width.  The color is determined by
 131                 // the code above.
 132                 g2.setColor(MetalLookAndFeel.getControlShadow());
 133 
 134                 if (progressBar.getPercentComplete() == 1.f) {
 135                     g2.setColor(MetalLookAndFeel.getPrimaryControlDarkShadow());
 136                 }
 137                 g2.drawLine(startX, startY, endX, startY);
 138             }
 139         }
 140     }
 141 
 142     /**
 143      * Draws a bit of special highlighting on the progress bar
 144      * and bouncing box.
 145      * The core painting is deferred to the BasicProgressBar's
 146      * <code>paintIndeterminate</code> method.
 147      * @since 1.4
 148      */
 149     public void paintIndeterminate(Graphics g, JComponent c) {
 150         super.paintIndeterminate(g, c);
 151 
 152         if (!progressBar.isBorderPainted() || (!(g instanceof Graphics2D))) {
 153             return;
 154         }
 155 
 156         Insets b = progressBar.getInsets(); // area for border
 157         int barRectWidth = progressBar.getWidth() - (b.left + b.right);
 158         int barRectHeight = progressBar.getHeight() - (b.top + b.bottom);
 159         int amountFull = getAmountFull(b, barRectWidth, barRectHeight);
 160         boolean isLeftToRight = MetalUtils.isLeftToRight(c);
 161         int startX, startY, endX, endY;
 162         Rectangle box = null;
 163         box = getBox(box);
 164 
 165         // The progress bar border is painted according to a light source.
 166         // This light source is stationary and does not change when the




  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package javax.swing.plaf.metal;
  27 
  28 import javax.swing.*;
  29 import javax.swing.plaf.*;
  30 import javax.swing.plaf.basic.*;
  31 import java.awt.*;
  32 
  33 /**
  34  * The Metal implementation of ProgressBarUI.
  35  * <p>
  36  * <strong>Warning:</strong>
  37  * Serialized objects of this class will not be compatible with
  38  * future Swing releases. The current serialization support is
  39  * appropriate for short term storage or RMI between applications running
  40  * the same version of Swing.  As of 1.4, support for long term storage
  41  * of all JavaBeans&trade;
  42  * has been added to the {@code java.beans} package.
  43  * Please see {@link java.beans.XMLEncoder}.
  44  *
  45  * @author Michael C. Albers
  46  */
  47 @SuppressWarnings("serial") // Same-version serialization only
  48 public class MetalProgressBarUI extends BasicProgressBarUI {
  49 
  50     private Rectangle innards;
  51     private Rectangle box;
  52 
  53     /**
  54      * Constructs an instance of {@code MetalProgressBarUI}.
  55      *
  56      * @param c a component
  57      * @return an instance of {@code MetalProgressBarUI}
  58      */
  59     public static ComponentUI createUI(JComponent c) {
  60         return new MetalProgressBarUI();
  61     }
  62 
  63     /**
  64      * Draws a bit of special highlighting on the progress bar.
  65      * The core painting is deferred to the BasicProgressBar's
  66      * {@code paintDeterminate} method.
  67      * @since 1.4
  68      */
  69     public void paintDeterminate(Graphics g, JComponent c) {
  70         super.paintDeterminate(g,c);
  71 
  72         if (!(g instanceof Graphics2D)) {
  73             return;
  74         }
  75 
  76         if (progressBar.isBorderPainted()) {
  77             Insets b = progressBar.getInsets(); // area for border
  78             int barRectWidth = progressBar.getWidth() - (b.left + b.right);
  79             int barRectHeight = progressBar.getHeight() - (b.top + b.bottom);
  80             int amountFull = getAmountFull(b, barRectWidth, barRectHeight);
  81             boolean isLeftToRight = MetalUtils.isLeftToRight(c);
  82             int startX, startY, endX, endY;
  83 
  84             // The progress bar border is painted according to a light source.
  85             // This light source is stationary and does not change when the
  86             // component orientation changes.


 126                     g2.setColor(MetalLookAndFeel.getPrimaryControlDarkShadow());
 127                     g2.drawLine(startX, endY,
 128                             startX, endY - amountFull + 1);
 129                 }
 130                 // Draw a line across the width.  The color is determined by
 131                 // the code above.
 132                 g2.setColor(MetalLookAndFeel.getControlShadow());
 133 
 134                 if (progressBar.getPercentComplete() == 1.f) {
 135                     g2.setColor(MetalLookAndFeel.getPrimaryControlDarkShadow());
 136                 }
 137                 g2.drawLine(startX, startY, endX, startY);
 138             }
 139         }
 140     }
 141 
 142     /**
 143      * Draws a bit of special highlighting on the progress bar
 144      * and bouncing box.
 145      * The core painting is deferred to the BasicProgressBar's
 146      * {@code paintIndeterminate} method.
 147      * @since 1.4
 148      */
 149     public void paintIndeterminate(Graphics g, JComponent c) {
 150         super.paintIndeterminate(g, c);
 151 
 152         if (!progressBar.isBorderPainted() || (!(g instanceof Graphics2D))) {
 153             return;
 154         }
 155 
 156         Insets b = progressBar.getInsets(); // area for border
 157         int barRectWidth = progressBar.getWidth() - (b.left + b.right);
 158         int barRectHeight = progressBar.getHeight() - (b.top + b.bottom);
 159         int amountFull = getAmountFull(b, barRectWidth, barRectHeight);
 160         boolean isLeftToRight = MetalUtils.isLeftToRight(c);
 161         int startX, startY, endX, endY;
 162         Rectangle box = null;
 163         box = getBox(box);
 164 
 165         // The progress bar border is painted according to a light source.
 166         // This light source is stationary and does not change when the


< prev index next >