27 * <p>These classes are designed to be used while the 28 * corresponding <code>LookAndFeel</code> class has been installed 29 * (<code>UIManager.setLookAndFeel(new <i>XXX</i>LookAndFeel())</code>). 30 * Using them while a different <code>LookAndFeel</code> is installed 31 * may produce unexpected results, including exceptions. 32 * Additionally, changing the <code>LookAndFeel</code> 33 * maintained by the <code>UIManager</code> without updating the 34 * corresponding <code>ComponentUI</code> of any 35 * <code>JComponent</code>s may also produce unexpected results, 36 * such as the wrong colors showing up, and is generally not 37 * encouraged. 38 * 39 */ 40 41 package com.sun.java.swing.plaf.windows; 42 43 import java.awt.*; 44 import java.awt.image.*; 45 import java.security.AccessController; 46 import java.util.*; 47 48 import javax.swing.*; 49 import javax.swing.border.*; 50 import javax.swing.plaf.*; 51 import javax.swing.text.JTextComponent; 52 53 import sun.awt.image.SunWritableRaster; 54 import sun.awt.windows.ThemeReader; 55 import sun.security.action.GetPropertyAction; 56 import sun.swing.CachedPainter; 57 58 import static com.sun.java.swing.plaf.windows.TMSchema.*; 59 60 61 /** 62 * Implements Windows XP Styles for the Windows Look and Feel. 63 * 64 * @author Leif Samuelsson 65 */ 66 class XPStyle { 67 // Singleton instance of this class 68 private static XPStyle xp; 69 70 // Singleton instance of SkinPainter 71 private static SkinPainter skinPainter = new SkinPainter(); 72 73 private static Boolean themeActive = null; 74 75 private HashMap<String, Border> borderMap; 76 private HashMap<String, Color> colorMap; 77 78 private boolean flatMenus; 79 80 static { 81 invalidateStyle(); 82 } 83 84 /** Static method for clearing the hashmap and loading the 85 * current XP style and theme 86 */ 87 static synchronized void invalidateStyle() { 88 xp = null; 89 themeActive = null; 90 skinPainter.flush(); 91 } 92 93 /** Get the singleton instance of this class 94 * 95 * @return the singleton instance of this class or null if XP styles 96 * are not active or if this is not Windows XP 97 */ 98 static synchronized XPStyle getXP() { 99 if (themeActive == null) { 100 Toolkit toolkit = Toolkit.getDefaultToolkit(); 101 themeActive = 102 (Boolean)toolkit.getDesktopProperty("win.xpstyle.themeActive"); 103 if (themeActive == null) { 104 themeActive = Boolean.FALSE; 105 } 106 if (themeActive.booleanValue()) { 107 GetPropertyAction propertyAction = 108 new GetPropertyAction("swing.noxp"); 109 if (AccessController.doPrivileged(propertyAction) == null && 110 ThemeReader.isThemed() && 111 !(UIManager.getLookAndFeel() 112 instanceof WindowsClassicLookAndFeel)) { 113 114 xp = new XPStyle(); 115 } 116 } 117 } 118 return xp; 119 } 120 121 static boolean isVista() { 122 XPStyle xp = XPStyle.getXP(); 123 return (xp != null && xp.isSkinDefined(null, Part.CP_DROPDOWNBUTTONRIGHT)); 124 } 125 | 27 * <p>These classes are designed to be used while the 28 * corresponding <code>LookAndFeel</code> class has been installed 29 * (<code>UIManager.setLookAndFeel(new <i>XXX</i>LookAndFeel())</code>). 30 * Using them while a different <code>LookAndFeel</code> is installed 31 * may produce unexpected results, including exceptions. 32 * Additionally, changing the <code>LookAndFeel</code> 33 * maintained by the <code>UIManager</code> without updating the 34 * corresponding <code>ComponentUI</code> of any 35 * <code>JComponent</code>s may also produce unexpected results, 36 * such as the wrong colors showing up, and is generally not 37 * encouraged. 38 * 39 */ 40 41 package com.sun.java.swing.plaf.windows; 42 43 import java.awt.*; 44 import java.awt.image.*; 45 import java.security.AccessController; 46 import java.util.*; 47 import java.util.concurrent.atomic.AtomicBoolean; 48 49 import javax.swing.*; 50 import javax.swing.border.*; 51 import javax.swing.plaf.*; 52 import javax.swing.text.JTextComponent; 53 54 import sun.awt.image.SunWritableRaster; 55 import sun.awt.windows.ThemeReader; 56 import sun.awt.windows.WToolkit; 57 import sun.security.action.GetPropertyAction; 58 import sun.swing.CachedPainter; 59 60 import static com.sun.java.swing.plaf.windows.TMSchema.*; 61 62 63 /** 64 * Implements Windows XP Styles for the Windows Look and Feel. 65 * 66 * @author Leif Samuelsson 67 */ 68 class XPStyle { 69 // Singleton instance of this class 70 private static XPStyle xp; 71 72 // Singleton instance of SkinPainter 73 private static SkinPainter skinPainter = new SkinPainter(); 74 75 private static Boolean themeActive = null; 76 77 private static final AtomicBoolean xpstyleEnabled = WToolkit.getWToolkit().getXPStyleEnabled(); 78 79 private HashMap<String, Border> borderMap; 80 private HashMap<String, Color> colorMap; 81 82 private boolean flatMenus; 83 84 static { 85 invalidateStyle(); 86 } 87 88 /** Static method for clearing the hashmap and loading the 89 * current XP style and theme 90 */ 91 static synchronized void invalidateStyle() { 92 xp = null; 93 themeActive = null; 94 skinPainter.flush(); 95 } 96 97 /** Get the singleton instance of this class 98 * 99 * @return the singleton instance of this class or null if XP styles 100 * are not active or if this is not Windows XP 101 */ 102 static synchronized XPStyle getXP() { 103 if (themeActive != null && themeActive.booleanValue() != xpstyleEnabled.get()) { 104 // JDK-8039383: theme changed, schedule updateAllUIs() 105 DesktopProperty.scheduleUpdateUI(); 106 } 107 if (themeActive == null) { 108 themeActive = Boolean.valueOf(xpstyleEnabled.get()); 109 if (themeActive.booleanValue()) { 110 GetPropertyAction propertyAction = 111 new GetPropertyAction("swing.noxp"); 112 if (AccessController.doPrivileged(propertyAction) == null && 113 ThemeReader.isThemed() && 114 !(UIManager.getLookAndFeel() 115 instanceof WindowsClassicLookAndFeel)) { 116 117 xp = new XPStyle(); 118 } 119 } 120 } 121 return xp; 122 } 123 124 static boolean isVista() { 125 XPStyle xp = XPStyle.getXP(); 126 return (xp != null && xp.isSkinDefined(null, Part.CP_DROPDOWNBUTTONRIGHT)); 127 } 128 |