1 7 8 package com.sun.java.swing.plaf.motif; 9 10 11 import javax.swing.*; 12 import javax.swing.event.*; 13 import java.awt.*; 14 import java.awt.event.*; 15 16 import javax.swing.plaf.*; 17 import javax.swing.plaf.basic.BasicMenuItemUI ; 18 19 20 27 public class MotifMenuItemUI extends BasicMenuItemUI 28 { 29 protected ChangeListener changeListener; 30 31 public static ComponentUI createUI(JComponent c) 32 { 33 return new MotifMenuItemUI(); 34 } 35 36 protected void installListeners() { 37 super.installListeners(); 38 changeListener = createChangeListener(menuItem); 39 menuItem.addChangeListener(changeListener); 40 } 41 42 protected void uninstallListeners() { 43 super.uninstallListeners(); 44 menuItem.removeChangeListener(changeListener); 45 } 46 47 protected ChangeListener createChangeListener(JComponent c) { 48 return new ChangeHandler(); 49 } 50 51 protected MouseInputListener createMouseInputListener(JComponent c) { 52 return new MouseInputHandler(); 53 } 54 55 public void paint(Graphics g, JComponent c) { 56 MotifGraphicsUtils.paintMenuItem(g, c, checkIcon,arrowIcon, 57 selectionBackground, selectionForeground, 58 defaultTextIconGap); 59 } 60 61 protected class ChangeHandler implements ChangeListener { 62 63 public void stateChanged(ChangeEvent e) { 64 JMenuItem c = (JMenuItem)e.getSource(); 65 LookAndFeel.installProperty(c, "borderPainted", 66 Boolean.valueOf(c.isArmed() || c.isSelected())); 67 } 68 } 69 70 protected class MouseInputHandler implements MouseInputListener { 71 public void mouseClicked(MouseEvent e) {} 72 public void mousePressed(MouseEvent e) { 73 MenuSelectionManager manager = MenuSelectionManager.defaultManager(); 74 manager.setSelectedPath(getPath()); 75 } 76 public void mouseReleased(MouseEvent e) { 77 MenuSelectionManager manager = 78 MenuSelectionManager.defaultManager(); 79 JMenuItem menuItem = (JMenuItem)e.getComponent(); 80 Point p = e.getPoint(); 81 if(p.x >= 0 && p.x < menuItem.getWidth() && 82 p.y >= 0 && p.y < menuItem.getHeight()) { 83 manager.clearSelectedPath(); 84 menuItem.doClick(0); 85 } else { 86 manager.processMouseEvent(e); 87 } 88 } 89 public void mouseEntered(MouseEvent e) {} 90 public void mouseExited(MouseEvent e) {} 91 public void mouseDragged(MouseEvent e) { 92 MenuSelectionManager.defaultManager().processMouseEvent(e); 93 } 94 public void mouseMoved(MouseEvent e) { } 95 } 96 97 } 98 99 100 101 102 103 104 105 | Popular Tags |