1. /*
  2. * @(#)MetalProgressBarUI.java 1.15 01/11/29
  3. *
  4. * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package javax.swing.plaf.metal;
  8. import javax.swing.*;
  9. import javax.swing.plaf.*;
  10. import javax.swing.plaf.basic.*;
  11. import java.awt.*;
  12. /**
  13. * The Metal implementation of ProgressBarUI.
  14. * <p>
  15. * <strong>Warning:</strong>
  16. * Serialized objects of this class will not be compatible with
  17. * future Swing releases. The current serialization support is appropriate
  18. * for short term storage or RMI between applications running the same
  19. * version of Swing. A future release of Swing will provide support for
  20. * long term persistence.
  21. *
  22. * @version 1.15 11/29/01
  23. * @author Michael C. Albers
  24. */
  25. public class MetalProgressBarUI extends BasicProgressBarUI {
  26. public static ComponentUI createUI(JComponent c) {
  27. return new MetalProgressBarUI();
  28. }
  29. /**
  30. * The sole reason for this paint method to even be here is that
  31. * the JLF/Metal ProgressBar has a bit of special highlighting that
  32. * needs to get drawn. The core painting is defered to the
  33. * BasicProgressBar's paint method.
  34. */
  35. public void paint(Graphics g, JComponent c) {
  36. super.paint(g,c);
  37. if (progressBar.isBorderPainted()) {
  38. BoundedRangeModel model = progressBar.getModel();
  39. int barRectX = 0;
  40. int barRectY = 0;
  41. int barRectWidth = progressBar.getWidth();
  42. int barRectHeight = progressBar.getHeight();
  43. Insets b = progressBar.getInsets(); // area for border
  44. barRectX += b.left;
  45. barRectY += b.top;
  46. barRectWidth -= (b.right + barRectX);
  47. barRectHeight -= (b.bottom + barRectY);
  48. int amountFull = getAmountFull(b, barRectWidth, barRectHeight);
  49. if (progressBar.getOrientation() == JProgressBar.HORIZONTAL) {
  50. // Highlighting
  51. // over the unfilled portion
  52. // well, draw all the way across; let others draw over it
  53. g.setColor(MetalLookAndFeel.getControlShadow());
  54. g.drawLine(barRectX,barRectY, barRectWidth,barRectY);
  55. // line on left
  56. if (model.getValue() == model.getMinimum()) { // haven't begun
  57. g.setColor(MetalLookAndFeel.getControlShadow());
  58. } else { // Some portion of bar is filled
  59. g.setColor(MetalLookAndFeel.getPrimaryControlDarkShadow());
  60. }
  61. g.drawLine(barRectX,barRectY, barRectX,barRectHeight);
  62. // over the filled portion
  63. // get color from "line on left" above
  64. g.drawLine(barRectX,barRectY, amountFull,barRectY);
  65. } else { // VERTICAL
  66. // Highlighting
  67. // left of the unfilled portion
  68. // well, draw all the way down; let others draw over it
  69. g.setColor(MetalLookAndFeel.getControlShadow());
  70. g.drawLine(barRectX,barRectY, barRectX,barRectHeight);
  71. // line on bottom
  72. if (model.getValue() == model.getMinimum()) { // haven't begun
  73. g.setColor(MetalLookAndFeel.getControlShadow());
  74. } else { // Some portion of bar is filled
  75. g.setColor(MetalLookAndFeel.getPrimaryControlDarkShadow());
  76. }
  77. g.drawLine(barRectX, barRectHeight,
  78. barRectWidth, barRectHeight);
  79. // left of the filled portion
  80. // pick up color from the "line on bottom" above
  81. g.drawLine(barRectX, barRectHeight,
  82. barRectX, barRectHeight-amountFull+b.top);
  83. }
  84. }
  85. }
  86. }