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