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

Print this page

        

@@ -113,11 +113,11 @@
 
                     xp = new XPStyle();
                 }
             }
         }
-        return xp;
+        return ThemeReader.isXPStyleEnabled() ? xp : null;
     }
 
     static boolean isVista() {
         XPStyle xp = XPStyle.getXP();
         return (xp != null && xp.isSkinDefined(null, Part.CP_DROPDOWNBUTTONRIGHT));

@@ -178,13 +178,14 @@
      *
      * This is currently only used by WindowsProgressBarUI and the value
      * should probably be cached there instead of here.
      */
     Dimension getDimension(Component c, Part part, State state, Prop prop) {
-        return ThemeReader.getPosition(part.getControlName(c), part.getValue(),
+        Dimension d = ThemeReader.getPosition(part.getControlName(c), part.getValue(),
                                        State.getValue(part, state),
                                        prop.getValue());
+        return (d != null) ? d : new Dimension();
     }
 
     /** Get a named <code>Point</code> (e.g. a location or an offset) value
      *  from the current style
      *

@@ -197,15 +198,11 @@
      */
     Point getPoint(Component c, Part part, State state, Prop prop) {
         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;
-        }
+        return (d != null) ? new Point(d.width, d.height) : new Point();
     }
 
     /** Get a named <code>Insets</code> value from the current style
      *
      * @param key a <code>String</code>

@@ -215,13 +212,14 @@
      * This is currently only used to create borders and by
      * WindowsInternalFrameTitlePane for painting title foregound.
      * The return value is already cached in those places.
      */
     Insets getMargin(Component c, Part part, State state, Prop prop) {
-        return ThemeReader.getThemeMargins(part.getControlName(c), part.getValue(),
+        Insets insets = ThemeReader.getThemeMargins(part.getControlName(c), part.getValue(),
                                            State.getValue(part, state),
                                            prop.getValue());
+        return (insets != null) ? insets : new Insets(0, 0, 0, 0);
     }
 
 
     /** Get a named <code>Color</code> value from the current style
      *

@@ -507,31 +505,32 @@
              * bounding rectangles.
              */
             int boundingWidth = 100;
             int boundingHeight = 100;
 
-            return ThemeReader.getThemeBackgroundContentMargins(
+            Insets insets = ThemeReader.getThemeBackgroundContentMargins(
                 part.getControlName(null), part.getValue(),
                 0, boundingWidth, boundingHeight);
+            return (insets != null) ? insets : new Insets(0, 0, 0, 0);
         }
 
         private int getWidth(State state) {
             if (size == null) {
                 size = getPartSize(part, state);
             }
-            return size.width;
+            return (size != null) ? size.width : 0;
         }
 
         int getWidth() {
             return getWidth((state != null) ? state : State.NORMAL);
         }
 
         private int getHeight(State state) {
             if (size == null) {
                 size = getPartSize(part, state);
             }
-            return size.height;
+            return (size != null) ? size.height : 0;
         }
 
         int getHeight() {
             return getHeight((state != null) ? state : State.NORMAL);
         }

@@ -584,10 +583,13 @@
          * @param dh  the height of the area to fill, may cause
          *                  the image to be stretched or tiled
          * @param state which state to paint
          */
         void paintSkin(Graphics g, int dx, int dy, int dw, int dh, State state) {
+            if (XPStyle.getXP() == null) {
+                return;
+            }
             if (ThemeReader.isGetThemeTransitionDurationDefined()
                   && component instanceof JComponent
                   && SwingUtilities.getAncestorOfClass(CellRendererPane.class,
                                                        component) == null) {
                 AnimationController.paintSkin((JComponent) component, this,

@@ -609,10 +611,13 @@
          * @param dh  the height of the area to fill, may cause
          *                  the image to be stretched or tiled
          * @param state which state to paint
          */
         void paintSkinRaw(Graphics g, int dx, int dy, int dw, int dh, State state) {
+            if (XPStyle.getXP() == null) {
+                return;
+            }
             skinPainter.paint(null, g, dx, dy, dw, dh, this, state);
         }
 
         /** Paint a skin at a defined position and size
          *

@@ -627,10 +632,13 @@
          * @param borderFill should test if the component uses a border fill
                             and skip painting if it is
          */
         void paintSkin(Graphics g, int dx, int dy, int dw, int dh, State state,
                 boolean borderFill) {
+            if (XPStyle.getXP() == null) {
+                return;
+            }
             if(borderFill && "borderfill".equals(getTypeEnumName(component, part,
                     state, Prop.BGTYPE))) {
                 return;
             }
             skinPainter.paint(null, g, dx, dy, dw, dh, this, state);

@@ -682,11 +690,11 @@
     static class GlyphButton extends JButton {
         private Skin skin;
 
         public GlyphButton(Component parent, Part part) {
             XPStyle xp = getXP();
-            skin = xp.getSkin(parent, part);
+            skin = xp != null ? xp.getSkin(parent, part) : null;
             setBorder(null);
             setContentAreaFilled(false);
             setMinimumSize(new Dimension(5, 5));
             setPreferredSize(new Dimension(16, 16));
             setMaximumSize(new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE));

@@ -707,17 +715,20 @@
             }
             return state;
         }
 
         public void paintComponent(Graphics g) {
+            if (XPStyle.getXP() == null || skin == null) {
+                return;
+            }
             Dimension d = getSize();
             skin.paintSkin(g, 0, 0, d.width, d.height, getState());
         }
 
         public void setPart(Component parent, Part part) {
             XPStyle xp = getXP();
-            skin = xp.getSkin(parent, part);
+            skin = xp != null ? xp.getSkin(parent, part) : null;
             revalidate();
             repaint();
         }
 
         protected void paintBorder(Graphics g) {