blueprintstyle.java
来自「JAVA的一些源码 JAVA2 STANDARD EDITION DEVELO」· Java 代码 · 共 693 行 · 第 1/2 页
JAVA
693 行
/* * @(#)BlueprintStyle.java 1.12 03/12/19 * * Copyright 2004 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */package com.sun.java.swing.plaf.gtk;import java.awt.*;import java.util.*;import javax.swing.*;import java.security.*;import javax.swing.plaf.synth.*;import sun.swing.plaf.synth.DefaultSynthStyle;/** * BlueprintStyle extends GTKStyle adding support for a set of <code>Info</code>s. * * @version 1.12 12/19/03 * @author Scott Violet */class BlueprintStyle extends GTKStyle implements GTKConstants { /** * There should only ever be one blueprint engine. */ private static final GTKEngine BLUEPRINT_ENGINE = new BlueprintEngine(); private static final BlueprintGraphicsUtils BLUEPRINT_GRAPHICS = new BlueprintGraphicsUtils(); /** * Set of Infos used to determine what to paint. */ private Info[] info; /** * Comes from the top level icon_colorize setting in rc files. */ private boolean iconColorize; /** * Comes from the top level icon_colorize_ancestor_type setting * in rec files. These Strings will all be interned by the parser. */ private String[] iconAncestorTypes; /** * Comes from the top level colorize_color setting in rc files. */ private Color colorizeColor; /** * Creates a duplicate of the passed in style. */ public BlueprintStyle(DefaultSynthStyle style) { super(style); if (style instanceof BlueprintStyle) { BlueprintStyle bpStyle = (BlueprintStyle)style; this.info = bpStyle.info; this.iconColorize = bpStyle.iconColorize; this.iconAncestorTypes = bpStyle.iconAncestorTypes; this.colorizeColor = bpStyle.colorizeColor; } } /** * Creates a BlueprintStyle from the passed in arguments. */ public BlueprintStyle(StateInfo[] states, CircularIdentityList classSpecificValues, Font font, int xThickness, int yThickness, GTKStockIconInfo[] icons, Info[] info, boolean iconColorize, String[] iconAncestorTypes, Color colorizeColor) { super(states, classSpecificValues, font, xThickness, yThickness, icons); this.info = info; this.iconColorize = iconColorize; this.iconAncestorTypes = iconAncestorTypes; this.colorizeColor = colorizeColor; } public SynthGraphicsUtils getGraphicsUtils(SynthContext context) { return BLUEPRINT_GRAPHICS; } /** * Adds the state of this BlueprintStyle to that of <code>s</code> * returning a combined SynthStyle. */ public DefaultSynthStyle addTo(DefaultSynthStyle s) { if (!(s instanceof BlueprintStyle)) { s = new BlueprintStyle(s); } BlueprintStyle style = (BlueprintStyle)super.addTo(s); if (info != null) { if (style.info == null) { style.info = info; } else { // Place the more specific first. Info[] merged = new Info[style.info.length + info.length]; System.arraycopy(info, 0, merged, 0, info.length); System.arraycopy(style.info, 0, merged, info.length, style.info.length); style.info = merged; } } // like the real blueprint, we only overwrite when iconColorize is true if (iconColorize) { style.iconColorize = true; style.colorizeColor = colorizeColor; } // like the real blueprint, we always overwrite style.iconAncestorTypes = iconAncestorTypes; return style; } /** * Creates a copy of the reciever and returns it. */ public Object clone() { BlueprintStyle style = (BlueprintStyle)super.clone(); // These fields are immutable, no need to clone them style.info = this.info; style.iconAncestorTypes = this.iconAncestorTypes; style.colorizeColor = this.colorizeColor; return style; } /** * Returns a GTKEngine to use for rendering. */ public GTKEngine getEngine(SynthContext context) { return BLUEPRINT_ENGINE; } /** * Returns the first instance of Info that matches the past in args, may * return null if nothing matches. * * @param function String name for the painting method * @param detail Description of what is being painted * @param componentState State of the Component * @param shadow Shadow type * @param orientation Orientation of what is being painted * @param gapSide Side of the gap being drawn * @param arrowDirection direction of the arrow. * @return Best matching Info, or null if none match */ public Info getInfo(String function, String detail, int componentState, int shadow, int orientation, int gapSide, int arrowDirection, String parentType) { if (info != null) { for (int counter = 0, max = info.length; counter < max;counter++) { if (info[counter].getFunction() == function && info[counter]. getMatchCount(detail, componentState, shadow, orientation, gapSide, arrowDirection, parentType) != -1) { return info[counter]; } } } return null; } /** * Returns the number of non-null arugments and arguments that are * != UNDEFINED. */ private int getMaxMatchCount(int componentState, int shadow, int orientation, int gapSide, int arrowDirection, String detail) { int count = 0; if (detail != null) { count++; } if (componentState != UNDEFINED) { count++; } if (shadow != UNDEFINED) { count++; } if (orientation != UNDEFINED) { count++; } if (gapSide != UNDEFINED) { count++; } if (arrowDirection != UNDEFINED) { count++; } return count; } /** * A description of how to paint a portion of a widget. */ public static class Info { // match data private String function = null; private String detail = null; int gapSide = UNDEFINED; int orientation = UNDEFINED; int componentState = UNDEFINED; int shadow = UNDEFINED; int arrowDirection = UNDEFINED; // strings in this list will be interned // this list could be null ArrayList parentTypeList = null; boolean useAsBkgMask = false; // background Object image = null; Insets fileInsets = null; boolean stretch = false; boolean recolorable = false; Color colorizeColor = null; // overlay Object overlayImage = null; Insets overlayInsets = null; boolean overlayStretch = false; boolean overlayRecolorable = false; Color overlayColorizeColor = null; // gap start Object gapStartImage = null; Insets gapStartInsets = null; // gap Object gapImage = null; Insets gapInsets = null; // gap end Object gapEndImage = null; Insets gapEndInsets = null; public void setFunction(String function) { this.function = function.intern(); } public void setDetail(String detail) { this.detail = detail.intern(); } public String getFunction() { return function; } public Image getImage() { image = getImage(image); return (Image)image; } public boolean isRecolorable() { return recolorable; } public Color getColorizeColor() { return colorizeColor; } public boolean isBkgMask() { return useAsBkgMask; } public Insets getImageInsets() { return fileInsets; } public boolean getStretch() { return stretch; } public String getDetail() { return detail; } public int getComponentState() { return componentState; } public int getShadow() { return shadow; } public int getGapSide() { return gapSide; } public Image getGapImage() { gapImage = getImage(gapImage); return (Image)gapImage; } public Insets getGapInsets() { return gapInsets; } public Image getGapStartImage() { gapStartImage = getImage(gapStartImage); return (Image)gapStartImage; } public Insets getGapStartInsets() { return gapStartInsets; } public Image getGapEndImage() { gapEndImage = getImage(gapEndImage); return (Image)gapEndImage; } public Insets getGapEndInsets() { return gapEndInsets; } public Image getOverlayImage() { overlayImage = getImage(overlayImage); return (Image)overlayImage; } public Insets getOverlayInsets() { return overlayInsets; } public boolean getOverlayStretch() { return overlayStretch; } public boolean getOverlayRecolorable() { return overlayRecolorable;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?