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

📄 synthgraphicsutils.java

📁 JAVA的一些源码 JAVA2 STANDARD EDITION DEVELOPMENT KIT 5.0
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * @(#)SynthGraphicsUtils.java	1.16 03/12/19 * * Copyright 2004 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */package javax.swing.plaf.synth;import com.sun.java.swing.SwingUtilities2;import java.awt.*;import javax.swing.*;import javax.swing.plaf.basic.BasicHTML;import javax.swing.text.*;import sun.swing.plaf.synth.*;/** * Wrapper for primitive graphics calls. * * @version 1.16, 12/19/03 * @since 1.5 * @author Scott Violet */public class SynthGraphicsUtils {    // These are used in the text painting code to avoid allocating a bunch of    // garbage.    private Rectangle paintIconR = new Rectangle();    private Rectangle paintTextR = new Rectangle();    private Rectangle paintViewR = new Rectangle();    private Insets paintInsets = new Insets(0, 0, 0, 0);    // These Rectangles/Insets are used in the text size calculation to avoid a    // a bunch of garbage.    private Rectangle iconR = new Rectangle();    private Rectangle textR = new Rectangle();    private Rectangle viewR = new Rectangle();    private Insets viewSizingInsets = new Insets(0, 0, 0, 0);    /**     * Creates a <code>SynthGraphicsUtils</code>.     */    public SynthGraphicsUtils() {    }    /**     * Draws a line between the two end points.     *     * @param context Identifies hosting region.     * @param paintKey Identifies the portion of the component being asked     *                 to paint, may be null.     * @param g Graphics object to paint to     * @param x1 x origin     * @param y1 y origin     * @param x2 x destination     * @param y2 y destination     */    public void drawLine(SynthContext context, Object paintKey,                         Graphics g, int x1, int y1, int x2, int y2) {        g.drawLine(x1, y1, x2, y2);    }    /**     * Lays out text and an icon returning, by reference, the location to     * place the icon and text.     *     * @param ss SynthContext     * @param fm FontMetrics for the Font to use, this may be ignored     * @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 viewR Rectangle to layout text and icon in.     * @param iconR Rectangle to place icon bounds in     * @param textR Rectangle to place text in     * @param iconTextGap gap between icon and text     */    public String layoutText(SynthContext ss, FontMetrics fm,                         String text, Icon icon, int hAlign,                         int vAlign, int hTextPosition,                         int vTextPosition, Rectangle viewR,                         Rectangle iconR, Rectangle textR, int iconTextGap) {        if (icon instanceof SynthIcon) {            SynthIconWrapper wrapper = SynthIconWrapper.get((SynthIcon)icon,                                                            ss);            String formattedText = SwingUtilities.layoutCompoundLabel(                      ss.getComponent(), fm, text, wrapper, vAlign, hAlign,                      vTextPosition, hTextPosition, viewR, iconR, textR,                      iconTextGap);            SynthIconWrapper.release(wrapper);            return formattedText;        }        return SwingUtilities.layoutCompoundLabel(                      ss.getComponent(), fm, text, icon, vAlign, hAlign,                      vTextPosition, hTextPosition, viewR, iconR, textR,                      iconTextGap);    }    /**     * Returns the size of the passed in string.     *     * @param ss SynthContext     * @param font Font to use     * @param metrics FontMetrics, may be ignored     * @param text Text to get size of.     */    public int computeStringWidth(SynthContext ss, Font font,                                  FontMetrics metrics, String text) {        return SwingUtilities2.stringWidth(ss.getComponent(), metrics,                                          text);    }    /**     * Returns the minimum 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 getMinimumSize(SynthContext ss, Font font, String text,                      Icon icon, int hAlign, int vAlign, int hTextPosition,                      int vTextPosition, int iconTextGap, int mnemonicIndex) {        JComponent c = ss.getComponent();        Dimension size = getPreferredSize(ss, font, text, icon, hAlign,                                          vAlign, hTextPosition, vTextPosition,                                          iconTextGap, mnemonicIndex);	View v = (View) c.getClientProperty(BasicHTML.propertyKey);	if (v != null) {	    size.width -= v.getPreferredSpan(View.X_AXIS) -                          v.getMinimumSpan(View.X_AXIS);	}        return size;    }    /**     * Returns the maximum 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 getMaximumSize(SynthContext ss, Font font, String text,                      Icon icon, int hAlign, int vAlign, int hTextPosition,                      int vTextPosition, int iconTextGap, int mnemonicIndex) {        JComponent c = ss.getComponent();        Dimension size = getPreferredSize(ss, font, text, icon, hAlign,                                          vAlign, hTextPosition, vTextPosition,                                          iconTextGap, mnemonicIndex);	View v = (View) c.getClientProperty(BasicHTML.propertyKey);	if (v != null) {	    size.width += v.getMaximumSpan(View.X_AXIS) -                          v.getPreferredSpan(View.X_AXIS);	}        return size;    }    /**     * Returns the maximum height of the the Font from the passed in     * SynthContext.     *     * @param context SynthContext used to determine font.     * @return maximum height of the characters for the font from the passed     *         in context.     */    public int getMaximumCharHeight(SynthContext context) {        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,

⌨️ 快捷键说明

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