1. /*
  2. * @(#)MotifToggleButtonUI.java 1.17 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 java.awt.*;
  12. import java.awt.event.*;
  13. import javax.swing.*;
  14. import javax.swing.border.*;
  15. import javax.swing.plaf.*;
  16. import javax.swing.plaf.basic.*;
  17. /**
  18. * BasicToggleButton 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.17 02/02/00
  28. * @author Rich Schiavi
  29. */
  30. public class MotifToggleButtonUI extends BasicToggleButtonUI
  31. {
  32. private final static MotifToggleButtonUI motifToggleButtonUI = new MotifToggleButtonUI();
  33. protected Color selectColor;
  34. private boolean defaults_initialized = false;
  35. // ********************************
  36. // Create PLAF
  37. // ********************************
  38. public static ComponentUI createUI(JComponent b) {
  39. return motifToggleButtonUI;
  40. }
  41. // ********************************
  42. // Install Defaults
  43. // ********************************
  44. public void installDefaults(AbstractButton b) {
  45. super.installDefaults(b);
  46. if(!defaults_initialized) {
  47. selectColor = UIManager.getColor(getPropertyPrefix() + "select");
  48. defaults_initialized = true;
  49. }
  50. b.setOpaque(false);
  51. }
  52. protected void uninstallDefaults(AbstractButton b) {
  53. super.uninstallDefaults(b);
  54. defaults_initialized = false;
  55. }
  56. // ********************************
  57. // Default Accessors
  58. // ********************************
  59. protected Color getSelectColor() {
  60. return selectColor;
  61. }
  62. // ********************************
  63. // Paint Methods
  64. // ********************************
  65. protected void paintButtonPressed(Graphics g, AbstractButton b) {
  66. if (b.isContentAreaFilled()) {
  67. Color oldColor = g.getColor();
  68. Dimension size = b.getSize();
  69. Insets insets = b.getInsets();
  70. Insets margin = b.getMargin();
  71. if(b.getBackground() instanceof UIResource) {
  72. g.setColor(getSelectColor());
  73. }
  74. g.fillRect(insets.left - margin.left,
  75. insets.top - margin.top,
  76. size.width - (insets.left-margin.left) - (insets.right - margin.right),
  77. size.height - (insets.top-margin.top) - (insets.bottom - margin.bottom));
  78. g.setColor(oldColor);
  79. }
  80. }
  81. public Insets getInsets(JComponent c) {
  82. Border border = c.getBorder();
  83. Insets i = border != null? border.getBorderInsets(c) : new Insets(0,0,0,0);
  84. return i;
  85. }
  86. }