gtkstyle.java

来自「java jdk 1.4的源码」· Java 代码 · 共 1,748 行 · 第 1/5 页

JAVA
1,748
字号
                    }                    if (!matched) {                        StateInfo[] newStates = new StateInfo[states.length+1];                        System.arraycopy(states, 0, newStates, 0,                                         states.length);                        newStates[states.length] = createStateInfo(                                 componentState, GTKColorType.TEXT_FOREGROUND,                                 color);                        states = newStates;                    }                }            }        }    }    /**     * Creates a StateInfo with the specified component state, ColorType     * and color. Subclasses that create a custom GTKStateInfo will need     * to subclass and override this.     */    GTKStateInfo createStateInfo(int state, ColorType type, Color color) {        Color[] colors = new Color[GTKColorType.MAX_COUNT];        colors[type.getID()] = color;        return new GTKStateInfo(state, null, null, null, colors, null);    }    /**     * Adds a value specific to the style.     */    void put(Object key, Object value) {        if (data == null) {            data = new HashMap();        }        data.put(key, value);    }    /**     * Returns true if the style should fill in the background of the     * specified context for the specified state.     */    boolean fillBackground(SynthContext context, int state) {        GTKStateInfo info = (GTKStateInfo)getStateInfo(state);        if (info != null) {            Object backgroundImage = info.getBackgroundImage();            if (backgroundImage == "<none>" || backgroundImage == null) {                return true;            }            return false;        }        return true;    }    /**     * Returns the Icon to fill the background in with for the specified     * context and state.     */    Image getBackgroundImage(SynthContext context, int state) {        GTKStateInfo info = (GTKStateInfo)getStateInfo(state);        if (info != null) {            Object backgroundImage = info.getBackgroundImage();            if (backgroundImage instanceof Image) {                return (Image)backgroundImage;            }        }        return null;    }    /**     * Creates a clone of the receiver.     */    public Object clone() {        GTKStyle style = (GTKStyle)super.clone();        style.classSpecificValues = cloneClassSpecificValues(                                         style.classSpecificValues);        return style;    }    public DefaultSynthStyle addTo(DefaultSynthStyle style) {        if (!(style instanceof GTKStyle)) {            style = new GTKStyle(style);        }        GTKStyle gtkStyle = (GTKStyle)super.addTo(style);        if (xThickness != UNDEFINED_THICKNESS) {            gtkStyle.xThickness = xThickness;        }        if (yThickness != UNDEFINED_THICKNESS) {            gtkStyle.yThickness = yThickness;        }        if (font != null) {            gtkStyle.font = font;        }        if (gtkStyle.icons == null) {            gtkStyle.icons = icons;        }        else if (icons != null) {            GTKStockIconInfo[] mergedIcons =                new GTKStockIconInfo[gtkStyle.icons.length + icons.length];                            System.arraycopy(icons, 0, mergedIcons, 0, icons.length);            System.arraycopy(gtkStyle.icons, 0, mergedIcons, icons.length, gtkStyle.icons.length);                        gtkStyle.icons = mergedIcons;        }                if (gtkStyle.classSpecificValues == null) {            gtkStyle.classSpecificValues =                cloneClassSpecificValues(classSpecificValues);        } else {            addClassSpecificValues(classSpecificValues, gtkStyle.classSpecificValues);        }                    return gtkStyle;    }    /**     * Adds the data from one set of class specific values into another.     *     * @param from the list to grab data from (may be null)     * @param to   the list to add data to (may not be null)     */    static void addClassSpecificValues(CircularIdentityList from,                                        CircularIdentityList to) {        if (to == null) {            throw new IllegalArgumentException("to may not be null");        }                if (from == null) {            return;        }        synchronized(from) {            Object firstKey = from.next();            if (firstKey != null) {                Object key = firstKey;                do {                    CircularIdentityList cList = ((CircularIdentityList)                            from.get());                    CircularIdentityList oSublist = (CircularIdentityList)                                     to.get(key);                    if (oSublist == null) {                        to.set(key, cList.clone());                    }                    else {                        Object cFirstKey = cList.next();                        if (cFirstKey != null) {                            Object cKey = cFirstKey;                            do {                                oSublist.set(cKey, cList.get());                                cKey = cList.next();                            } while (cKey != cFirstKey);                        }                    }                    key = from.next();                } while (key != firstKey);            }        }    }    /**     * Clones the class specific values.     */    static CircularIdentityList cloneClassSpecificValues(                    CircularIdentityList list) {        if (list == null) {            return null;        }        CircularIdentityList clone;        synchronized(list) {            Object firstKey = list.next();            if (firstKey == null) {                // Empty list                return null;            }            clone = new CircularIdentityList();            Object key = firstKey;            do {                clone.set(key, ((CircularIdentityList)list.get()).clone());                key = list.next();            } while (key != firstKey);        }        return clone;    }    /**         * GTKStockIconInfo mirrors the information from a stock declaration     * in the rc file: stock icon id, and a set of icon source     * specifications.     */    static class GTKStockIconInfo {        private String key;        private GTKIconSource[] sources;                GTKStockIconInfo(String key, GTKIconSource[] sources) {            this.key = key.intern();            this.sources = sources;            Arrays.sort(this.sources);        }                public String getKey() {            return key;        }                public GTKIconSource getBestIconSource(int direction, int state, String 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 == null || sizesMatch(src.size, size))) {                    return src;                }            }                        return null;        }        private static boolean sizesMatch(String sizeOne, String sizeTwo) {            //Dimension one = getIconSize(sizeOne);            //Dimension two = getIconSize(sizeTwo);            //return one.width == two.width && one.height == two.height;            // An earlier version of GTK compared the actual pixel sizes for            // equality. Now it just compares the logical sizes.            return sizeOne == sizeTwo;        }        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();        }    }    /**     * 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 String size;        GTKIconSource(String image, int direction, int state, String size) {            this.image = image;            this.direction = direction;            this.state = state;                        if (size != null) {                this.size = size.intern();            }        }        public int getDirection() {            return direction;        }                public int getState() {            return state;        }        public String 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 != null && other.size == null) {                return -1;            } else if (size == null && other.size != null) {                return 1;            } else {                return 0;            }        }        public String toString() {            return "image=" + image + ", dir=" + getDirectionName(direction)                   + ", state=" + getStateName(state, "*")                   + ", size=" + (size == null ? "*" : 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();        buf.append("class=");        buf.append(getClass().getName()).append('\n');        if (font != null) {            buf.append("font=").append(font.toString()).append('\n');

⌨️ 快捷键说明

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