1. /*
  2. * @(#)MotifButtonUI.java 1.21 00/02/02
  3. *
  4. * Copyright 1997-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 com.sun.java.swing.plaf.motif;
  11. import javax.swing.*;
  12. import javax.swing.border.*;
  13. import javax.swing.plaf.basic.*;
  14. import java.awt.*;
  15. import java.awt.event.*;
  16. import javax.swing.plaf.*;
  17. /**
  18. * MotifButton implementation
  19. * <p>
  20. * <strong>Warning:</strong>
  21. * Serialized objects of this class will not be compatible with
  22. * future Swing releases. The current serialization support is appropriate
  23. * for short term storage or RMI between applications running the same
  24. * version of Swing. A future release of Swing will provide support for
  25. * long term persistence.
  26. *
  27. * @version 1.21 02/02/00
  28. * @author Rich Schiavi
  29. */
  30. public class MotifButtonUI extends BasicButtonUI {
  31. private final static MotifButtonUI motifButtonUI = new MotifButtonUI();
  32. protected Color selectColor;
  33. private boolean defaults_initialized = false;
  34. // ********************************
  35. // Create PLAF
  36. // ********************************
  37. public static ComponentUI createUI(JComponent c){
  38. return motifButtonUI;
  39. }
  40. // ********************************
  41. // Create Listeners
  42. // ********************************
  43. protected BasicButtonListener createButtonListener(AbstractButton b){
  44. return new MotifButtonListener(b);
  45. }
  46. // ********************************
  47. // Install Defaults
  48. // ********************************
  49. public void installDefaults(AbstractButton b) {
  50. super.installDefaults(b);
  51. if(!defaults_initialized) {
  52. selectColor = UIManager.getColor(getPropertyPrefix() + "select");
  53. defaults_initialized = true;
  54. }
  55. b.setOpaque(false);
  56. }
  57. protected void uninstallDefaults(AbstractButton b) {
  58. super.uninstallDefaults(b);
  59. defaults_initialized = false;
  60. }
  61. // ********************************
  62. // Default Accessors
  63. // ********************************
  64. protected Color getSelectColor() {
  65. return selectColor;
  66. }
  67. // ********************************
  68. // Paint Methods
  69. // ********************************
  70. public void paint(Graphics g, JComponent c) {
  71. fillContentArea( g, (AbstractButton)c , c.getBackground() );
  72. super.paint(g,c);
  73. }
  74. protected void paintFocus(Graphics g, AbstractButton b, Rectangle viewRect, Rectangle textRect, Rectangle iconRect){
  75. // focus painting is handled by the border
  76. }
  77. protected void paintButtonPressed(Graphics g, AbstractButton b) {
  78. fillContentArea( g, b , selectColor );
  79. }
  80. protected void fillContentArea( Graphics g, AbstractButton b, Color fillColor) {
  81. if (b.isContentAreaFilled()) {
  82. Insets margin = b.getMargin();
  83. Insets insets = b.getInsets();
  84. Dimension size = b.getSize();
  85. g.setColor(fillColor);
  86. g.fillRect(insets.left - margin.left,
  87. insets.top - margin.top,
  88. size.width - (insets.left-margin.left) - (insets.right - margin.right),
  89. size.height - (insets.top-margin.top) - (insets.bottom - margin.bottom));
  90. }
  91. }
  92. }