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