?? parsedsynthstyle.java
字號(hào):
/* * @(#)ParsedSynthStyle.java 1.3 03/12/19 * * Copyright 2004 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */package javax.swing.plaf.synth;import java.awt.*;import javax.swing.*;import sun.swing.plaf.synth.*;/** * ParsedSynthStyle are the SynthStyle's that SynthParser creates. * * @version 1.3, 12/19/03 * @author Scott Violet */class ParsedSynthStyle extends DefaultSynthStyle { private static SynthPainter DELEGATING_PAINTER_INSTANCE = new DelegatingPainter(); private PainterInfo[] _painters; private static PainterInfo[] mergePainterInfo(PainterInfo[] old, PainterInfo[] newPI) { if (old == null) { return newPI; } if (newPI == null) { return old; } int oldLength = old.length; int newLength = newPI.length; int dups = 0; PainterInfo[] merged = new PainterInfo[oldLength + newLength]; System.arraycopy(old, 0, merged, 0, oldLength); for (int newCounter = 0; newCounter < newLength; newCounter++) { boolean found = false; for (int oldCounter = 0; oldCounter < oldLength - dups; oldCounter++) { if (newPI[newCounter].equalsPainter(old[oldCounter])) { merged[oldCounter] = newPI[newCounter]; dups++; found = true; break; } } if (!found) { merged[oldLength + newCounter - dups] = newPI[newCounter]; } } if (dups > 0) { PainterInfo[] tmp = merged; merged = new PainterInfo[merged.length - dups]; System.arraycopy(tmp, 0, merged, 0, merged.length); } return merged; } public ParsedSynthStyle() { } public ParsedSynthStyle(DefaultSynthStyle style) { super(style); if (style instanceof ParsedSynthStyle) { ParsedSynthStyle pStyle = (ParsedSynthStyle)style; if (pStyle._painters != null) { _painters = pStyle._painters; } } } public SynthPainter getPainter(SynthContext ss) { return DELEGATING_PAINTER_INSTANCE; } public void setPainters(PainterInfo[] info) { _painters = info; } public DefaultSynthStyle addTo(DefaultSynthStyle style) { if (!(style instanceof ParsedSynthStyle)) { style = new ParsedSynthStyle(style); } ParsedSynthStyle pStyle = (ParsedSynthStyle)super.addTo(style); pStyle._painters = mergePainterInfo(pStyle._painters, _painters); return pStyle; } private SynthPainter getBestPainter(SynthContext context, String method, int direction) { // Check the state info first StateInfo info = (StateInfo)getStateInfo(context.getComponentState()); SynthPainter painter; if (info != null) { if ((painter = getBestPainter(info.getPainters(), method, direction)) != null) { return painter; } } if ((painter = getBestPainter(_painters, method, direction)) != null) { return painter; } return SynthPainter.NULL_PAINTER; } private SynthPainter getBestPainter(PainterInfo[] info, String method, int direction) { if (info != null) { // Painter specified with no method SynthPainter nullPainter = null; // Painter specified for this method SynthPainter methodPainter = null; for (int counter = info.length - 1; counter >= 0; counter--) { PainterInfo pi = info[counter]; if (pi.getMethod() == method) { if (pi.getDirection() == direction) { return pi.getPainter(); } else if (methodPainter == null &&pi.getDirection() == -1) { methodPainter = pi.getPainter(); } } else if (nullPainter == null && pi.getMethod() == null) { nullPainter = pi.getPainter(); } } if (methodPainter != null) { return methodPainter; } return nullPainter; } return null; } public String toString() { StringBuffer text = new StringBuffer(super.toString()); if (_painters != null) { text.append(",painters=["); for (int i = 0; i < +_painters.length; i++) { text.append(_painters[i].toString()); } text.append("]"); } return text.toString(); } static class StateInfo extends DefaultSynthStyle.StateInfo { private PainterInfo[] _painterInfo; public StateInfo() { } public StateInfo(DefaultSynthStyle.StateInfo info) { super(info); if (info instanceof StateInfo) { _painterInfo = ((StateInfo)info)._painterInfo; } } public void setPainters(PainterInfo[] painterInfo) { _painterInfo = painterInfo; } public PainterInfo[] getPainters() { return _painterInfo; } public Object clone() { return new StateInfo(this); } public DefaultSynthStyle.StateInfo addTo( DefaultSynthStyle.StateInfo info) { if (!(info instanceof StateInfo)) { info = new StateInfo(info); } else { info = super.addTo(info); StateInfo si = (StateInfo)info; si._painterInfo = mergePainterInfo(si._painterInfo, _painterInfo); } return info; } public String toString() { StringBuffer text = new StringBuffer(super.toString()); text.append(",painters=["); if (_painterInfo != null) { for (int i = 0; i < +_painterInfo.length; i++) { text.append(" ").append(_painterInfo[i].toString()); } } text.append("]"); return text.toString(); } } static class PainterInfo { private String _method; private SynthPainter _painter; private int _direction; PainterInfo(String method, SynthPainter painter, int direction) { if (method != null) { _method = method.intern(); } _painter = painter; _direction = direction; } String getMethod() { return _method; } SynthPainter getPainter() { return _painter; } int getDirection() { return _direction; } private boolean equalsPainter(PainterInfo info) { return (_method == info._method && _direction == info._direction); } public String toString() { return "PainterInfo {method=" + _method + ",direction=" + _direction + ",painter=" + _painter +"}"; } } private static class DelegatingPainter extends SynthPainter { private static SynthPainter getPainter(SynthContext context, String method, int direction) { return ((ParsedSynthStyle)context.getStyle()).getBestPainter( context, method, direction); } public void paintArrowButtonBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { getPainter(context, "arrowButtonBackground", -1). paintArrowButtonBackground(context, g, x, y, w, h); } public void paintArrowButtonBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { getPainter(context, "arrowButtonBorder", -1). paintArrowButtonBorder(context, g, x, y, w, h); } public void paintArrowButtonForeground(SynthContext context, Graphics g, int x, int y, int w, int h, int direction) { getPainter(context, "arrowButtonForeground", direction). paintArrowButtonForeground(context, g, x, y, w, h, direction); } public void paintButtonBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { getPainter(context, "buttonBackground", -1). paintButtonBackground(context, g, x, y, w, h); } public void paintButtonBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { getPainter(context, "buttonBorder", -1). paintButtonBorder(context, g, x, y, w, h); } public void paintCheckBoxMenuItemBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { getPainter(context, "checkBoxMenuItemBackground", -1). paintCheckBoxMenuItemBackground(context, g, x, y, w, h); } public void paintCheckBoxMenuItemBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { getPainter(context, "checkBoxMenuItemBorder", -1). paintCheckBoxMenuItemBorder(context, g, x, y, w, h); } public void paintCheckBoxBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { getPainter(context, "checkBoxBackground", -1). paintCheckBoxBackground(context, g, x, y, w, h); } public void paintCheckBoxBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { getPainter(context, "checkBoxBorder", -1). paintCheckBoxBorder(context, g, x, y, w, h); } public void paintColorChooserBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { getPainter(context, "colorChooserBackground", -1). paintColorChooserBackground(context, g, x, y, w, h); } public void paintColorChooserBorder(SynthContext context, Graphics g, int x, int y, int w, int h) {
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -