1 /*
   2  * Copyright (c) 2002, 2007, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 /*
  27  * <p>These classes are designed to be used while the
  28  * corresponding <code>LookAndFeel</code> class has been installed
  29  * (<code>UIManager.setLookAndFeel(new <i>XXX</i>LookAndFeel())</code>).
  30  * Using them while a different <code>LookAndFeel</code> is installed
  31  * may produce unexpected results, including exceptions.
  32  * Additionally, changing the <code>LookAndFeel</code>
  33  * maintained by the <code>UIManager</code> without updating the
  34  * corresponding <code>ComponentUI</code> of any
  35  * <code>JComponent</code>s may also produce unexpected results,
  36  * such as the wrong colors showing up, and is generally not
  37  * encouraged.
  38  *
  39  */
  40 
  41 package com.sun.java.swing.plaf.windows;
  42 
  43 import java.awt.*;
  44 import java.awt.image.*;
  45 import java.security.AccessController;
  46 import java.util.*;
  47 
  48 import javax.swing.*;
  49 import javax.swing.border.*;
  50 import javax.swing.plaf.*;
  51 import javax.swing.text.JTextComponent;
  52 
  53 import sun.awt.image.SunWritableRaster;
  54 import sun.awt.windows.ThemeReader;
  55 import sun.security.action.GetPropertyAction;
  56 import sun.swing.CachedPainter;
  57 
  58 import static com.sun.java.swing.plaf.windows.TMSchema.*;
  59 
  60 
  61 /**
  62  * Implements Windows XP Styles for the Windows Look and Feel.
  63  *
  64  * @author Leif Samuelsson
  65  */
  66 class XPStyle {
  67     // Singleton instance of this class
  68     private static XPStyle xp;
  69 
  70     // Singleton instance of SkinPainter
  71     private static SkinPainter skinPainter = new SkinPainter();
  72 
  73     private static Boolean themeActive = null;
  74 
  75     private HashMap<String, Border> borderMap;
  76     private HashMap<String, Color>  colorMap;
  77 
  78     private boolean flatMenus;
  79 
  80     static {
  81         invalidateStyle();
  82     }
  83 
  84     /** Static method for clearing the hashmap and loading the
  85      * current XP style and theme
  86      */
  87     static synchronized void invalidateStyle() {
  88         xp = null;
  89         themeActive = null;
  90         skinPainter.flush();
  91     }
  92 
  93     /** Get the singleton instance of this class
  94      *
  95      * @return the singleton instance of this class or null if XP styles
  96      * are not active or if this is not Windows XP
  97      */
  98     static synchronized XPStyle getXP() {
  99         if (themeActive == null) {
 100             Toolkit toolkit = Toolkit.getDefaultToolkit();
 101             themeActive =
 102                 (Boolean)toolkit.getDesktopProperty("win.xpstyle.themeActive");
 103             if (themeActive == null) {
 104                 themeActive = Boolean.FALSE;
 105             }
 106             if (themeActive.booleanValue()) {
 107                 GetPropertyAction propertyAction =
 108                     new GetPropertyAction("swing.noxp");
 109                 if (AccessController.doPrivileged(propertyAction) == null &&
 110                     ThemeReader.isThemed() &&
 111                     !(UIManager.getLookAndFeel()
 112                       instanceof WindowsClassicLookAndFeel)) {
 113 
 114                     xp = new XPStyle();
 115                 }
 116             }
 117         }
 118         return xp;
 119     }
 120 
 121     static boolean isVista() {
 122         XPStyle xp = XPStyle.getXP();
 123         return (xp != null && xp.isSkinDefined(null, Part.CP_DROPDOWNBUTTONRIGHT));
 124     }
 125 
 126     /** Get a named <code>String</code> value from the current style
 127      *
 128      * @param part a <code>Part</code>
 129      * @param state a <code>String</code>
 130      * @param attributeKey a <code>String</code>
 131      * @return a <code>String</code> or null if key is not found
 132      *    in the current style
 133      *
 134      * This is currently only used by WindowsInternalFrameTitlePane for painting
 135      * title foregound and can be removed when no longer needed
 136      */
 137     String getString(Component c, Part part, State state, Prop prop) {
 138         return getTypeEnumName(c, part, state, prop);
 139     }
 140 
 141     TypeEnum getTypeEnum(Component c, Part part, State state, Prop prop) {
 142         int enumValue = ThemeReader.getEnum(part.getControlName(c), part.getValue(),
 143                                             State.getValue(part, state),
 144                                             prop.getValue());
 145         return TypeEnum.getTypeEnum(prop, enumValue);
 146     }
 147 
 148     private static String getTypeEnumName(Component c, Part part, State state, Prop prop) {
 149         int enumValue = ThemeReader.getEnum(part.getControlName(c), part.getValue(),
 150                                             State.getValue(part, state),
 151                                             prop.getValue());
 152         if (enumValue == -1) {
 153             return null;
 154         }
 155         return TypeEnum.getTypeEnum(prop, enumValue).getName();
 156     }
 157 
 158 
 159 
 160 
 161     /** Get a named <code>int</code> value from the current style
 162      *
 163      * @param part a <code>Part</code>
 164      * @return an <code>int</code> or null if key is not found
 165      *    in the current style
 166      */
 167     int getInt(Component c, Part part, State state, Prop prop, int fallback) {
 168         return ThemeReader.getInt(part.getControlName(c), part.getValue(),
 169                                   State.getValue(part, state),
 170                                   prop.getValue());
 171     }
 172 
 173     /** Get a named <code>Dimension</code> value from the current style
 174      *
 175      * @param key a <code>String</code>
 176      * @return a <code>Dimension</code> or null if key is not found
 177      *    in the current style
 178      *
 179      * This is currently only used by WindowsProgressBarUI and the value
 180      * should probably be cached there instead of here.
 181      */
 182     Dimension getDimension(Component c, Part part, State state, Prop prop) {
 183         return ThemeReader.getPosition(part.getControlName(c), part.getValue(),
 184                                        State.getValue(part, state),
 185                                        prop.getValue());
 186     }
 187 
 188     /** Get a named <code>Point</code> (e.g. a location or an offset) value
 189      *  from the current style
 190      *
 191      * @param key a <code>String</code>
 192      * @return a <code>Point</code> or null if key is not found
 193      *    in the current style
 194      *
 195      * This is currently only used by WindowsInternalFrameTitlePane for painting
 196      * title foregound and can be removed when no longer needed
 197      */
 198     Point getPoint(Component c, Part part, State state, Prop prop) {
 199         Dimension d = ThemeReader.getPosition(part.getControlName(c), part.getValue(),
 200                                               State.getValue(part, state),
 201                                               prop.getValue());
 202         if (d != null) {
 203             return new Point(d.width, d.height);
 204         } else {
 205             return null;
 206         }
 207     }
 208 
 209     /** Get a named <code>Insets</code> value from the current style
 210      *
 211      * @param key a <code>String</code>
 212      * @return an <code>Insets</code> object or null if key is not found
 213      *    in the current style
 214      *
 215      * This is currently only used to create borders and by
 216      * WindowsInternalFrameTitlePane for painting title foregound.
 217      * The return value is already cached in those places.
 218      */
 219     Insets getMargin(Component c, Part part, State state, Prop prop) {
 220         return ThemeReader.getThemeMargins(part.getControlName(c), part.getValue(),
 221                                            State.getValue(part, state),
 222                                            prop.getValue());
 223     }
 224 
 225 
 226     /** Get a named <code>Color</code> value from the current style
 227      *
 228      * @param part a <code>Part</code>
 229      * @return a <code>Color</code> or null if key is not found
 230      *    in the current style
 231      */
 232     synchronized Color getColor(Skin skin, Prop prop, Color fallback) {
 233         String key = skin.toString() + "." + prop.name();
 234         Part part = skin.part;
 235         Color color = colorMap.get(key);
 236         if (color == null) {
 237             color = ThemeReader.getColor(part.getControlName(null), part.getValue(),
 238                                          State.getValue(part, skin.state),
 239                                          prop.getValue());
 240             if (color != null) {
 241                 color = new ColorUIResource(color);
 242                 colorMap.put(key, color);
 243             }
 244         }
 245         return (color != null) ? color : fallback;
 246     }
 247 
 248     Color getColor(Component c, Part part, State state, Prop prop, Color fallback) {
 249         return getColor(new Skin(c, part, state), prop, fallback);
 250     }
 251 
 252 
 253 
 254     /** Get a named <code>Border</code> value from the current style
 255      *
 256      * @param part a <code>Part</code>
 257      * @return a <code>Border</code> or null if key is not found
 258      *    in the current style or if the style for the particular
 259      *    part is not defined as "borderfill".
 260      */
 261     synchronized Border getBorder(Component c, Part part) {
 262         if (part == Part.MENU) {
 263             // Special case because XP has no skin for menus
 264             if (flatMenus) {
 265                 // TODO: The classic border uses this color, but we should
 266                 // create a new UI property called "PopupMenu.borderColor"
 267                 // instead.
 268                 return new XPFillBorder(UIManager.getColor("InternalFrame.borderShadow"),
 269                                         1);
 270             } else {
 271                 return null;    // Will cause L&F to use classic border
 272             }
 273         }
 274         Skin skin = new Skin(c, part, null);
 275         Border border = borderMap.get(skin.string);
 276         if (border == null) {
 277             String bgType = getTypeEnumName(c, part, null, Prop.BGTYPE);
 278             if ("borderfill".equalsIgnoreCase(bgType)) {
 279                 int thickness = getInt(c, part, null, Prop.BORDERSIZE, 1);
 280                 Color color = getColor(skin, Prop.BORDERCOLOR, Color.black);
 281                 border = new XPFillBorder(color, thickness);
 282                 if (part == Part.CP_COMBOBOX) {
 283                     border = new XPStatefulFillBorder(color, thickness, part, Prop.BORDERCOLOR);
 284                 }
 285             } else if ("imagefile".equalsIgnoreCase(bgType)) {
 286                 Insets m = getMargin(c, part, null, Prop.SIZINGMARGINS);
 287                 if (m != null) {
 288                     if (getBoolean(c, part, null, Prop.BORDERONLY)) {
 289                         border = new XPImageBorder(c, part);
 290                     } else if (part == Part.CP_COMBOBOX) {
 291                         border = new EmptyBorder(1, 1, 1, 1);
 292                     } else {
 293                         if(part == Part.TP_BUTTON) {
 294                             border = new XPEmptyBorder(new Insets(3,3,3,3));
 295                         } else {
 296                             border = new XPEmptyBorder(m);
 297                         }
 298                     }
 299                 }
 300             }
 301             if (border != null) {
 302                 borderMap.put(skin.string, border);
 303             }
 304         }
 305         return border;
 306     }
 307 
 308     private class XPFillBorder extends LineBorder implements UIResource {
 309         XPFillBorder(Color color, int thickness) {
 310             super(color, thickness);
 311         }
 312 
 313         public Insets getBorderInsets(Component c, Insets insets)       {
 314             Insets margin = null;
 315             //
 316             // Ideally we'd have an interface defined for classes which
 317             // support margins (to avoid this hackery), but we've
 318             // decided against it for simplicity
 319             //
 320            if (c instanceof AbstractButton) {
 321                margin = ((AbstractButton)c).getMargin();
 322            } else if (c instanceof JToolBar) {
 323                margin = ((JToolBar)c).getMargin();
 324            } else if (c instanceof JTextComponent) {
 325                margin = ((JTextComponent)c).getMargin();
 326            }
 327            insets.top    = (margin != null? margin.top : 0)    + thickness;
 328            insets.left   = (margin != null? margin.left : 0)   + thickness;
 329            insets.bottom = (margin != null? margin.bottom : 0) + thickness;
 330            insets.right =  (margin != null? margin.right : 0)  + thickness;
 331 
 332            return insets;
 333         }
 334     }
 335 
 336     private class XPStatefulFillBorder extends XPFillBorder {
 337         private final Part part;
 338         private final Prop prop;
 339         XPStatefulFillBorder(Color color, int thickness, Part part, Prop prop) {
 340             super(color, thickness);
 341             this.part = part;
 342             this.prop = prop;
 343         }
 344 
 345         public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
 346             State state = State.NORMAL;
 347             // special casing for comboboxes.
 348             // there may be more special cases in the future
 349             if(c instanceof JComboBox) {
 350                 JComboBox cb = (JComboBox)c;
 351                 // note. in the future this should be replaced with a call
 352                 // to BasicLookAndFeel.getUIOfType()
 353                 if(cb.getUI() instanceof WindowsComboBoxUI) {
 354                     WindowsComboBoxUI wcb = (WindowsComboBoxUI)cb.getUI();
 355                     state = wcb.getXPComboBoxState(cb);
 356                 }
 357             }
 358             lineColor = getColor(c, part, state, prop, Color.black);
 359             super.paintBorder(c, g, x, y, width, height);
 360         }
 361     }
 362 
 363     private class XPImageBorder extends AbstractBorder implements UIResource {
 364         Skin skin;
 365 
 366         XPImageBorder(Component c, Part part) {
 367             this.skin = getSkin(c, part);
 368         }
 369 
 370         public void paintBorder(Component c, Graphics g,
 371                                 int x, int y, int width, int height) {
 372             skin.paintSkin(g, x, y, width, height, null);
 373         }
 374 
 375         public Insets getBorderInsets(Component c, Insets insets)       {
 376             Insets margin = null;
 377             Insets borderInsets = skin.getContentMargin();
 378             if(borderInsets == null) {
 379                 borderInsets = new Insets(0, 0, 0, 0);
 380             }
 381             //
 382             // Ideally we'd have an interface defined for classes which
 383             // support margins (to avoid this hackery), but we've
 384             // decided against it for simplicity
 385             //
 386            if (c instanceof AbstractButton) {
 387                margin = ((AbstractButton)c).getMargin();
 388            } else if (c instanceof JToolBar) {
 389                margin = ((JToolBar)c).getMargin();
 390            } else if (c instanceof JTextComponent) {
 391                margin = ((JTextComponent)c).getMargin();
 392            }
 393            insets.top    = (margin != null? margin.top : 0)    + borderInsets.top;
 394            insets.left   = (margin != null? margin.left : 0)   + borderInsets.left;
 395            insets.bottom = (margin != null? margin.bottom : 0) + borderInsets.bottom;
 396            insets.right  = (margin != null? margin.right : 0)  + borderInsets.right;
 397 
 398            return insets;
 399         }
 400     }
 401 
 402     private class XPEmptyBorder extends EmptyBorder implements UIResource {
 403         XPEmptyBorder(Insets m) {
 404             super(m.top+2, m.left+2, m.bottom+2, m.right+2);
 405         }
 406 
 407         public Insets getBorderInsets(Component c, Insets insets)       {
 408             insets = super.getBorderInsets(c, insets);
 409 
 410             Insets margin = null;
 411             if (c instanceof AbstractButton) {
 412                 Insets m = ((AbstractButton)c).getMargin();
 413                 // if this is a toolbar button then ignore getMargin()
 414                 // and subtract the padding added by the constructor
 415                 if(c.getParent() instanceof JToolBar
 416                    && ! (c instanceof JRadioButton)
 417                    && ! (c instanceof JCheckBox)
 418                    && m instanceof InsetsUIResource) {
 419                     insets.top -= 2;
 420                     insets.left -= 2;
 421                     insets.bottom -= 2;
 422                     insets.right -= 2;
 423                 } else {
 424                     margin = m;
 425                 }
 426             } else if (c instanceof JToolBar) {
 427                 margin = ((JToolBar)c).getMargin();
 428             } else if (c instanceof JTextComponent) {
 429                 margin = ((JTextComponent)c).getMargin();
 430             }
 431             if (margin != null) {
 432                 insets.top    = margin.top + 2;
 433                 insets.left   = margin.left + 2;
 434                 insets.bottom = margin.bottom + 2;
 435                 insets.right  = margin.right + 2;
 436             }
 437             return insets;
 438         }
 439     }
 440     boolean isSkinDefined(Component c, Part part) {
 441         return (part.getValue() == 0)
 442             || ThemeReader.isThemePartDefined(
 443                    part.getControlName(c), part.getValue(), 0);
 444     }
 445 
 446 
 447     /** Get a <code>Skin</code> object from the current style
 448      * for a named part (component type)
 449      *
 450      * @param part a <code>Part</code>
 451      * @return a <code>Skin</code> object
 452      */
 453     synchronized Skin getSkin(Component c, Part part) {
 454         assert isSkinDefined(c, part) : "part " + part + " is not defined";
 455         return new Skin(c, part, null);
 456     }
 457 
 458 
 459     long getThemeTransitionDuration(Component c, Part part, State stateFrom,
 460                                     State stateTo, Prop prop) {
 461          return ThemeReader.getThemeTransitionDuration(part.getControlName(c),
 462                                           part.getValue(),
 463                                           State.getValue(part, stateFrom),
 464                                           State.getValue(part, stateTo),
 465                                           (prop != null) ? prop.getValue() : 0);
 466     }
 467 
 468 
 469     /** A class which encapsulates attributes for a given part
 470      * (component type) and which provides methods for painting backgrounds
 471      * and glyphs
 472      */
 473     static class Skin {
 474         final Component component;
 475         final Part part;
 476         final State state;
 477 
 478         private final String string;
 479         private Dimension size = null;
 480 
 481         Skin(Component component, Part part) {
 482             this(component, part, null);
 483         }
 484 
 485         Skin(Part part, State state) {
 486             this(null, part, state);
 487         }
 488 
 489         Skin(Component component, Part part, State state) {
 490             this.component = component;
 491             this.part  = part;
 492             this.state = state;
 493 
 494             String str = part.getControlName(component) +"." + part.name();
 495             if (state != null) {
 496                 str += "("+state.name()+")";
 497             }
 498             string = str;
 499         }
 500 
 501         Insets getContentMargin() {
 502             /* idk: it seems margins are the same for all 'big enough'
 503              * bounding rectangles.
 504              */
 505             int boundingWidth = 100;
 506             int boundingHeight = 100;
 507 
 508             return ThemeReader.getThemeBackgroundContentMargins(
 509                 part.getControlName(null), part.getValue(),
 510                 0, boundingWidth, boundingHeight);
 511         }
 512 
 513         private int getWidth(State state) {
 514             if (size == null) {
 515                 size = getPartSize(part, state);
 516             }
 517             return size.width;
 518         }
 519 
 520         int getWidth() {
 521             return getWidth((state != null) ? state : State.NORMAL);
 522         }
 523 
 524         private int getHeight(State state) {
 525             if (size == null) {
 526                 size = getPartSize(part, state);
 527             }
 528             return size.height;
 529         }
 530 
 531         int getHeight() {
 532             return getHeight((state != null) ? state : State.NORMAL);
 533         }
 534 
 535         public String toString() {
 536             return string;
 537         }
 538 
 539         public boolean equals(Object obj) {
 540             return (obj instanceof Skin && ((Skin)obj).string.equals(string));
 541         }
 542 
 543         public int hashCode() {
 544             return string.hashCode();
 545         }
 546 
 547         /** Paint a skin at x, y.
 548          *
 549          * @param g   the graphics context to use for painting
 550          * @param dx  the destination <i>x</i> coordinate
 551          * @param dy  the destination <i>y</i> coordinate
 552          * @param state which state to paint
 553          */
 554         void paintSkin(Graphics g, int dx, int dy, State state) {
 555             if (state == null) {
 556                 state = this.state;
 557             }
 558             paintSkin(g, dx, dy, getWidth(state), getHeight(state), state);
 559         }
 560 
 561         /** Paint a skin in an area defined by a rectangle.
 562          *
 563          * @param g the graphics context to use for painting
 564          * @param r     a <code>Rectangle</code> defining the area to fill,
 565          *                     may cause the image to be stretched or tiled
 566          * @param state which state to paint
 567          */
 568         void paintSkin(Graphics g, Rectangle r, State state) {
 569             paintSkin(g, r.x, r.y, r.width, r.height, state);
 570         }
 571 
 572         /** Paint a skin at a defined position and size
 573          *  This method supports animation.
 574          *
 575          * @param g   the graphics context to use for painting
 576          * @param dx  the destination <i>x</i> coordinate
 577          * @param dy  the destination <i>y</i> coordinate
 578          * @param dw  the width of the area to fill, may cause
 579          *                  the image to be stretched or tiled
 580          * @param dh  the height of the area to fill, may cause
 581          *                  the image to be stretched or tiled
 582          * @param state which state to paint
 583          */
 584         void paintSkin(Graphics g, int dx, int dy, int dw, int dh, State state) {
 585             if (ThemeReader.isGetThemeTransitionDurationDefined()
 586                   && component instanceof JComponent
 587                   && SwingUtilities.getAncestorOfClass(CellRendererPane.class,
 588                                                        component) == null) {
 589                 AnimationController.paintSkin((JComponent) component, this,
 590                                               g, dx, dy, dw, dh, state);
 591             } else {
 592                 paintSkinRaw(g, dx, dy, dw, dh, state);
 593             }
 594         }
 595 
 596         /** Paint a skin at a defined position and size. This method
 597          *  does not trigger animation. It is needed for the animation
 598          *  support.
 599          *
 600          * @param g   the graphics context to use for painting
 601          * @param dx  the destination <i>x</i> coordinate.
 602          * @param dy  the destination <i>y</i> coordinate.
 603          * @param dw  the width of the area to fill, may cause
 604          *                  the image to be stretched or tiled
 605          * @param dh  the height of the area to fill, may cause
 606          *                  the image to be stretched or tiled
 607          * @param state which state to paint
 608          */
 609         void paintSkinRaw(Graphics g, int dx, int dy, int dw, int dh, State state) {
 610             skinPainter.paint(null, g, dx, dy, dw, dh, this, state);
 611         }
 612 
 613         /** Paint a skin at a defined position and size
 614          *
 615          * @param g   the graphics context to use for painting
 616          * @param dx  the destination <i>x</i> coordinate
 617          * @param dy  the destination <i>y</i> coordinate
 618          * @param dw  the width of the area to fill, may cause
 619          *                  the image to be stretched or tiled
 620          * @param dh  the height of the area to fill, may cause
 621          *                  the image to be stretched or tiled
 622          * @param state which state to paint
 623          * @param borderFill should test if the component uses a border fill
 624                             and skip painting if it is
 625          */
 626         void paintSkin(Graphics g, int dx, int dy, int dw, int dh, State state,
 627                 boolean borderFill) {
 628             if(borderFill && "borderfill".equals(getTypeEnumName(component, part,
 629                     state, Prop.BGTYPE))) {
 630                 return;
 631             }
 632             skinPainter.paint(null, g, dx, dy, dw, dh, this, state);
 633         }
 634     }
 635 
 636     private static class SkinPainter extends CachedPainter {
 637         SkinPainter() {
 638             super(30);
 639             flush();
 640         }
 641 
 642         public void flush() {
 643             super.flush();
 644         }
 645 
 646         protected void paintToImage(Component c, Image image, Graphics g,
 647                                     int w, int h, Object[] args) {
 648             boolean accEnabled = false;
 649             Skin skin = (Skin)args[0];
 650             Part part = skin.part;
 651             State state = (State)args[1];
 652             if (state == null) {
 653                 state = skin.state;
 654             }
 655             if (c == null) {
 656                 c = skin.component;
 657             }
 658             BufferedImage bi = (BufferedImage)image;
 659 
 660             WritableRaster raster = bi.getRaster();
 661             DataBufferInt dbi = (DataBufferInt)raster.getDataBuffer();
 662             // Note that stealData() requires a markDirty() afterwards
 663             // since we modify the data in it.
 664             ThemeReader.paintBackground(SunWritableRaster.stealData(dbi, 0),
 665                                         part.getControlName(c), part.getValue(),
 666                                         State.getValue(part, state),
 667                                         0, 0, w, h, w);
 668             SunWritableRaster.markDirty(dbi);
 669         }
 670 
 671         protected Image createImage(Component c, int w, int h,
 672                                     GraphicsConfiguration config, Object[] args) {
 673             return new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
 674         }
 675     }
 676 
 677     static class GlyphButton extends JButton {
 678         private Skin skin;
 679 
 680         public GlyphButton(Component parent, Part part) {
 681             XPStyle xp = getXP();
 682             skin = xp.getSkin(parent, part);
 683             setBorder(null);
 684             setContentAreaFilled(false);
 685             setMinimumSize(new Dimension(5, 5));
 686             setPreferredSize(new Dimension(16, 16));
 687             setMaximumSize(new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE));
 688         }
 689 
 690         public boolean isFocusTraversable() {
 691             return false;
 692         }
 693 
 694         protected State getState() {
 695             State state = State.NORMAL;
 696             if (!isEnabled()) {
 697                 state = State.DISABLED;
 698             } else if (getModel().isPressed()) {
 699                 state = State.PRESSED;
 700             } else if (getModel().isRollover()) {
 701                 state = State.HOT;
 702             }
 703             return state;
 704         }
 705 
 706         public void paintComponent(Graphics g) {
 707             Dimension d = getSize();
 708             skin.paintSkin(g, 0, 0, d.width, d.height, getState());
 709         }
 710 
 711         public void setPart(Component parent, Part part) {
 712             XPStyle xp = getXP();
 713             skin = xp.getSkin(parent, part);
 714             revalidate();
 715             repaint();
 716         }
 717 
 718         protected void paintBorder(Graphics g) {
 719         }
 720 
 721 
 722     }
 723 
 724     // Private constructor
 725     private XPStyle() {
 726         flatMenus = getSysBoolean(Prop.FLATMENUS);
 727 
 728         colorMap  = new HashMap<String, Color>();
 729         borderMap = new HashMap<String, Border>();
 730         // Note: All further access to the maps must be synchronized
 731     }
 732 
 733 
 734     private boolean getBoolean(Component c, Part part, State state, Prop prop) {
 735         return ThemeReader.getBoolean(part.getControlName(c), part.getValue(),
 736                                       State.getValue(part, state),
 737                                       prop.getValue());
 738     }
 739 
 740 
 741 
 742     static Dimension getPartSize(Part part, State state) {
 743         return ThemeReader.getPartSize(part.getControlName(null), part.getValue(),
 744                                        State.getValue(part, state));
 745     }
 746 
 747     private static boolean getSysBoolean(Prop prop) {
 748         // We can use any widget name here, I guess.
 749         return ThemeReader.getSysBoolean("window", prop.getValue());
 750     }
 751 }