windowsiconfactory.java

来自「JAVA的一些源码 JAVA2 STANDARD EDITION DEVELO」· Java 代码 · 共 878 行 · 第 1/3 页

JAVA
878
字号
/* * @(#)WindowsIconFactory.java	1.24 07/01/18 * * Copyright 2004 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */package com.sun.java.swing.plaf.windows;import javax.swing.*;import javax.swing.plaf.ButtonUI;import javax.swing.plaf.UIResource;import java.awt.*;import java.io.Serializable;import com.sun.java.swing.plaf.windows.TMSchema.*;import com.sun.java.swing.plaf.windows.XPStyle.Skin;import sun.swing.MenuItemCheckIconFactory;/** * Factory object that can vend Icons appropriate for the Windows L & F. * <p> * <strong>Warning:</strong> * Serialized objects of this class will not be compatible with  * future Swing releases.  The current serialization support is appropriate * for short term storage or RMI between applications running the same * version of Swing.  A future release of Swing will provide support for * long term persistence. * * @version 1.24 01/18/07 * @author David Kloba * @author Georges Saab * @author Rich Schiavi */public class WindowsIconFactory implements Serializable{    private static Icon frame_closeIcon;    private static Icon frame_iconifyIcon;    private static Icon frame_maxIcon;    private static Icon frame_minIcon;    private static Icon frame_resizeIcon;    private static Icon checkBoxIcon;    private static Icon radioButtonIcon;    private static Icon checkBoxMenuItemIcon;    private static Icon radioButtonMenuItemIcon;    private static Icon menuItemCheckIcon;    private static Icon menuItemArrowIcon;    private static Icon menuArrowIcon;    private static VistaMenuItemCheckIconFactory menuItemCheckIconFactory;    public static Icon getMenuItemCheckIcon() {	if (menuItemCheckIcon == null) {	    menuItemCheckIcon = new MenuItemCheckIcon();	}	return menuItemCheckIcon;    }    public static Icon getMenuItemArrowIcon() {	if (menuItemArrowIcon == null) {	    menuItemArrowIcon = new MenuItemArrowIcon();	}	return menuItemArrowIcon;    }    public static Icon getMenuArrowIcon() {	if (menuArrowIcon == null) {	    menuArrowIcon = new MenuArrowIcon();	}	return menuArrowIcon;    }    public static Icon getCheckBoxIcon() {	if (checkBoxIcon == null) {	    checkBoxIcon = new CheckBoxIcon();	}	return checkBoxIcon;    }    public static Icon getRadioButtonIcon() {	if (radioButtonIcon == null) {	    radioButtonIcon = new RadioButtonIcon();	}	return radioButtonIcon;    }    public static Icon getCheckBoxMenuItemIcon() {	if (checkBoxMenuItemIcon == null) {	    checkBoxMenuItemIcon = new CheckBoxMenuItemIcon();	}	return checkBoxMenuItemIcon;    }    public static Icon getRadioButtonMenuItemIcon() {	if (radioButtonMenuItemIcon == null) {	    radioButtonMenuItemIcon = new RadioButtonMenuItemIcon();	}	return radioButtonMenuItemIcon;    }    static    synchronized VistaMenuItemCheckIconFactory getMenuItemCheckIconFactory() {        if (menuItemCheckIconFactory == null) {            menuItemCheckIconFactory =                new VistaMenuItemCheckIconFactory();        }        return menuItemCheckIconFactory;    }    public static Icon createFrameCloseIcon() {	if (frame_closeIcon == null) {            frame_closeIcon = new FrameButtonIcon(Part.WP_CLOSEBUTTON);	}	return frame_closeIcon;    }    public static Icon createFrameIconifyIcon() {	if (frame_iconifyIcon == null) {            frame_iconifyIcon = new FrameButtonIcon(Part.WP_MINBUTTON);	}	return frame_iconifyIcon;    }    public static Icon createFrameMaximizeIcon() {	if (frame_maxIcon == null) {            frame_maxIcon = new FrameButtonIcon(Part.WP_MAXBUTTON);	}	return frame_maxIcon;    }    public static Icon createFrameMinimizeIcon() {	if (frame_minIcon == null) {            frame_minIcon = new FrameButtonIcon(Part.WP_RESTOREBUTTON);	}	return frame_minIcon;    }    public static Icon createFrameResizeIcon() {	if(frame_resizeIcon == null)	    frame_resizeIcon = new ResizeIcon();	return frame_resizeIcon;    }    private static class FrameButtonIcon implements Icon, Serializable {        private Part part;        private FrameButtonIcon(Part part) {            this.part = part;	}	public void paintIcon(Component c, Graphics g, int x0, int y0) {	    int width = getIconWidth();	    int height = getIconHeight();	    XPStyle xp = XPStyle.getXP();	    if (xp != null) {                Skin skin = xp.getSkin(c, part);		JButton b = (JButton)c;		ButtonModel model = b.getModel();		// Find out if frame is inactive		JInternalFrame jif = (JInternalFrame)SwingUtilities.					getAncestorOfClass(JInternalFrame.class, b);                boolean jifSelected = (jif != null && jif.isSelected());                State state;                if (jifSelected) {                    if (!model.isEnabled()) {                        state = State.DISABLED;                    } else if (model.isArmed() && model.isPressed()) {                        state = State.PUSHED;                    } else if (model.isRollover()) {                        state = State.HOT;                    } else {                        state = State.NORMAL;                    }                } else {                    if (!model.isEnabled()) {                        state = State.INACTIVEDISABLED;                    } else if (model.isArmed() && model.isPressed()) {                        state = State.INACTIVEPUSHED;                    } else if (model.isRollover()) {                        state = State.INACTIVEHOT;                    } else {                        state = State.INACTIVENORMAL;                    }		}                skin.paintSkin(g, 0, 0, width, height, state);	    } else {		g.setColor(Color.black);		int x = width / 12 + 2;		int y = height / 5;		int h = height - y * 2 - 1;		int w = width * 3/4 -3;		int thickness2 = Math.max(height / 8, 2);		int thickness  = Math.max(width / 15, 1);                if (part == Part.WP_CLOSEBUTTON) {		    int lineWidth;		    if      (width > 47) lineWidth = 6;		    else if (width > 37) lineWidth = 5;		    else if (width > 26) lineWidth = 4;		    else if (width > 16) lineWidth = 3;		    else if (width > 12) lineWidth = 2;		    else                 lineWidth = 1;		    y = height / 12 + 2;		    if (lineWidth == 1) {			if (w % 2 == 1) { x++; w++; }			g.drawLine(x,     y, x+w-2, y+w-2);			g.drawLine(x+w-2, y, x,     y+w-2);		    } else if (lineWidth == 2) {			if (w > 6) { x++; w--; }			g.drawLine(x,     y, x+w-2, y+w-2);			g.drawLine(x+w-2, y, x,     y+w-2);			g.drawLine(x+1,   y, x+w-1, y+w-2);			g.drawLine(x+w-1, y, x+1,   y+w-2);		    } else {			x += 2; y++; w -= 2;			g.drawLine(x,     y,   x+w-1, y+w-1);			g.drawLine(x+w-1, y,   x,     y+w-1);			g.drawLine(x+1,   y,   x+w-1, y+w-2);			g.drawLine(x+w-2, y,   x,     y+w-2);			g.drawLine(x,     y+1, x+w-2, y+w-1);			g.drawLine(x+w-1, y+1, x+1,   y+w-1);			for (int i = 4; i <= lineWidth; i++) {			    g.drawLine(x+i-2,   y,     x+w-1,   y+w-i+1);			    g.drawLine(x,       y+i-2, x+w-i+1, y+w-1);			    g.drawLine(x+w-i+1, y,     x,       y+w-i+1);			    g.drawLine(x+w-1,   y+i-2, x+i-2,   y+w-1);			}		    }                } else if (part == Part.WP_MINBUTTON) {		    g.fillRect(x, y+h-thickness2, w-w/3, thickness2);                } else if (part == Part.WP_MAXBUTTON) {		    g.fillRect(x, y, w, thickness2);		    g.fillRect(x, y, thickness, h);		    g.fillRect(x+w-thickness, y, thickness, h);		    g.fillRect(x, y+h-thickness, w, thickness);                } else if (part == Part.WP_RESTOREBUTTON) {		    g.fillRect(x+w/3, y, w-w/3, thickness2);		    g.fillRect(x+w/3, y, thickness, h/3);		    g.fillRect(x+w-thickness, y, thickness, h-h/3);		    g.fillRect(x+w-w/3, y+h-h/3-thickness, w/3, thickness);		    g.fillRect(x, y+h/3, w-w/3, thickness2);		    g.fillRect(x, y+h/3, thickness, h-h/3);		    g.fillRect(x+w-w/3-thickness, y+h/3, thickness, h-h/3);		    g.fillRect(x, y+h-thickness, w-w/3, thickness);		}	    }	}	public int getIconWidth() {	    int width;	    if (XPStyle.getXP() != null) {		// Fix for XP bug where sometimes these sizes aren't updated properly		// Assume for now that XP buttons are always square		width = UIManager.getInt("InternalFrame.titleButtonHeight") -2;	    } else {		width = UIManager.getInt("InternalFrame.titleButtonWidth") -2;	    }	    if (XPStyle.getXP() != null) {		width -= 2;	    }	    return width;	}	public int getIconHeight() {	    int height = UIManager.getInt("InternalFrame.titleButtonHeight")-4;	    return height;	}    }        private static class ResizeIcon implements Icon, Serializable {            public void paintIcon(Component c, Graphics g, int x, int y) {                g.setColor(UIManager.getColor("InternalFrame.resizeIconHighlight"));                g.drawLine(0, 11, 11, 0);                g.drawLine(4, 11, 11, 4);                g.drawLine(8, 11, 11, 8);                g.setColor(UIManager.getColor("InternalFrame.resizeIconShadow"));                g.drawLine(1, 11, 11, 1);                g.drawLine(2, 11, 11, 2);                g.drawLine(5, 11, 11, 5);                g.drawLine(6, 11, 11, 6);                g.drawLine(9, 11, 11, 9);                g.drawLine(10, 11, 11, 10);            }            public int getIconWidth() { return 13; }            public int getIconHeight() { return 13; }

⌨️ 快捷键说明

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