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

📄 basicmenuitemui.java

📁 JAVA 所有包
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
            g.setColor(holdc);        }        // Paint the Icon        if(icon != null ) {             if(!model.isEnabled()) {                icon = (Icon) b.getDisabledIcon();            } else if(model.isPressed() && model.isArmed()) {                icon = (Icon) b.getPressedIcon();                if(icon == null) {                    // Use default icon                    icon = (Icon) b.getIcon();                }             } else {                icon = (Icon) b.getIcon();            }                          if (icon!=null) {                icon.paintIcon(c, g, iconRect.x, iconRect.y);                g.setColor(holdc);            }        }        // Draw the Text        if(text != null) { 	    View v = (View) c.getClientProperty(BasicHTML.propertyKey); 	    if (v != null) { 		v.paint(g, textRect); 	    } else {		paintText(g, b, textRect, text);	    }	}	        // Draw the Accelerator Text        if(acceleratorText != null && !acceleratorText.equals("")) {	  //Get the maxAccWidth from the parent to calculate the offset.	  int accOffset = 0;          JComponent p = getMenuItemParent(menuItem);          if(p != null) {	    Integer maxValueInt = (Integer) p.getClientProperty(BasicMenuItemUI.MAX_ACC_WIDTH);	    int maxValue = maxValueInt != null ?                maxValueInt.intValue() : acceleratorRect.width;	    //Calculate the offset, with which the accelerator texts will be drawn with.	    accOffset = maxValue - acceleratorRect.width;	  }	  	  g.setFont( acceleratorFont );            if(!model.isEnabled()) {                // *** paint the acceleratorText disabled	      if ( disabledForeground != null )		  {                  g.setColor( disabledForeground );                  SwingUtilities2.drawString(b, g,acceleratorText,                                                acceleratorRect.x - accOffset,                                                 acceleratorRect.y + fmAccel.getAscent());                }                else                {                  g.setColor(b.getBackground().brighter());                  SwingUtilities2.drawString(b, g,acceleratorText,                                                acceleratorRect.x - accOffset, 						acceleratorRect.y + fmAccel.getAscent());                  g.setColor(b.getBackground().darker());                  SwingUtilities2.drawString(b, g,acceleratorText,                                                acceleratorRect.x - accOffset - 1, 						acceleratorRect.y + fmAccel.getAscent() - 1);                }            } else {                // *** paint the acceleratorText normally                if (model.isArmed()|| (c instanceof JMenu && model.isSelected())) {                    g.setColor( acceleratorSelectionForeground );                } else {                    g.setColor( acceleratorForeground );                }                SwingUtilities2.drawString(b, g,acceleratorText,                                              acceleratorRect.x - accOffset,                                              acceleratorRect.y + fmAccel.getAscent());            }        }        // Paint the Arrow        if (arrowIcon != null) {            if(model.isArmed() || (c instanceof JMenu &&model.isSelected()))                g.setColor(foreground);            if(useCheckAndArrow())                arrowIcon.paintIcon(c, g, arrowIconRect.x, arrowIconRect.y);        }        g.setColor(holdc);        g.setFont(holdf);    }    /**     * Draws the background of the menu item.     *      * @param g the paint graphics     * @param menuItem menu item to be painted     * @param bgColor selection background color     * @since 1.4     */    protected void paintBackground(Graphics g, JMenuItem menuItem, Color bgColor) {	ButtonModel model = menuItem.getModel();        Color oldColor = g.getColor();        int menuWidth = menuItem.getWidth();        int menuHeight = menuItem.getHeight();        if(menuItem.isOpaque()) {            if (model.isArmed()|| (menuItem instanceof JMenu && model.isSelected())) {                g.setColor(bgColor);                g.fillRect(0,0, menuWidth, menuHeight);            } else {                g.setColor(menuItem.getBackground());                g.fillRect(0,0, menuWidth, menuHeight);            }            g.setColor(oldColor);        }        else if (model.isArmed() || (menuItem instanceof JMenu &&                                     model.isSelected())) {            g.setColor(bgColor);            g.fillRect(0,0, menuWidth, menuHeight);            g.setColor(oldColor);        }    }    /**     * Renders the text of the current menu item.     * <p>     * @param g graphics context     * @param menuItem menu item to render     * @param textRect bounding rectangle for rendering the text     * @param text string to render     * @since 1.4     */    protected void paintText(Graphics g, JMenuItem menuItem, Rectangle textRect, String text) {	ButtonModel model = menuItem.getModel();	FontMetrics fm = SwingUtilities2.getFontMetrics(menuItem, g);	int mnemIndex = menuItem.getDisplayedMnemonicIndex();	if(!model.isEnabled()) {	    // *** paint the text disabled	    if ( UIManager.get("MenuItem.disabledForeground") instanceof Color ) {		g.setColor( UIManager.getColor("MenuItem.disabledForeground") );		SwingUtilities2.drawStringUnderlineCharAt(menuItem, g,text,                          mnemIndex, textRect.x,  textRect.y + fm.getAscent());	    } else {		g.setColor(menuItem.getBackground().brighter());		SwingUtilities2.drawStringUnderlineCharAt(menuItem, g, text,                           mnemIndex, textRect.x, textRect.y + fm.getAscent());		g.setColor(menuItem.getBackground().darker());		SwingUtilities2.drawStringUnderlineCharAt(menuItem, g,text,                           mnemIndex,  textRect.x - 1, textRect.y +                           fm.getAscent() - 1);	    }	} else {	    // *** paint the text normally	    if (model.isArmed()|| (menuItem instanceof JMenu && model.isSelected())) {		g.setColor(selectionForeground); // Uses protected field.	    }	    SwingUtilities2.drawStringUnderlineCharAt(menuItem, g,text,                           mnemIndex, textRect.x, textRect.y + fm.getAscent());	}    }    /**      * Compute and return the location of the icons origin, the      * location of origin of the text baseline, and a possibly clipped     * version of the compound labels string.  Locations are computed     * relative to the viewRect rectangle.      */    private String layoutMenuItem(        FontMetrics fm,        String text,        FontMetrics fmAccel,        String acceleratorText,        Icon icon,        Icon checkIcon,        Icon arrowIcon,        int verticalAlignment,        int horizontalAlignment,        int verticalTextPosition,        int horizontalTextPosition,        Rectangle viewRect,         Rectangle iconRect,         Rectangle textRect,        Rectangle acceleratorRect,        Rectangle checkIconRect,         Rectangle arrowIconRect,         int textIconGap,        int menuItemGap        )    {        SwingUtilities.layoutCompoundLabel(                            menuItem, fm, text, icon, verticalAlignment,                             horizontalAlignment, verticalTextPosition,                             horizontalTextPosition, viewRect, iconRect, textRect,                             textIconGap);        /* Initialize the acceelratorText bounds rectangle textRect.  If a null          * or and empty String was specified we substitute "" here          * and use 0,0,0,0 for acceleratorTextRect.         */        if( (acceleratorText == null) || acceleratorText.equals("") ) {            acceleratorRect.width = acceleratorRect.height = 0;            acceleratorText = "";        }        else {            acceleratorRect.width = SwingUtilities2.stringWidth(                                         menuItem, fmAccel, acceleratorText);            acceleratorRect.height = fmAccel.getHeight();        }        /* Initialize the checkIcon bounds rectangle's width & height.         */	if( useCheckAndArrow()) {	    if (checkIcon != null) {		checkIconRect.width = checkIcon.getIconWidth();		checkIconRect.height = checkIcon.getIconHeight();	    } 	    else {		checkIconRect.width = checkIconRect.height = 0;	    }	    	    /* Initialize the arrowIcon bounds rectangle width & height.	     */	    	    if (arrowIcon != null) {		arrowIconRect.width = arrowIcon.getIconWidth();		arrowIconRect.height = arrowIcon.getIconHeight();	    } else {		arrowIconRect.width = arrowIconRect.height = 0;	    }        }        JComponent p = getMenuItemParent(menuItem);        Rectangle labelRect = iconRect.union(textRect);                        int checkIconOffset = menuItemGap;        Object checkIconOffsetObject =             UIManager.get(getPropertyPrefix() + ".checkIconOffset");        if (checkIconOffsetObject instanceof Integer) {            checkIconOffset = (Integer) checkIconOffsetObject;        }        if( BasicGraphicsUtils.isLeftToRight(menuItem) ) {            /* get minimum text offset. It is defined for LTR case only. */            int minimumTextOffset = 0;            Object minimumTextOffsetObject =                 UIManager.get(getPropertyPrefix()                     + ".minimumTextOffset");            if (minimumTextOffsetObject instanceof Integer) {                minimumTextOffset = (Integer) minimumTextOffsetObject;            }            textRect.x += menuItemGap;            iconRect.x += menuItemGap;            // Position the Accelerator text rect            acceleratorRect.x = viewRect.x + viewRect.width - arrowIconRect.width                              - menuItemGap - acceleratorRect.width;                        // Position the Check and Arrow Icons             if (useCheckAndArrow()) {                checkIconRect.x = viewRect.x + checkIconOffset;                if(icon == null || checkIcon != null) {                    iconRect.x += menuItemGap + checkIconRect.width;                }                textRect.x += menuItemGap + checkIconRect.width;                                textRect.x = Math.max(textRect.x, minimumTextOffset);                arrowIconRect.x = viewRect.x + viewRect.width - menuItemGap                                  - arrowIconRect.width;            }            /* Align icons and text vertically */            if(p != null) {                Integer maxIconOffset = (Integer)                         p.getClientProperty(BasicMenuItemUI.MAX_ICON_OFFSET);                Integer maxTextOffset = (Integer)                         p.getClientProperty(BASICMENUITEMUI_MAX_TEXT_OFFSET);                int maxIconValue = maxIconOffset == null ? 0 : maxIconOffset;                int maxTextValue = maxTextOffset == null ? 0 : maxTextOffset;                int thisTextOffset = textRect.x - viewRect.x;                if(thisTextOffset > maxTextValue) {                    p.putClientProperty(BASICMENUITEMUI_MAX_TEXT_OFFSET,                                        new Integer(thisTextOffset));                } else {                    textRect.x = maxTextValue + viewRect.x;                }                if(icon != null) {                    if(horizontalTextPosition == SwingConstants.TRAILING ||                       horizontalTextPosition == SwingConstants.RIGHT) {                        int thisIconOffset = iconRect.x - viewRect.x;                        if(thisIconOffset > maxIconValue) {                            p.putClientProperty(BasicMenuItemUI.MAX_ICON_OFFSET,                                    new Integer(thisIconOffset));                        } else {                            iconRect.x = maxIconValue+viewRect.x;                        }                    } else if(horizontalTextPosition                                  == SwingConstants.LEADING ||                              horizontalTextPosition == SwingConstants.LEFT) {                        iconRect.x = textRect.x + textRect.width + menuItemGap;                    } else {                        iconRect.x = Math.max(textRect.x + textRect.width/2                            - iconRect.width/2, maxIconValue + viewRect.x);                    }                }            }        } else {            textRect.x -= menuItemGap;            iconRect.x -= menuItemGap;            // Position the Accelerator text rect            acceleratorRect.x = viewRect.x + arrowIconRect.width + menuItemGap;            // Position the Check and Arrow Icons             if (useCheckAndArrow()) {                checkIconRect.x = viewRect.x + viewRect.width - checkIconOffset                                  - checkIconRect.width;                if(icon == null || checkIcon != null) {                    iconRect.x -= menuItemGap + checkIconRect.width;                      }                textRect.x -= menuItemGap + checkIconRect.width;                arrowIconRect.x = viewRect.x + menuItemGap;            }            /* Align icons and text vertically */            if(p != null) {                Integer maxIconOffset = (Integer)                         p.getClientProperty(BasicMenuItemUI.MAX_ICON_OFFSET);                Integer maxTextOffset = (Integer)                         p.getClientProperty(BASICMENUITEMUI_MAX_TEXT_OFFSET);                int maxIconValue =  maxIconOffset == null ? 0 : maxIconOffset;                int maxTextValue =  maxTextOffset == null ? 0 : maxTextOffset;

⌨️ 快捷键说明

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