1. /*
  2. * @(#)BasicCheckBoxMenuItemUI.java 1.49 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 java.awt.*;
  12. import java.awt.event.*;
  13. import javax.swing.*;
  14. import javax.swing.plaf.*;
  15. import javax.swing.border.*;
  16. import java.io.Serializable;
  17. /**
  18. * BasicCheckboxMenuItem implementation
  19. *
  20. * @version 1.49 02/02/00
  21. * @author Georges Saab
  22. * @author David Karlton
  23. * @author Arnaud Weber
  24. */
  25. public class BasicCheckBoxMenuItemUI extends BasicMenuItemUI {
  26. public static ComponentUI createUI(JComponent c) {
  27. return new BasicCheckBoxMenuItemUI();
  28. }
  29. protected void installDefaults() {
  30. super.installDefaults();
  31. String prefix = getPropertyPrefix();
  32. if (menuItem.getSelectedIcon() == null ||
  33. menuItem.getSelectedIcon() instanceof UIResource) {
  34. menuItem.setSelectedIcon(
  35. UIManager.getIcon(prefix + ".checkIcon"));
  36. }
  37. }
  38. protected String getPropertyPrefix() {
  39. return "CheckBoxMenuItem";
  40. }
  41. public void processMouseEvent(JMenuItem item,MouseEvent e,MenuElement path[],MenuSelectionManager manager) {
  42. Point p = e.getPoint();
  43. if(p.x >= 0 && p.x < item.getWidth() &&
  44. p.y >= 0 && p.y < item.getHeight()) {
  45. if(e.getID() == MouseEvent.MOUSE_RELEASED) {
  46. manager.clearSelectedPath();
  47. item.doClick(0);
  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. }