--- old/src/share/classes/com/sun/java/swing/plaf/windows/AnimationController.java 2014-07-10 18:18:42.148813600 +0400 +++ new/src/share/classes/com/sun/java/swing/plaf/windows/AnimationController.java 2014-07-10 18:18:41.424221600 +0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2006, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -130,11 +130,14 @@ //one second seems plausible value duration = 1000; } else { - duration = XPStyle.getXP().getThemeTransitionDuration( - c, part, - normalizeState(oldState), - normalizeState(newState), - Prop.TRANSITIONDURATIONS); + XPStyle xp = XPStyle.getXP(); + duration = (xp != null) + ? xp.getThemeTransitionDuration( + c, part, + normalizeState(oldState), + normalizeState(newState), + Prop.TRANSITIONDURATIONS) + : 1000; } controller.startAnimation(c, part, oldState, newState, duration); } --- old/src/share/classes/com/sun/java/swing/plaf/windows/WindowsComboBoxUI.java 2014-07-10 18:18:48.421110100 +0400 +++ new/src/share/classes/com/sun/java/swing/plaf/windows/WindowsComboBoxUI.java 2014-07-10 18:18:47.551499700 +0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -37,6 +37,7 @@ import static com.sun.java.swing.plaf.windows.TMSchema.Part; import static com.sun.java.swing.plaf.windows.TMSchema.State; import static com.sun.java.swing.plaf.windows.XPStyle.Skin; + import sun.swing.DefaultLookup; import sun.swing.StringUIClientPropertyKey; @@ -231,6 +232,9 @@ private void paintXPComboBoxBackground(Graphics g, JComponent c) { XPStyle xp = XPStyle.getXP(); + if (xp == null) { + return; + } State state = getXPComboBoxState(c); Skin skin = null; if (! comboBox.isEditable() @@ -400,17 +404,18 @@ * @return a button which represents the popup control */ protected JButton createArrowButton() { - if (XPStyle.getXP() != null) { - return new XPComboBoxButton(); + XPStyle xp = XPStyle.getXP(); + if (xp != null) { + return new XPComboBoxButton(xp); } else { return super.createArrowButton(); } } private class XPComboBoxButton extends XPStyle.GlyphButton { - public XPComboBoxButton() { + public XPComboBoxButton(XPStyle xp) { super(null, - (! XPStyle.getXP().isSkinDefined(comboBox, Part.CP_DROPDOWNBUTTONRIGHT)) + (! xp.isSkinDefined(comboBox, Part.CP_DROPDOWNBUTTONRIGHT)) ? Part.CP_DROPDOWNBUTTON : (comboBox.getComponentOrientation() == ComponentOrientation.RIGHT_TO_LEFT) ? Part.CP_DROPDOWNBUTTONLEFT @@ -423,10 +428,11 @@ protected State getState() { State rv; rv = super.getState(); + XPStyle xp = XPStyle.getXP(); if (rv != State.DISABLED && comboBox != null && ! comboBox.isEditable() - && XPStyle.getXP().isSkinDefined(comboBox, - Part.CP_DROPDOWNBUTTONRIGHT)) { + && xp != null && xp.isSkinDefined(comboBox, + Part.CP_DROPDOWNBUTTONRIGHT)) { /* * for non editable ComboBoxes Vista seems to have the * same glyph for all non DISABLED states --- old/src/share/classes/com/sun/java/swing/plaf/windows/WindowsGraphicsUtils.java 2014-07-10 18:18:53.182714800 +0400 +++ new/src/share/classes/com/sun/java/swing/plaf/windows/WindowsGraphicsUtils.java 2014-07-10 18:18:52.408116400 +0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2006, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -125,6 +125,9 @@ static void paintXPText(AbstractButton b, Part part, State state, Graphics g, int x, int y, String text, int mnemIndex) { XPStyle xp = XPStyle.getXP(); + if (xp == null) { + return; + } Color textColor = b.getForeground(); if (textColor instanceof UIResource) { --- old/src/share/classes/com/sun/java/swing/plaf/windows/WindowsIconFactory.java 2014-07-10 18:18:57.613277400 +0400 +++ new/src/share/classes/com/sun/java/swing/plaf/windows/WindowsIconFactory.java 2014-07-10 18:18:56.906187600 +0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2006, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -613,8 +613,8 @@ private static class MenuArrowIcon implements Icon, UIResource, Serializable { public void paintIcon(Component c, Graphics g, int x, int y) { - if (WindowsMenuItemUI.isVistaPainting()) { - XPStyle xp = XPStyle.getXP(); + XPStyle xp = XPStyle.getXP(); + if (WindowsMenuItemUI.isVistaPainting(xp)) { State state = State.NORMAL; if (c instanceof JMenuItem) { state = ((JMenuItem) c).getModel().isEnabled() @@ -647,16 +647,18 @@ } } public int getIconWidth() { - if (WindowsMenuItemUI.isVistaPainting()) { - Skin skin = XPStyle.getXP().getSkin(null, Part.MP_POPUPSUBMENU); + XPStyle xp = XPStyle.getXP(); + if (WindowsMenuItemUI.isVistaPainting(xp)) { + Skin skin = xp.getSkin(null, Part.MP_POPUPSUBMENU); return skin.getWidth(); } else { return 4; } } public int getIconHeight() { - if (WindowsMenuItemUI.isVistaPainting()) { - Skin skin = XPStyle.getXP().getSkin(null, Part.MP_POPUPSUBMENU); + XPStyle xp = XPStyle.getXP(); + if (WindowsMenuItemUI.isVistaPainting(xp)) { + Skin skin = xp.getSkin(null, Part.MP_POPUPSUBMENU); return skin.getHeight(); } else { return 8; @@ -682,7 +684,8 @@ } static int getIconWidth() { - return XPStyle.getXP().getSkin(null, Part.MP_POPUPCHECK).getWidth() + XPStyle xp = XPStyle.getXP(); + return ((xp != null) ? xp.getSkin(null, Part.MP_POPUPCHECK).getWidth() : 16) + 2 * OFFSET; } @@ -745,12 +748,17 @@ Icon icon = getIcon(); int height = 0; if (icon != null) { - height = icon.getIconHeight() + 2 * OFFSET; + height = icon.getIconHeight(); } else { - Skin skin = - XPStyle.getXP().getSkin(null, Part.MP_POPUPCHECK); - height = skin.getHeight() + 2 * OFFSET; + XPStyle xp = XPStyle.getXP(); + if (xp != null) { + Skin skin = xp.getSkin(null, Part.MP_POPUPCHECK); + height = skin.getHeight(); + } else { + height = 16; + } } + height += 2 * OFFSET; return height; } @@ -798,14 +806,16 @@ ? State.BULLETDISABLED : State.CHECKMARKDISABLED; } - Skin skin; XPStyle xp = XPStyle.getXP(); - skin = xp.getSkin(c, backgroundPart); - skin.paintSkin(g, x, y, - getIconWidth(), getIconHeight(), backgroundState); - if (icon == null) { - skin = xp.getSkin(c, part); - skin.paintSkin(g, x + OFFSET, y + OFFSET, state); + if (xp != null) { + Skin skin; + skin = xp.getSkin(c, backgroundPart); + skin.paintSkin(g, x, y, + getIconWidth(), getIconHeight(), backgroundState); + if (icon == null) { + skin = xp.getSkin(c, part); + skin.paintSkin(g, x + OFFSET, y + OFFSET, state); + } } } } --- old/src/share/classes/com/sun/java/swing/plaf/windows/WindowsInternalFrameTitlePane.java 2014-07-10 18:19:02.221862600 +0400 +++ new/src/share/classes/com/sun/java/swing/plaf/windows/WindowsInternalFrameTitlePane.java 2014-07-10 18:19:01.509772200 +0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001, 2008, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2001, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -85,14 +85,15 @@ } } else { buttonWidth += 2; - selectedTitleGradientColor = - UIManager.getColor("InternalFrame.activeTitleGradient"); - notSelectedTitleGradientColor = - UIManager.getColor("InternalFrame.inactiveTitleGradient"); Color activeBorderColor = UIManager.getColor("InternalFrame.activeBorderColor"); setBorder(BorderFactory.createLineBorder(activeBorderColor, 1)); } + // JDK-8039383: initialize these colors because getXP() may return null when theme is changed + selectedTitleGradientColor = + UIManager.getColor("InternalFrame.activeTitleGradient"); + notSelectedTitleGradientColor = + UIManager.getColor("InternalFrame.inactiveTitleGradient"); } protected void uninstallListeners() { --- old/src/share/classes/com/sun/java/swing/plaf/windows/WindowsLookAndFeel.java 2014-07-10 18:19:07.527036300 +0400 +++ new/src/share/classes/com/sun/java/swing/plaf/windows/WindowsLookAndFeel.java 2014-07-10 18:19:06.729435000 +0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -2400,8 +2400,9 @@ } public Object getXPValue(UIDefaults table) { - Border xpBorder = XPStyle.getXP().getBorder(null, (Part)xpValue); - if (extraMargin != null) { + XPStyle xp = XPStyle.getXP(); + Border xpBorder = xp != null ? xp.getBorder(null, (Part)xpValue) : null; + if (xpBorder != null && extraMargin != null) { return new BorderUIResource. CompoundBorderUIResource(xpBorder, extraMargin); } else { @@ -2417,7 +2418,8 @@ public Object getXPValue(UIDefaults table) { XPColorValueKey key = (XPColorValueKey)xpValue; - return XPStyle.getXP().getColor(key.skin, key.prop, null); + XPStyle xp = XPStyle.getXP(); + return xp != null ? xp.getColor(key.skin, key.prop, null) : null; } private static class XPColorValueKey { --- old/src/share/classes/com/sun/java/swing/plaf/windows/WindowsMenuBarUI.java 2014-07-10 18:19:13.246262500 +0400 +++ new/src/share/classes/com/sun/java/swing/plaf/windows/WindowsMenuBarUI.java 2014-07-10 18:19:12.453161800 +0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2006, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -155,8 +155,8 @@ @Override public void paint(Graphics g, JComponent c) { - if (WindowsMenuItemUI.isVistaPainting()) { - XPStyle xp = XPStyle.getXP(); + XPStyle xp = XPStyle.getXP(); + if (WindowsMenuItemUI.isVistaPainting(xp)) { Skin skin; skin = xp.getSkin(c, Part.MP_BARBACKGROUND); int width = c.getWidth(); --- old/src/share/classes/com/sun/java/swing/plaf/windows/WindowsMenuItemUI.java 2014-07-10 18:19:18.726458400 +0400 +++ new/src/share/classes/com/sun/java/swing/plaf/windows/WindowsMenuItemUI.java 2014-07-10 18:19:17.802341100 +0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2006, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -108,8 +108,9 @@ static void paintBackground(WindowsMenuItemUIAccessor menuItemUI, Graphics g, JMenuItem menuItem, Color bgColor) { - assert isVistaPainting(); - if (isVistaPainting()) { + XPStyle xp = XPStyle.getXP(); + assert isVistaPainting(xp); + if (isVistaPainting(xp)) { int menuWidth = menuItem.getWidth(); int menuHeight = menuItem.getHeight(); if (menuItem.isOpaque()) { @@ -118,7 +119,6 @@ g.fillRect(0,0, menuWidth, menuHeight); g.setColor(oldColor); } - XPStyle xp = XPStyle.getXP(); Part part = menuItemUI.getPart(menuItem); Skin skin = xp.getSkin(menuItem, part); skin.paintSkin(g, 0 , 0, @@ -170,8 +170,11 @@ * is it possible that in some theme some Vista parts are not defined while * others are? */ - static boolean isVistaPainting() { - XPStyle xp = XPStyle.getXP(); + static boolean isVistaPainting(final XPStyle xp) { return xp != null && xp.isSkinDefined(null, Part.MP_POPUPITEM); } + + static boolean isVistaPainting() { + return isVistaPainting(XPStyle.getXP()); + } } --- old/src/share/classes/com/sun/java/swing/plaf/windows/WindowsPopupMenuSeparatorUI.java 2014-07-10 18:19:24.319168600 +0400 +++ new/src/share/classes/com/sun/java/swing/plaf/windows/WindowsPopupMenuSeparatorUI.java 2014-07-10 18:19:23.443057300 +0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004, 2006, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2004, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -50,7 +50,8 @@ public void paint(Graphics g, JComponent c) { Dimension s = c.getSize(); - if (WindowsMenuItemUI.isVistaPainting()) { + XPStyle xp = XPStyle.getXP(); + if (WindowsMenuItemUI.isVistaPainting(xp)) { int x = 1; Component parent = c.getParent(); if (parent instanceof JComponent) { @@ -67,7 +68,7 @@ x += WindowsPopupMenuUI.getGutterWidth(); } } - Skin skin = XPStyle.getXP().getSkin(c, Part.MP_POPUPSEPARATOR); + Skin skin = xp.getSkin(c, Part.MP_POPUPSEPARATOR); int skinHeight = skin.getHeight(); int y = (s.height - skinHeight) / 2; skin.paintSkin(g, x, y, s.width - x - 1, skinHeight, State.NORMAL); --- old/src/share/classes/com/sun/java/swing/plaf/windows/WindowsPopupMenuUI.java 2014-07-10 18:19:30.046395900 +0400 +++ new/src/share/classes/com/sun/java/swing/plaf/windows/WindowsPopupMenuUI.java 2014-07-10 18:19:29.170284600 +0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2006, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -194,8 +194,8 @@ @Override public void paint(Graphics g, JComponent c) { - if (WindowsMenuItemUI.isVistaPainting()) { - XPStyle xp = XPStyle.getXP(); + XPStyle xp = XPStyle.getXP(); + if (WindowsMenuItemUI.isVistaPainting(xp)) { Skin skin = xp.getSkin(c, Part.MP_POPUPBACKGROUND); skin.paintSkin(g, 0, 0, c.getWidth(),c.getHeight(), State.NORMAL); int textOffset = getTextOffset(c); --- old/src/share/classes/com/sun/java/swing/plaf/windows/WindowsProgressBarUI.java 2014-07-10 18:19:35.062032800 +0400 +++ new/src/share/classes/com/sun/java/swing/plaf/windows/WindowsProgressBarUI.java 2014-07-10 18:19:34.412450300 +0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2006, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -317,8 +317,9 @@ private Rectangle getFullChunkBounds(Rectangle box) { boolean vertical = (progressBar.getOrientation() == JProgressBar.VERTICAL); XPStyle xp = XPStyle.getXP(); - int gap = xp.getInt(progressBar, Part.PP_PROGRESS, null, - Prop.PROGRESSSPACESIZE, 0); + int gap = (xp != null) ? xp.getInt(progressBar, Part.PP_PROGRESS, + null, Prop.PROGRESSSPACESIZE, 0) + : 0; if (!vertical) { int chunksize = box.width+gap; @@ -333,6 +334,9 @@ boolean vertical, int bgwidth, int bgheight) { XPStyle xp = XPStyle.getXP(); + if (xp == null) { + return; + } // create a new graphics to keep drawing surface state Graphics2D gfx = (Graphics2D)g.create(); @@ -391,6 +395,9 @@ private void paintXPBackground(Graphics g, boolean vertical, int barRectWidth, int barRectHeight) { XPStyle xp = XPStyle.getXP(); + if (xp == null) { + return; + } Part part = vertical ? Part.PP_BARVERT : Part.PP_BAR; Skin skin = xp.getSkin(progressBar, part); --- old/src/share/classes/com/sun/java/swing/plaf/windows/WindowsSliderUI.java 2014-07-10 18:19:39.352577600 +0400 +++ new/src/share/classes/com/sun/java/swing/plaf/windows/WindowsSliderUI.java 2014-07-10 18:19:38.695994200 +0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2005, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -215,7 +215,6 @@ } private Part getXPThumbPart() { - XPStyle xp = XPStyle.getXP(); Part part; boolean vertical = (slider.getOrientation() == JSlider.VERTICAL); boolean leftToRight = slider.getComponentOrientation().isLeftToRight(); --- old/src/share/classes/com/sun/java/swing/plaf/windows/WindowsSpinnerUI.java 2014-07-10 18:19:43.175063000 +0400 +++ new/src/share/classes/com/sun/java/swing/plaf/windows/WindowsSpinnerUI.java 2014-07-10 18:19:42.597989700 +0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2006, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -63,6 +63,9 @@ private void paintXPBackground(Graphics g, JComponent c) { XPStyle xp = XPStyle.getXP(); + if (xp == null) { + return; + } Skin skin = xp.getSkin(c, Part.EP_EDIT); State state = getXPState(c); skin.paintSkin(g, 0, 0, c.getWidth(), c.getHeight(), state); --- old/src/share/classes/com/sun/java/swing/plaf/windows/WindowsTableHeaderUI.java 2014-07-10 18:19:46.924539100 +0400 +++ new/src/share/classes/com/sun/java/swing/plaf/windows/WindowsTableHeaderUI.java 2014-07-10 18:19:46.270456100 +0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -90,9 +90,10 @@ this.column = column; this.hasRollover = (column == getRolloverColumn()); if (skin == null) { - skin = XPStyle.getXP().getSkin(header, Part.HP_HEADERITEM); + XPStyle xp = XPStyle.getXP(); + skin = (xp != null) ? xp.getSkin(header, Part.HP_HEADERITEM) : null; } - Insets margins = skin.getContentMargin(); + Insets margins = (skin != null) ? skin.getContentMargin() : null; Border border = null; int contentTop = 0; int contentLeft = 0; --- old/src/share/classes/com/sun/java/swing/plaf/windows/XPStyle.java 2014-07-10 18:19:50.754525500 +0400 +++ new/src/share/classes/com/sun/java/swing/plaf/windows/XPStyle.java 2014-07-10 18:19:50.181952700 +0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, 2007, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -115,7 +115,7 @@ } } } - return xp; + return ThemeReader.isXPStyleEnabled() ? xp : null; } static boolean isVista() { @@ -180,9 +180,10 @@ * 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(), - State.getValue(part, state), - prop.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 Point (e.g. a location or an offset) value @@ -199,11 +200,7 @@ 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 Insets value from the current style @@ -217,9 +214,10 @@ * 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(), - State.getValue(part, state), - prop.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); } @@ -505,16 +503,17 @@ 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() { @@ -525,7 +524,7 @@ if (size == null) { size = getPartSize(part, state); } - return size.height; + return (size != null) ? size.height : 0; } int getHeight() { @@ -582,6 +581,9 @@ * @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, @@ -607,6 +609,9 @@ * @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); } @@ -625,6 +630,9 @@ */ 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; @@ -679,7 +687,7 @@ 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)); @@ -704,13 +712,16 @@ } 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(); } --- old/src/solaris/classes/sun/awt/windows/ThemeReader.java 2014-07-10 18:19:54.598013500 +0400 +++ new/src/solaris/classes/sun/awt/windows/ThemeReader.java 2014-07-10 18:19:53.992436600 +0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004, 2006, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2004, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -41,6 +41,10 @@ return false; } + public static boolean isXPStyleEnabled() { + return false; + } + public static void paintBackground(int[] buffer, String widget, int part, int state, int x, int y, int w, int h, int stride) { } --- old/src/windows/classes/sun/awt/windows/ThemeReader.java 2014-07-10 18:19:58.267479500 +0400 +++ new/src/windows/classes/sun/awt/windows/ThemeReader.java 2014-07-10 18:19:57.635899300 +0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004, 2006, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2004, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -56,22 +56,22 @@ new ReentrantReadWriteLock(); private static final Lock readLock = readWriteLock.readLock(); private static final Lock writeLock = readWriteLock.writeLock(); + private static volatile boolean valid = false; + + static volatile boolean xpStyleEnabled; static void flush() { - writeLock.lock(); - try { - // Close old themes. - for (Long value : widgetToTheme.values()) { - closeTheme(value.longValue()); - } - widgetToTheme.clear(); - } finally { - writeLock.unlock(); - } + // Could be called on Toolkit thread, so do not try to acquire locks + // to avoid deadlock with theme initialization + valid = false; } public native static boolean isThemed(); + public static boolean isXPStyleEnabled() { + return xpStyleEnabled; + } + // this should be called only with writeLock held private static Long getThemeImpl(String widget) { Long theme = widgetToTheme.get(widget); @@ -94,6 +94,24 @@ // returns theme value // this method should be invoked with readLock locked private static Long getTheme(String widget) { + if (!valid) { + readLock.unlock(); + writeLock.lock(); + try { + if (!valid) { + // Close old themes. + for (Long value : widgetToTheme.values()) { + closeTheme(value); + } + widgetToTheme.clear(); + valid = true; + } + } finally { + readLock.lock(); + writeLock.unlock(); + } + } + // mostly copied from the javadoc for ReentrantReadWriteLock Long theme = widgetToTheme.get(widget); if (theme == null) { --- old/src/windows/classes/sun/awt/windows/WToolkit.java 2014-07-10 18:20:01.933945100 +0400 +++ new/src/windows/classes/sun/awt/windows/WToolkit.java 2014-07-10 18:20:01.325867800 +0400 @@ -36,6 +36,7 @@ import java.beans.PropertyChangeListener; import java.security.AccessController; import java.security.PrivilegedAction; +import sun.awt.AppContext; import sun.awt.AWTAutoShutdown; import sun.awt.AppContext; import sun.awt.SunToolkit; @@ -70,6 +71,9 @@ private static final PlatformLogger log = PlatformLogger.getLogger("sun.awt.windows.WToolkit"); + // Desktop property which specifies whether XP visual styles are in effect + public static final String XPSTYLE_THEME_ACTIVE = "win.xpstyle.themeActive"; + static GraphicsConfiguration config; // System clipboard. @@ -829,7 +833,7 @@ private synchronized void lazilyInitWProps() { if (wprops == null) { wprops = new WDesktopProperties(this); - updateProperties(); + updateProperties(wprops.getProperties()); } } @@ -864,21 +868,41 @@ * Windows doesn't always send WM_SETTINGCHANGE when it should. */ private void windowsSettingChange() { - EventQueue.invokeLater(new Runnable() { - @Override - public void run() { - updateProperties(); - } - }); + // JDK-8039383: Have to update the value of XPSTYLE_THEME_ACTIVE property + // as soon as possible to prevent NPE and other errors because theme data + // has become unavailable. + final Map props = getWProps(); + if (props == null) { + // props has not been initialized, so we have nothing to update + return; + } + + updateXPStyleEnabled(props.get(XPSTYLE_THEME_ACTIVE)); + + if (AppContext.getAppContext() == null) { + // We cannot post the update to any EventQueue. Listeners will + // be called on EDTs by DesktopPropertyChangeSupport + updateProperties(props); + } else { + // Cannot update on Toolkit thread. + // DesktopPropertyChangeSupport will call listeners on Toolkit + // thread if it has AppContext (standalone mode) + EventQueue.invokeLater(new Runnable() { + @Override + public void run() { + updateProperties(props); + } + }); + } } - private synchronized void updateProperties() { - if (null == wprops) { - // wprops has not been initialized, so we have nothing to update + private synchronized void updateProperties(final Map props) { + if (null == props) { return; } - Map props = wprops.getProperties(); + updateXPStyleEnabled(props.get(XPSTYLE_THEME_ACTIVE)); + for (String propName : props.keySet()) { Object val = props.get(propName); if (log.isLoggable(PlatformLogger.FINER)) { @@ -1007,6 +1031,14 @@ private native synchronized int getNumberOfButtonsImpl(); + private synchronized Map getWProps() { + return (wprops != null) ? wprops.getProperties() : null; + } + + private void updateXPStyleEnabled(final Object dskProp) { + ThemeReader.xpStyleEnabled = Boolean.TRUE.equals(dskProp); + } + @Override public int getNumberOfButtons(){ if (numberOfButtons == 0) { --- /dev/null 2014-07-10 18:20:05.000000000 +0400 +++ new/test/javax/swing/JFileChooser/8046391/bug8046391.java 2014-07-10 18:20:05.000834500 +0400 @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 8046391 + * @summary JFileChooser hangs if displayed in Windows L&F + * @author Alexey Ivanov + * @run main/othervm/timeout=10 bug8046391 +*/ + +import com.sun.java.swing.plaf.windows.WindowsLookAndFeel; +import sun.awt.OSInfo; +import sun.awt.OSInfo.OSType; + +import javax.swing.JFileChooser; +import javax.swing.SwingUtilities; +import javax.swing.UIManager; +import javax.swing.UnsupportedLookAndFeelException; + +public class bug8046391 { + + public static void main(String[] args) throws Exception { + OSType type = OSInfo.getOSType(); + if (type != OSType.WINDOWS) { + System.out.println("This test is for Windows only... skipping!"); + return; + } + + SwingUtilities.invokeAndWait(() -> { + try { + UIManager.setLookAndFeel(new WindowsLookAndFeel()); + } catch (UnsupportedLookAndFeelException e) { + e.printStackTrace(); + } + System.out.println("Creating JFileChooser..."); + JFileChooser fileChooser = new JFileChooser(); + System.out.println("Test passed: chooser = " + fileChooser); + }); + // Test fails if creating JFileChooser hangs + } + +}