1. /*
  2. * @(#)WindowsButtonUI.java 1.17 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.border.*;
  10. import javax.swing.plaf.*;
  11. import javax.swing.*;
  12. import java.awt.*;
  13. /**
  14. * Windows button.
  15. * <p>
  16. * <strong>Warning:</strong>
  17. * Serialized objects of this class will not be compatible with
  18. * future Swing releases. The current serialization support is appropriate
  19. * for short term storage or RMI between applications running the same
  20. * version of Swing. A future release of Swing will provide support for
  21. * long term persistence.
  22. *
  23. * @version 1.17 11/29/01
  24. * @author Jeff Dinkins
  25. *
  26. */
  27. public class WindowsButtonUI extends BasicButtonUI
  28. {
  29. private final static WindowsButtonUI windowsButtonUI = new WindowsButtonUI();
  30. protected int dashedRectGapX;
  31. protected int dashedRectGapY;
  32. protected int dashedRectGapWidth;
  33. protected int dashedRectGapHeight;
  34. protected Color focusColor;
  35. private boolean defaults_initialized = false;
  36. // ********************************
  37. // Create PLAF
  38. // ********************************
  39. public static ComponentUI createUI(JComponent c){
  40. return windowsButtonUI;
  41. }
  42. // ********************************
  43. // Create Listeners
  44. // ********************************
  45. protected BasicButtonListener createButtonListener(AbstractButton b) {
  46. return new WindowsButtonListener(b);
  47. }
  48. // ********************************
  49. // Defaults
  50. // ********************************
  51. protected void installDefaults(AbstractButton b) {
  52. super.installDefaults(b);
  53. if(!defaults_initialized) {
  54. String pp = getPropertyPrefix();
  55. dashedRectGapX = UIManager.getInt(pp + "dashedRectGapX");
  56. dashedRectGapY = UIManager.getInt(pp + "dashedRectGapY");
  57. dashedRectGapWidth = UIManager.getInt(pp + "dashedRectGapWidth");
  58. dashedRectGapHeight = UIManager.getInt(pp + "dashedRectGapHeight");
  59. focusColor = UIManager.getColor(pp + "focus");
  60. defaults_initialized = true;
  61. }
  62. }
  63. protected void uninstallDefaults(AbstractButton b) {
  64. super.uninstallDefaults(b);
  65. defaults_initialized = false;
  66. }
  67. protected Color getFocusColor() {
  68. return focusColor;
  69. }
  70. // ********************************
  71. // Paint Methods
  72. // ********************************
  73. protected void paintFocus(Graphics g, AbstractButton b, Rectangle viewRect, Rectangle textRect, Rectangle iconRect){
  74. // focus painted same color as text on Basic??
  75. int width = b.getWidth();
  76. int height = b.getHeight();
  77. g.setColor(getFocusColor());
  78. BasicGraphicsUtils.drawDashedRect(g, dashedRectGapX, dashedRectGapY,
  79. width - dashedRectGapWidth, height - dashedRectGapHeight);
  80. }
  81. protected void paintButtonPressed(Graphics g, AbstractButton b){
  82. setTextShiftOffset();
  83. }
  84. }