src/share/classes/com/sun/java/swing/plaf/windows/XPStyle.java

Print this page




  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 


  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);


 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);


 492 
 493         Skin(Component component, Part part, State state) {
 494             this.component = component;
 495             this.part  = part;
 496             this.state = state;
 497 
 498             String str = part.getControlName(component) +"." + part.name();
 499             if (state != null) {
 500                 str += "("+state.name()+")";
 501             }
 502             string = str;
 503         }
 504 
 505         Insets getContentMargin() {
 506             /* idk: it seems margins are the same for all 'big enough'
 507              * bounding rectangles.
 508              */
 509             int boundingWidth = 100;
 510             int boundingHeight = 100;
 511 
 512             return ThemeReader.getThemeBackgroundContentMargins(
 513                 part.getControlName(null), part.getValue(),
 514                 0, boundingWidth, boundingHeight);

 515         }
 516 
 517         private int getWidth(State state) {
 518             if (size == null) {
 519                 size = getPartSize(part, state);
 520             }
 521             return size.width;
 522         }
 523 
 524         int getWidth() {
 525             return getWidth((state != null) ? state : State.NORMAL);
 526         }
 527 
 528         private int getHeight(State state) {
 529             if (size == null) {
 530                 size = getPartSize(part, state);
 531             }
 532             return size.height;
 533         }
 534 
 535         int getHeight() {
 536             return getHeight((state != null) ? state : State.NORMAL);
 537         }
 538 
 539         public String toString() {
 540             return string;
 541         }
 542 
 543         public boolean equals(Object obj) {
 544             return (obj instanceof Skin && ((Skin)obj).string.equals(string));
 545         }
 546 
 547         public int hashCode() {
 548             return string.hashCode();
 549         }
 550 
 551         /** Paint a skin at x, y.
 552          *


 569          *                     may cause the image to be stretched or tiled
 570          * @param state which state to paint
 571          */
 572         void paintSkin(Graphics g, Rectangle r, State state) {
 573             paintSkin(g, r.x, r.y, r.width, r.height, state);
 574         }
 575 
 576         /** Paint a skin at a defined position and size
 577          *  This method supports animation.
 578          *
 579          * @param g   the graphics context to use for painting
 580          * @param dx  the destination <i>x</i> coordinate
 581          * @param dy  the destination <i>y</i> coordinate
 582          * @param dw  the width of the area to fill, may cause
 583          *                  the image to be stretched or tiled
 584          * @param dh  the height of the area to fill, may cause
 585          *                  the image to be stretched or tiled
 586          * @param state which state to paint
 587          */
 588         void paintSkin(Graphics g, int dx, int dy, int dw, int dh, State state) {



 589             if (ThemeReader.isGetThemeTransitionDurationDefined()
 590                   && component instanceof JComponent
 591                   && SwingUtilities.getAncestorOfClass(CellRendererPane.class,
 592                                                        component) == null) {
 593                 AnimationController.paintSkin((JComponent) component, this,
 594                                               g, dx, dy, dw, dh, state);
 595             } else {
 596                 paintSkinRaw(g, dx, dy, dw, dh, state);
 597             }
 598         }
 599 
 600         /** Paint a skin at a defined position and size. This method
 601          *  does not trigger animation. It is needed for the animation
 602          *  support.
 603          *
 604          * @param g   the graphics context to use for painting
 605          * @param dx  the destination <i>x</i> coordinate.
 606          * @param dy  the destination <i>y</i> coordinate.
 607          * @param dw  the width of the area to fill, may cause
 608          *                  the image to be stretched or tiled
 609          * @param dh  the height of the area to fill, may cause
 610          *                  the image to be stretched or tiled
 611          * @param state which state to paint
 612          */
 613         void paintSkinRaw(Graphics g, int dx, int dy, int dw, int dh, State state) {



 614             skinPainter.paint(null, g, dx, dy, dw, dh, this, state);
 615         }
 616 
 617         /** Paint a skin at a defined position and size
 618          *
 619          * @param g   the graphics context to use for painting
 620          * @param dx  the destination <i>x</i> coordinate
 621          * @param dy  the destination <i>y</i> coordinate
 622          * @param dw  the width of the area to fill, may cause
 623          *                  the image to be stretched or tiled
 624          * @param dh  the height of the area to fill, may cause
 625          *                  the image to be stretched or tiled
 626          * @param state which state to paint
 627          * @param borderFill should test if the component uses a border fill
 628                             and skip painting if it is
 629          */
 630         void paintSkin(Graphics g, int dx, int dy, int dw, int dh, State state,
 631                 boolean borderFill) {
 632             if(borderFill && "borderfill".equals(getTypeEnumName(component, part,
 633                     state, Prop.BGTYPE))) {
 634                 return;
 635             }
 636             skinPainter.paint(null, g, dx, dy, dw, dh, this, state);
 637         }
 638     }
 639 
 640     private static class SkinPainter extends CachedPainter {
 641         SkinPainter() {
 642             super(30);
 643             flush();
 644         }
 645 
 646         public void flush() {
 647             super.flush();
 648         }
 649 
 650         protected void paintToImage(Component c, Image image, Graphics g,
 651                                     int w, int h, Object[] args) {
 652             boolean accEnabled = false;
 653             Skin skin = (Skin)args[0];


 667             // since we modify the data in it.
 668             ThemeReader.paintBackground(SunWritableRaster.stealData(dbi, 0),
 669                                         part.getControlName(c), part.getValue(),
 670                                         State.getValue(part, state),
 671                                         0, 0, w, h, w);
 672             SunWritableRaster.markDirty(dbi);
 673         }
 674 
 675         protected Image createImage(Component c, int w, int h,
 676                                     GraphicsConfiguration config, Object[] args) {
 677             return new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
 678         }
 679     }
 680 
 681     @SuppressWarnings("serial") // Superclass is not serializable across versions
 682     static class GlyphButton extends JButton {
 683         private Skin skin;
 684 
 685         public GlyphButton(Component parent, Part part) {
 686             XPStyle xp = getXP();
 687             skin = xp.getSkin(parent, part);
 688             setBorder(null);
 689             setContentAreaFilled(false);
 690             setMinimumSize(new Dimension(5, 5));
 691             setPreferredSize(new Dimension(16, 16));
 692             setMaximumSize(new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE));
 693         }
 694 
 695         public boolean isFocusTraversable() {
 696             return false;
 697         }
 698 
 699         protected State getState() {
 700             State state = State.NORMAL;
 701             if (!isEnabled()) {
 702                 state = State.DISABLED;
 703             } else if (getModel().isPressed()) {
 704                 state = State.PRESSED;
 705             } else if (getModel().isRollover()) {
 706                 state = State.HOT;
 707             }
 708             return state;
 709         }
 710 
 711         public void paintComponent(Graphics g) {



 712             Dimension d = getSize();
 713             skin.paintSkin(g, 0, 0, d.width, d.height, getState());
 714         }
 715 
 716         public void setPart(Component parent, Part part) {
 717             XPStyle xp = getXP();
 718             skin = xp.getSkin(parent, part);
 719             revalidate();
 720             repaint();
 721         }
 722 
 723         protected void paintBorder(Graphics g) {
 724         }
 725 
 726 
 727     }
 728 
 729     // Private constructor
 730     private XPStyle() {
 731         flatMenus = getSysBoolean(Prop.FLATMENUS);
 732 
 733         colorMap  = new HashMap<String, Color>();
 734         borderMap = new HashMap<String, Border>();
 735         // Note: All further access to the maps must be synchronized
 736     }
 737 
 738 


  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.awt.windows.WToolkit;
  56 import sun.security.action.GetPropertyAction;
  57 import sun.swing.CachedPainter;
  58 
  59 import static com.sun.java.swing.plaf.windows.TMSchema.*;
  60 
  61 
  62 /**
  63  * Implements Windows XP Styles for the Windows Look and Feel.
  64  *
  65  * @author Leif Samuelsson
  66  */
  67 class XPStyle {
  68     // Singleton instance of this class
  69     private static XPStyle xp;
  70 
  71     // Singleton instance of SkinPainter
  72     private static SkinPainter skinPainter = new SkinPainter();
  73 
  74     private static Boolean themeActive = null;
  75 


  83     }
  84 
  85     /** Static method for clearing the hashmap and loading the
  86      * current XP style and theme
  87      */
  88     static synchronized void invalidateStyle() {
  89         xp = null;
  90         themeActive = null;
  91         skinPainter.flush();
  92     }
  93 
  94     /** Get the singleton instance of this class
  95      *
  96      * @return the singleton instance of this class or null if XP styles
  97      * are not active or if this is not Windows XP
  98      */
  99     static synchronized XPStyle getXP() {
 100         if (themeActive == null) {
 101             Toolkit toolkit = Toolkit.getDefaultToolkit();
 102             themeActive =
 103                 (Boolean)toolkit.getDesktopProperty(WToolkit.XPSTYLE_THEME_ACTIVE);
 104             if (themeActive == null) {
 105                 themeActive = Boolean.FALSE;
 106             }
 107             if (themeActive.booleanValue()) {
 108                 GetPropertyAction propertyAction =
 109                     new GetPropertyAction("swing.noxp");
 110                 if (AccessController.doPrivileged(propertyAction) == null &&
 111                     ThemeReader.isThemed() &&
 112                     !(UIManager.getLookAndFeel()
 113                       instanceof WindowsClassicLookAndFeel)) {
 114 
 115                     xp = new XPStyle();
 116                 }
 117             }
 118         }
 119         return ThemeReader.isXPStyleEnabled() ? xp : null;
 120     }
 121 
 122     static boolean isVista() {
 123         XPStyle xp = XPStyle.getXP();
 124         return (xp != null && xp.isSkinDefined(null, Part.CP_DROPDOWNBUTTONRIGHT));
 125     }
 126 
 127     /** Get a named <code>String</code> value from the current style
 128      *
 129      * @param part a <code>Part</code>
 130      * @param state a <code>String</code>
 131      * @param attributeKey a <code>String</code>
 132      * @return a <code>String</code> or null if key is not found
 133      *    in the current style
 134      *
 135      * This is currently only used by WindowsInternalFrameTitlePane for painting
 136      * title foregound and can be removed when no longer needed
 137      */
 138     String getString(Component c, Part part, State state, Prop prop) {
 139         return getTypeEnumName(c, part, state, prop);


 164      * @param part a <code>Part</code>
 165      * @return an <code>int</code> or null if key is not found
 166      *    in the current style
 167      */
 168     int getInt(Component c, Part part, State state, Prop prop, int fallback) {
 169         return ThemeReader.getInt(part.getControlName(c), part.getValue(),
 170                                   State.getValue(part, state),
 171                                   prop.getValue());
 172     }
 173 
 174     /** Get a named <code>Dimension</code> value from the current style
 175      *
 176      * @param key a <code>String</code>
 177      * @return a <code>Dimension</code> or null if key is not found
 178      *    in the current style
 179      *
 180      * This is currently only used by WindowsProgressBarUI and the value
 181      * should probably be cached there instead of here.
 182      */
 183     Dimension getDimension(Component c, Part part, State state, Prop prop) {
 184         Dimension d = ThemeReader.getPosition(part.getControlName(c), part.getValue(),
 185                                               State.getValue(part, state),
 186                                               prop.getValue());
 187         return (d != null) ? d : new Dimension();
 188     }
 189 
 190     /** Get a named <code>Point</code> (e.g. a location or an offset) value
 191      *  from the current style
 192      *
 193      * @param key a <code>String</code>
 194      * @return a <code>Point</code> or null if key is not found
 195      *    in the current style
 196      *
 197      * This is currently only used by WindowsInternalFrameTitlePane for painting
 198      * title foregound and can be removed when no longer needed
 199      */
 200     Point getPoint(Component c, Part part, State state, Prop prop) {
 201         Dimension d = ThemeReader.getPosition(part.getControlName(c), part.getValue(),
 202                                               State.getValue(part, state),
 203                                               prop.getValue());
 204         return (d != null) ? new Point(d.width, d.height) : new Point();




 205     }
 206 
 207     /** Get a named <code>Insets</code> value from the current style
 208      *
 209      * @param key a <code>String</code>
 210      * @return an <code>Insets</code> object or null if key is not found
 211      *    in the current style
 212      *
 213      * This is currently only used to create borders and by
 214      * WindowsInternalFrameTitlePane for painting title foregound.
 215      * The return value is already cached in those places.
 216      */
 217     Insets getMargin(Component c, Part part, State state, Prop prop) {
 218         Insets insets = ThemeReader.getThemeMargins(part.getControlName(c), part.getValue(),
 219                                                     State.getValue(part, state),
 220                                                     prop.getValue());
 221         return (insets != null) ? insets : new Insets(0, 0, 0, 0);
 222     }
 223 
 224 
 225     /** Get a named <code>Color</code> value from the current style
 226      *
 227      * @param part a <code>Part</code>
 228      * @return a <code>Color</code> or null if key is not found
 229      *    in the current style
 230      */
 231     synchronized Color getColor(Skin skin, Prop prop, Color fallback) {
 232         String key = skin.toString() + "." + prop.name();
 233         Part part = skin.part;
 234         Color color = colorMap.get(key);
 235         if (color == null) {
 236             color = ThemeReader.getColor(part.getControlName(null), part.getValue(),
 237                                          State.getValue(part, skin.state),
 238                                          prop.getValue());
 239             if (color != null) {
 240                 color = new ColorUIResource(color);
 241                 colorMap.put(key, color);


 491 
 492         Skin(Component component, Part part, State state) {
 493             this.component = component;
 494             this.part  = part;
 495             this.state = state;
 496 
 497             String str = part.getControlName(component) +"." + part.name();
 498             if (state != null) {
 499                 str += "("+state.name()+")";
 500             }
 501             string = str;
 502         }
 503 
 504         Insets getContentMargin() {
 505             /* idk: it seems margins are the same for all 'big enough'
 506              * bounding rectangles.
 507              */
 508             int boundingWidth = 100;
 509             int boundingHeight = 100;
 510 
 511             Insets insets = ThemeReader.getThemeBackgroundContentMargins(
 512                 part.getControlName(null), part.getValue(),
 513                 0, boundingWidth, boundingHeight);
 514             return (insets != null) ? insets : new Insets(0, 0, 0, 0);
 515         }
 516 
 517         private int getWidth(State state) {
 518             if (size == null) {
 519                 size = getPartSize(part, state);
 520             }
 521             return (size != null) ? size.width : 0;
 522         }
 523 
 524         int getWidth() {
 525             return getWidth((state != null) ? state : State.NORMAL);
 526         }
 527 
 528         private int getHeight(State state) {
 529             if (size == null) {
 530                 size = getPartSize(part, state);
 531             }
 532             return (size != null) ? size.height : 0;
 533         }
 534 
 535         int getHeight() {
 536             return getHeight((state != null) ? state : State.NORMAL);
 537         }
 538 
 539         public String toString() {
 540             return string;
 541         }
 542 
 543         public boolean equals(Object obj) {
 544             return (obj instanceof Skin && ((Skin)obj).string.equals(string));
 545         }
 546 
 547         public int hashCode() {
 548             return string.hashCode();
 549         }
 550 
 551         /** Paint a skin at x, y.
 552          *


 569          *                     may cause the image to be stretched or tiled
 570          * @param state which state to paint
 571          */
 572         void paintSkin(Graphics g, Rectangle r, State state) {
 573             paintSkin(g, r.x, r.y, r.width, r.height, state);
 574         }
 575 
 576         /** Paint a skin at a defined position and size
 577          *  This method supports animation.
 578          *
 579          * @param g   the graphics context to use for painting
 580          * @param dx  the destination <i>x</i> coordinate
 581          * @param dy  the destination <i>y</i> coordinate
 582          * @param dw  the width of the area to fill, may cause
 583          *                  the image to be stretched or tiled
 584          * @param dh  the height of the area to fill, may cause
 585          *                  the image to be stretched or tiled
 586          * @param state which state to paint
 587          */
 588         void paintSkin(Graphics g, int dx, int dy, int dw, int dh, State state) {
 589             if (XPStyle.getXP() == null) {
 590                 return;
 591             }
 592             if (ThemeReader.isGetThemeTransitionDurationDefined()
 593                   && component instanceof JComponent
 594                   && SwingUtilities.getAncestorOfClass(CellRendererPane.class,
 595                                                        component) == null) {
 596                 AnimationController.paintSkin((JComponent) component, this,
 597                                               g, dx, dy, dw, dh, state);
 598             } else {
 599                 paintSkinRaw(g, dx, dy, dw, dh, state);
 600             }
 601         }
 602 
 603         /** Paint a skin at a defined position and size. This method
 604          *  does not trigger animation. It is needed for the animation
 605          *  support.
 606          *
 607          * @param g   the graphics context to use for painting
 608          * @param dx  the destination <i>x</i> coordinate.
 609          * @param dy  the destination <i>y</i> coordinate.
 610          * @param dw  the width of the area to fill, may cause
 611          *                  the image to be stretched or tiled
 612          * @param dh  the height of the area to fill, may cause
 613          *                  the image to be stretched or tiled
 614          * @param state which state to paint
 615          */
 616         void paintSkinRaw(Graphics g, int dx, int dy, int dw, int dh, State state) {
 617             if (XPStyle.getXP() == null) {
 618                 return;
 619             }
 620             skinPainter.paint(null, g, dx, dy, dw, dh, this, state);
 621         }
 622 
 623         /** Paint a skin at a defined position and size
 624          *
 625          * @param g   the graphics context to use for painting
 626          * @param dx  the destination <i>x</i> coordinate
 627          * @param dy  the destination <i>y</i> coordinate
 628          * @param dw  the width of the area to fill, may cause
 629          *                  the image to be stretched or tiled
 630          * @param dh  the height of the area to fill, may cause
 631          *                  the image to be stretched or tiled
 632          * @param state which state to paint
 633          * @param borderFill should test if the component uses a border fill
 634                             and skip painting if it is
 635          */
 636         void paintSkin(Graphics g, int dx, int dy, int dw, int dh, State state,
 637                 boolean borderFill) {
 638             if(borderFill && "borderfill".equals(getTypeEnumName(component, part,
 639                     state, Prop.BGTYPE)) && XPStyle.getXP() == null) {
 640                 return;
 641             }
 642             skinPainter.paint(null, g, dx, dy, dw, dh, this, state);
 643         }
 644     }
 645 
 646     private static class SkinPainter extends CachedPainter {
 647         SkinPainter() {
 648             super(30);
 649             flush();
 650         }
 651 
 652         public void flush() {
 653             super.flush();
 654         }
 655 
 656         protected void paintToImage(Component c, Image image, Graphics g,
 657                                     int w, int h, Object[] args) {
 658             boolean accEnabled = false;
 659             Skin skin = (Skin)args[0];


 673             // since we modify the data in it.
 674             ThemeReader.paintBackground(SunWritableRaster.stealData(dbi, 0),
 675                                         part.getControlName(c), part.getValue(),
 676                                         State.getValue(part, state),
 677                                         0, 0, w, h, w);
 678             SunWritableRaster.markDirty(dbi);
 679         }
 680 
 681         protected Image createImage(Component c, int w, int h,
 682                                     GraphicsConfiguration config, Object[] args) {
 683             return new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
 684         }
 685     }
 686 
 687     @SuppressWarnings("serial") // Superclass is not serializable across versions
 688     static class GlyphButton extends JButton {
 689         private Skin skin;
 690 
 691         public GlyphButton(Component parent, Part part) {
 692             XPStyle xp = getXP();
 693             skin = xp != null ? xp.getSkin(parent, part) : null;
 694             setBorder(null);
 695             setContentAreaFilled(false);
 696             setMinimumSize(new Dimension(5, 5));
 697             setPreferredSize(new Dimension(16, 16));
 698             setMaximumSize(new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE));
 699         }
 700 
 701         public boolean isFocusTraversable() {
 702             return false;
 703         }
 704 
 705         protected State getState() {
 706             State state = State.NORMAL;
 707             if (!isEnabled()) {
 708                 state = State.DISABLED;
 709             } else if (getModel().isPressed()) {
 710                 state = State.PRESSED;
 711             } else if (getModel().isRollover()) {
 712                 state = State.HOT;
 713             }
 714             return state;
 715         }
 716 
 717         public void paintComponent(Graphics g) {
 718             if (XPStyle.getXP() == null || skin == null) {
 719                 return;
 720             }
 721             Dimension d = getSize();
 722             skin.paintSkin(g, 0, 0, d.width, d.height, getState());
 723         }
 724 
 725         public void setPart(Component parent, Part part) {
 726             XPStyle xp = getXP();
 727             skin = xp != null ? xp.getSkin(parent, part) : null;
 728             revalidate();
 729             repaint();
 730         }
 731 
 732         protected void paintBorder(Graphics g) {
 733         }
 734 
 735 
 736     }
 737 
 738     // Private constructor
 739     private XPStyle() {
 740         flatMenus = getSysBoolean(Prop.FLATMENUS);
 741 
 742         colorMap  = new HashMap<String, Color>();
 743         borderMap = new HashMap<String, Border>();
 744         // Note: All further access to the maps must be synchronized
 745     }
 746 
 747