gtkstyle.java
来自「java jdk 1.4的源码」· Java 代码 · 共 1,748 行 · 第 1/5 页
JAVA
1,748 行
} 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 (states != null) { buf.append("*** Colors and Pixmaps ***\n"); for (int i = 0; i < states.length; i++) { buf.append(states[i].toString()).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; public GTKStateInfo(int state, SynthPainter bPainter, SynthPainter bgPainter, Font font, Color[] colors, Object backgroundImage) { super(state, bPainter, bgPainter, font, colors); this.backgroundImage = backgroundImage; } public GTKStateInfo(StateInfo info) { super(info); if (info instanceof GTKStateInfo) { backgroundImage = ((GTKStateInfo)info).backgroundImage; } } void setColor(ColorType type, Color color) { if (colors == null) { if (color == null) { return; } colors = new Color[GTKColorType.MAX_COUNT]; } colors[type.getID()] = 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) || 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; } public Object clone() { return new GTKStateInfo(this); } 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 String size; private boolean loadedLTR; private boolean loadedRTL; private Icon ltrIcon; private Icon rtlIcon; private SynthStyle style; GTKStockIcon(String key, String 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().
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?