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

📄 basicmenuitemui.java

📁 JAVA 所有包
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
                int thisTextOffset = viewRect.x + viewRect.width                                     - textRect.x - textRect.width;                if(thisTextOffset > maxTextValue) {                    p.putClientProperty(BASICMENUITEMUI_MAX_TEXT_OFFSET,                                        new Integer(thisTextOffset));                } else {                    textRect.x = viewRect.x + viewRect.width                                 - maxTextValue - textRect.width;                }                int thisIconOffset = 0;                if(icon != null) {                    if(horizontalTextPosition == SwingConstants.TRAILING ||                       horizontalTextPosition == SwingConstants.LEFT) {                        thisIconOffset = viewRect.x + viewRect.width                                - iconRect.x - iconRect.width;                        if(thisIconOffset > maxIconValue) {                            p.putClientProperty(BasicMenuItemUI.MAX_ICON_OFFSET,                                    new Integer(thisIconOffset));                        } else {                            iconRect.x = viewRect.x + viewRect.width                                    - maxIconValue - iconRect.width;                        }                    } else if(horizontalTextPosition                                  == SwingConstants.LEADING ||                              horizontalTextPosition == SwingConstants.RIGHT) {                        iconRect.x = textRect.x - menuItemGap - iconRect.width;                    } else {                        iconRect.x = textRect.x + textRect.width/2                                     - iconRect.width/2;                        if(iconRect.x + iconRect.width >                               viewRect.x + viewRect.width - maxIconValue  ) {                            iconRect.x = iconRect.x = viewRect.x +                                viewRect.width - maxIconValue - iconRect.width;                        }                    }                }            }        }        // Align the accelertor text and the check and arrow icons vertically        // with the center of the label rect.          acceleratorRect.y = labelRect.y + (labelRect.height/2) - (acceleratorRect.height/2);        if( useCheckAndArrow() ) {            arrowIconRect.y = labelRect.y + (labelRect.height/2) - (arrowIconRect.height/2);            checkIconRect.y = labelRect.y + (labelRect.height/2) - (checkIconRect.height/2);        }        /*        System.out.println("Layout: text="+menuItem.getText()+"\n\tv="                           +viewRect+"\n\tc="+checkIconRect+"\n\ti="                           +iconRect+"\n\tt="+textRect+"\n\tacc="                           +acceleratorRect+"\n\ta="+arrowIconRect+"\n");        */                return text;    }    /*     * Returns false if the component is a JMenu and it is a top     * level menu (on the menubar).     */    private boolean useCheckAndArrow(){	boolean b = true;	if((menuItem instanceof JMenu) &&	   (((JMenu)menuItem).isTopLevelMenu())) {	    b = false;	}	return b;    }    public MenuElement[] getPath() {        MenuSelectionManager m = MenuSelectionManager.defaultManager();        MenuElement oldPath[] = m.getSelectedPath();        MenuElement newPath[];        int i = oldPath.length;        if (i == 0)            return new MenuElement[0];        Component parent = menuItem.getParent();        if (oldPath[i-1].getComponent() == parent) {            // The parent popup menu is the last so far            newPath = new MenuElement[i+1];            System.arraycopy(oldPath, 0, newPath, 0, i);            newPath[i] = menuItem;        } else {            // A sibling menuitem is the current selection            //             //  This probably needs to handle 'exit submenu into             // a menu item.  Search backwards along the current            // selection until you find the parent popup menu,            // then copy up to that and add yourself...            int j;            for (j = oldPath.length-1; j >= 0; j--) {                if (oldPath[j].getComponent() == parent)                    break;            }            newPath = new MenuElement[j+2];            System.arraycopy(oldPath, 0, newPath, 0, j+1);            newPath[j+1] = menuItem;            /*            System.out.println("Sibling condition -- ");            System.out.println("Old array : ");            printMenuElementArray(oldPath, false);            System.out.println("New array : ");            printMenuElementArray(newPath, false);            */        }        return newPath;    }    void printMenuElementArray(MenuElement path[], boolean dumpStack) {        System.out.println("Path is(");        int i, j;        for(i=0,j=path.length; i<j ;i++){            for (int k=0; k<=i; k++)                System.out.print("  ");            MenuElement me = (MenuElement) path[i];            if(me instanceof JMenuItem)                 System.out.println(((JMenuItem)me).getText() + ", ");            else if (me == null)                System.out.println("NULL , ");            else                System.out.println("" + me + ", ");        }        System.out.println(")");        if (dumpStack == true)            Thread.dumpStack();    }    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);        }        public void mousePressed(MouseEvent e) {            getHandler().mousePressed(e);        }        public void mouseReleased(MouseEvent e) {            getHandler().mouseReleased(e);        }        public void mouseEntered(MouseEvent e) {            getHandler().mouseEntered(e);        }        public void mouseExited(MouseEvent e) {            getHandler().mouseExited(e);        }        public void mouseDragged(MouseEvent e) {            getHandler().mouseDragged(e);        }        public void mouseMoved(MouseEvent e) {            getHandler().mouseMoved(e);        }    }    private static class Actions extends UIAction {        private static final String CLICK = "doClick";        Actions(String key) {            super(key);        }	public void actionPerformed(ActionEvent e) {	    JMenuItem mi = (JMenuItem)e.getSource();	    MenuSelectionManager.defaultManager().clearSelectedPath();	    mi.doClick();	}    }    /**     * Call this method when a menu item is to be activated.     * This method handles some of the details of menu item activation     * such as clearing the selected path and messaging the      * JMenuItem's doClick() method.     *     * @param msm  A MenuSelectionManager. The visual feedback and      *             internal bookkeeping tasks are delegated to      *             this MenuSelectionManager. If <code>null</code> is     *             passed as this argument, the      *             <code>MenuSelectionManager.defaultManager</code> is     *             used.     * @see MenuSelectionManager     * @see JMenuItem#doClick(int)     * @since 1.4     */    protected void doClick(MenuSelectionManager msm) {	// Auditory cue	if (! isInternalFrameSystemMenu()) {            BasicLookAndFeel.playSound(menuItem, getPropertyPrefix() +                                       ".commandSound");	}	// Visual feedback	if (msm == null) {	    msm = MenuSelectionManager.defaultManager();	}	msm.clearSelectedPath();	menuItem.doClick(0);    }    /**      * This is to see if the menu item in question is part of the      * system menu on an internal frame.     * The Strings that are being checked can be found in      * MetalInternalFrameTitlePaneUI.java,     * WindowsInternalFrameTitlePaneUI.java, and     * MotifInternalFrameTitlePaneUI.java.     *     * @since 1.4     */    private boolean isInternalFrameSystemMenu() {	String actionCommand = menuItem.getActionCommand(); 	if ((actionCommand == "Close") ||	    (actionCommand == "Minimize") ||	    (actionCommand == "Restore") ||	    (actionCommand == "Maximize")) {	  return true;	} else {	  return false;	}     }    // BasicMenuUI subclasses this.    class Handler implements MenuDragMouseListener,                           MouseInputListener, PropertyChangeListener {        //        // MouseInputListener        //        public void mouseClicked(MouseEvent e) {}        public void mousePressed(MouseEvent e) {        }        public void mouseReleased(MouseEvent e) {            MenuSelectionManager manager =                 MenuSelectionManager.defaultManager();            Point p = e.getPoint();            if(p.x >= 0 && p.x < menuItem.getWidth() &&               p.y >= 0 && p.y < menuItem.getHeight()) {		doClick(manager);            } else {                manager.processMouseEvent(e);            }        }        public void mouseEntered(MouseEvent e) {            MenuSelectionManager manager = MenuSelectionManager.defaultManager();	    int modifiers = e.getModifiers();	    // 4188027: drag enter/exit added in JDK 1.1.7A, JDK1.2	    	    if ((modifiers & (InputEvent.BUTTON1_MASK |			      InputEvent.BUTTON2_MASK | InputEvent.BUTTON3_MASK)) !=0 ) {		MenuSelectionManager.defaultManager().processMouseEvent(e);	    } else {	    manager.setSelectedPath(getPath());	     }        }        public void mouseExited(MouseEvent e) {            MenuSelectionManager manager = MenuSelectionManager.defaultManager();	    int modifiers = e.getModifiers();	    // 4188027: drag enter/exit added in JDK 1.1.7A, JDK1.2	    if ((modifiers & (InputEvent.BUTTON1_MASK |			      InputEvent.BUTTON2_MASK | InputEvent.BUTTON3_MASK)) !=0 ) {		MenuSelectionManager.defaultManager().processMouseEvent(e);	    } else {		MenuElement path[] = manager.getSelectedPath();		if (path.length > 1 && path[path.length-1] == menuItem) {		    MenuElement newPath[] = new MenuElement[path.length-1];		    int i,c;		    for(i=0,c=path.length-1;i<c;i++)			newPath[i] = path[i];		    manager.setSelectedPath(newPath);		}		}        }        public void mouseDragged(MouseEvent e) {            MenuSelectionManager.defaultManager().processMouseEvent(e);        }        public void mouseMoved(MouseEvent e) {        }        //        // MenuDragListener        //        public void menuDragMouseEntered(MenuDragMouseEvent e) {            MenuSelectionManager manager = e.getMenuSelectionManager();            MenuElement path[] = e.getPath();            manager.setSelectedPath(path);        }        public void menuDragMouseDragged(MenuDragMouseEvent e) {            MenuSelectionManager manager = e.getMenuSelectionManager();            MenuElement path[] = e.getPath();            manager.setSelectedPath(path);        }        public void menuDragMouseExited(MenuDragMouseEvent e) {}        public void menuDragMouseReleased(MenuDragMouseEvent e) {            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()) {		doClick(manager);            } else {                manager.clearSelectedPath();            }        }        //        // PropertyChangeListener        //	public void propertyChange(PropertyChangeEvent e) {	    String name = e.getPropertyName();	    if (name == "labelFor" || name == "displayedMnemonic" ||		name == "accelerator") {		updateAcceleratorBinding();	    } else if (name == "text" || "font" == name ||                       "foreground" == name) {		// remove the old html view client property if one		// existed, and install a new one if the text installed		// into the JLabel is html source.		JMenuItem lbl = ((JMenuItem) e.getSource());		String text = lbl.getText();		BasicHTML.updateRenderer(lbl, text);            } else if (name  == "iconTextGap") {                defaultTextIconGap = ((Number)e.getNewValue()).intValue();            }	}    }}

⌨️ 快捷键说明

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