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

📄 metalutils.java

📁 Mobile 应用程序使用 Java Micro Edition (Java ME) 平台
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * @(#)MetalUtils.java	1.39 05/11/17 * * Copyright 2006 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ package javax.swing.plaf.metal;import javax.swing.plaf.*;import javax.swing.*;import java.awt.*;import java.awt.image.*;import java.lang.ref.*;import java.util.*;import sun.swing.CachedPainter;import sun.swing.ImageIconUIResource;/** * This is a dumping ground for random stuff we want to use in several places. * * @version 1.39 11/17/05 * @author Steve Wilson */class MetalUtils {    static void drawFlush3DBorder(Graphics g, Rectangle r) {        drawFlush3DBorder(g, r.x, r.y, r.width, r.height);    }    /**      * This draws the "Flush 3D Border" which is used throughout the Metal L&F      */    static void drawFlush3DBorder(Graphics g, int x, int y, int w, int h) {        g.translate( x, y);        g.setColor( MetalLookAndFeel.getControlDarkShadow() );	g.drawRect( 0, 0, w-2, h-2 );        g.setColor( MetalLookAndFeel.getControlHighlight() );	g.drawRect( 1, 1, w-2, h-2 );        g.setColor( MetalLookAndFeel.getControl() );	g.drawLine( 0, h-1, 1, h-2 );	g.drawLine( w-1, 0, w-2, 1 );        g.translate( -x, -y);    }    /**      * This draws a variant "Flush 3D Border"      * It is used for things like pressed buttons.      */    static void drawPressed3DBorder(Graphics g, Rectangle r) {        drawPressed3DBorder( g, r.x, r.y, r.width, r.height );    }    static void drawDisabledBorder(Graphics g, int x, int y, int w, int h) {        g.translate( x, y);        g.setColor( MetalLookAndFeel.getControlShadow() );	g.drawRect( 0, 0, w-1, h-1 );        g.translate(-x, -y);    }    /**      * This draws a variant "Flush 3D Border"      * It is used for things like pressed buttons.      */    static void drawPressed3DBorder(Graphics g, int x, int y, int w, int h) {        g.translate( x, y);        drawFlush3DBorder(g, 0, 0, w, h);        g.setColor( MetalLookAndFeel.getControlShadow() );	g.drawLine( 1, 1, 1, h-2 );	g.drawLine( 1, 1, w-2, 1 );        g.translate( -x, -y);    }    /**      * This draws a variant "Flush 3D Border"      * It is used for things like active toggle buttons.      * This is used rarely.      */    static void drawDark3DBorder(Graphics g, Rectangle r) {        drawDark3DBorder(g, r.x, r.y, r.width, r.height);    }    /**      * This draws a variant "Flush 3D Border"      * It is used for things like active toggle buttons.      * This is used rarely.      */    static void drawDark3DBorder(Graphics g, int x, int y, int w, int h) {        g.translate( x, y);        drawFlush3DBorder(g, 0, 0, w, h);        g.setColor( MetalLookAndFeel.getControl() );	g.drawLine( 1, 1, 1, h-2 );	g.drawLine( 1, 1, w-2, 1 );        g.setColor( MetalLookAndFeel.getControlShadow() );	g.drawLine( 1, h-2, 1, h-2 );	g.drawLine( w-2, 1, w-2, 1 );        g.translate( -x, -y);    }    static void drawButtonBorder(Graphics g, int x, int y, int w, int h, boolean active) {        if (active) {            drawActiveButtonBorder(g, x, y, w, h);	            } else {            drawFlush3DBorder(g, x, y, w, h);	}    }    static void drawActiveButtonBorder(Graphics g, int x, int y, int w, int h) {        drawFlush3DBorder(g, x, y, w, h);        g.setColor( MetalLookAndFeel.getPrimaryControl() );	g.drawLine( x+1, y+1, x+1, h-3 );	g.drawLine( x+1, y+1, w-3, x+1 );        g.setColor( MetalLookAndFeel.getPrimaryControlDarkShadow() );	g.drawLine( x+2, h-2, w-2, h-2 );	g.drawLine( w-2, y+2, w-2, h-2 );    }    static void drawDefaultButtonBorder(Graphics g, int x, int y, int w, int h, boolean active) {        drawButtonBorder(g, x+1, y+1, w-1, h-1, active);	            g.translate(x, y);        g.setColor( MetalLookAndFeel.getControlDarkShadow() );	g.drawRect( 0, 0, w-3, h-3 );	g.drawLine( w-2, 0, w-2, 0);	g.drawLine( 0, h-2, 0, h-2);        g.translate(-x, -y);    }        static void drawDefaultButtonPressedBorder(Graphics g, int x, int y, int w, int h) {        drawPressed3DBorder(g, x + 1, y + 1, w - 1, h - 1);        g.translate(x, y);        g.setColor(MetalLookAndFeel.getControlDarkShadow());        g.drawRect(0, 0, w - 3, h - 3);        g.drawLine(w - 2, 0, w - 2, 0);        g.drawLine(0, h - 2, 0, h - 2);        g.setColor(MetalLookAndFeel.getControl());        g.drawLine(w - 1, 0, w - 1, 0);        g.drawLine(0, h - 1, 0, h - 1);        g.translate(-x, -y);    }    /*     * Convenience function for determining ComponentOrientation.  Helps us     * avoid having Munge directives throughout the code.     */    static boolean isLeftToRight( Component c ) {        return c.getComponentOrientation().isLeftToRight();    }        static int getInt(Object key, int defaultValue) {        Object value = UIManager.get(key);        if (value instanceof Integer) {            return ((Integer)value).intValue();        }        if (value instanceof String) {            try {                return Integer.parseInt((String)value);            } catch (NumberFormatException nfe) {}        }        return defaultValue;    }    //    // Ocean specific stuff.    //     /**     * Draws a radial type gradient. The gradient will be drawn vertically if     * <code>vertical</code> is true, otherwise horizontally.     * The UIManager key consists of five values:     * r1 r2 c1 c2 c3. The gradient is broken down into four chunks drawn     * in order from the origin.     * <ol>     * <li>Gradient r1 % of the size from c1 to c2     * <li>Rectangle r2 % of the size in c2.     * <li>Gradient r1 % of the size from c2 to c1     * <li>The remaining size will be filled with a gradient from c1 to c3.     * </ol>     *     * @param c Component rendering to     * @param g Graphics to draw to.     * @param key UIManager key used to look up gradient values.     * @param x X coordinate to draw from     * @param y Y coordinate to draw from     * @param w Width to draw to     * @param h Height to draw to     * @param vertical Direction of the gradient     * @return true if <code>key</code> exists, otherwise false.     */    static boolean drawGradient(Component c, Graphics g, String key,                                int x, int y, int w, int h, boolean vertical) {        java.util.List gradient = (java.util.List)UIManager.get(key);        if (gradient == null || !(g instanceof Graphics2D)) {            return false;        }        if (w <= 0 || h <= 0) {            return true;        }        GradientPainter.INSTANCE.paint(                c, (Graphics2D)g, gradient, x, y, w, h, vertical);        return true;    }    private static class GradientPainter extends CachedPainter {        /**         * Instance used for painting.  This is the only instance that is         * ever created.         */        public static final GradientPainter INSTANCE = new GradientPainter(8);        // Size of images to create. For vertical gradients this is the width,

⌨️ 快捷键说明

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