8039383: NPE when changing Windows theme
Reviewed-by: pchelko, anthony
This commit is contained in:
parent
52233220f2
commit
b3090f044e
@ -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 @@ class AnimationController implements ActionListener, PropertyChangeListener {
|
||||
//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);
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -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.State;
|
||||
import static com.sun.java.swing.plaf.windows.XPStyle.Skin;
|
||||
|
||||
import sun.swing.DefaultLookup;
|
||||
import sun.swing.StringUIClientPropertyKey;
|
||||
|
||||
@ -231,6 +232,9 @@ public class WindowsComboBoxUI extends BasicComboBoxUI {
|
||||
|
||||
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,8 +404,9 @@ public class WindowsComboBoxUI extends BasicComboBoxUI {
|
||||
* @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();
|
||||
}
|
||||
@ -409,9 +414,9 @@ public class WindowsComboBoxUI extends BasicComboBoxUI {
|
||||
|
||||
@SuppressWarnings("serial") // Superclass is not serializable across versions
|
||||
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
|
||||
@ -424,10 +429,11 @@ public class WindowsComboBoxUI extends BasicComboBoxUI {
|
||||
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
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -125,6 +125,9 @@ public class WindowsGraphicsUtils {
|
||||
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) {
|
||||
|
@ -623,8 +623,8 @@ public class WindowsIconFactory implements Serializable
|
||||
@SuppressWarnings("serial") // Same-version serialization only
|
||||
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 (xp != null && WindowsMenuItemUI.isVistaPainting()) {
|
||||
State state = State.NORMAL;
|
||||
if (c instanceof JMenuItem) {
|
||||
state = ((JMenuItem) c).getModel().isEnabled()
|
||||
@ -657,16 +657,18 @@ public class WindowsIconFactory implements Serializable
|
||||
}
|
||||
}
|
||||
public int getIconWidth() {
|
||||
if (WindowsMenuItemUI.isVistaPainting()) {
|
||||
Skin skin = XPStyle.getXP().getSkin(null, Part.MP_POPUPSUBMENU);
|
||||
XPStyle xp = XPStyle.getXP();
|
||||
if (xp != null && WindowsMenuItemUI.isVistaPainting()) {
|
||||
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 (xp != null && WindowsMenuItemUI.isVistaPainting()) {
|
||||
Skin skin = xp.getSkin(null, Part.MP_POPUPSUBMENU);
|
||||
return skin.getHeight();
|
||||
} else {
|
||||
return 8;
|
||||
@ -692,7 +694,8 @@ public class WindowsIconFactory implements Serializable
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@ -756,12 +759,17 @@ public class WindowsIconFactory implements Serializable
|
||||
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;
|
||||
}
|
||||
|
||||
@ -809,14 +817,16 @@ public class WindowsIconFactory implements Serializable
|
||||
? 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -86,14 +86,15 @@ public class WindowsInternalFrameTitlePane extends BasicInternalFrameTitlePane {
|
||||
}
|
||||
} 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() {
|
||||
@ -388,7 +389,7 @@ public class WindowsInternalFrameTitlePane extends BasicInternalFrameTitlePane {
|
||||
public class WindowsTitlePaneLayout extends BasicInternalFrameTitlePane.TitlePaneLayout {
|
||||
private Insets captionMargin = null;
|
||||
private Insets contentMargin = null;
|
||||
private XPStyle xp = XPStyle.getXP();
|
||||
private final XPStyle xp = XPStyle.getXP();
|
||||
|
||||
WindowsTitlePaneLayout() {
|
||||
if (xp != null) {
|
||||
|
@ -2327,8 +2327,9 @@ public class WindowsLookAndFeel extends BasicLookAndFeel
|
||||
}
|
||||
|
||||
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 {
|
||||
@ -2344,7 +2345,8 @@ public class WindowsLookAndFeel extends BasicLookAndFeel
|
||||
|
||||
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 {
|
||||
|
@ -156,8 +156,8 @@ public class WindowsMenuBarUI extends BasicMenuBarUI
|
||||
|
||||
@Override
|
||||
public void paint(Graphics g, JComponent c) {
|
||||
if (WindowsMenuItemUI.isVistaPainting()) {
|
||||
XPStyle xp = XPStyle.getXP();
|
||||
XPStyle xp = XPStyle.getXP();
|
||||
if (xp != null && WindowsMenuItemUI.isVistaPainting()) {
|
||||
Skin skin;
|
||||
skin = xp.getSkin(c, Part.MP_BARBACKGROUND);
|
||||
int width = c.getWidth();
|
||||
|
@ -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
|
||||
@ -109,7 +109,8 @@ public class WindowsMenuItemUI extends BasicMenuItemUI {
|
||||
static void paintBackground(WindowsMenuItemUIAccessor menuItemUI,
|
||||
Graphics g, JMenuItem menuItem, Color bgColor) {
|
||||
assert isVistaPainting();
|
||||
if (isVistaPainting()) {
|
||||
XPStyle xp = XPStyle.getXP();
|
||||
if (xp != null && isVistaPainting()) {
|
||||
int menuWidth = menuItem.getWidth();
|
||||
int menuHeight = menuItem.getHeight();
|
||||
if (menuItem.isOpaque()) {
|
||||
@ -118,7 +119,6 @@ public class WindowsMenuItemUI extends BasicMenuItemUI {
|
||||
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,
|
||||
|
@ -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 class WindowsPopupMenuSeparatorUI extends BasicPopupMenuSeparatorUI {
|
||||
|
||||
public void paint(Graphics g, JComponent c) {
|
||||
Dimension s = c.getSize();
|
||||
if (WindowsMenuItemUI.isVistaPainting()) {
|
||||
XPStyle xp = XPStyle.getXP();
|
||||
if (xp != null && WindowsMenuItemUI.isVistaPainting()) {
|
||||
int x = 1;
|
||||
Component parent = c.getParent();
|
||||
if (parent instanceof JComponent) {
|
||||
@ -67,7 +68,7 @@ public class WindowsPopupMenuSeparatorUI extends BasicPopupMenuSeparatorUI {
|
||||
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);
|
||||
|
@ -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 @@ public class WindowsPopupMenuUI extends BasicPopupMenuUI {
|
||||
|
||||
@Override
|
||||
public void paint(Graphics g, JComponent c) {
|
||||
if (WindowsMenuItemUI.isVistaPainting()) {
|
||||
XPStyle xp = XPStyle.getXP();
|
||||
XPStyle xp = XPStyle.getXP();
|
||||
if (xp != null && WindowsMenuItemUI.isVistaPainting()) {
|
||||
Skin skin = xp.getSkin(c, Part.MP_POPUPBACKGROUND);
|
||||
skin.paintSkin(g, 0, 0, c.getWidth(),c.getHeight(), State.NORMAL);
|
||||
int textOffset = getTextOffset(c);
|
||||
|
@ -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
|
||||
@ -322,8 +322,9 @@ public class WindowsProgressBarUI extends BasicProgressBarUI
|
||||
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;
|
||||
@ -338,6 +339,9 @@ public class WindowsProgressBarUI extends BasicProgressBarUI
|
||||
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();
|
||||
@ -396,6 +400,9 @@ public class WindowsProgressBarUI extends BasicProgressBarUI
|
||||
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);
|
||||
|
||||
|
@ -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 @@ public class WindowsSliderUI extends BasicSliderUI
|
||||
}
|
||||
|
||||
private Part getXPThumbPart() {
|
||||
XPStyle xp = XPStyle.getXP();
|
||||
Part part;
|
||||
boolean vertical = (slider.getOrientation() == JSlider.VERTICAL);
|
||||
boolean leftToRight = slider.getComponentOrientation().isLeftToRight();
|
||||
|
@ -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 @@ public class WindowsSpinnerUI extends BasicSpinnerUI {
|
||||
|
||||
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);
|
||||
|
@ -91,9 +91,10 @@ public class WindowsTableHeaderUI extends BasicTableHeaderUI {
|
||||
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;
|
||||
|
@ -52,6 +52,7 @@ import javax.swing.text.JTextComponent;
|
||||
|
||||
import sun.awt.image.SunWritableRaster;
|
||||
import sun.awt.windows.ThemeReader;
|
||||
import sun.awt.windows.WToolkit;
|
||||
import sun.security.action.GetPropertyAction;
|
||||
import sun.swing.CachedPainter;
|
||||
|
||||
@ -99,7 +100,7 @@ class XPStyle {
|
||||
if (themeActive == null) {
|
||||
Toolkit toolkit = Toolkit.getDefaultToolkit();
|
||||
themeActive =
|
||||
(Boolean)toolkit.getDesktopProperty("win.xpstyle.themeActive");
|
||||
(Boolean)toolkit.getDesktopProperty(WToolkit.XPSTYLE_THEME_ACTIVE);
|
||||
if (themeActive == null) {
|
||||
themeActive = Boolean.FALSE;
|
||||
}
|
||||
@ -115,7 +116,7 @@ class XPStyle {
|
||||
}
|
||||
}
|
||||
}
|
||||
return xp;
|
||||
return ThemeReader.isXPStyleEnabled() ? xp : null;
|
||||
}
|
||||
|
||||
static boolean isVista() {
|
||||
@ -180,9 +181,10 @@ class XPStyle {
|
||||
* 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 <code>Point</code> (e.g. a location or an offset) value
|
||||
@ -199,11 +201,7 @@ class XPStyle {
|
||||
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
|
||||
@ -217,9 +215,10 @@ class XPStyle {
|
||||
* 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);
|
||||
}
|
||||
|
||||
|
||||
@ -509,16 +508,17 @@ class XPStyle {
|
||||
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() {
|
||||
@ -529,7 +529,7 @@ class XPStyle {
|
||||
if (size == null) {
|
||||
size = getPartSize(part, state);
|
||||
}
|
||||
return size.height;
|
||||
return (size != null) ? size.height : 0;
|
||||
}
|
||||
|
||||
int getHeight() {
|
||||
@ -586,6 +586,9 @@ class XPStyle {
|
||||
* @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,
|
||||
@ -611,6 +614,9 @@ class XPStyle {
|
||||
* @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);
|
||||
}
|
||||
|
||||
@ -630,7 +636,7 @@ class XPStyle {
|
||||
void paintSkin(Graphics g, int dx, int dy, int dw, int dh, State state,
|
||||
boolean borderFill) {
|
||||
if(borderFill && "borderfill".equals(getTypeEnumName(component, part,
|
||||
state, Prop.BGTYPE))) {
|
||||
state, Prop.BGTYPE)) && XPStyle.getXP() == null) {
|
||||
return;
|
||||
}
|
||||
skinPainter.paint(null, g, dx, dy, dw, dh, this, state);
|
||||
@ -684,7 +690,7 @@ class XPStyle {
|
||||
|
||||
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));
|
||||
@ -709,13 +715,16 @@ class XPStyle {
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
@ -61,6 +61,8 @@ public final class ThemeReader {
|
||||
private static final Lock readLock = readWriteLock.readLock();
|
||||
private static final Lock writeLock = readWriteLock.writeLock();
|
||||
|
||||
static volatile boolean xpStyleEnabled;
|
||||
|
||||
static void flush() {
|
||||
writeLock.lock();
|
||||
try {
|
||||
@ -76,6 +78,10 @@ public final class ThemeReader {
|
||||
|
||||
public static native 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);
|
||||
|
@ -72,6 +72,9 @@ public final class WToolkit extends SunToolkit implements Runnable {
|
||||
|
||||
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.
|
||||
@ -894,7 +897,7 @@ public final class WToolkit extends SunToolkit implements Runnable {
|
||||
private synchronized void lazilyInitWProps() {
|
||||
if (wprops == null) {
|
||||
wprops = new WDesktopProperties(this);
|
||||
updateProperties();
|
||||
updateProperties(wprops.getProperties());
|
||||
}
|
||||
}
|
||||
|
||||
@ -929,21 +932,27 @@ public final class WToolkit extends SunToolkit implements Runnable {
|
||||
* Windows doesn't always send WM_SETTINGCHANGE when it should.
|
||||
*/
|
||||
private void windowsSettingChange() {
|
||||
// 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<String, Object> props = getWProps();
|
||||
updateXPStyleEnabled(props.get(XPSTYLE_THEME_ACTIVE));
|
||||
|
||||
EventQueue.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
updateProperties();
|
||||
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<String, Object> props) {
|
||||
if (null == props) {
|
||||
return;
|
||||
}
|
||||
|
||||
Map<String, Object> props = wprops.getProperties();
|
||||
updateXPStyleEnabled(props.get(XPSTYLE_THEME_ACTIVE));
|
||||
|
||||
for (String propName : props.keySet()) {
|
||||
Object val = props.get(propName);
|
||||
if (log.isLoggable(PlatformLogger.Level.FINER)) {
|
||||
@ -953,6 +962,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
|
||||
public synchronized void addPropertyChangeListener(String name, PropertyChangeListener pcl) {
|
||||
if (name == null) {
|
||||
|
Loading…
Reference in New Issue
Block a user