1. /*
  2. * @(#)MotifButtonUI.java 1.26 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.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.26 12/19/03
  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. LookAndFeel.installProperty(b, "opaque", Boolean.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. // Overridden to ensure we don't paint icon over button borders.
  72. protected void paintIcon(Graphics g, JComponent c, Rectangle iconRect) {
  73. Shape oldClip = g.getClip();
  74. Rectangle newClip =
  75. AbstractBorder.getInteriorRectangle(c, c.getBorder(), 0, 0,
  76. c.getWidth(), c.getHeight());
  77. Rectangle r = oldClip.getBounds();
  78. newClip =
  79. SwingUtilities.computeIntersection(r.x, r.y, r.width, r.height,
  80. newClip);
  81. g.setClip(newClip);
  82. super.paintIcon(g, c, iconRect);
  83. g.setClip(oldClip);
  84. }
  85. protected void paintFocus(Graphics g, AbstractButton b, Rectangle viewRect, Rectangle textRect, Rectangle iconRect){
  86. // focus painting is handled by the border
  87. }
  88. protected void paintButtonPressed(Graphics g, AbstractButton b) {
  89. fillContentArea( g, b , selectColor );
  90. }
  91. protected void fillContentArea( Graphics g, AbstractButton b, Color fillColor) {
  92. if (b.isContentAreaFilled()) {
  93. Insets margin = b.getMargin();
  94. Insets insets = b.getInsets();
  95. Dimension size = b.getSize();
  96. g.setColor(fillColor);
  97. g.fillRect(insets.left - margin.left,
  98. insets.top - margin.top,
  99. size.width - (insets.left-margin.left) - (insets.right - margin.right),
  100. size.height - (insets.top-margin.top) - (insets.bottom - margin.bottom));
  101. }
  102. }
  103. }