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