pixmapstyle.java

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

JAVA
542
字号
/* * @(#)PixmapStyle.java	1.19 03/12/19 * * Copyright 2004 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */package com.sun.java.swing.plaf.gtk;import javax.swing.plaf.synth.*;import java.awt.*;import java.util.*;import javax.swing.*;import java.security.*;import sun.swing.plaf.synth.*;/** * PixmapStyle extends GTKStyle adding support for a set of <code>Info</code>s. * * @version 1.19, 12/19/03 * @author Scott Violet */class PixmapStyle extends GTKStyle implements GTKConstants {    /**     * There should only ever be one pixmap engine.     */    private static final GTKEngine PIXMAP_ENGINE = new PixmapEngine();    /**     * Set of Infos used to determine what to paint.     */    private Info[] info;    /**     * Creates a duplicate of the passed in style.     */    public PixmapStyle(DefaultSynthStyle style) {        super(style);        if (style instanceof PixmapStyle) {            this.info = ((PixmapStyle)style).info;        }    }    /**     * Creates a PixmapStyle from the passed in arguments.     */    public PixmapStyle(StateInfo[] states,                       CircularIdentityList classSpecificValues,                       Font font,                       int xThickness, int yThickness,                       GTKStockIconInfo[] icons,                       Info[] info) {        super(states, classSpecificValues, font, xThickness, yThickness, icons);        this.info = info;    }    /**     * Adds the state of this PixmapStyle to that of <code>s</code>     * returning a combined SynthStyle.     */    public DefaultSynthStyle addTo(DefaultSynthStyle s) {        if (!(s instanceof PixmapStyle)) {            s = new PixmapStyle(s);        }        PixmapStyle style = (PixmapStyle)super.addTo(s);        if (info != null) {            if (style.info == null) {                style.info = info;            }            else {                // Place the more specific first.                Info[] merged = new Info[style.info.length + info.length];                System.arraycopy(info, 0, merged, 0, info.length);                System.arraycopy(style.info, 0, merged, info.length,                                 style.info.length);                style.info = merged;            }        }        return style;    }    /**     * Creates a copy of the reciever and returns it.     */    public Object clone() {        PixmapStyle style = (PixmapStyle)super.clone();        // Info is immutable, no need to clone it.        style.info = this.info;        return style;    }    /**     * Returns a GTKEngine to use for rendering.     */    public GTKEngine getEngine(SynthContext context) {        return PIXMAP_ENGINE;    }    /**     * Returns the first instance of Info that matches the past in args, may     * return null if nothing matches.     *     * @param function String name for the painting method     * @param detail Description of what is being painted     * @param componentState State of the Component     * @param shadow Shadow type     * @param orientation Orientation of what is being painted     * @param gapSide Side of the gap being drawn     * @param arrowDirection direction of the arrow.     * @return Best matching Info, or null if none match     */    public Info getInfo(String function, String detail, int componentState,                        int shadow, int orientation, int gapSide,                        int arrowDirection) {        if (info != null) {            for (int counter = 0, max = info.length; counter < max;counter++) {                if (info[counter].getFunction() == function && info[counter].                              getMatchCount(detail, componentState, shadow,                              orientation, gapSide, arrowDirection) != -1) {                    return info[counter];                }            }        }        return null;    }    /**     * Returns the number of non-null arugments and arguments that are     * != UNDEFINED.     */    private int getMaxMatchCount(int componentState, int shadow,                                 int orientation, int gapSide,                                 int arrowDirection, String detail) {        int count = 0;        if (detail != null) {            count++;        }        if (componentState != UNDEFINED) {            count++;        }        if (shadow != UNDEFINED) {            count++;        }        if (orientation != UNDEFINED) {            count++;        }        if (gapSide != UNDEFINED) {            count++;        }        if (arrowDirection != UNDEFINED) {            count++;        }        return count;    }    /**     * A description of how to paint a portion of a widget.     */    public static class Info {        // match data        private String function = null;        private String detail = null;        int gapSide = UNDEFINED;        int orientation = UNDEFINED;        int componentState = UNDEFINED;        int shadow = UNDEFINED;        int arrowDirection = UNDEFINED;        boolean recolorable = false;        // background        Object image = null;        Insets fileInsets = null;        boolean stretch = false;        // overlay        Object overlayImage = null;        Insets overlayInsets = null;        boolean overlayStretch = false;        // gap start        Object gapStartImage = null;        Insets gapStartInsets = null;        // gap        Object gapImage = null;        Insets gapInsets = null;        // gap end        Object gapEndImage = null;        Insets gapEndInsets = null;        public void setFunction(String function) {            this.function = function.intern();        }        public void setDetail(String detail) {            this.detail = detail.intern();        }        public String getFunction() {            return function;        }        public Image getImage() {            image = getImage(image);            return (Image)image;        }        public boolean isRecolorable() {            return recolorable;        }        public Insets getImageInsets() {            return fileInsets;        }        public boolean getStretch() {            return stretch;        }        public String getDetail() {            return detail;        }        public int getComponentState() {            return componentState;        }        public int getShadow() {            return shadow;        }        public int getGapSide() {            return gapSide;        }        public Image getGapImage() {            gapImage = getImage(gapImage);            return (Image)gapImage;        }        public Insets getGapInsets() {            return gapInsets;        }        public Image getGapStartImage() {            gapStartImage = getImage(gapStartImage);            return (Image)gapStartImage;        }        public Insets getGapStartInsets() {            return gapStartInsets;        }        public Image getGapEndImage() {            gapEndImage = getImage(gapEndImage);            return (Image)gapEndImage;        }        public Insets getGapEndInsets() {            return gapEndInsets;        }        public Image getOverlayImage() {            overlayImage = getImage(overlayImage);            return (Image)overlayImage;

⌨️ 快捷键说明

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