⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 basicmenuui.java

📁 Mobile 应用程序使用 Java Micro Edition (Java ME) 平台
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
     * @since 1.4     */    protected class MouseInputHandler implements MouseInputListener {        // NOTE: This class exists only for backward compatability. All        // its functionality has been moved into Handler. If you need to add        // new functionality add it to the Handler, but make sure this        // class calls into the Handler.	public void mouseClicked(MouseEvent e) {            getHandler().mouseClicked(e);        }	/**	 * Invoked when the mouse has been clicked on the menu. This	 * method clears or sets the selection path of the	 * MenuSelectionManager.	 * 	 * @param e the mouse event	 */        public void mousePressed(MouseEvent e) {            getHandler().mousePressed(e);        }	/**	 * Invoked when the mouse has been released on the menu. Delegates the 	 * mouse event to the MenuSelectionManager.	 *	 * @param e the mouse event	 */	public void mouseReleased(MouseEvent e) {            getHandler().mouseReleased(e);	}	/**	 * Invoked when the cursor enters the menu. This method sets the selected	 * path for the MenuSelectionManager and handles the case	 * in which a menu item is used to pop up an additional menu, as in a 	 * hierarchical menu system.	 * 	 * @param e the mouse event; not used	 */ 	public void mouseEntered(MouseEvent e) {            getHandler().mouseEntered(e);	}	public void mouseExited(MouseEvent e) {            getHandler().mouseExited(e);	}		/**	 * Invoked when a mouse button is pressed on the menu and then dragged.	 * Delegates the mouse event to the MenuSelectionManager.	 *	 * @param e the mouse event	 * @see java.awt.event.MouseMotionListener#mouseDragged	 */	public void mouseDragged(MouseEvent e) {            getHandler().mouseDragged(e);	}	public void mouseMoved(MouseEvent e) {            getHandler().mouseMoved(e);	}    }    /**     * As of Java 2 platform 1.4, this previously undocumented class     * is now obsolete. KeyBindings are now managed by the popup menu.     */    public class ChangeHandler implements ChangeListener {        public JMenu    menu;	public BasicMenuUI ui;        public boolean  isSelected = false;        public Component wasFocused;        public ChangeHandler(JMenu m, BasicMenuUI ui) {            menu = m;            this.ui = ui;        }        public void stateChanged(ChangeEvent e) { }    }    private class Handler extends BasicMenuItemUI.Handler implements            MenuKeyListener {        //        // PropertyChangeListener        //        public void propertyChange(PropertyChangeEvent e) {	    if (e.getPropertyName() == AbstractButton.                             MNEMONIC_CHANGED_PROPERTY) {                updateMnemonicBinding();	    }            else {		if (e.getPropertyName().equals("ancestor")) {		    updateDefaultBackgroundColor();	        }                super.propertyChange(e);            }	}        //        // MouseInputListener        //	public void mouseClicked(MouseEvent e) {        }	/**	 * Invoked when the mouse has been clicked on the menu. This	 * method clears or sets the selection path of the	 * MenuSelectionManager.	 * 	 * @param e the mouse event	 */        public void mousePressed(MouseEvent e) {	    JMenu menu = (JMenu)menuItem;	    if (!menu.isEnabled())		return;	    MenuSelectionManager manager = 		MenuSelectionManager.defaultManager();            if(menu.isTopLevelMenu()) {		if(menu.isSelected()) {		    manager.clearSelectedPath();		} else {		    Container cnt = menu.getParent();		    if(cnt != null && cnt instanceof JMenuBar) {			MenuElement me[] = new MenuElement[2];			me[0]=(MenuElement)cnt;			me[1]=menu;			manager.setSelectedPath(me);		    }		}	    }            MenuElement selectedPath[] = manager.getSelectedPath();            if (selectedPath.length > 0 &&                 selectedPath[selectedPath.length-1] != menu.getPopupMenu()) {		if(menu.isTopLevelMenu() || 		   menu.getDelay() == 0) {                    appendPath(selectedPath, menu.getPopupMenu());		} else {		    setupPostTimer(menu);		}            }        }	/**	 * Invoked when the mouse has been released on the menu. Delegates the 	 * mouse event to the MenuSelectionManager.	 *	 * @param e the mouse event	 */	public void mouseReleased(MouseEvent e) {	    JMenu menu = (JMenu)menuItem;	    if (!menu.isEnabled())		return;	    MenuSelectionManager manager = 		MenuSelectionManager.defaultManager();	    manager.processMouseEvent(e);	    if (!e.isConsumed())		manager.clearSelectedPath();			}	/**	 * Invoked when the cursor enters the menu. This method sets the selected	 * path for the MenuSelectionManager and handles the case	 * in which a menu item is used to pop up an additional menu, as in a 	 * hierarchical menu system.	 * 	 * @param e the mouse event; not used	 */ 	public void mouseEntered(MouseEvent e) {	    JMenu menu = (JMenu)menuItem;            // only disable the menu highlighting if it's disabled and the property isn't            // true. This allows disabled rollovers to work in WinL&F            if (!menu.isEnabled() && !UIManager.getBoolean("MenuItem.disabledAreNavigable")) {                return;            }	    MenuSelectionManager manager = 		MenuSelectionManager.defaultManager();	    MenuElement selectedPath[] = manager.getSelectedPath();	    	    if (!menu.isTopLevelMenu()) {		if(!(selectedPath.length > 0 && 		     selectedPath[selectedPath.length-1] == 		     menu.getPopupMenu())) {		    if(menu.getDelay() == 0) {                        appendPath(getPath(), menu.getPopupMenu());                    } else {			manager.setSelectedPath(getPath());			setupPostTimer(menu);		    }		}	    } else {		if(selectedPath.length > 0 &&		   selectedPath[0] == menu.getParent()) {		    MenuElement newPath[] = new MenuElement[3];		    // A top level menu's parent is by definition 		    // a JMenuBar		    newPath[0] = (MenuElement)menu.getParent();		    newPath[1] = menu;		    newPath[2] = menu.getPopupMenu();		    manager.setSelectedPath(newPath);		}	    }	}	public void mouseExited(MouseEvent e) {	}		/**	 * Invoked when a mouse button is pressed on the menu and then dragged.	 * Delegates the mouse event to the MenuSelectionManager.	 *	 * @param e the mouse event	 * @see java.awt.event.MouseMotionListener#mouseDragged	 */	public void mouseDragged(MouseEvent e) {	    JMenu menu = (JMenu)menuItem;	    if (!menu.isEnabled())		return;	    MenuSelectionManager.defaultManager().processMouseEvent(e);	}	public void mouseMoved(MouseEvent e) {	}        //        // MenuDragHandler        //	public void menuDragMouseEntered(MenuDragMouseEvent e) {}	public void menuDragMouseDragged(MenuDragMouseEvent e) {	    if (menuItem.isEnabled() == false)		return;	    	    MenuSelectionManager manager = e.getMenuSelectionManager();	    MenuElement path[] = e.getPath();	    	    Point p = e.getPoint();	    if(p.x >= 0 && p.x < menuItem.getWidth() &&	       p.y >= 0 && p.y < menuItem.getHeight()) {		JMenu menu = (JMenu)menuItem;		MenuElement selectedPath[] = manager.getSelectedPath();		if(!(selectedPath.length > 0 && 		     selectedPath[selectedPath.length-1] == 		     menu.getPopupMenu())) {		    if(menu.isTopLevelMenu() || 		       menu.getDelay() == 0  ||		       e.getID() == MouseEvent.MOUSE_DRAGGED) {                        appendPath(path, menu.getPopupMenu());		    } else {			manager.setSelectedPath(path);			setupPostTimer(menu);		    }		}	    } else if(e.getID() == MouseEvent.MOUSE_RELEASED) {		Component comp = manager.componentForPoint(e.getComponent(), e.getPoint());		if (comp == null)		    manager.clearSelectedPath();	    }	    	}	public void menuDragMouseExited(MenuDragMouseEvent e) {}	public void menuDragMouseReleased(MenuDragMouseEvent e) {}	            //        // MenuKeyListener        //	/**	 * Open the Menu	 */	public void menuKeyTyped(MenuKeyEvent e) {            if (!crossMenuMnemonic && BasicPopupMenuUI.getLastPopup() != null) {                // when crossMenuMnemonic is not set, we don't open a toplevel                // menu if another toplevel menu is already open                    return;                }            char key = Character.toLowerCase((char)menuItem.getMnemonic());            MenuElement path[] = e.getPath();            if (key == Character.toLowerCase(e.getKeyChar())) {                JPopupMenu popupMenu = ((JMenu)menuItem).getPopupMenu();                ArrayList newList = new ArrayList(Arrays.asList(path));                newList.add(popupMenu);                MenuElement subs[] = popupMenu.getSubElements();                MenuElement sub =                        BasicPopupMenuUI.findEnabledChild(subs, -1, true);                if(sub != null) {                    newList.add(sub);                }                MenuSelectionManager manager = e.getMenuSelectionManager();                MenuElement newPath[] = new MenuElement[0];;                newPath = (MenuElement[]) newList.toArray(newPath);                manager.setSelectedPath(newPath);                e.consume();            }        }        public void menuKeyPressed(MenuKeyEvent e) {}	public void menuKeyReleased(MenuKeyEvent e) {}    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -