gtkstyle.java

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

JAVA
1,779
字号
        }                public String getKey() {            return key;        }                public GTKIconSource getBestIconSource(int direction, int state, int size) {            for (int i = 0; i < sources.length; i++) {                GTKIconSource src = sources[i];                                if ((src.direction == UNDEFINED || src.direction == direction)                        && (src.state == UNDEFINED || src.state == state)                        && (src.size == UNDEFINED || src.size == size)) {                    return src;                }            }                        return null;        }        public String toString() {            StringBuffer buf = new StringBuffer("STOCK ICON " + key + ":\n");                        for (int i = 0; i < sources.length; i++) {                buf.append("    ").append(sources[i].toString()).append('\n');            }                        // remove last newline            buf.deleteCharAt(buf.length() - 1);                        return buf.toString();        }                /**         * Return icon type (GtkIconSize value) given a symbolic name which can         * occur in a theme file.         *          * @param size symbolic name, e.g. gtk-button         * @return icon type. Valid types are 1 to 6          */         public static int getIconType(String size) {            if (size == null) {                return UNDEFINED;            }            if (ICON_TYPE_MAP == null) {                initIconTypeMap();            }            Integer n = ICON_TYPE_MAP.get(size);            return n != null ? n.intValue() : UNDEFINED;        }                private static void initIconTypeMap() {            ICON_TYPE_MAP = new HashMap<String,Integer>();            ICON_TYPE_MAP.put("gtk-menu", new Integer(1));            ICON_TYPE_MAP.put("gtk-small-toolbar", new Integer(2));            ICON_TYPE_MAP.put("gtk-large-toolbar", new Integer(3));            ICON_TYPE_MAP.put("gtk-button", new Integer(4));            ICON_TYPE_MAP.put("gtk-dnd", new Integer(5));            ICON_TYPE_MAP.put("gtk-dialog", new Integer(6));        }        /**          * Return the size of a particular icon type (logical size)         *          * @param type icon type (GtkIconSize value)         * @return a Dimension object, or null if lsize is invalid         */        public static Dimension getIconSize(int type) {            Dimension[] iconSizes = getIconSizesMap();            return type >= 0 && type < iconSizes.length ?                iconSizes[type] : null;          }                /**         * Change icon size in a type to size mapping. This is called by code         * that parses the gtk-icon-sizes setting         *           * @param type icon type (GtkIconSize value)         * @param w the new icon width         * @param h the new icon height         */         public static void setIconSize(int type, int w, int h) {            Dimension[] iconSizes = getIconSizesMap();            if (type >= 0 && type < iconSizes.length) {                iconSizes[type] = new Dimension(w, h);            }        }                private static Dimension[] getIconSizesMap() {            AppContext appContext = AppContext.getAppContext();             Dimension[] iconSizes = (Dimension[])appContext.get(ICON_SIZE_KEY);             if (iconSizes == null) {                 iconSizes = new Dimension[7];                iconSizes[0] = null;                  // GTK_ICON_SIZE_INVALID                iconSizes[1] = new Dimension(16, 16); // GTK_ICON_SIZE_MENU                iconSizes[2] = new Dimension(18, 18); // GTK_ICON_SIZE_SMALL_TOOLBAR                iconSizes[3] = new Dimension(24, 24); // GTK_ICON_SIZE_LARGE_TOOLBAR                iconSizes[4] = new Dimension(20, 20); // GTK_ICON_SIZE_BUTTON                iconSizes[5] = new Dimension(32, 32); // GTK_ICON_SIZE_DND                iconSizes[6] = new Dimension(48, 48); // GTK_ICON_SIZE_DIALOG                appContext.put(ICON_SIZE_KEY, iconSizes);            }            return iconSizes;        }    }    /**     * GTKIconSource represents a single icon source specification,     * as declared inside a stock definition in an rc file:     * path to image, size, direction, and state.     */    static class GTKIconSource implements Comparable {        private Object image;        private int direction;        private int state;        private int size;                GTKIconSource(String image, int direction, int state, String size) {            this.image = image;            this.direction = direction;            this.state = state;                        this.size = GTKStockIconInfo.getIconType(size);        }        public int getDirection() {            return direction;        }                public int getState() {            return state;        }        public int getSize() {            return size;        }                public int compareTo(Object o) {            GTKIconSource other = (GTKIconSource)o;                        if (direction != UNDEFINED && other.direction == UNDEFINED) {                return -1;            } else if (direction == UNDEFINED && other.direction != UNDEFINED) {                return 1;            } else if (state != UNDEFINED && other.state == UNDEFINED) {                return -1;            } else if (state == UNDEFINED && other.state != UNDEFINED) {                return 1;            } else if (size != UNDEFINED && other.size == UNDEFINED) {                return -1;            } else if (size == UNDEFINED && other.size != UNDEFINED) {                return 1;            } else {                return 0;            }        }        public String toString() {            return "image=" + image + ", dir=" + getDirectionName(direction)                   + ", state=" + getStateName(state, "*")                   + ", size=" + (size == UNDEFINED ? "*" : ""+size);        }                // used above by toString()        private static String getDirectionName(int dir) {            switch(dir) {                case LTR: return "LTR";                case RTL: return "RTL";                case UNDEFINED: return "*";            }            return "UNKNOWN";        }                public Icon toIcon() {            if (image == null || image instanceof Icon) {                return (Icon)image;            }                        ImageIcon ii = (ImageIcon)AccessController.doPrivileged(new PrivilegedAction() {                public Object run() {                    return new ImageIcon((String)image);                }            });            if (ii.getIconWidth() > 0 && ii.getIconHeight() > 0) {                image = ii;            } else {                // if we decide to mimic GTK and show a broken image,                // it would be assigned to 'image' here                image = null;            }                        return (Icon)image;        }    }    public String toString() {        StringBuffer buf = new StringBuffer(super.toString());        if (xThickness != UNDEFINED_THICKNESS) {            buf.append("xt=").append(String.valueOf(xThickness)).append('\n');        }        if (yThickness != UNDEFINED_THICKNESS) {            buf.append("yt=").append(String.valueOf(yThickness)).append('\n');        }        if (classSpecificValues != null) {            buf.append("*** Properties ***\n");            buf.append(classSpecValsToString(classSpecificValues)).append('\n');        }        if (icons != null) {            buf.append("*** Stock Icons ***\n");            for (int i = 0; i < icons.length; i++) {                buf.append(icons[i].toString()).append('\n');            }        }        // remove last newline        buf.deleteCharAt(buf.length() - 1);        return buf.toString();    }    // used by toString()    private static String classSpecValsToString(CircularIdentityList parent) {        StringBuffer buf = new StringBuffer();        Object parentFirst = parent.next();                    if (parentFirst == null) {            return "";        }        Object parentKey = parentFirst;        do {            buf.append(parentKey).append('\n');            CircularIdentityList child = (CircularIdentityList)parent.get();            Object childFirst = child.next();                            if (childFirst == null) {                break;            }                                Object childKey = childFirst;                                do {                buf.append("    ").append(childKey).append('=').append(child.get()).append('\n');                childKey = child.next();            } while (childKey != childFirst);                        parentKey = parent.next();        } while (parentKey != parentFirst);        // remove last newline        buf.deleteCharAt(buf.length() - 1);        return buf.toString();    }    /**     * A subclass of StateInfo adding additional GTK state information.     */    public static class GTKStateInfo extends StateInfo {        // <none>: fill in with background color        // <parent>: do nothing, parent will have handled it        // image: paint it.        private Object backgroundImage;        /**         * Creates a new GTKStateInfo with the specified properties         *         * @param state Component state that this StateInfo should be used         * for         * @param font Font for this state         * @param colors Colors for this state         * @param backgroundImage Background image         */        public GTKStateInfo(int state, Font font, Color[] colors,                            Object backgroundImage) {            super(state, font, colors);            this.backgroundImage = backgroundImage;        }        /**         * Creates a GTKStateInfo that is a copy of the passed in         * <code>StateInfo</code>.         *         * @param info StateInfo to copy.         */        public GTKStateInfo(StateInfo info) {            super(info);            if (info instanceof GTKStateInfo) {                backgroundImage = ((GTKStateInfo)info).backgroundImage;            }        }        void setColor(ColorType type, Color color) {            Color[] colors = getColors();            if (colors == null) {                if (color == null) {                    return;                }                colors = new Color[GTKColorType.MAX_COUNT];                setColors(colors);            }            colors[type.getID()] = color;        }        /**         * Returns the Color to used for the specified ColorType.         *         * @return Color.         */        public Color getColor(ColorType type) {            Color color = super.getColor(type);            if (color == null) {                Color[] colors = getColors();                Color bg;                if (colors != null && (bg = super.getColor(                                        GTKColorType.BACKGROUND)) != null) {                    if (type == GTKColorType.LIGHT) {                        color = colors[GTKColorType.LIGHT.getID()] =                                  calculateLightColor(bg);                    }                    else if (type == GTKColorType.MID) {                        color = colors[GTKColorType.MID.getID()] =                                       calculateMidColor(bg);                    }                    else if (type == GTKColorType.DARK) {                        color = colors[GTKColorType.DARK.getID()] =                                       calculateDarkColor(bg);                    }                }            }            return color;        }        /**         * This returns the background image, and will be one of:         * the String "<none>", the String "<parent>" or an Image.         *         * @return the background.         */        Object getBackgroundImage() {            if (backgroundImage == null ||                     (backgroundImage instanceof Image) ||

⌨️ 快捷键说明

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