提交 cb477d31 编写于 作者: A aivanov

8046559: NPE when changing Windows theme

Reviewed-by: pchelko, anthony
上级 f698cb32
/* /*
* 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -130,11 +130,14 @@ class AnimationController implements ActionListener, PropertyChangeListener { ...@@ -130,11 +130,14 @@ class AnimationController implements ActionListener, PropertyChangeListener {
//one second seems plausible value //one second seems plausible value
duration = 1000; duration = 1000;
} else { } else {
duration = XPStyle.getXP().getThemeTransitionDuration( XPStyle xp = XPStyle.getXP();
c, part, duration = (xp != null)
normalizeState(oldState), ? xp.getThemeTransitionDuration(
normalizeState(newState), c, part,
Prop.TRANSITIONDURATIONS); normalizeState(oldState),
normalizeState(newState),
Prop.TRANSITIONDURATIONS)
: 1000;
} }
controller.startAnimation(c, part, oldState, newState, duration); controller.startAnimation(c, part, oldState, newState, duration);
} }
......
/* /*
* Copyright (c) 1997, 2013, 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -37,6 +37,7 @@ import java.awt.*; ...@@ -37,6 +37,7 @@ import java.awt.*;
import static com.sun.java.swing.plaf.windows.TMSchema.Part; 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.TMSchema.State;
import static com.sun.java.swing.plaf.windows.XPStyle.Skin; import static com.sun.java.swing.plaf.windows.XPStyle.Skin;
import sun.swing.DefaultLookup; import sun.swing.DefaultLookup;
import sun.swing.StringUIClientPropertyKey; import sun.swing.StringUIClientPropertyKey;
...@@ -231,6 +232,9 @@ public class WindowsComboBoxUI extends BasicComboBoxUI { ...@@ -231,6 +232,9 @@ public class WindowsComboBoxUI extends BasicComboBoxUI {
private void paintXPComboBoxBackground(Graphics g, JComponent c) { private void paintXPComboBoxBackground(Graphics g, JComponent c) {
XPStyle xp = XPStyle.getXP(); XPStyle xp = XPStyle.getXP();
if (xp == null) {
return;
}
State state = getXPComboBoxState(c); State state = getXPComboBoxState(c);
Skin skin = null; Skin skin = null;
if (! comboBox.isEditable() if (! comboBox.isEditable()
...@@ -400,17 +404,18 @@ public class WindowsComboBoxUI extends BasicComboBoxUI { ...@@ -400,17 +404,18 @@ public class WindowsComboBoxUI extends BasicComboBoxUI {
* @return a button which represents the popup control * @return a button which represents the popup control
*/ */
protected JButton createArrowButton() { protected JButton createArrowButton() {
if (XPStyle.getXP() != null) { XPStyle xp = XPStyle.getXP();
return new XPComboBoxButton(); if (xp != null) {
return new XPComboBoxButton(xp);
} else { } else {
return super.createArrowButton(); return super.createArrowButton();
} }
} }
private class XPComboBoxButton extends XPStyle.GlyphButton { private class XPComboBoxButton extends XPStyle.GlyphButton {
public XPComboBoxButton() { public XPComboBoxButton(XPStyle xp) {
super(null, super(null,
(! XPStyle.getXP().isSkinDefined(comboBox, Part.CP_DROPDOWNBUTTONRIGHT)) (! xp.isSkinDefined(comboBox, Part.CP_DROPDOWNBUTTONRIGHT))
? Part.CP_DROPDOWNBUTTON ? Part.CP_DROPDOWNBUTTON
: (comboBox.getComponentOrientation() == ComponentOrientation.RIGHT_TO_LEFT) : (comboBox.getComponentOrientation() == ComponentOrientation.RIGHT_TO_LEFT)
? Part.CP_DROPDOWNBUTTONLEFT ? Part.CP_DROPDOWNBUTTONLEFT
...@@ -423,10 +428,11 @@ public class WindowsComboBoxUI extends BasicComboBoxUI { ...@@ -423,10 +428,11 @@ public class WindowsComboBoxUI extends BasicComboBoxUI {
protected State getState() { protected State getState() {
State rv; State rv;
rv = super.getState(); rv = super.getState();
XPStyle xp = XPStyle.getXP();
if (rv != State.DISABLED if (rv != State.DISABLED
&& comboBox != null && ! comboBox.isEditable() && comboBox != null && ! comboBox.isEditable()
&& XPStyle.getXP().isSkinDefined(comboBox, && xp != null && xp.isSkinDefined(comboBox,
Part.CP_DROPDOWNBUTTONRIGHT)) { Part.CP_DROPDOWNBUTTONRIGHT)) {
/* /*
* for non editable ComboBoxes Vista seems to have the * for non editable ComboBoxes Vista seems to have the
* same glyph for all non DISABLED states * same glyph for all non DISABLED states
......
/* /*
* Copyright (c) 2000, 2013, 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -125,6 +125,9 @@ public class WindowsGraphicsUtils { ...@@ -125,6 +125,9 @@ public class WindowsGraphicsUtils {
static void paintXPText(AbstractButton b, Part part, State state, static void paintXPText(AbstractButton b, Part part, State state,
Graphics g, int x, int y, String text, int mnemIndex) { Graphics g, int x, int y, String text, int mnemIndex) {
XPStyle xp = XPStyle.getXP(); XPStyle xp = XPStyle.getXP();
if (xp == null) {
return;
}
Color textColor = b.getForeground(); Color textColor = b.getForeground();
if (textColor instanceof UIResource) { if (textColor instanceof UIResource) {
......
...@@ -613,8 +613,8 @@ public class WindowsIconFactory implements Serializable ...@@ -613,8 +613,8 @@ public class WindowsIconFactory implements Serializable
private static class MenuArrowIcon implements Icon, UIResource, Serializable { private static class MenuArrowIcon implements Icon, UIResource, Serializable {
public void paintIcon(Component c, Graphics g, int x, int y) { 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; State state = State.NORMAL;
if (c instanceof JMenuItem) { if (c instanceof JMenuItem) {
state = ((JMenuItem) c).getModel().isEnabled() state = ((JMenuItem) c).getModel().isEnabled()
...@@ -647,16 +647,18 @@ public class WindowsIconFactory implements Serializable ...@@ -647,16 +647,18 @@ public class WindowsIconFactory implements Serializable
} }
} }
public int getIconWidth() { public int getIconWidth() {
if (WindowsMenuItemUI.isVistaPainting()) { XPStyle xp = XPStyle.getXP();
Skin skin = XPStyle.getXP().getSkin(null, Part.MP_POPUPSUBMENU); if (WindowsMenuItemUI.isVistaPainting(xp)) {
Skin skin = xp.getSkin(null, Part.MP_POPUPSUBMENU);
return skin.getWidth(); return skin.getWidth();
} else { } else {
return 4; return 4;
} }
} }
public int getIconHeight() { public int getIconHeight() {
if (WindowsMenuItemUI.isVistaPainting()) { XPStyle xp = XPStyle.getXP();
Skin skin = XPStyle.getXP().getSkin(null, Part.MP_POPUPSUBMENU); if (WindowsMenuItemUI.isVistaPainting(xp)) {
Skin skin = xp.getSkin(null, Part.MP_POPUPSUBMENU);
return skin.getHeight(); return skin.getHeight();
} else { } else {
return 8; return 8;
...@@ -682,7 +684,8 @@ public class WindowsIconFactory implements Serializable ...@@ -682,7 +684,8 @@ public class WindowsIconFactory implements Serializable
} }
static int getIconWidth() { 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; + 2 * OFFSET;
} }
...@@ -745,12 +748,17 @@ public class WindowsIconFactory implements Serializable ...@@ -745,12 +748,17 @@ public class WindowsIconFactory implements Serializable
Icon icon = getIcon(); Icon icon = getIcon();
int height = 0; int height = 0;
if (icon != null) { if (icon != null) {
height = icon.getIconHeight() + 2 * OFFSET; height = icon.getIconHeight();
} else { } else {
Skin skin = XPStyle xp = XPStyle.getXP();
XPStyle.getXP().getSkin(null, Part.MP_POPUPCHECK); if (xp != null) {
height = skin.getHeight() + 2 * OFFSET; Skin skin = xp.getSkin(null, Part.MP_POPUPCHECK);
height = skin.getHeight();
} else {
height = 16;
}
} }
height += 2 * OFFSET;
return height; return height;
} }
...@@ -798,14 +806,16 @@ public class WindowsIconFactory implements Serializable ...@@ -798,14 +806,16 @@ public class WindowsIconFactory implements Serializable
? State.BULLETDISABLED ? State.BULLETDISABLED
: State.CHECKMARKDISABLED; : State.CHECKMARKDISABLED;
} }
Skin skin;
XPStyle xp = XPStyle.getXP(); XPStyle xp = XPStyle.getXP();
skin = xp.getSkin(c, backgroundPart); if (xp != null) {
skin.paintSkin(g, x, y, Skin skin;
getIconWidth(), getIconHeight(), backgroundState); skin = xp.getSkin(c, backgroundPart);
if (icon == null) { skin.paintSkin(g, x, y,
skin = xp.getSkin(c, part); getIconWidth(), getIconHeight(), backgroundState);
skin.paintSkin(g, x + OFFSET, y + OFFSET, state); if (icon == null) {
skin = xp.getSkin(c, part);
skin.paintSkin(g, x + OFFSET, y + OFFSET, state);
}
} }
} }
} }
......
/* /*
* Copyright (c) 2001, 2013, 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -85,14 +85,15 @@ public class WindowsInternalFrameTitlePane extends BasicInternalFrameTitlePane { ...@@ -85,14 +85,15 @@ public class WindowsInternalFrameTitlePane extends BasicInternalFrameTitlePane {
} }
} else { } else {
buttonWidth += 2; buttonWidth += 2;
selectedTitleGradientColor =
UIManager.getColor("InternalFrame.activeTitleGradient");
notSelectedTitleGradientColor =
UIManager.getColor("InternalFrame.inactiveTitleGradient");
Color activeBorderColor = Color activeBorderColor =
UIManager.getColor("InternalFrame.activeBorderColor"); UIManager.getColor("InternalFrame.activeBorderColor");
setBorder(BorderFactory.createLineBorder(activeBorderColor, 1)); 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() { protected void uninstallListeners() {
......
...@@ -2399,8 +2399,9 @@ public class WindowsLookAndFeel extends BasicLookAndFeel ...@@ -2399,8 +2399,9 @@ public class WindowsLookAndFeel extends BasicLookAndFeel
} }
public Object getXPValue(UIDefaults table) { public Object getXPValue(UIDefaults table) {
Border xpBorder = XPStyle.getXP().getBorder(null, (Part)xpValue); XPStyle xp = XPStyle.getXP();
if (extraMargin != null) { Border xpBorder = xp != null ? xp.getBorder(null, (Part)xpValue) : null;
if (xpBorder != null && extraMargin != null) {
return new BorderUIResource. return new BorderUIResource.
CompoundBorderUIResource(xpBorder, extraMargin); CompoundBorderUIResource(xpBorder, extraMargin);
} else { } else {
...@@ -2416,7 +2417,8 @@ public class WindowsLookAndFeel extends BasicLookAndFeel ...@@ -2416,7 +2417,8 @@ public class WindowsLookAndFeel extends BasicLookAndFeel
public Object getXPValue(UIDefaults table) { public Object getXPValue(UIDefaults table) {
XPColorValueKey key = (XPColorValueKey)xpValue; 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 { private static class XPColorValueKey {
......
...@@ -155,8 +155,8 @@ public class WindowsMenuBarUI extends BasicMenuBarUI ...@@ -155,8 +155,8 @@ public class WindowsMenuBarUI extends BasicMenuBarUI
@Override @Override
public void paint(Graphics g, JComponent c) { 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 skin;
skin = xp.getSkin(c, Part.MP_BARBACKGROUND); skin = xp.getSkin(c, Part.MP_BARBACKGROUND);
int width = c.getWidth(); int width = c.getWidth();
......
/* /*
* 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -108,8 +108,9 @@ public class WindowsMenuItemUI extends BasicMenuItemUI { ...@@ -108,8 +108,9 @@ public class WindowsMenuItemUI extends BasicMenuItemUI {
static void paintBackground(WindowsMenuItemUIAccessor menuItemUI, static void paintBackground(WindowsMenuItemUIAccessor menuItemUI,
Graphics g, JMenuItem menuItem, Color bgColor) { Graphics g, JMenuItem menuItem, Color bgColor) {
assert isVistaPainting(); XPStyle xp = XPStyle.getXP();
if (isVistaPainting()) { assert isVistaPainting(xp);
if (isVistaPainting(xp)) {
int menuWidth = menuItem.getWidth(); int menuWidth = menuItem.getWidth();
int menuHeight = menuItem.getHeight(); int menuHeight = menuItem.getHeight();
if (menuItem.isOpaque()) { if (menuItem.isOpaque()) {
...@@ -118,7 +119,6 @@ public class WindowsMenuItemUI extends BasicMenuItemUI { ...@@ -118,7 +119,6 @@ public class WindowsMenuItemUI extends BasicMenuItemUI {
g.fillRect(0,0, menuWidth, menuHeight); g.fillRect(0,0, menuWidth, menuHeight);
g.setColor(oldColor); g.setColor(oldColor);
} }
XPStyle xp = XPStyle.getXP();
Part part = menuItemUI.getPart(menuItem); Part part = menuItemUI.getPart(menuItem);
Skin skin = xp.getSkin(menuItem, part); Skin skin = xp.getSkin(menuItem, part);
skin.paintSkin(g, 0 , 0, skin.paintSkin(g, 0 , 0,
...@@ -170,8 +170,11 @@ public class WindowsMenuItemUI extends BasicMenuItemUI { ...@@ -170,8 +170,11 @@ public class WindowsMenuItemUI extends BasicMenuItemUI {
* is it possible that in some theme some Vista parts are not defined while * is it possible that in some theme some Vista parts are not defined while
* others are? * others are?
*/ */
static boolean isVistaPainting() { static boolean isVistaPainting(final XPStyle xp) {
XPStyle xp = XPStyle.getXP();
return xp != null && xp.isSkinDefined(null, Part.MP_POPUPITEM); return xp != null && xp.isSkinDefined(null, Part.MP_POPUPITEM);
} }
static boolean isVistaPainting() {
return isVistaPainting(XPStyle.getXP());
}
} }
/* /*
* 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -50,7 +50,8 @@ public class WindowsPopupMenuSeparatorUI extends BasicPopupMenuSeparatorUI { ...@@ -50,7 +50,8 @@ public class WindowsPopupMenuSeparatorUI extends BasicPopupMenuSeparatorUI {
public void paint(Graphics g, JComponent c) { public void paint(Graphics g, JComponent c) {
Dimension s = c.getSize(); Dimension s = c.getSize();
if (WindowsMenuItemUI.isVistaPainting()) { XPStyle xp = XPStyle.getXP();
if (WindowsMenuItemUI.isVistaPainting(xp)) {
int x = 1; int x = 1;
Component parent = c.getParent(); Component parent = c.getParent();
if (parent instanceof JComponent) { if (parent instanceof JComponent) {
...@@ -67,7 +68,7 @@ public class WindowsPopupMenuSeparatorUI extends BasicPopupMenuSeparatorUI { ...@@ -67,7 +68,7 @@ public class WindowsPopupMenuSeparatorUI extends BasicPopupMenuSeparatorUI {
x += WindowsPopupMenuUI.getGutterWidth(); 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 skinHeight = skin.getHeight();
int y = (s.height - skinHeight) / 2; int y = (s.height - skinHeight) / 2;
skin.paintSkin(g, x, y, s.width - x - 1, skinHeight, State.NORMAL); skin.paintSkin(g, x, y, s.width - x - 1, skinHeight, State.NORMAL);
......
/* /*
* 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -194,8 +194,8 @@ public class WindowsPopupMenuUI extends BasicPopupMenuUI { ...@@ -194,8 +194,8 @@ public class WindowsPopupMenuUI extends BasicPopupMenuUI {
@Override @Override
public void paint(Graphics g, JComponent c) { 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 skin = xp.getSkin(c, Part.MP_POPUPBACKGROUND);
skin.paintSkin(g, 0, 0, c.getWidth(),c.getHeight(), State.NORMAL); skin.paintSkin(g, 0, 0, c.getWidth(),c.getHeight(), State.NORMAL);
int textOffset = getTextOffset(c); int textOffset = getTextOffset(c);
......
/* /*
* 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -322,8 +322,9 @@ public class WindowsProgressBarUI extends BasicProgressBarUI ...@@ -322,8 +322,9 @@ public class WindowsProgressBarUI extends BasicProgressBarUI
private Rectangle getFullChunkBounds(Rectangle box) { private Rectangle getFullChunkBounds(Rectangle box) {
boolean vertical = (progressBar.getOrientation() == JProgressBar.VERTICAL); boolean vertical = (progressBar.getOrientation() == JProgressBar.VERTICAL);
XPStyle xp = XPStyle.getXP(); XPStyle xp = XPStyle.getXP();
int gap = xp.getInt(progressBar, Part.PP_PROGRESS, null, int gap = (xp != null) ? xp.getInt(progressBar, Part.PP_PROGRESS,
Prop.PROGRESSSPACESIZE, 0); null, Prop.PROGRESSSPACESIZE, 0)
: 0;
if (!vertical) { if (!vertical) {
int chunksize = box.width+gap; int chunksize = box.width+gap;
...@@ -338,6 +339,9 @@ public class WindowsProgressBarUI extends BasicProgressBarUI ...@@ -338,6 +339,9 @@ public class WindowsProgressBarUI extends BasicProgressBarUI
boolean vertical, boolean vertical,
int bgwidth, int bgheight) { int bgwidth, int bgheight) {
XPStyle xp = XPStyle.getXP(); XPStyle xp = XPStyle.getXP();
if (xp == null) {
return;
}
// create a new graphics to keep drawing surface state // create a new graphics to keep drawing surface state
Graphics2D gfx = (Graphics2D)g.create(); Graphics2D gfx = (Graphics2D)g.create();
...@@ -396,6 +400,9 @@ public class WindowsProgressBarUI extends BasicProgressBarUI ...@@ -396,6 +400,9 @@ public class WindowsProgressBarUI extends BasicProgressBarUI
private void paintXPBackground(Graphics g, boolean vertical, private void paintXPBackground(Graphics g, boolean vertical,
int barRectWidth, int barRectHeight) { int barRectWidth, int barRectHeight) {
XPStyle xp = XPStyle.getXP(); XPStyle xp = XPStyle.getXP();
if (xp == null) {
return;
}
Part part = vertical ? Part.PP_BARVERT : Part.PP_BAR; Part part = vertical ? Part.PP_BARVERT : Part.PP_BAR;
Skin skin = xp.getSkin(progressBar, part); Skin skin = xp.getSkin(progressBar, part);
......
/* /*
* 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -215,7 +215,6 @@ public class WindowsSliderUI extends BasicSliderUI ...@@ -215,7 +215,6 @@ public class WindowsSliderUI extends BasicSliderUI
} }
private Part getXPThumbPart() { private Part getXPThumbPart() {
XPStyle xp = XPStyle.getXP();
Part part; Part part;
boolean vertical = (slider.getOrientation() == JSlider.VERTICAL); boolean vertical = (slider.getOrientation() == JSlider.VERTICAL);
boolean leftToRight = slider.getComponentOrientation().isLeftToRight(); boolean leftToRight = slider.getComponentOrientation().isLeftToRight();
......
/* /*
* 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -63,6 +63,9 @@ public class WindowsSpinnerUI extends BasicSpinnerUI { ...@@ -63,6 +63,9 @@ public class WindowsSpinnerUI extends BasicSpinnerUI {
private void paintXPBackground(Graphics g, JComponent c) { private void paintXPBackground(Graphics g, JComponent c) {
XPStyle xp = XPStyle.getXP(); XPStyle xp = XPStyle.getXP();
if (xp == null) {
return;
}
Skin skin = xp.getSkin(c, Part.EP_EDIT); Skin skin = xp.getSkin(c, Part.EP_EDIT);
State state = getXPState(c); State state = getXPState(c);
skin.paintSkin(g, 0, 0, c.getWidth(), c.getHeight(), state); skin.paintSkin(g, 0, 0, c.getWidth(), c.getHeight(), state);
......
...@@ -90,9 +90,10 @@ public class WindowsTableHeaderUI extends BasicTableHeaderUI { ...@@ -90,9 +90,10 @@ public class WindowsTableHeaderUI extends BasicTableHeaderUI {
this.column = column; this.column = column;
this.hasRollover = (column == getRolloverColumn()); this.hasRollover = (column == getRolloverColumn());
if (skin == null) { 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; Border border = null;
int contentTop = 0; int contentTop = 0;
int contentLeft = 0; int contentLeft = 0;
......
...@@ -115,7 +115,7 @@ class XPStyle { ...@@ -115,7 +115,7 @@ class XPStyle {
} }
} }
} }
return xp; return ThemeReader.isXPStyleEnabled() ? xp : null;
} }
static boolean isVista() { static boolean isVista() {
...@@ -180,9 +180,10 @@ class XPStyle { ...@@ -180,9 +180,10 @@ class XPStyle {
* should probably be cached there instead of here. * should probably be cached there instead of here.
*/ */
Dimension getDimension(Component c, Part part, State state, Prop prop) { 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), State.getValue(part, state),
prop.getValue()); prop.getValue());
return (d != null) ? d : new Dimension();
} }
/** Get a named <code>Point</code> (e.g. a location or an offset) value /** Get a named <code>Point</code> (e.g. a location or an offset) value
...@@ -199,11 +200,7 @@ class XPStyle { ...@@ -199,11 +200,7 @@ class XPStyle {
Dimension d = ThemeReader.getPosition(part.getControlName(c), part.getValue(), Dimension d = ThemeReader.getPosition(part.getControlName(c), part.getValue(),
State.getValue(part, state), State.getValue(part, state),
prop.getValue()); prop.getValue());
if (d != null) { return (d != null) ? new Point(d.width, d.height) : new Point();
return new Point(d.width, d.height);
} else {
return null;
}
} }
/** Get a named <code>Insets</code> value from the current style /** Get a named <code>Insets</code> value from the current style
...@@ -217,9 +214,10 @@ class XPStyle { ...@@ -217,9 +214,10 @@ class XPStyle {
* The return value is already cached in those places. * The return value is already cached in those places.
*/ */
Insets getMargin(Component c, Part part, State state, Prop prop) { 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), State.getValue(part, state),
prop.getValue()); prop.getValue());
return (insets != null) ? insets : new Insets(0, 0, 0, 0);
} }
...@@ -505,16 +503,17 @@ class XPStyle { ...@@ -505,16 +503,17 @@ class XPStyle {
int boundingWidth = 100; int boundingWidth = 100;
int boundingHeight = 100; int boundingHeight = 100;
return ThemeReader.getThemeBackgroundContentMargins( Insets insets = ThemeReader.getThemeBackgroundContentMargins(
part.getControlName(null), part.getValue(), part.getControlName(null), part.getValue(),
0, boundingWidth, boundingHeight); 0, boundingWidth, boundingHeight);
return (insets != null) ? insets : new Insets(0, 0, 0, 0);
} }
private int getWidth(State state) { private int getWidth(State state) {
if (size == null) { if (size == null) {
size = getPartSize(part, state); size = getPartSize(part, state);
} }
return size.width; return (size != null) ? size.width : 0;
} }
int getWidth() { int getWidth() {
...@@ -525,7 +524,7 @@ class XPStyle { ...@@ -525,7 +524,7 @@ class XPStyle {
if (size == null) { if (size == null) {
size = getPartSize(part, state); size = getPartSize(part, state);
} }
return size.height; return (size != null) ? size.height : 0;
} }
int getHeight() { int getHeight() {
...@@ -582,6 +581,9 @@ class XPStyle { ...@@ -582,6 +581,9 @@ class XPStyle {
* @param state which state to paint * @param state which state to paint
*/ */
void paintSkin(Graphics g, int dx, int dy, int dw, int dh, State state) { void paintSkin(Graphics g, int dx, int dy, int dw, int dh, State state) {
if (XPStyle.getXP() == null) {
return;
}
if (ThemeReader.isGetThemeTransitionDurationDefined() if (ThemeReader.isGetThemeTransitionDurationDefined()
&& component instanceof JComponent && component instanceof JComponent
&& SwingUtilities.getAncestorOfClass(CellRendererPane.class, && SwingUtilities.getAncestorOfClass(CellRendererPane.class,
...@@ -607,6 +609,9 @@ class XPStyle { ...@@ -607,6 +609,9 @@ class XPStyle {
* @param state which state to paint * @param state which state to paint
*/ */
void paintSkinRaw(Graphics g, int dx, int dy, int dw, int dh, State state) { 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); skinPainter.paint(null, g, dx, dy, dw, dh, this, state);
} }
...@@ -625,6 +630,9 @@ class XPStyle { ...@@ -625,6 +630,9 @@ class XPStyle {
*/ */
void paintSkin(Graphics g, int dx, int dy, int dw, int dh, State state, void paintSkin(Graphics g, int dx, int dy, int dw, int dh, State state,
boolean borderFill) { boolean borderFill) {
if (XPStyle.getXP() == null) {
return;
}
if(borderFill && "borderfill".equals(getTypeEnumName(component, part, if(borderFill && "borderfill".equals(getTypeEnumName(component, part,
state, Prop.BGTYPE))) { state, Prop.BGTYPE))) {
return; return;
...@@ -679,7 +687,7 @@ class XPStyle { ...@@ -679,7 +687,7 @@ class XPStyle {
public GlyphButton(Component parent, Part part) { public GlyphButton(Component parent, Part part) {
XPStyle xp = getXP(); XPStyle xp = getXP();
skin = xp.getSkin(parent, part); skin = xp != null ? xp.getSkin(parent, part) : null;
setBorder(null); setBorder(null);
setContentAreaFilled(false); setContentAreaFilled(false);
setMinimumSize(new Dimension(5, 5)); setMinimumSize(new Dimension(5, 5));
...@@ -704,13 +712,16 @@ class XPStyle { ...@@ -704,13 +712,16 @@ class XPStyle {
} }
public void paintComponent(Graphics g) { public void paintComponent(Graphics g) {
if (XPStyle.getXP() == null || skin == null) {
return;
}
Dimension d = getSize(); Dimension d = getSize();
skin.paintSkin(g, 0, 0, d.width, d.height, getState()); skin.paintSkin(g, 0, 0, d.width, d.height, getState());
} }
public void setPart(Component parent, Part part) { public void setPart(Component parent, Part part) {
XPStyle xp = getXP(); XPStyle xp = getXP();
skin = xp.getSkin(parent, part); skin = xp != null ? xp.getSkin(parent, part) : null;
revalidate(); revalidate();
repaint(); repaint();
} }
......
...@@ -45,6 +45,10 @@ public final class ThemeReader { ...@@ -45,6 +45,10 @@ public final class ThemeReader {
return false; return false;
} }
public static boolean isXPStyleEnabled() {
return false;
}
public static void paintBackground(int[] buffer, String widget, public static void paintBackground(int[] buffer, String widget,
int part, int state, int x, int y, int w, int h, int stride) { int part, int state, int x, int y, int w, int h, int stride) {
} }
......
...@@ -60,22 +60,22 @@ public final class ThemeReader { ...@@ -60,22 +60,22 @@ public final class ThemeReader {
new ReentrantReadWriteLock(); new ReentrantReadWriteLock();
private static final Lock readLock = readWriteLock.readLock(); private static final Lock readLock = readWriteLock.readLock();
private static final Lock writeLock = readWriteLock.writeLock(); private static final Lock writeLock = readWriteLock.writeLock();
private static volatile boolean valid = false;
static volatile boolean xpStyleEnabled;
static void flush() { static void flush() {
writeLock.lock(); // Could be called on Toolkit thread, so do not try to acquire locks
try { // to avoid deadlock with theme initialization
// Close old themes. valid = false;
for (Long value : widgetToTheme.values()) {
closeTheme(value.longValue());
}
widgetToTheme.clear();
} finally {
writeLock.unlock();
}
} }
public static native boolean isThemed(); public static native boolean isThemed();
public static boolean isXPStyleEnabled() {
return xpStyleEnabled;
}
// this should be called only with writeLock held // this should be called only with writeLock held
private static Long getThemeImpl(String widget) { private static Long getThemeImpl(String widget) {
Long theme = widgetToTheme.get(widget); Long theme = widgetToTheme.get(widget);
...@@ -98,6 +98,24 @@ public final class ThemeReader { ...@@ -98,6 +98,24 @@ public final class ThemeReader {
// returns theme value // returns theme value
// this method should be invoked with readLock locked // this method should be invoked with readLock locked
private static Long getTheme(String widget) { 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 // mostly copied from the javadoc for ReentrantReadWriteLock
Long theme = widgetToTheme.get(widget); Long theme = widgetToTheme.get(widget);
if (theme == null) { if (theme == null) {
......
...@@ -36,6 +36,7 @@ import java.awt.TrayIcon; ...@@ -36,6 +36,7 @@ import java.awt.TrayIcon;
import java.beans.PropertyChangeListener; import java.beans.PropertyChangeListener;
import java.security.AccessController; import java.security.AccessController;
import java.security.PrivilegedAction; import java.security.PrivilegedAction;
import sun.awt.AppContext;
import sun.awt.AWTAutoShutdown; import sun.awt.AWTAutoShutdown;
import sun.awt.LightweightFrame; import sun.awt.LightweightFrame;
import sun.awt.SunToolkit; import sun.awt.SunToolkit;
...@@ -72,6 +73,9 @@ public final class WToolkit extends SunToolkit implements Runnable { ...@@ -72,6 +73,9 @@ public final class WToolkit extends SunToolkit implements Runnable {
private static final PlatformLogger log = PlatformLogger.getLogger("sun.awt.windows.WToolkit"); 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; static GraphicsConfiguration config;
// System clipboard. // System clipboard.
...@@ -894,7 +898,7 @@ public final class WToolkit extends SunToolkit implements Runnable { ...@@ -894,7 +898,7 @@ public final class WToolkit extends SunToolkit implements Runnable {
private synchronized void lazilyInitWProps() { private synchronized void lazilyInitWProps() {
if (wprops == null) { if (wprops == null) {
wprops = new WDesktopProperties(this); wprops = new WDesktopProperties(this);
updateProperties(); updateProperties(wprops.getProperties());
} }
} }
...@@ -929,21 +933,36 @@ public final class WToolkit extends SunToolkit implements Runnable { ...@@ -929,21 +933,36 @@ public final class WToolkit extends SunToolkit implements Runnable {
* Windows doesn't always send WM_SETTINGCHANGE when it should. * Windows doesn't always send WM_SETTINGCHANGE when it should.
*/ */
private void windowsSettingChange() { private void windowsSettingChange() {
EventQueue.invokeLater(new Runnable() { // JDK-8039383: Have to update the value of XPSTYLE_THEME_ACTIVE property
@Override // as soon as possible to prevent NPE and other errors because theme data
public void run() { // has become unavailable.
updateProperties(); final Map<String, Object> 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(() -> updateProperties(props));
}
} }
private synchronized void updateProperties() { private synchronized void updateProperties(final Map<String, Object> props) {
if (null == wprops) { if (null == props) {
// wprops has not been initialized, so we have nothing to update
return; return;
} }
Map<String, Object> props = wprops.getProperties(); updateXPStyleEnabled(props.get(XPSTYLE_THEME_ACTIVE));
for (String propName : props.keySet()) { for (String propName : props.keySet()) {
Object val = props.get(propName); Object val = props.get(propName);
if (log.isLoggable(PlatformLogger.Level.FINER)) { if (log.isLoggable(PlatformLogger.Level.FINER)) {
...@@ -953,6 +972,14 @@ public final class WToolkit extends SunToolkit implements Runnable { ...@@ -953,6 +972,14 @@ public final class WToolkit extends SunToolkit implements Runnable {
} }
} }
private synchronized Map<String, Object> getWProps() {
return (wprops != null) ? wprops.getProperties() : null;
}
private void updateXPStyleEnabled(final Object dskProp) {
ThemeReader.xpStyleEnabled = Boolean.TRUE.equals(dskProp);
}
@Override @Override
public synchronized void addPropertyChangeListener(String name, PropertyChangeListener pcl) { public synchronized void addPropertyChangeListener(String name, PropertyChangeListener pcl) {
if (name == null) { if (name == null) {
......
/*
* 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
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册