1 7 package com.sun.java.swing.plaf.motif; 8 9 import java.awt.*; 10 import java.awt.event.*; 11 import javax.swing.*; 12 import javax.swing.event.*; 13 import javax.swing.plaf.*; 14 import javax.swing.border.*; 15 import javax.swing.plaf.basic.*; 16 17 18 import javax.swing.plaf.basic.BasicMenuUI ; 19 20 28 public class MotifMenuUI extends BasicMenuUI 29 { 30 31 public static ComponentUI createUI( JComponent x ) { 32 return new MotifMenuUI(); 33 } 34 35 48 protected ChangeListener createChangeListener(JComponent c) { 49 return new MotifChangeHandler((JMenu)c, this); 50 } 51 52 public void paint(Graphics g, JComponent c){ 53 MotifGraphicsUtils.paintMenuItem(g,c,checkIcon,arrowIcon, 54 selectionBackground, selectionForeground, 55 defaultTextIconGap); 56 } 57 58 private boolean popupIsOpen(JMenu m,MenuElement me[]) { 59 int i; 60 JPopupMenu pm = m.getPopupMenu(); 61 62 for(i=me.length-1;i>=0;i--) { 63 if(me[i].getComponent() == pm) 64 return true; 65 } 66 return false; 67 } 68 69 protected MouseInputListener createMouseInputListener(JComponent c) { 70 return new MouseInputHandler(); 71 } 72 73 public class MotifChangeHandler extends ChangeHandler { 74 public MotifChangeHandler(JMenu m, MotifMenuUI ui) { 75 super(m, ui); 76 } 77 78 79 public void stateChanged(ChangeEvent e) { 80 JMenuItem c = (JMenuItem)e.getSource(); 81 if (c.isArmed() || c.isSelected()) { 82 c.setBorderPainted(true); 83 } else { 85 c.setBorderPainted(false); 86 } 87 88 super.stateChanged(e); 89 } 90 } 91 92 protected class MouseInputHandler implements MouseInputListener { 93 public void mouseClicked(MouseEvent e) {} 94 public void mousePressed(MouseEvent e) { 95 MenuSelectionManager manager = MenuSelectionManager.defaultManager(); 96 JMenu menu = (JMenu)e.getComponent(); 97 if(menu.isEnabled()) { 98 if(menu.isTopLevelMenu()) { 99 if(menu.isSelected()) { 100 manager.clearSelectedPath(); 101 } else { 102 Container cnt = menu.getParent(); 103 if(cnt != null && cnt instanceof JMenuBar) { 104 MenuElement me[] = new MenuElement[2]; 105 me[0]=(MenuElement)cnt; 106 me[1]=menu; 107 manager.setSelectedPath(me); 108 } 109 } 110 } 111 112 MenuElement path[] = getPath(); 113 if (path.length > 0) { 114 MenuElement newPath[] = new MenuElement[path.length+1]; 115 System.arraycopy(path,0,newPath,0,path.length); 116 newPath[path.length] = menu.getPopupMenu(); 117 manager.setSelectedPath(newPath); 118 } 119 } 120 } 121 122 public void mouseReleased(MouseEvent e) { 123 MenuSelectionManager manager = 124 MenuSelectionManager.defaultManager(); 125 JMenuItem menuItem = (JMenuItem)e.getComponent(); 126 Point p = e.getPoint(); 127 if(!(p.x >= 0 && p.x < menuItem.getWidth() && 128 p.y >= 0 && p.y < menuItem.getHeight())) { 129 manager.processMouseEvent(e); 130 } 131 } 132 public void mouseEntered(MouseEvent e) {} 133 public void mouseExited(MouseEvent e) {} 134 public void mouseDragged(MouseEvent e) { 135 MenuSelectionManager.defaultManager().processMouseEvent(e); 136 } 137 public void mouseMoved(MouseEvent e) { } 138 } 139 140 } 141 142 143 144 145 146 | Popular Tags |