1. /*
  2. * @(#)WindowsLabelUI.java 1.18 03/12/19
  3. *
  4. * Copyright 2004 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 com.sun.java.swing.SwingUtilities2;
  9. import java.awt.Color;
  10. import java.awt.Graphics;
  11. import javax.swing.JComponent;
  12. import javax.swing.JLabel;
  13. import javax.swing.UIManager;
  14. import javax.swing.plaf.ComponentUI;
  15. import javax.swing.plaf.basic.BasicLabelUI;
  16. /**
  17. * Windows rendition of the component.
  18. * <p>
  19. * <strong>Warning:</strong>
  20. * Serialized objects of this class will not be compatible with
  21. * future Swing releases. The current serialization support is appropriate
  22. * for short term storage or RMI between applications running the same
  23. * version of Swing. A future release of Swing will provide support for
  24. * long term persistence.
  25. */
  26. public class WindowsLabelUI extends BasicLabelUI {
  27. private final static WindowsLabelUI windowsLabelUI = new WindowsLabelUI();
  28. // ********************************
  29. // Create PLAF
  30. // ********************************
  31. public static ComponentUI createUI(JComponent c){
  32. return windowsLabelUI;
  33. }
  34. protected void paintEnabledText(JLabel l, Graphics g, String s,
  35. int textX, int textY) {
  36. int mnemonicIndex = l.getDisplayedMnemonicIndex();
  37. // W2K Feature: Check to see if the Underscore should be rendered.
  38. if (WindowsLookAndFeel.isMnemonicHidden() == true) {
  39. mnemonicIndex = -1;
  40. }
  41. g.setColor(l.getForeground());
  42. SwingUtilities2.drawStringUnderlineCharAt(l, g, s, mnemonicIndex,
  43. textX, textY);
  44. }
  45. protected void paintDisabledText(JLabel l, Graphics g, String s,
  46. int textX, int textY) {
  47. int mnemonicIndex = l.getDisplayedMnemonicIndex();
  48. // W2K Feature: Check to see if the Underscore should be rendered.
  49. if (WindowsLookAndFeel.isMnemonicHidden() == true) {
  50. mnemonicIndex = -1;
  51. }
  52. if ( UIManager.getColor("Label.disabledForeground") instanceof Color &&
  53. UIManager.getColor("Label.disabledShadow") instanceof Color) {
  54. g.setColor( UIManager.getColor("Label.disabledShadow") );
  55. SwingUtilities2.drawStringUnderlineCharAt(l, g, s,
  56. mnemonicIndex,
  57. textX + 1, textY + 1);
  58. g.setColor( UIManager.getColor("Label.disabledForeground") );
  59. SwingUtilities2.drawStringUnderlineCharAt(l, g, s,
  60. mnemonicIndex,
  61. textX, textY);
  62. } else {
  63. Color background = l.getBackground();
  64. g.setColor(background.brighter());
  65. SwingUtilities2.drawStringUnderlineCharAt(l,g, s, mnemonicIndex,
  66. textX + 1, textY + 1);
  67. g.setColor(background.darker());
  68. SwingUtilities2.drawStringUnderlineCharAt(l,g, s, mnemonicIndex,
  69. textX, textY);
  70. }
  71. }
  72. }