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

📄 synthgraphicsutils.java

📁 Mobile 应用程序使用 Java Micro Edition (Java ME) 平台
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        FontMetrics fm = context.getComponent().getFontMetrics(            context.getStyle().getFont(context));        return (fm.getAscent() + fm.getDescent());    }    /**     * Returns the preferred size needed to properly render an icon and text.     *     * @param ss SynthContext     * @param font Font to use     * @param text Text to layout     * @param icon Icon to layout     * @param hAlign horizontal alignment     * @param vAlign vertical alignment     * @param hTextPosition horizontal text position     * @param vTextPosition vertical text position     * @param iconTextGap gap between icon and text     * @param mnemonicIndex Index into text to render the mnemonic at, -1     *        indicates no mnemonic.     */    public Dimension getPreferredSize(SynthContext ss, Font font, String text,                      Icon icon, int hAlign, int vAlign, int hTextPosition,                      int vTextPosition, int iconTextGap, int mnemonicIndex) {        JComponent c = ss.getComponent();        Insets insets = c.getInsets(viewSizingInsets);        int dx = insets.left + insets.right;        int dy = insets.top + insets.bottom;        if (icon == null && (text == null || font == null)) {            return new Dimension(dx, dy);        }        else if ((text == null) || ((icon != null) && (font == null))) {            return new Dimension(SynthIcon.getIconWidth(icon, ss) + dx,                                  SynthIcon.getIconHeight(icon, ss) + dy);        }        else {            FontMetrics fm = c.getFontMetrics(font);            iconR.x = iconR.y = iconR.width = iconR.height = 0;            textR.x = textR.y = textR.width = textR.height = 0;            viewR.x = dx;            viewR.y = dy;            viewR.width = viewR.height = Short.MAX_VALUE;            layoutText(ss, fm, text, icon, hAlign, vAlign,                   hTextPosition, vTextPosition, viewR, iconR, textR,                   iconTextGap);            int x1 = Math.min(iconR.x, textR.x);            int x2 = Math.max(iconR.x + iconR.width, textR.x + textR.width);            int y1 = Math.min(iconR.y, textR.y);            int y2 = Math.max(iconR.y + iconR.height, textR.y + textR.height);            Dimension rv = new Dimension(x2 - x1, y2 - y1);            rv.width += dx;            rv.height += dy;            return rv;        }    }    /**     * Paints text at the specified location. This will not attempt to     * render the text as html nor will it offset by the insets of the     * component.     *     * @param ss SynthContext     * @param g Graphics used to render string in.     * @param text Text to render     * @param bounds Bounds of the text to be drawn.     * @param mnemonicIndex Index to draw string at.     */    public void paintText(SynthContext ss, Graphics g, String text,                          Rectangle bounds, int mnemonicIndex) {        paintText(ss, g, text, bounds.x, bounds.y, mnemonicIndex);    }    /**     * Paints text at the specified location. This will not attempt to     * render the text as html nor will it offset by the insets of the     * component.     *     * @param ss SynthContext     * @param g Graphics used to render string in.     * @param text Text to render     * @param x X location to draw text at.     * @param y Upper left corner to draw text at.     * @param mnemonicIndex Index to draw string at.     */    public void paintText(SynthContext ss, Graphics g, String text,                          int x, int y, int mnemonicIndex) {        if (text != null) {            JComponent c = ss.getComponent();            SynthStyle style = ss.getStyle();            FontMetrics fm = SwingUtilities2.getFontMetrics(c, g);            y += fm.getAscent();            SwingUtilities2.drawString(c, g, text, x, y);            if (mnemonicIndex >= 0 && mnemonicIndex < text.length()) {                int underlineX = x + SwingUtilities2.stringWidth(                             c, fm, text.substring(0, mnemonicIndex));                int underlineY = y;                int underlineWidth = fm.charWidth(text.charAt(mnemonicIndex));                int underlineHeight = 1;                g.fillRect(underlineX, underlineY + fm.getDescent() - 1,                           underlineWidth, underlineHeight);            }        }    }    /**     * Paints an icon and text. This will render the text as html, if     * necessary, and offset the location by the insets of the component.     *     * @param ss SynthContext     * @param g Graphics to render string and icon into     * @param text Text to layout     * @param icon Icon to layout     * @param hAlign horizontal alignment     * @param vAlign vertical alignment     * @param hTextPosition horizontal text position     * @param vTextPosition vertical text position     * @param iconTextGap gap between icon and text     * @param mnemonicIndex Index into text to render the mnemonic at, -1     *        indicates no mnemonic.     * @param textOffset Amount to offset the text when painting     */    public void paintText(SynthContext ss, Graphics g, String text,                      Icon icon, int hAlign, int vAlign, int hTextPosition,                      int vTextPosition, int iconTextGap, int mnemonicIndex,                      int textOffset) {        if ((icon == null) && (text == null)) {            return;        }        JComponent c = ss.getComponent();        FontMetrics fm = SwingUtilities2.getFontMetrics(c, g);        Insets insets = SynthLookAndFeel.getPaintingInsets(ss, paintInsets);        paintViewR.x = insets.left;        paintViewR.y = insets.top;        paintViewR.width = c.getWidth() - (insets.left + insets.right);        paintViewR.height = c.getHeight() - (insets.top + insets.bottom);        paintIconR.x = paintIconR.y = paintIconR.width = paintIconR.height = 0;        paintTextR.x = paintTextR.y = paintTextR.width = paintTextR.height = 0;        String clippedText =             layoutText(ss, fm, text, icon, hAlign, vAlign,                   hTextPosition, vTextPosition, paintViewR, paintIconR,                   paintTextR, iconTextGap);        if (icon != null) {            Color color = g.getColor();            paintIconR.x += textOffset;            paintIconR.y += textOffset;            SynthIcon.paintIcon(icon, ss, g, paintIconR.x, paintIconR.y,                                paintIconR.width, paintIconR.height);            g.setColor(color);        }        if (text != null) {	    View v = (View) c.getClientProperty(BasicHTML.propertyKey);	    if (v != null) {		v.paint(g, paintTextR);	    } else {                paintTextR.x += textOffset;                paintTextR.y += textOffset;                paintText(ss, g, clippedText, paintTextR, mnemonicIndex);	    }        }    }    /**     * Wraps a SynthIcon around the Icon interface, forwarding calls to     * the SynthIcon with a given SynthContext.     */    private static class SynthIconWrapper implements Icon {        private static final java.util.List CACHE = new java.util.ArrayList(1);        private SynthIcon synthIcon;        private SynthContext context;        static SynthIconWrapper get(SynthIcon icon, SynthContext context) {            synchronized(CACHE) {                int size = CACHE.size();                if (size > 0) {                    SynthIconWrapper wrapper = (SynthIconWrapper)CACHE.remove(                                               size - 1);                    wrapper.reset(icon, context);                    return wrapper;                }            }            return new SynthIconWrapper(icon, context);        }        static void release(SynthIconWrapper wrapper) {            wrapper.reset(null, null);            synchronized(CACHE) {                CACHE.add(wrapper);            }        }        SynthIconWrapper(SynthIcon icon, SynthContext context) {            reset(icon, context);        }        void reset(SynthIcon icon, SynthContext context) {            synthIcon = icon;            this.context = context;        }        public void paintIcon(Component c, Graphics g, int x, int y) {            // This is a noop as this should only be for sizing calls.        }        public int getIconWidth() {            return synthIcon.getIconWidth(context);        }        public int getIconHeight() {            return synthIcon.getIconHeight(context);        }    }}

⌨️ 快捷键说明

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