gtkstyle.java
来自「JAVA的一些源码 JAVA2 STANDARD EDITION DEVELO」· Java 代码 · 共 1,779 行 · 第 1/5 页
JAVA
1,779 行
backgroundImage == "<none>" || backgroundImage == "<parent>") { return backgroundImage; } ImageIcon ii = (ImageIcon)AccessController.doPrivileged(new PrivilegedAction() { public Object run() { return new ImageIcon((String)backgroundImage); } }); if (ii.getIconWidth() > 0 && ii.getIconHeight() > 0) { backgroundImage = ii.getImage(); } else { backgroundImage = null; } return backgroundImage; } /** * Creates and returns a copy of this GTKStateInfo. * * @return Copy of this StateInfo. */ public Object clone() { return new GTKStateInfo(this); } /** * Merges the contents of this GTKStateInfo with that of the passed in * GTKStateInfo, returning the resulting merged StateInfo. Properties * of this <code>GTKStateInfo</code> will take precedence over those * of the * passed in <code>GTKStateInfo</code>. For example, if this * GTKStateInfo specifics a non-null font, the returned GTKStateInfo * will have its font so to that regardless of the * <code>GTKStateInfo</code>'s font. * * @param info StateInfo to add our styles to * @return Merged StateInfo. */ public StateInfo addTo(StateInfo info) { if (!(info instanceof GTKStateInfo)) { info = new GTKStateInfo(info); } else { super.addTo(info); } GTKStateInfo gInfo = (GTKStateInfo)info; if (backgroundImage != null) { gInfo.backgroundImage = backgroundImage; } return gInfo; } public String toString() { StringBuffer buf = new StringBuffer(); buf.append(getStateName(getComponentState(), "UNDEFINED")).append(":\n"); if (getColor(GTKColorType.FOREGROUND) != null) { buf.append(" fg=").append(getColor(GTKColorType.FOREGROUND)).append('\n'); } if (getColor(GTKColorType.BACKGROUND) != null) { buf.append(" bg=").append(getColor(GTKColorType.BACKGROUND)).append('\n'); } if (getColor(GTKColorType.TEXT_FOREGROUND) != null) { buf.append(" text=").append(getColor(GTKColorType.TEXT_FOREGROUND)).append('\n'); } if (getColor(GTKColorType.TEXT_BACKGROUND) != null) { buf.append(" base=").append(getColor(GTKColorType.TEXT_BACKGROUND)).append('\n'); } if (backgroundImage != null) { buf.append(" pmn=").append(backgroundImage).append('\n'); } // remove last newline buf.deleteCharAt(buf.length() - 1); return buf.toString(); } } // used by toString() in some of our inner classes static String getStateName(int state, String undef) { switch(state) { case SynthConstants.ENABLED: return "NORMAL"; case SynthConstants.PRESSED: return "ACTIVE"; case SynthConstants.SELECTED: return "SELECTED"; case SynthConstants.MOUSE_OVER: return "PRELIGHT"; case SynthConstants.DISABLED: return "INSENSITIVE"; case UNDEFINED: return undef; } return "UNKNOWN"; } /** * A tagging interface indicating that a value coming from * DATA should be added to the Style's data after invoking getValue. * This is useful for lazy type properties that need to key off information * kept in the style. */ interface StyleSpecificValue { public Object getValue(SynthContext context); } /** * An Icon that is fetched using getStockIcon. */ private static class GTKStockIcon extends SynthIcon implements Cloneable, StyleSpecificValue { private String key; private int size; private boolean loadedLTR; private boolean loadedRTL; private Icon ltrIcon; private Icon rtlIcon; private SynthStyle style; GTKStockIcon(String key, int size) { this.key = key; this.size = size; } public void paintIcon(SynthContext context, Graphics g, int x, int y, int w, int h) { Icon icon = getIcon(context); if (icon != null) { if (context == null) { icon.paintIcon(null, g, x, y); } else { icon.paintIcon(context.getComponent(), g, x, y); } } } public int getIconWidth(SynthContext context) { Icon icon = getIcon(context); if (icon != null) { return icon.getIconWidth(); } return 0; } public int getIconHeight(SynthContext context) { Icon icon = getIcon(context); if (icon != null) { return icon.getIconHeight(); } return 0; } private Icon getIcon(SynthContext context) { if (context != null) { ComponentOrientation co = context.getComponent(). getComponentOrientation(); SynthStyle style = context.getStyle(); if (style != this.style) { this.style = style; loadedLTR = loadedRTL = false; } if (co == null || co.isLeftToRight()) { if (!loadedLTR) { loadedLTR = true; ltrIcon = ((GTKStyle)context.getStyle()). getStockIcon(context, key, size); } return ltrIcon; } else if (!loadedRTL) { loadedRTL = true; rtlIcon = ((GTKStyle)context.getStyle()). getStockIcon(context, key,size); } return rtlIcon; } return ltrIcon; } public Object getValue(SynthContext context) { try { return clone(); } catch (CloneNotSupportedException cnse) { } return null; } } /** * MetalLazyValue is a slimmed down version of <code>ProxyLaxyValue</code>. * The code is duplicate so that it can get at the package private * classes in gtk. */ static class GTKLazyValue implements UIDefaults.LazyValue { /** * Name of the class to create. */ private String className; private String methodName; GTKLazyValue(String name) { this(name, null); } GTKLazyValue(String name, String methodName) { this.className = name; this.methodName = methodName; } public Object createValue(UIDefaults table) { try { Class c = Class.forName(className, true,Thread.currentThread(). getContextClassLoader()); if (methodName == null) { return c.newInstance(); } Method m = c.getMethod(methodName, null); return m.invoke(c, null); } catch (ClassNotFoundException cnfe) { } catch (IllegalAccessException iae) { } catch (InvocationTargetException ite) { } catch (NoSuchMethodException nsme) { } catch (InstantiationException ie) { } return null; } } static { DEFAULT_COLOR_MAP = new int[] { SynthConstants.PRESSED, SynthConstants.SELECTED, SynthConstants.ENABLED, SynthConstants.MOUSE_OVER, SynthConstants.DISABLED }; DEFAULT_COLORS = new Color[5][]; // 2.0 colors // if (!GTKLookAndFeel.is2_2()) { DEFAULT_COLORS[0] = getColorsFrom( new ColorUIResource(195, 195, 195), BLACK_COLOR); DEFAULT_COLORS[1] = getColorsFrom( new ColorUIResource(0, 0, 156), WHITE_COLOR); DEFAULT_COLORS[2] = getColorsFrom( new ColorUIResource(214, 214, 214), BLACK_COLOR); DEFAULT_COLORS[3] = getColorsFrom( new ColorUIResource(233, 233, 233), BLACK_COLOR); DEFAULT_COLORS[4] = getColorsFrom( new ColorUIResource(214, 214, 214), new ColorUIResource(117, 117, 117)); DEFAULT_COLORS[0][GTKColorType.TEXT_BACKGROUND.getID()] = new ColorUIResource(188, 210, 238); DEFAULT_COLORS[1][GTKColorType.TEXT_BACKGROUND.getID()] = new ColorUIResource(164, 223, 255); DEFAULT_COLORS[1][GTKColorType.TEXT_FOREGROUND.getID()] = BLACK_COLOR; DEFAULT_COLORS[2][GTKColorType.TEXT_FOREGROUND.getID()] = BLACK_COLOR; DEFAULT_COLORS[4][GTKColorType.TEXT_FOREGROUND.getID()] = DEFAULT_COLORS[2][GTKColorType.TEXT_FOREGROUND.getID()]; } else { // 2.2 colors DEFAULT_COLORS[0] = getColorsFrom( new ColorUIResource(186, 181, 171), BLACK_COLOR); DEFAULT_COLORS[1] = getColorsFrom( new ColorUIResource(75, 105, 131), WHITE_COLOR); DEFAULT_COLORS[2] = getColorsFrom( new ColorUIResource(220, 218, 213), BLACK_COLOR); DEFAULT_COLORS[3] = getColorsFrom( new ColorUIResource(238, 235, 231), BLACK_COLOR); DEFAULT_COLORS[4] = getColorsFrom( new ColorUIResource(220, 218, 213), new ColorUIResource(117, 117, 117)); DEFAULT_COLORS[0][GTKColorType.TEXT_BACKGROUND.getID()] = new ColorUIResource(128, 125, 116); DEFAULT_COLORS[1][GTKColorType.TEXT_BACKGROUND.getID()] = new ColorUIResource(75, 105, 131); DEFAULT_COLORS[2][GTKColorType.TEXT_BACKGROUND.getID()] = WHITE_COLOR; DEFAULT_COLORS[3][GTKColorType.TEXT_BACKGROUND.getID()] = WHITE_COLOR; DEFAULT_COLORS[4][GTKColorType.TEXT_BACKGROUND.getID()] = new ColorUIResource(238, 235, 231); DEFAULT_COLORS[0][GTKColorType.TEXT_FOREGROUND.getID()] = WHITE_COLOR; DEFAULT_COLORS[1][GTKColorType.TEXT_FOREGROUND.getID()] = WHITE_COLOR; DEFAULT_COLORS[2][GTKColorType.TEXT_FOREGROUND.getID()] = BLACK_COLOR; DEFAULT_COLORS[3][GTKColorType.TEXT_FOREGROUND.getID()] = BLACK_COLOR; DEFAULT_COLORS[4][GTKColorType.TEXT_FOREGROUND.getID()] = new ColorUIResource(117, 117, 117); } CLASS_SPECIFIC_MAP = new HashMap(); CLASS_SPECIFIC_MAP.put("CheckBox.iconTextGap", "indicator-spacing"); CLASS_SPECIFIC_MAP.put("Slider.thumbHeight", "slider-width"); CLASS_SPECIFIC_MAP.put("Slider.trackBorder", "trough-border"); CLASS_SPECIFIC_MAP.put("SplitPane.size", "handle-size"); CLASS_SPECIFIC_MAP.put("Tree.expanderSize", "expander-size"); CLASS_SPECIFIC_MAP.put("ScrollBar.thumbHeight", "slider-width"); CLASS_SPECIFIC_MAP.put("TextArea.caretForeground", "cursor-color"); CLASS_SPECIFIC_MAP.put("TextArea.caretAspectRatio", "cursor-aspect-ratio"); CLASS_SPECIFIC_MAP.put("TextField.caretForeground", "cursor-color"); CLASS_SPECIFIC_MAP.put("TextField.caretAspectRatio", "cursor-aspect-ratio"); CLASS_SPECIFIC_MAP.put("PasswordField.caretForeground", "cursor-color"); CLASS_SPECIFIC_MAP.put("PasswordField.caretAspectRatio", "cursor-aspect-ratio"); CLASS_SPECIFIC_MAP.put("FormattedTextField.caretForeground", "cursor-color"); CLASS_SPECIFIC_MAP.put("FormattedTextField.caretAspectRatio", "cursor-aspect-"); CLASS_SPECIFIC_MAP.put("TextPane.caretForeground", "cursor-color"); CLASS_SPECIFIC_MAP.put("TextPane.caretAspectRatio", "cursor-aspect-ratio"); CLASS_SPECIFIC_MAP.put("EditorPane.caretForeground", "cursor-color"); CLASS_SPECIFIC_MAP.put("EditorPane.caretAspectRatio", "cursor-aspect-ratio"); Object[] defaults = { "FileChooser.cancelIcon", new GTKStockIcon("gtk-cancel", 4), "FileChooser.okIcon", new GTKStockIcon("gtk-ok", 4), "OptionPane.errorIcon", new GTKStockIcon("gtk-dialog-error", 6), "OptionPane.informationIcon", new GTKStockIcon("gtk-dialog-info", 6), "OptionPane.warningIcon", new GTKStockIcon("gtk-dialog-warning", 6), "OptionPane.questionIcon", new GTKStockIcon("gtk-dialog-question", 6), "OptionPane.yesIcon", new GTKStockIcon("gtk-yes", 4), "OptionPane.noIcon", new GTKStockIcon("gtk-no", 4), "OptionPane.cancelIcon", new GTKStockIcon("gtk-cancel", 4), "OptionPane.okIcon", new GTKStockIcon("gtk-ok", 4), }; for (int counter = 0, max = defaults.length; counter < max; counter++) { DATA.put(defaults[counter], defaults[++counter]); } }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?