1. /*
  2. * @(#)BasicRadioButtonMenuItemUI.java 1.41 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 javax.swing.plaf.basic;
  11. import javax.swing.*;
  12. import java.awt.*;
  13. import java.awt.event.*;
  14. import javax.swing.plaf.*;
  15. import javax.swing.border.*;
  16. /**
  17. * BasicRadioButtonMenuItem implementation
  18. *
  19. * @version 1.41 02/02/00
  20. * @author Georges Saab
  21. * @author David Karlton
  22. */
  23. public class BasicRadioButtonMenuItemUI extends BasicMenuItemUI
  24. {
  25. public static ComponentUI createUI(JComponent b) {
  26. return new BasicRadioButtonMenuItemUI();
  27. }
  28. protected void installDefaults() {
  29. super.installDefaults();
  30. String prefix = getPropertyPrefix();
  31. if (menuItem.getSelectedIcon() == null ||
  32. menuItem.getSelectedIcon() instanceof UIResource) {
  33. menuItem.setSelectedIcon(
  34. UIManager.getIcon(prefix + ".checkIcon"));
  35. }
  36. }
  37. protected String getPropertyPrefix() {
  38. return "RadioButtonMenuItem";
  39. }
  40. public void processMouseEvent(JMenuItem item,MouseEvent e,MenuElement path[],MenuSelectionManager manager) {
  41. Point p = e.getPoint();
  42. if(p.x >= 0 && p.x < item.getWidth() &&
  43. p.y >= 0 && p.y < item.getHeight()) {
  44. if(e.getID() == MouseEvent.MOUSE_RELEASED) {
  45. manager.clearSelectedPath();
  46. item.doClick(0);
  47. item.setArmed(false);
  48. } else
  49. manager.setSelectedPath(path);
  50. } else if(item.getModel().isArmed()) {
  51. MenuElement newPath[] = new MenuElement[path.length-1];
  52. int i,c;
  53. for(i=0,c=path.length-1;i<c;i++)
  54. newPath[i] = path[i];
  55. manager.setSelectedPath(newPath);
  56. }
  57. }
  58. }