FileDocCategorySizeDatePackage
XPStyle.javaAPI DocJava SE 6 API27929Tue Jun 10 00:21:58 BST 2008com.sun.java.swing.plaf.windows

XPStyle

public class XPStyle extends Object
Implements Windows XP Styles for the Windows Look and Feel.
version
1.34 07/13/06
author
Leif Samuelsson

Fields Summary
private static XPStyle
xp
private static SkinPainter
skinPainter
private static Boolean
themeActive
private HashMap
borderMap
private HashMap
colorMap
private boolean
flatMenus
Constructors Summary
private XPStyle()

        flatMenus = getSysBoolean(Prop.FLATMENUS);

        colorMap  = new HashMap<String, Color>();
        borderMap = new HashMap<String, Border>();
        // Note: All further access to the maps must be synchronized
    
Methods Summary
private booleangetBoolean(java.awt.Component c, Part part, State state, Prop prop)

        return ThemeReader.getBoolean(part.getControlName(c), part.getValue(),
				      State.getValue(part, state),
                                      prop.getValue());
    
synchronized javax.swing.border.BordergetBorder(java.awt.Component c, Part part)
Get a named Border value from the current style

param
part a Part
return
a Border or null if key is not found in the current style or if the style for the particular part is not defined as "borderfill".

        if (part == Part.MENU) {
            // Special case because XP has no skin for menus
            if (flatMenus) {
                // TODO: The classic border uses this color, but we should
                // create a new UI property called "PopupMenu.borderColor"
                // instead.
                return new XPFillBorder(UIManager.getColor("InternalFrame.borderShadow"),
                                        1);
            } else {
                return null;    // Will cause L&F to use classic border
            }
        }
        Skin skin = new Skin(c, part, null);
        Border border = borderMap.get(skin.string);
        if (border == null) {
            String bgType = getTypeEnumName(c, part, null, Prop.BGTYPE);
            if ("borderfill".equalsIgnoreCase(bgType)) {
                int thickness = getInt(c, part, null, Prop.BORDERSIZE, 1);
                Color color = getColor(skin, Prop.BORDERCOLOR, Color.black);
                border = new XPFillBorder(color, thickness);
                if (part == Part.CP_COMBOBOX) {
                    border = new XPStatefulFillBorder(color, thickness, part, Prop.BORDERCOLOR);
                }
            } else if ("imagefile".equalsIgnoreCase(bgType)) {
                Insets m = getMargin(c, part, null, Prop.SIZINGMARGINS);
                if (m != null) {
                    if (getBoolean(c, part, null, Prop.BORDERONLY)) {
                        border = new XPImageBorder(c, part);
                    } else if (part == Part.CP_COMBOBOX) {
                        border = new EmptyBorder(1, 1, 1, 1);
                    } else {
                        if(part == Part.TP_BUTTON) {
                            border = new XPEmptyBorder(new Insets(3,3,3,3));
                        } else {
                            border = new XPEmptyBorder(m);
                        }
                    }
                }
            }
            if (border != null) {
                borderMap.put(skin.string, border);
            }
        }
        return border;
    
synchronized java.awt.ColorgetColor(com.sun.java.swing.plaf.windows.XPStyle$Skin skin, Prop prop, java.awt.Color fallback)
Get a named Color value from the current style

param
part a Part
return
a Color or null if key is not found in the current style

	String key = skin.toString() + "." + prop.name();
	Part part = skin.part;
        Color color = colorMap.get(key);
        if (color == null) {
            color = ThemeReader.getColor(part.getControlName(null), part.getValue(),
                                         State.getValue(part, skin.state),
					 prop.getValue());
            if (color != null) {
                color = new ColorUIResource(color);
                colorMap.put(key, color);
            }
        }
        return (color != null) ? color : fallback;
    
java.awt.ColorgetColor(java.awt.Component c, Part part, State state, Prop prop, java.awt.Color fallback)

	return getColor(new Skin(c, part, state), prop, fallback);
    
java.awt.DimensiongetDimension(java.awt.Component c, Part part, State state, Prop prop)
Get a named Dimension value from the current style

param
key a String
return
a Dimension or null if key is not found in the current style This is currently only used by WindowsProgressBarUI and the value should probably be cached there instead of here.

        return ThemeReader.getPosition(part.getControlName(c), part.getValue(),
				       State.getValue(part, state),
                                       prop.getValue());
    
intgetInt(java.awt.Component c, Part part, State state, Prop prop, int fallback)
Get a named int value from the current style

param
part a Part
return
an int or null if key is not found in the current style

        return ThemeReader.getInt(part.getControlName(c), part.getValue(),
				  State.getValue(part, state),
                                  prop.getValue());
    
java.awt.InsetsgetMargin(java.awt.Component c, Part part, State state, Prop prop)
Get a named Insets value from the current style

param
key a String
return
an Insets object or null if key is not found in the current style This is currently only used to create borders and by WindowsInternalFrameTitlePane for painting title foregound. The return value is already cached in those places.

        return ThemeReader.getThemeMargins(part.getControlName(c), part.getValue(),
					   State.getValue(part, state),
                                           prop.getValue());
    
static java.awt.DimensiongetPartSize(Part part, State state)

        return ThemeReader.getPartSize(part.getControlName(null), part.getValue(),
				       State.getValue(part, state));
    
java.awt.PointgetPoint(java.awt.Component c, Part part, State state, Prop prop)
Get a named Point (e.g. a location or an offset) value from the current style

param
key a String
return
a Point or null if key is not found in the current style This is currently only used by WindowsInternalFrameTitlePane for painting title foregound and can be removed when no longer needed

        Dimension d = ThemeReader.getPosition(part.getControlName(c), part.getValue(),
					      State.getValue(part, state),
                                              prop.getValue());
        if (d != null) {
            return new Point(d.width, d.height);
        } else {
            return null;
        }
    
synchronized com.sun.java.swing.plaf.windows.XPStyle$SkingetSkin(java.awt.Component c, Part part)
Get a Skin object from the current style for a named part (component type)

param
part a Part
return
a Skin object

        assert isSkinDefined(c, part) : "part " + part + " is not defined";
        return new Skin(c, part, null);
    
java.lang.StringgetString(java.awt.Component c, Part part, State state, Prop prop)
Get a named String value from the current style

param
part a Part
param
state a String
param
attributeKey a String
return
a String or null if key is not found in the current style This is currently only used by WindowsInternalFrameTitlePane for painting title foregound and can be removed when no longer needed

        return getTypeEnumName(c, part, state, prop);
    
private static booleangetSysBoolean(Prop prop)

        // We can use any widget name here, I guess.
        return ThemeReader.getSysBoolean("window", prop.getValue());
    
longgetThemeTransitionDuration(java.awt.Component c, Part part, State stateFrom, State stateTo, Prop prop)

         return ThemeReader.getThemeTransitionDuration(part.getControlName(c),
                                          part.getValue(),
                                          State.getValue(part, stateFrom),
                                          State.getValue(part, stateTo),
                                          (prop != null) ? prop.getValue() : 0);
    
TypeEnumgetTypeEnum(java.awt.Component c, Part part, State state, Prop prop)

        int enumValue = ThemeReader.getEnum(part.getControlName(c), part.getValue(),
                                            State.getValue(part, state),
                                            prop.getValue());
        return TypeEnum.getTypeEnum(prop, enumValue);
    
private static java.lang.StringgetTypeEnumName(java.awt.Component c, Part part, State state, Prop prop)

        int enumValue = ThemeReader.getEnum(part.getControlName(c), part.getValue(),
					    State.getValue(part, state),
                                            prop.getValue());
        if (enumValue == -1) {
            return null;
        }
        return TypeEnum.getTypeEnum(prop, enumValue).getName();
    
static synchronized com.sun.java.swing.plaf.windows.XPStylegetXP()
Get the singleton instance of this class

return
the singleton instance of this class or null if XP styles are not active or if this is not Windows XP

        if (themeActive == null) {
            Toolkit toolkit = Toolkit.getDefaultToolkit();
            themeActive =
                (Boolean)toolkit.getDesktopProperty("win.xpstyle.themeActive");
            if (themeActive == null) {
                themeActive = Boolean.FALSE;
            }
            if (themeActive.booleanValue()) {
                GetPropertyAction propertyAction =
                    new GetPropertyAction("swing.noxp");
                if (AccessController.doPrivileged(propertyAction) == null &&
                    ThemeReader.isThemed() &&
                    !(UIManager.getLookAndFeel()
                      instanceof WindowsClassicLookAndFeel)) {

                    xp = new XPStyle();
                }
            }
        }
        return xp;
    
static synchronized voidinvalidateStyle()
Static method for clearing the hashmap and loading the current XP style and theme


     
        invalidateStyle();
    
        xp = null;
        themeActive = null;
        skinPainter.flush();
    
booleanisSkinDefined(java.awt.Component c, Part part)

        return (part.getValue() == 0) 
            || ThemeReader.isThemePartDefined(
                   part.getControlName(c), part.getValue(), 0);
    
static booleanisVista()

        XPStyle xp = XPStyle.getXP();
        return (xp != null && xp.isSkinDefined(null, Part.CP_DROPDOWNBUTTONRIGHT));