src/share/classes/com/sun/java/swing/plaf/windows/WindowsProgressBarUI.java

Print this page


   1 /*
   2  * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 305                     return;
 306                 }
 307                 paintIndeterminateFrame(boxRect, (Graphics2D)g, vertical,
 308                                         barRectWidth, barRectHeight);
 309                 if (progressBar.isStringPainted()) {
 310                     if (!vertical) {
 311                         paintString(g, -1, -1, barRectWidth, barRectHeight, 0, null);
 312                     } else {
 313                         paintString(g, 1, 1, barRectWidth, barRectHeight, 0, null);
 314                     }
 315                 }
 316             }
 317         } else {
 318             super.paintIndeterminate(g, c);
 319         }
 320     }
 321 
 322     private Rectangle getFullChunkBounds(Rectangle box) {
 323         boolean vertical = (progressBar.getOrientation() == JProgressBar.VERTICAL);
 324         XPStyle xp = XPStyle.getXP();
 325         int gap = xp.getInt(progressBar, Part.PP_PROGRESS, null,
 326                             Prop.PROGRESSSPACESIZE, 0);

 327 
 328         if (!vertical) {
 329             int chunksize = box.width+gap;
 330             return new Rectangle(box.x-chunksize*2, box.y, chunksize*3, box.height);
 331         } else {
 332             int chunksize = box.height+gap;
 333             return new Rectangle(box.x, box.y-chunksize*2, box.width, chunksize*3);
 334         }
 335     }
 336 
 337     private void paintIndeterminateFrame(Rectangle box, Graphics2D g,
 338                                           boolean vertical,
 339                                           int bgwidth, int bgheight) {
 340         XPStyle xp = XPStyle.getXP();



 341 
 342         // create a new graphics to keep drawing surface state
 343         Graphics2D gfx = (Graphics2D)g.create();
 344 
 345         Part part = vertical ? Part.PP_BARVERT : Part.PP_BAR;
 346         Part chunk = vertical ? Part.PP_CHUNKVERT : Part.PP_CHUNK;
 347 
 348         // calculate the chunk offsets
 349         int gap = xp.getInt(progressBar, Part.PP_PROGRESS, null,
 350                             Prop.PROGRESSSPACESIZE, 0);
 351         int deltax = 0;
 352         int deltay = 0;
 353         if (!vertical) {
 354             deltax = -box.width - gap;
 355             deltay = 0;
 356         } else {
 357             deltax = 0;
 358             deltay = -box.height - gap;
 359         }
 360 


 379         // get the skin
 380         XPStyle.Skin skin = xp.getSkin(progressBar, chunk);
 381 
 382         // do the drawing
 383         gfx.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.8f));
 384         skin.paintSkin(gfx, box.x, box.y, box.width, box.height, null);
 385         box.translate(deltax, deltay);
 386         gfx.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f));
 387         skin.paintSkin(gfx, box.x, box.y, box.width, box.height, null);
 388         box.translate(deltax, deltay);
 389         gfx.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.2f));
 390         skin.paintSkin(gfx, box.x, box.y, box.width, box.height, null);
 391 
 392         // get rid of our clip and composite changes
 393         gfx.dispose();
 394     }
 395 
 396     private void paintXPBackground(Graphics g, boolean vertical,
 397                                    int barRectWidth, int barRectHeight) {
 398         XPStyle xp = XPStyle.getXP();



 399         Part part = vertical ? Part.PP_BARVERT : Part.PP_BAR;
 400         Skin skin = xp.getSkin(progressBar, part);
 401 
 402         // Paint background
 403         skin.paintSkin(g, 0, 0, barRectWidth, barRectHeight, null);
 404     }
 405 }
   1 /*
   2  * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 305                     return;
 306                 }
 307                 paintIndeterminateFrame(boxRect, (Graphics2D)g, vertical,
 308                                         barRectWidth, barRectHeight);
 309                 if (progressBar.isStringPainted()) {
 310                     if (!vertical) {
 311                         paintString(g, -1, -1, barRectWidth, barRectHeight, 0, null);
 312                     } else {
 313                         paintString(g, 1, 1, barRectWidth, barRectHeight, 0, null);
 314                     }
 315                 }
 316             }
 317         } else {
 318             super.paintIndeterminate(g, c);
 319         }
 320     }
 321 
 322     private Rectangle getFullChunkBounds(Rectangle box) {
 323         boolean vertical = (progressBar.getOrientation() == JProgressBar.VERTICAL);
 324         XPStyle xp = XPStyle.getXP();
 325         int gap = (xp != null) ? xp.getInt(progressBar, Part.PP_PROGRESS,
 326                                            null, Prop.PROGRESSSPACESIZE, 0)
 327                                : 0;
 328 
 329         if (!vertical) {
 330             int chunksize = box.width+gap;
 331             return new Rectangle(box.x-chunksize*2, box.y, chunksize*3, box.height);
 332         } else {
 333             int chunksize = box.height+gap;
 334             return new Rectangle(box.x, box.y-chunksize*2, box.width, chunksize*3);
 335         }
 336     }
 337 
 338     private void paintIndeterminateFrame(Rectangle box, Graphics2D g,
 339                                           boolean vertical,
 340                                           int bgwidth, int bgheight) {
 341         XPStyle xp = XPStyle.getXP();
 342         if (xp == null) {
 343             return;
 344         }
 345 
 346         // create a new graphics to keep drawing surface state
 347         Graphics2D gfx = (Graphics2D)g.create();
 348 
 349         Part part = vertical ? Part.PP_BARVERT : Part.PP_BAR;
 350         Part chunk = vertical ? Part.PP_CHUNKVERT : Part.PP_CHUNK;
 351 
 352         // calculate the chunk offsets
 353         int gap = xp.getInt(progressBar, Part.PP_PROGRESS, null,
 354                             Prop.PROGRESSSPACESIZE, 0);
 355         int deltax = 0;
 356         int deltay = 0;
 357         if (!vertical) {
 358             deltax = -box.width - gap;
 359             deltay = 0;
 360         } else {
 361             deltax = 0;
 362             deltay = -box.height - gap;
 363         }
 364 


 383         // get the skin
 384         XPStyle.Skin skin = xp.getSkin(progressBar, chunk);
 385 
 386         // do the drawing
 387         gfx.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.8f));
 388         skin.paintSkin(gfx, box.x, box.y, box.width, box.height, null);
 389         box.translate(deltax, deltay);
 390         gfx.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f));
 391         skin.paintSkin(gfx, box.x, box.y, box.width, box.height, null);
 392         box.translate(deltax, deltay);
 393         gfx.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.2f));
 394         skin.paintSkin(gfx, box.x, box.y, box.width, box.height, null);
 395 
 396         // get rid of our clip and composite changes
 397         gfx.dispose();
 398     }
 399 
 400     private void paintXPBackground(Graphics g, boolean vertical,
 401                                    int barRectWidth, int barRectHeight) {
 402         XPStyle xp = XPStyle.getXP();
 403         if (xp == null) {
 404             return;
 405         }
 406         Part part = vertical ? Part.PP_BARVERT : Part.PP_BAR;
 407         Skin skin = xp.getSkin(progressBar, part);
 408 
 409         // Paint background
 410         skin.paintSkin(g, 0, 0, barRectWidth, barRectHeight, null);
 411     }
 412 }