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

📄 synthmenuitemui.java

📁 Mobile 应用程序使用 Java Micro Edition (Java ME) 平台
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        else {            SynthStyle style = accContext.getStyle();            acceleratorRect.width = style.getGraphicsUtils(accContext).                    computeStringWidth(accContext, fmAccel.getFont(), fmAccel,                                       acceleratorText);            acceleratorRect.height = fmAccel.getHeight();        }        /* Initialize the checkIcon bounds rectangle's width & height.         */	if( useCheckAndArrow) {	    if (checkIcon != null) {		checkIconRect.width = SynthIcon.getIconWidth(checkIcon,                                                             context);		checkIconRect.height = SynthIcon.getIconHeight(checkIcon,                                                               context);	    } 	    else {		checkIconRect.width = checkIconRect.height = 0;	    }	    	    /* Initialize the arrowIcon bounds rectangle width & height.	     */	    	    if (arrowIcon != null) {		arrowIconRect.width = SynthIcon.getIconWidth(arrowIcon,                                                             context);		arrowIconRect.height = SynthIcon.getIconHeight(arrowIcon,                                                               context);	    } else {		arrowIconRect.width = arrowIconRect.height = 0;	    }        }        Rectangle labelRect = iconRect.union(textRect);        if( SynthLookAndFeel.isLeftToRight(context.getComponent()) ) {            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 + menuItemGap;                textRect.x += menuItemGap + checkIconRect.width;                iconRect.x += menuItemGap + checkIconRect.width;                arrowIconRect.x = viewRect.x + viewRect.width - menuItemGap                                  - arrowIconRect.width;            }            /* Align icons and text horizontally */            if(popupUI != null) {                int thisTextOffset = popupUI.adjustTextOffset(textRect.x                                                              - viewRect.x);                textRect.x = thisTextOffset + viewRect.x;                if(icon != null) {                    if(horizontalTextPosition == SwingConstants.TRAILING ||                       horizontalTextPosition == SwingConstants.RIGHT) {                        int thisIconOffset =                            popupUI.adjustIconOffset(iconRect.x - viewRect.x);                        iconRect.x = thisIconOffset + viewRect.x;                    } else if(horizontalTextPosition                                  == SwingConstants.LEADING ||                              horizontalTextPosition == SwingConstants.LEFT) {                        iconRect.x = textRect.x + textRect.width + menuItemGap;                    } else {                        int maxIconValue = popupUI.adjustIconOffset(0);                        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 - menuItemGap                                  - checkIconRect.width;                textRect.x -= menuItemGap + checkIconRect.width;                iconRect.x -= menuItemGap + checkIconRect.width;                      arrowIconRect.x = viewRect.x + menuItemGap;            }            /* Align icons and text horizontally */            if(popupUI != null) {                int thisTextOffset = viewRect.x + viewRect.width                                     - textRect.x - textRect.width;                thisTextOffset = popupUI.adjustTextOffset(thisTextOffset);                textRect.x = viewRect.x + viewRect.width                             - thisTextOffset - textRect.width;                if(icon != null) {                    if(horizontalTextPosition == SwingConstants.TRAILING ||                       horizontalTextPosition == SwingConstants.LEFT) {                        int thisIconOffset = viewRect.x + viewRect.width                                             - iconRect.x - iconRect.width;                        thisIconOffset =                            popupUI.adjustIconOffset(thisIconOffset);                        iconRect.x = viewRect.x + viewRect.width                                     - thisIconOffset - iconRect.width;                    } else if(horizontalTextPosition                                  == SwingConstants.LEADING ||                              horizontalTextPosition == SwingConstants.RIGHT) {                        iconRect.x = textRect.x - menuItemGap - iconRect.width;                    } else {                        int maxIconValue = popupUI.adjustIconOffset(0);                        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);        }        return text;    }    // these rects are used for painting and preferredsize calculations.    // they used to be regenerated constantly.  Now they are reused.    static Rectangle iconRect = new Rectangle();    static Rectangle textRect = new Rectangle();    static Rectangle acceleratorRect = new Rectangle();    static Rectangle checkIconRect = new Rectangle();    static Rectangle arrowIconRect = new Rectangle();    static Rectangle viewRect = new Rectangle(Short.MAX_VALUE,Short.MAX_VALUE);    static Rectangle r = new Rectangle();    private static void resetRects() {        iconRect.setBounds(0, 0, 0, 0);        textRect.setBounds(0, 0, 0, 0);        acceleratorRect.setBounds(0, 0, 0, 0);        checkIconRect.setBounds(0, 0, 0, 0);        arrowIconRect.setBounds(0, 0, 0, 0);        viewRect.setBounds(0,0,Short.MAX_VALUE, Short.MAX_VALUE);        r.setBounds(0, 0, 0, 0);    }    protected void installDefaults() {        updateStyle(menuItem);    }    protected void installListeners() {        super.installListeners();        menuItem.addPropertyChangeListener(this);    }    private void updateStyle(JMenuItem mi) {        SynthContext context = getContext(mi, ENABLED);        SynthStyle oldStyle = style;        style = SynthLookAndFeel.updateStyle(context, this);        if (oldStyle != style) {            String prefix = getPropertyPrefix();             Object value = style.get(context, prefix + ".textIconGap");             if (value != null) {                 LookAndFeel.installProperty(mi, "iconTextGap", value);             }             defaultTextIconGap = mi.getIconTextGap();               if (menuItem.getMargin() == null ||                          (menuItem.getMargin() instanceof UIResource)) {                Insets insets = (Insets)style.get(context, prefix + ".margin");                if (insets == null) {                    // Some places assume margins are non-null.                    insets = SynthLookAndFeel.EMPTY_UIRESOURCE_INSETS;                }                menuItem.setMargin(insets);            }            acceleratorDelimiter = style.getString(context, prefix +                                            ".acceleratorDelimiter", "+");            arrowIcon = style.getIcon(context, prefix + ".arrowIcon");            checkIcon = style.getIcon(context, prefix + ".checkIcon");            if (oldStyle != null) {                uninstallKeyboardActions();                installKeyboardActions();            }        }        context.dispose();        SynthContext accContext = getContext(mi, Region.MENU_ITEM_ACCELERATOR,                                             ENABLED);        accStyle = SynthLookAndFeel.updateStyle(accContext, this);        accContext.dispose();    }    protected void uninstallDefaults() {        SynthContext context = getContext(menuItem, ENABLED);        style.uninstallDefaults(context);        context.dispose();        style = null;        SynthContext accContext = getContext(menuItem,                                     Region.MENU_ITEM_ACCELERATOR, ENABLED);        accStyle.uninstallDefaults(accContext);        accContext.dispose();        accStyle = null;        super.uninstallDefaults();    }    protected void uninstallListeners() {        super.uninstallListeners();        menuItem.removePropertyChangeListener(this);    }    public SynthContext getContext(JComponent c) {        return getContext(c, getComponentState(c));    }    SynthContext getContext(JComponent c, int state) {        return SynthContext.getContext(SynthContext.class, c,                    SynthLookAndFeel.getRegion(c), style, state);    }    public SynthContext getContext(JComponent c, Region region) {        return getContext(c, region, getComponentState(c, region));    }    private SynthContext getContext(JComponent c, Region region, int state) {        return SynthContext.getContext(SynthContext.class, c,                                       region, accStyle, state);    }    private Region getRegion(JComponent c) {        return SynthLookAndFeel.getRegion(c);    }    private int getComponentState(JComponent c) {        int state;        if (!c.isEnabled()) {            state = DISABLED;        }        else if (menuItem.isArmed()) {            state = MOUSE_OVER;        }        else {            state = SynthLookAndFeel.getComponentState(c);        }        if (menuItem.isSelected()) {            state |= SELECTED;        }        return state;    }    private int getComponentState(JComponent c, Region region) {        return getComponentState(c);    }    protected Dimension getPreferredMenuItemSize(JComponent c,                                                     Icon checkIcon,                                                     Icon arrowIcon,                                                     int defaultTextIconGap) {        SynthContext context = getContext(c);        SynthContext accContext = getContext(c, Region.MENU_ITEM_ACCELERATOR);        Dimension value = getPreferredMenuItemSize(context, accContext,                  true, c, checkIcon, arrowIcon, defaultTextIconGap,                  acceleratorDelimiter);        context.dispose();        accContext.dispose();        return value;    }    public void update(Graphics g, JComponent c) {        SynthContext context = getContext(c);        SynthLookAndFeel.update(context, g);        paintBackground(context, g, c);        paint(context, g);        context.dispose();    }    public void paint(Graphics g, JComponent c) {        SynthContext context = getContext(c);        paint(context, g);        context.dispose();    }    protected void paint(SynthContext context, Graphics g) {        SynthContext accContext = getContext(menuItem,                                             Region.MENU_ITEM_ACCELERATOR);        String prefix = getPropertyPrefix();        paint(context, accContext, g,                style.getIcon(getContext(context.getComponent()),                    prefix + ".checkIcon"),                style.getIcon(getContext(context.getComponent()),                    prefix + ".arrowIcon"),                true, acceleratorDelimiter, defaultTextIconGap);        accContext.dispose();    }    void paintBackground(SynthContext context, Graphics g, JComponent c) {        context.getPainter().paintMenuItemBackground(context, g, 0, 0,                                                c.getWidth(), c.getHeight());    }    public void paintBorder(SynthContext context, Graphics g, int x,                            int y, int w, int h) {        context.getPainter().paintMenuItemBorder(context, g, x, y, w, h);    }    public void propertyChange(PropertyChangeEvent e) {        if (SynthLookAndFeel.shouldUpdateStyle(e)) {            updateStyle((JMenuItem)e.getSource());        }    }}

⌨️ 快捷键说明

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