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