8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 /* 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.BufferedImage; 45 import java.awt.image.ImageFilter; 46 import java.awt.image.ImageProducer; 47 import java.awt.image.FilteredImageSource; 48 import java.awt.image.RGBImageFilter; 49 50 import javax.swing.plaf.*; 51 import javax.swing.*; 52 import javax.swing.plaf.basic.*; 53 import javax.swing.border.*; 54 import javax.swing.text.DefaultEditorKit; 55 import static javax.swing.UIDefaults.LazyValue; 1917 return isMnemonicHidden; 1918 } 1919 1920 /** 1921 * Gets the state of the flag which indicates if the old Windows 1922 * look and feel should be rendered. This flag is used by the 1923 * component UI delegates as a hint to determine which style the component 1924 * should be rendered. 1925 * 1926 * @return true if Windows 95 and Windows NT 4 look and feel should 1927 * be rendered 1928 * @since 1.4 1929 */ 1930 public static boolean isClassicWindows() { 1931 return isClassicWindows; 1932 } 1933 1934 /** 1935 * <p> 1936 * Invoked when the user attempts an invalid operation, 1937 * such as pasting into an uneditable <code>JTextField</code> 1938 * that has focus. 1939 * </p> 1940 * <p> 1941 * If the user has enabled visual error indication on 1942 * the desktop, this method will flash the caption bar 1943 * of the active window. The user can also set the 1944 * property awt.visualbell=true to achieve the same 1945 * results. 1946 * </p> 1947 * 1948 * @param component Component the error occurred in, may be 1949 * null indicating the error condition is 1950 * not directly associated with a 1951 * <code>Component</code>. 1952 * 1953 * @see javax.swing.LookAndFeel#provideErrorFeedback 1954 */ 1955 public void provideErrorFeedback(Component component) { 1956 super.provideErrorFeedback(component); 1957 } 1958 1959 /** 1960 * {@inheritDoc} 1961 */ 1962 public LayoutStyle getLayoutStyle() { 1963 LayoutStyle style = this.style; 1964 if (style == null) { 1965 style = new WindowsLayoutStyle(); 1966 this.style = style; 1967 } 1968 return style; 1969 } 1970 1971 // ********* Auditory Cue support methods and objects ********* 1972 1973 /** 1974 * Returns an <code>Action</code>. 1975 * <P> 1976 * This Action contains the information and logic to render an 1977 * auditory cue. The <code>Object</code> that is passed to this 1978 * method contains the information needed to render the auditory 1979 * cue. Normally, this <code>Object</code> is a <code>String</code> 1980 * that points to a <code>Toolkit</code> <code>desktopProperty</code>. 1981 * This <code>desktopProperty</code> is resolved by AWT and the 1982 * Windows OS. 1983 * <P> 1984 * This <code>Action</code>'s <code>actionPerformed</code> method 1985 * is fired by the <code>playSound</code> method. 1986 * 1987 * @return an Action which knows how to render the auditory 1988 * cue for one particular system or user activity 1989 * @see #playSound(Action) 1990 * @since 1.4 1991 */ 1992 protected Action createAudioAction(Object key) { 1993 if (key != null) { 1994 String audioKey = (String)key; 1995 String audioValue = (String)UIManager.get(key); 1996 return new AudioAction(audioKey, audioValue); 1997 } else { 1998 return null; 1999 } 2000 } 2001 2002 static void repaintRootPane(Component c) { 2003 JRootPane root = null; 2004 for (; c != null; c = c.getParent()) { 2005 if (c instanceof JRootPane) { 2006 root = (JRootPane)c; 2007 } 2008 } 2009 2010 if (root != null) { 2011 root.repaint(); 2012 } else { 2013 c.repaint(); 2014 } 2015 } 2016 2017 /** 2018 * Pass the name String to the super constructor. This is used 2019 * later to identify the Action and decide whether to play it or 2020 * not. Store the resource String. It is used to get the audio 2021 * resource. In this case, the resource is a <code>Runnable</code> 2022 * supplied by <code>Toolkit</code>. This <code>Runnable</code> is 2023 * effectively a pointer down into the Win32 OS that knows how to 2024 * play the right sound. 2025 * 2026 * @since 1.4 2027 */ 2028 @SuppressWarnings("serial") // Superclass is not serializable across versions 2029 private static class AudioAction extends AbstractAction { 2030 private Runnable audioRunnable; 2031 private String audioResource; 2032 /** 2033 * We use the String as the name of the Action and as a pointer to 2034 * the underlying OSes audio resource. 2035 */ 2036 public AudioAction(String name, String resource) { 2037 super(name); 2038 audioResource = resource; 2039 } 2040 public void actionPerformed(ActionEvent e) { 2041 if (audioRunnable == null) { 2042 audioRunnable = (Runnable)Toolkit.getDefaultToolkit().getDesktopProperty(audioResource); 2043 } 2044 if (audioRunnable != null) { 2045 // Runnable appears to block until completed playing, hence 2046 // start up another thread to handle playing. 2047 new ManagedLocalsThread(audioRunnable).start(); 2048 } 2049 } 2050 } 2051 2052 /** 2053 * Gets an <code>Icon</code> from the native libraries if available, 2054 * otherwise gets it from an image resource file. 2055 */ 2056 private static class LazyWindowsIcon implements UIDefaults.LazyValue { 2057 private String nativeImage; 2058 private String resource; 2059 2060 LazyWindowsIcon(String nativeImage, String resource) { 2061 this.nativeImage = nativeImage; 2062 this.resource = resource; 2063 } 2064 2065 public Object createValue(UIDefaults table) { 2066 if (nativeImage != null) { 2067 Image image = (Image)ShellFolder.get(nativeImage); 2068 if (image != null) { 2069 return new ImageIcon(image); 2070 } 2071 } 2072 return SwingUtilities2.makeIcon(getClass(), 2073 WindowsLookAndFeel.class, 2074 resource); 2075 } 2076 } 2077 2078 2079 /** 2080 * Gets an <code>Icon</code> from the native libraries if available. 2081 * A desktop property is used to trigger reloading the icon when needed. 2082 */ 2083 private class ActiveWindowsIcon implements UIDefaults.ActiveValue { 2084 private Icon icon; 2085 private String nativeImageName; 2086 private String fallbackName; 2087 private DesktopProperty desktopProperty; 2088 2089 ActiveWindowsIcon(String desktopPropertyName, 2090 String nativeImageName, String fallbackName) { 2091 this.nativeImageName = nativeImageName; 2092 this.fallbackName = fallbackName; 2093 2094 if (OSInfo.getOSType() == OSInfo.OSType.WINDOWS && 2095 OSInfo.getWindowsVersion().compareTo(OSInfo.WINDOWS_XP) < 0) { 2096 // This desktop property is needed to trigger reloading the icon. 2097 // It is kept in member variable to avoid GC. 2098 this.desktopProperty = new TriggerDesktopProperty(desktopPropertyName) { 2099 @Override protected void updateUI() { 2100 icon = null; | 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 /* 27 * <p>These classes are designed to be used while the 28 * corresponding {@code LookAndFeel} class has been installed 29 * (<code>UIManager.setLookAndFeel(new <i>XXX</i>LookAndFeel())</code>). 30 * Using them while a different {@code LookAndFeel} is installed 31 * may produce unexpected results, including exceptions. 32 * Additionally, changing the {@code LookAndFeel} 33 * maintained by the {@code UIManager} without updating the 34 * corresponding {@code ComponentUI} of any 35 * {@code JComponent}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.BufferedImage; 45 import java.awt.image.ImageFilter; 46 import java.awt.image.ImageProducer; 47 import java.awt.image.FilteredImageSource; 48 import java.awt.image.RGBImageFilter; 49 50 import javax.swing.plaf.*; 51 import javax.swing.*; 52 import javax.swing.plaf.basic.*; 53 import javax.swing.border.*; 54 import javax.swing.text.DefaultEditorKit; 55 import static javax.swing.UIDefaults.LazyValue; 1917 return isMnemonicHidden; 1918 } 1919 1920 /** 1921 * Gets the state of the flag which indicates if the old Windows 1922 * look and feel should be rendered. This flag is used by the 1923 * component UI delegates as a hint to determine which style the component 1924 * should be rendered. 1925 * 1926 * @return true if Windows 95 and Windows NT 4 look and feel should 1927 * be rendered 1928 * @since 1.4 1929 */ 1930 public static boolean isClassicWindows() { 1931 return isClassicWindows; 1932 } 1933 1934 /** 1935 * <p> 1936 * Invoked when the user attempts an invalid operation, 1937 * such as pasting into an uneditable {@code JTextField} 1938 * that has focus. 1939 * </p> 1940 * <p> 1941 * If the user has enabled visual error indication on 1942 * the desktop, this method will flash the caption bar 1943 * of the active window. The user can also set the 1944 * property awt.visualbell=true to achieve the same 1945 * results. 1946 * </p> 1947 * 1948 * @param component Component the error occurred in, may be 1949 * null indicating the error condition is 1950 * not directly associated with a 1951 * {@code Component}. 1952 * 1953 * @see javax.swing.LookAndFeel#provideErrorFeedback 1954 */ 1955 public void provideErrorFeedback(Component component) { 1956 super.provideErrorFeedback(component); 1957 } 1958 1959 /** 1960 * {@inheritDoc} 1961 */ 1962 public LayoutStyle getLayoutStyle() { 1963 LayoutStyle style = this.style; 1964 if (style == null) { 1965 style = new WindowsLayoutStyle(); 1966 this.style = style; 1967 } 1968 return style; 1969 } 1970 1971 // ********* Auditory Cue support methods and objects ********* 1972 1973 /** 1974 * Returns an {@code Action}. 1975 * <P> 1976 * This Action contains the information and logic to render an 1977 * auditory cue. The {@code Object} that is passed to this 1978 * method contains the information needed to render the auditory 1979 * cue. Normally, this {@code Object} is a {@code String} 1980 * that points to a {@code Toolkit desktopProperty}. 1981 * This {@code desktopProperty} is resolved by AWT and the 1982 * Windows OS. 1983 * <P> 1984 * This {@code Action}'s {@code actionPerformed} method 1985 * is fired by the {@code playSound} method. 1986 * 1987 * @return an Action which knows how to render the auditory 1988 * cue for one particular system or user activity 1989 * @see #playSound(Action) 1990 * @since 1.4 1991 */ 1992 protected Action createAudioAction(Object key) { 1993 if (key != null) { 1994 String audioKey = (String)key; 1995 String audioValue = (String)UIManager.get(key); 1996 return new AudioAction(audioKey, audioValue); 1997 } else { 1998 return null; 1999 } 2000 } 2001 2002 static void repaintRootPane(Component c) { 2003 JRootPane root = null; 2004 for (; c != null; c = c.getParent()) { 2005 if (c instanceof JRootPane) { 2006 root = (JRootPane)c; 2007 } 2008 } 2009 2010 if (root != null) { 2011 root.repaint(); 2012 } else { 2013 c.repaint(); 2014 } 2015 } 2016 2017 /** 2018 * Pass the name String to the super constructor. This is used 2019 * later to identify the Action and decide whether to play it or 2020 * not. Store the resource String. It is used to get the audio 2021 * resource. In this case, the resource is a {@code Runnable} 2022 * supplied by {@code Toolkit}. This {@code Runnable} is 2023 * effectively a pointer down into the Win32 OS that knows how to 2024 * play the right sound. 2025 * 2026 * @since 1.4 2027 */ 2028 @SuppressWarnings("serial") // Superclass is not serializable across versions 2029 private static class AudioAction extends AbstractAction { 2030 private Runnable audioRunnable; 2031 private String audioResource; 2032 /** 2033 * We use the String as the name of the Action and as a pointer to 2034 * the underlying OSes audio resource. 2035 */ 2036 public AudioAction(String name, String resource) { 2037 super(name); 2038 audioResource = resource; 2039 } 2040 public void actionPerformed(ActionEvent e) { 2041 if (audioRunnable == null) { 2042 audioRunnable = (Runnable)Toolkit.getDefaultToolkit().getDesktopProperty(audioResource); 2043 } 2044 if (audioRunnable != null) { 2045 // Runnable appears to block until completed playing, hence 2046 // start up another thread to handle playing. 2047 new ManagedLocalsThread(audioRunnable).start(); 2048 } 2049 } 2050 } 2051 2052 /** 2053 * Gets an {@code Icon} from the native libraries if available, 2054 * otherwise gets it from an image resource file. 2055 */ 2056 private static class LazyWindowsIcon implements UIDefaults.LazyValue { 2057 private String nativeImage; 2058 private String resource; 2059 2060 LazyWindowsIcon(String nativeImage, String resource) { 2061 this.nativeImage = nativeImage; 2062 this.resource = resource; 2063 } 2064 2065 public Object createValue(UIDefaults table) { 2066 if (nativeImage != null) { 2067 Image image = (Image)ShellFolder.get(nativeImage); 2068 if (image != null) { 2069 return new ImageIcon(image); 2070 } 2071 } 2072 return SwingUtilities2.makeIcon(getClass(), 2073 WindowsLookAndFeel.class, 2074 resource); 2075 } 2076 } 2077 2078 2079 /** 2080 * Gets an {@code Icon} from the native libraries if available. 2081 * A desktop property is used to trigger reloading the icon when needed. 2082 */ 2083 private class ActiveWindowsIcon implements UIDefaults.ActiveValue { 2084 private Icon icon; 2085 private String nativeImageName; 2086 private String fallbackName; 2087 private DesktopProperty desktopProperty; 2088 2089 ActiveWindowsIcon(String desktopPropertyName, 2090 String nativeImageName, String fallbackName) { 2091 this.nativeImageName = nativeImageName; 2092 this.fallbackName = fallbackName; 2093 2094 if (OSInfo.getOSType() == OSInfo.OSType.WINDOWS && 2095 OSInfo.getWindowsVersion().compareTo(OSInfo.WINDOWS_XP) < 0) { 2096 // This desktop property is needed to trigger reloading the icon. 2097 // It is kept in member variable to avoid GC. 2098 this.desktopProperty = new TriggerDesktopProperty(desktopPropertyName) { 2099 @Override protected void updateUI() { 2100 icon = null; |