< prev index next >

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

Print this page

        

@@ -131,10 +131,12 @@
     /** For bouncing-box animation, the change in position per frame. */
     private double delta = 0.0;
 
     private int maxPosition = 0; //maximum X (horiz) or Y box location
 
+    private TextUIDrawing textUIDrawing;
+
     /**
      * Returns a new instance of {@code BasicProgressBarUI}.
      *
      * @param x a component
      * @return a new instance of {@code BasicProgressBarUI}

@@ -174,17 +176,22 @@
         cellLength = UIManager.getInt("ProgressBar.cellLength");
         if (cellLength == 0) cellLength = 1;
         cellSpacing = UIManager.getInt("ProgressBar.cellSpacing");
         selectionForeground = UIManager.getColor("ProgressBar.selectionForeground");
         selectionBackground = UIManager.getColor("ProgressBar.selectionBackground");
+        textUIDrawing = SwingUtilities2.getTextUIDrawing(textUIDrawing);
     }
 
     /**
      * Unintalls default properties.
      */
     protected void uninstallDefaults() {
         LookAndFeel.uninstallBorder(progressBar);
+        if (textUIDrawing != SwingUtilities2.DEFAULT_UI_TEXT_DRAWING
+                && textUIDrawing instanceof UIResource) {
+            textUIDrawing = SwingUtilities2.DEFAULT_UI_TEXT_DRAWING;
+        }
     }
 
     /**
      * Registers listeners.
      */

@@ -825,28 +832,28 @@
                                                   x, y, width, height);
         Rectangle oldClip = g2.getClipBounds();
 
         if (progressBar.getOrientation() == JProgressBar.HORIZONTAL) {
             g2.setColor(getSelectionBackground());
-            SwingUtilities2.drawString(progressBar, g2, progressString,
+            textUIDrawing.drawString(progressBar, g2, progressString,
                                        renderLocation.x, renderLocation.y);
             g2.setColor(getSelectionForeground());
             g2.clipRect(fillStart, y, amountFull, height);
-            SwingUtilities2.drawString(progressBar, g2, progressString,
+            textUIDrawing.drawString(progressBar, g2, progressString,
                                        renderLocation.x, renderLocation.y);
         } else { // VERTICAL
             g2.setColor(getSelectionBackground());
             AffineTransform rotate =
                     AffineTransform.getRotateInstance(Math.PI/2);
             g2.setFont(progressBar.getFont().deriveFont(rotate));
             renderLocation = getStringPlacement(g2, progressString,
                                                   x, y, width, height);
-            SwingUtilities2.drawString(progressBar, g2, progressString,
+            textUIDrawing.drawString(progressBar, g2, progressString,
                                        renderLocation.x, renderLocation.y);
             g2.setColor(getSelectionForeground());
             g2.clipRect(x, fillStart, width, amountFull);
-            SwingUtilities2.drawString(progressBar, g2, progressString,
+            textUIDrawing.drawString(progressBar, g2, progressString,
                                        renderLocation.x, renderLocation.y);
         }
         g2.setClip(oldClip);
     }
 

@@ -868,11 +875,11 @@
      */
     protected Point getStringPlacement(Graphics g, String progressString,
                                        int x,int y,int width,int height) {
         FontMetrics fontSizer = SwingUtilities2.getFontMetrics(progressBar, g,
                                             progressBar.getFont());
-        int stringWidth = SwingUtilities2.stringWidth(progressBar, fontSizer,
+        int stringWidth = textUIDrawing.getStringWidth(progressBar, fontSizer,
                                                       progressString);
 
         if (progressBar.getOrientation() == JProgressBar.HORIZONTAL) {
             return new Point(x + Math.round(width/2 - stringWidth/2),
                              y + ((height +

@@ -897,11 +904,11 @@
             size = new Dimension(getPreferredInnerHorizontal());
             // Ensure that the progress string will fit
             if (progressBar.isStringPainted()) {
                 // I'm doing this for completeness.
                 String progString = progressBar.getString();
-                int stringWidth = SwingUtilities2.stringWidth(
+                int stringWidth = textUIDrawing.getStringWidth(
                           progressBar, fontSizer, progString);
                 if (stringWidth > size.width) {
                     size.width = stringWidth;
                 }
                 // This uses both Height and Descent to be sure that

@@ -924,11 +931,11 @@
                         fontSizer.getDescent();
                 if (stringHeight > size.width) {
                     size.width = stringHeight;
                 }
                 // This is also for completeness.
-                int stringWidth = SwingUtilities2.stringWidth(
+                int stringWidth = textUIDrawing.getStringWidth(
                                        progressBar, fontSizer, progString);
                 if (stringWidth > size.height) {
                     size.height = stringWidth;
                 }
             }
< prev index next >