1. /*
  2. * @(#)WindowsGraphicsUtils.java 1.9 03/01/23
  3. *
  4. * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package com.sun.java.swing.plaf.windows;
  8. import java.awt.*;
  9. import javax.swing.*;
  10. import javax.swing.plaf.basic.BasicGraphicsUtils;
  11. /**
  12. * A collection of static utility methods used for rendering the Windows look
  13. * and feel.
  14. *
  15. * @version 1.9 01/23/03
  16. * @author Mark Davidson
  17. * @since 1.4
  18. */
  19. public class WindowsGraphicsUtils {
  20. /**
  21. * Renders a text String in Windows without the mnemonic.
  22. * This is here because the WindowsUI hiearchy doesn't match the Component heirarchy. All
  23. * the overriden paintText methods of the ButtonUI delegates will call this static method.
  24. * <p>
  25. * @param g Graphics context
  26. * @param b Current button to render
  27. * @param textRect Bounding rectangle to render the text.
  28. * @param text String to render
  29. */
  30. public static void paintText(Graphics g, AbstractButton b,
  31. Rectangle textRect, String text,
  32. int textShiftOffset) {
  33. ButtonModel model = b.getModel();
  34. FontMetrics fm = g.getFontMetrics();
  35. int mnemIndex = b.getDisplayedMnemonicIndex();
  36. // W2K Feature: Check to see if the Underscore should be rendered.
  37. if (WindowsLookAndFeel.isMnemonicHidden() == true) {
  38. mnemIndex = -1;
  39. }
  40. /* Draw the Text */
  41. Color color = b.getForeground();
  42. if(model.isEnabled()) {
  43. /*** paint the text normally */
  44. g.setColor(color);
  45. BasicGraphicsUtils.drawStringUnderlineCharAt(g,text, mnemIndex,
  46. textRect.x + textShiftOffset,
  47. textRect.y + fm.getAscent() + textShiftOffset);
  48. } else { /*** paint the text disabled ***/
  49. color = UIManager.getColor("Button.disabledForeground");
  50. Color shadow = UIManager.getColor("Button.disabledShadow");
  51. XPStyle xp = XPStyle.getXP();
  52. if (xp != null) {
  53. color = xp.getColor("button.pushbutton(disabled).textcolor", color);
  54. } else {
  55. // Paint shadow only if not XP
  56. if (shadow == null) {
  57. shadow = b.getBackground().darker();
  58. }
  59. g.setColor(shadow);
  60. BasicGraphicsUtils.drawStringUnderlineCharAt(g,text,
  61. mnemIndex,
  62. textRect.x,
  63. textRect.y + fm.getAscent());
  64. }
  65. if (color == null) {
  66. color = b.getBackground().brighter();
  67. }
  68. g.setColor(color);
  69. BasicGraphicsUtils.drawStringUnderlineCharAt(g,text,
  70. mnemIndex,
  71. textRect.x - 1,
  72. textRect.y + fm.getAscent() - 1);
  73. }
  74. }
  75. static boolean isLeftToRight(Component c) {
  76. return c.getComponentOrientation().isLeftToRight();
  77. }
  78. }