1. /*
  2. * @(#)MotifRadioButtonMenuItemUI.java 1.38 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.event.*;
  13. import javax.swing.plaf.*;
  14. import javax.swing.plaf.basic.BasicRadioButtonMenuItemUI;
  15. import javax.swing.plaf.basic.BasicGraphicsUtils;
  16. import java.awt.*;
  17. import java.awt.event.*;
  18. import java.io.Serializable;
  19. /**
  20. * MotifRadioButtonMenuItem implementation
  21. * <p>
  22. * <strong>Warning:</strong>
  23. * Serialized objects of this class will not be compatible with
  24. * future Swing releases. The current serialization support is appropriate
  25. * for short term storage or RMI between applications running the same
  26. * version of Swing. A future release of Swing will provide support for
  27. * long term persistence.
  28. *
  29. * @version 1.38 02/02/00
  30. * @author Georges Saab
  31. * @author Rich Schiavi
  32. */
  33. public class MotifRadioButtonMenuItemUI extends BasicRadioButtonMenuItemUI
  34. {
  35. protected ChangeListener changeListener;
  36. public static ComponentUI createUI(JComponent b) {
  37. return new MotifRadioButtonMenuItemUI();
  38. }
  39. protected void installListeners() {
  40. super.installListeners();
  41. changeListener = createChangeListener(menuItem);
  42. menuItem.addChangeListener(changeListener);
  43. }
  44. protected void uninstallListeners() {
  45. super.uninstallListeners();
  46. menuItem.removeChangeListener(changeListener);
  47. }
  48. protected ChangeListener createChangeListener(JComponent c) {
  49. return new ChangeHandler();
  50. }
  51. protected class ChangeHandler implements ChangeListener, Serializable {
  52. public void stateChanged(ChangeEvent e) {
  53. JMenuItem c = (JMenuItem)e.getSource();
  54. if (c.isArmed()) {
  55. c.setBorderPainted(true);
  56. } else {
  57. c.setBorderPainted(false);
  58. }
  59. }
  60. }
  61. public void paint(Graphics g, JComponent c) {
  62. MotifGraphicsUtils.paintMenuItem(g, c,
  63. checkIcon,
  64. arrowIcon,
  65. selectionBackground,
  66. selectionForeground,
  67. defaultTextIconGap);
  68. }
  69. protected MouseInputListener createMouseInputListener(JComponent c) {
  70. return new MouseInputHandler();
  71. }
  72. protected class MouseInputHandler implements MouseInputListener {
  73. public void mouseClicked(MouseEvent e) {}
  74. public void mousePressed(MouseEvent e) {
  75. MenuSelectionManager manager = MenuSelectionManager.defaultManager();
  76. manager.setSelectedPath(getPath());
  77. }
  78. public void mouseReleased(MouseEvent e) {
  79. MenuSelectionManager manager =
  80. MenuSelectionManager.defaultManager();
  81. JMenuItem menuItem = (JMenuItem)e.getComponent();
  82. Point p = e.getPoint();
  83. if(p.x >= 0 && p.x < menuItem.getWidth() &&
  84. p.y >= 0 && p.y < menuItem.getHeight()) {
  85. manager.clearSelectedPath();
  86. menuItem.doClick(0);
  87. } else {
  88. manager.processMouseEvent(e);
  89. }
  90. }
  91. public void mouseEntered(MouseEvent e) {}
  92. public void mouseExited(MouseEvent e) {}
  93. public void mouseDragged(MouseEvent e) {
  94. MenuSelectionManager.defaultManager().processMouseEvent(e);
  95. }
  96. public void mouseMoved(MouseEvent e) { }
  97. }
  98. }