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