1. /*
  2. * @(#)WindowsToggleButtonUI.java 1.16 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 com.sun.java.swing.plaf.windows;
  8. import javax.swing.plaf.basic.*;
  9. import javax.swing.plaf.*;
  10. import javax.swing.*;
  11. import java.awt.*;
  12. /**
  13. * A Windows toggle button.
  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.16 11/29/01
  23. * @author Jeff Dinkins
  24. */
  25. public class WindowsToggleButtonUI extends BasicToggleButtonUI
  26. {
  27. protected static int dashedRectGapX;
  28. protected static int dashedRectGapY;
  29. protected static int dashedRectGapWidth;
  30. protected static int dashedRectGapHeight;
  31. protected Color focusColor;
  32. private final static WindowsToggleButtonUI windowsToggleButtonUI = new WindowsToggleButtonUI();
  33. private boolean defaults_initialized = false;
  34. public static ComponentUI createUI(JComponent b) {
  35. return windowsToggleButtonUI;
  36. }
  37. // ********************************
  38. // Defaults
  39. // ********************************
  40. protected void installDefaults(AbstractButton b) {
  41. super.installDefaults(b);
  42. if(!defaults_initialized) {
  43. String pp = getPropertyPrefix();
  44. dashedRectGapX = ((Integer)UIManager.get("Button.dashedRectGapX")).intValue();
  45. dashedRectGapY = ((Integer)UIManager.get("Button.dashedRectGapY")).intValue();
  46. dashedRectGapWidth = ((Integer)UIManager.get("Button.dashedRectGapWidth")).intValue();
  47. dashedRectGapHeight = ((Integer)UIManager.get("Button.dashedRectGapHeight")).intValue();
  48. focusColor = UIManager.getColor(pp + "focus");
  49. defaults_initialized = true;
  50. }
  51. }
  52. protected void uninstallDefaults(AbstractButton b) {
  53. super.uninstallDefaults(b);
  54. defaults_initialized = false;
  55. }
  56. protected Color getFocusColor() {
  57. return focusColor;
  58. }
  59. // ********************************
  60. // Paint Methods
  61. // ********************************
  62. protected void paintFocus(Graphics g, AbstractButton b,
  63. Rectangle viewRect, Rectangle textRect, Rectangle iconRect) {
  64. g.setColor(getFocusColor());
  65. BasicGraphicsUtils.drawDashedRect(g, dashedRectGapX, dashedRectGapY,
  66. b.getWidth() - dashedRectGapWidth,
  67. b.getHeight() - dashedRectGapHeight);
  68. }
  69. }