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