gtkstyle.java

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

JAVA
1,748
字号
            return ((Boolean)value).booleanValue();        }        return defaultValue;    }    public Object get(SynthContext context, Object key) {        Object value = super.get(context, key);        if (value == null) {	// See if this is a class specific value.	Object classKey = CLASS_SPECIFIC_MAP.get(key); 	    if (classKey != null) {		value = getClassSpecificValue(context, (String)classKey);		if (value != null) {			return value;		}	    }            if (key == "foreground" || key == "focus" ||                      key == "SplitPane.dragPainter" ||                      key == "ScrollPane.viewportBorderPainter") {                return GTKPainter.INSTANCE;            }            else if (key == "ScrollPane.viewportBorderInsets") {                return GTKPainter.INSTANCE.getScrollPaneInsets(context,                                           new Insets(0,0,0,0));            }            synchronized (DATA) {                value = DATA.get(key);                try {                    while (value == PENDING) {                        DATA.wait();                        value = DATA.get(key);                    }                } catch (InterruptedException ie) {                }                if (value instanceof UIDefaults.LazyValue) {                    DATA.put(key, PENDING);                }            }            if (value instanceof StyleSpecificValue) {                put(key, ((StyleSpecificValue)value).getValue(context));            }            else if (value instanceof UIDefaults.ActiveValue) {                value = ((UIDefaults.ActiveValue)value).                                             createValue(null);            }            else if (value instanceof UIDefaults.LazyValue) {                value = ((UIDefaults.LazyValue)value).                                             createValue(null);                synchronized(DATA) {                    DATA.put(key, value);                    DATA.notifyAll();                }            }        }        return value;    }    protected Font _getFont(JComponent c, Region id, int state) {        if (font != null) {            return font;        }                state = GTKLookAndFeel.synthStateToGTKState(id, state);        Font f = super._getFont(c, id, state);        if (f == null) {            return DEFAULT_FONT;        }        return f;    }    /**     * This method is to be used inside the GTK package when we want a     * color for an explicit state, it will not attempt to remap the state     * as getColor will.     */    Color getGTKColor(JComponent c, Region id,                      int state, ColorType type) {        Color color = super._getColor(c, id, state, type);        if (color != null) {            return color;        }        return getDefaultColor(c, id, state, type);    }    /**     * getColor is overriden to map the state from a Synth state to the     * GTK state, this should be not used when you have already mapped the     * state. Additionally this will map TEXT_FOREGROUND to the     * <code>c.getForeground()</code> if it is non-null and not a UIResource.     */    public Color getColor(JComponent c, Region id, int state,                          ColorType type) {        if (id == Region.LABEL && type == ColorType.TEXT_FOREGROUND) {            type = ColorType.FOREGROUND;        }        state = GTKLookAndFeel.synthStateToGTKState(id, state);        if (!id.isSubregion() &&                (state & SynthConstants.ENABLED) == SynthConstants.ENABLED) {            if (type == ColorType.BACKGROUND) {                return c.getBackground();            }            else if (type == ColorType.FOREGROUND) {                return c.getForeground();            }            else if (type == ColorType.TEXT_FOREGROUND) {                Color fg = c.getForeground();                if (fg != null && !(fg instanceof UIResource)) {                    // Only use the fg for text if specified.                    return fg;                }            }        }        return _getColor(c, id, state, type);    }    protected Color _getColor(JComponent c, Region id, int state,                              ColorType type) {        Color color = super._getColor(c, id, state, type);        if (color != null) {            return color;        }        if (type == ColorType.FOCUS) {            return BLACK_COLOR;        }        else if (type == GTKColorType.BLACK) {            return BLACK_COLOR;        }        else if (type == GTKColorType.WHITE) {            return WHITE_COLOR;        }        if (type == ColorType.TEXT_FOREGROUND && (GTKStyleFactory.                    isLabelBearing(id) || id == Region.MENU_ITEM_ACCELERATOR ||                    id == Region.TABBED_PANE_TAB)) {            type = ColorType.FOREGROUND;        }        else if (id == Region.TABLE || id == Region.LIST ||                 id == Region.TREE || id == Region.TREE_CELL){            if (type == ColorType.FOREGROUND) {                type = ColorType.TEXT_FOREGROUND;                if (state == SynthConstants.PRESSED) {                    state = SynthConstants.SELECTED;                }            }            else if (type == ColorType.BACKGROUND) {                type = ColorType.TEXT_BACKGROUND;                if (state == SynthConstants.PRESSED) {                    state = SynthConstants.SELECTED;                }            }        }        return getDefaultColor(c, id, state, type);    }    Color getDefaultColor(JComponent c, Region id, int state,                          ColorType type) {        if (type == ColorType.FOCUS) {            return BLACK_COLOR;        }        else if (type == GTKColorType.BLACK) {            return BLACK_COLOR;        }        else if (type == GTKColorType.WHITE) {            return WHITE_COLOR;        }        for (int counter = DEFAULT_COLOR_MAP.length - 1;                     counter >= 0; counter--) {            if ((DEFAULT_COLOR_MAP[counter] & state) != 0) {                if (type.getID() < DEFAULT_COLORS[counter].length) {                    return DEFAULT_COLORS[counter][type.getID()];                }            }        }        if (type.getID() < DEFAULT_COLORS[2].length) {            return DEFAULT_COLORS[2][type.getID()];        }        return null;    }    public boolean isOpaque(SynthContext context) {        Region region = context.getRegion();        if (region == Region.COMBO_BOX ||              region == Region.DESKTOP_PANE ||              region == Region.DESKTOP_ICON ||              region == Region.EDITOR_PANE ||              region == Region.FORMATTED_TEXT_FIELD ||              region == Region.INTERNAL_FRAME ||              region == Region.LIST ||              region == Region.MENU_BAR ||              region == Region.PASSWORD_FIELD ||               region == Region.POPUP_MENU ||              region == Region.PROGRESS_BAR ||              region == Region.ROOT_PANE ||              region == Region.SCROLL_PANE ||              region == Region.SPINNER ||              region == Region.TABLE ||              region == Region.TEXT_AREA ||              region == Region.TEXT_FIELD ||              region == Region.TEXT_PANE ||              region == Region.TOOL_BAR_DRAG_WINDOW ||              region == Region.TOOL_TIP ||              region == Region.TREE ||              region == Region.VIEWPORT) {            return true;        }        return false;    }    public int getXThickness() {        return xThickness;    }    public int getYThickness() {        return yThickness;    }    private Icon getStockIcon(SynthContext context, String key, String size) {        Icon icon = null;        GTKStockIconInfo iconInfo = null;        GTKIconSource bestSource = null;        int direction = LTR;        if (context != null) {            ComponentOrientation co = context.getComponent().                                              getComponentOrientation();            if (co == null || co.isLeftToRight()) {                direction = LTR;            }            else {                direction = RTL;            }        }        // See if the style defines an icon        if (icons != null) {            for (int i = 0; i < icons.length; i++) {                // find the first one that matches our key                if (icons[i].getKey() == key) {                    iconInfo = icons[i];                    break;                }            }                        if (iconInfo != null) {                // PENDING(shannonh) - pass in actual state                bestSource = iconInfo.getBestIconSource(direction,                                                        SynthConstants.ENABLED,                                                        size);            }                        if (bestSource != null) {                icon = bestSource.toIcon();            }        }                if (icon == null) {            // Use a default icon            icon = (Icon)((UIDefaults.LazyValue)LookAndFeel.makeIcon(                              GTKStyle.class, "resources/" + key + "-" + size +                              ".png")).createValue(null);        }                // If we used a default, or if the stock icon we found had a wildcard size,        // we force the size to match that requested        if (icon != null && (bestSource == null || bestSource.getSize() == null)) {            Dimension iconSize = getIconSize(size);            if (iconSize != null && (icon.getIconWidth() != iconSize.width ||                                    icon.getIconHeight() != iconSize.height)) {                Image image = new BufferedImage(iconSize.width, iconSize.height,                                                BufferedImage.TYPE_INT_ARGB);                Graphics2D g2d = (Graphics2D)image.getGraphics();                // for nicer scaling                g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION,                                     RenderingHints.VALUE_INTERPOLATION_BILINEAR);                Image oldImage = null;                if (icon instanceof ImageIcon) {                    oldImage = ((ImageIcon)icon).getImage();                } else {                    oldImage = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(),                                                 BufferedImage.TYPE_INT_ARGB);                    Graphics g = oldImage.getGraphics();                    icon.paintIcon(null, g, 0, 0);                    g.dispose();                }                g2d.drawImage(oldImage, 0, 0, iconSize.width, iconSize.height, null);                g2d.dispose();                                icon = new ImageIcon(image);            }        }        return icon;    }    /**     * Adds the specific label based properties from <code>style</code> to     * this style.     */    void addLabelProperties(GTKStyle style) {        // Take the font        this.font = style.font;        // And TEXT_FOREGROUND        if (states == null) {            if (style.states == null) {                return;            }            states = new StateInfo[style.states.length];            for (int counter = 0; counter < style.states.length; counter++) {                Color color = style.states[counter].getColor(                                     GTKColorType.FOREGROUND);                states[counter] = createStateInfo(style.states[counter].                     getComponentState(), GTKColorType.TEXT_FOREGROUND, color);            }        }        else {            // Reset the text foreground of all our states, this will ensure            // the correct color is picked up if style doesn't specify a            // text color.            for (int counter = states.length - 1; counter >= 0; counter--) {                ((GTKStateInfo)states[counter]).setColor(                               GTKColorType.TEXT_FOREGROUND, null);            }            if (style.states != null) {                for (int oCounter = style.states.length - 1; oCounter >= 0;                         oCounter--) {                    boolean matched = false;                    StateInfo oState = style.states[oCounter];                    int componentState = oState.getComponentState();                    Color color = oState.getColor(GTKColorType.FOREGROUND);                    for (int tCounter = states.length - 1; tCounter >= 0;                             tCounter--) {                        if (componentState == states[tCounter].                                     getComponentState()) {                            ((GTKStateInfo)states[tCounter]).setColor(                                      GTKColorType.TEXT_FOREGROUND, color);                            matched = true;                            break;                        }

⌨️ 快捷键说明

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