src/share/classes/com/sun/java/swing/plaf/windows/DesktopProperty.java

Print this page


   1 /*
   2  * Copyright (c) 2001, 2009, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   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


  83 
  84 
  85     /**
  86      * Sets whether or not an updateUI call is pending.
  87      */
  88     private static synchronized void setUpdatePending(boolean update) {
  89         updatePending = update;
  90     }
  91 
  92     /**
  93      * Returns true if a UI update is pending.
  94      */
  95     private static synchronized boolean isUpdatePending() {
  96         return updatePending;
  97     }
  98 
  99     /**
 100      * Updates the UIs of all the known Frames.
 101      */
 102     private static void updateAllUIs() {











 103         // Check if the current UI is WindowsLookAndfeel and flush the XP style map.
 104         // Note: Change the package test if this class is moved to a different package.
 105         Class uiClass = UIManager.getLookAndFeel().getClass();
 106         if (uiClass.getPackage().equals(DesktopProperty.class.getPackage())) {
 107             XPStyle.invalidateStyle();
 108         }
 109         Frame appFrames[] = Frame.getFrames();
 110         for (Frame appFrame : appFrames) {
 111             updateWindowUI(appFrame);
 112         }
 113     }
 114 
 115     /**
 116      * Updates the UI of the passed in window and all its children.
 117      */
 118     private static void updateWindowUI(Window window) {
 119         SwingUtilities.updateComponentTreeUI(window);
 120         Window ownedWins[] = window.getOwnedWindows();
 121         for (Window ownedWin : ownedWins) {
 122             updateWindowUI(ownedWin);
 123         }
 124     }
 125 
 126 
 127     /**
 128      * Creates a DesktopProperty.
 129      *
 130      * @param key Key used in looking up desktop value.
 131      * @param fallback Value used if desktop property is null.
 132      */


 190     }
 191 
 192     /**
 193      * Invalides the current value so that the next invocation of
 194      * <code>createValue</code> will ask for the property again.
 195      */
 196     public void invalidate() {
 197         value = null;
 198     }
 199 
 200     /**
 201      * Requests that all components in the GUI hierarchy be updated
 202      * to reflect dynamic changes in this look&feel.  This update occurs
 203      * by uninstalling and re-installing the UI objects. Requests are
 204      * batched and collapsed into a single update pass because often
 205      * many desktop properties will change at once.
 206      */
 207     protected void updateUI() {
 208         if (!isUpdatePending()) {
 209             setUpdatePending(true);


 210             Runnable uiUpdater = new Runnable() {
 211                 public void run() {
 212                     updateAllUIs();
 213                     setUpdatePending(false);
 214                 }
 215             };
 216             SwingUtilities.invokeLater(uiUpdater);
 217         }
 218     }
 219 
 220     /**
 221      * Configures the value as appropriate for a defaults property in
 222      * the UIDefaults table.
 223      */
 224     protected Object configureValue(Object value) {
 225         if (value != null) {
 226             if (value instanceof Color) {
 227                 return new ColorUIResource((Color)value);
 228             }
 229             else if (value instanceof Font) {


   1 /*
   2  * Copyright (c) 2001, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   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


  83 
  84 
  85     /**
  86      * Sets whether or not an updateUI call is pending.
  87      */
  88     private static synchronized void setUpdatePending(boolean update) {
  89         updatePending = update;
  90     }
  91 
  92     /**
  93      * Returns true if a UI update is pending.
  94      */
  95     private static synchronized boolean isUpdatePending() {
  96         return updatePending;
  97     }
  98 
  99     /**
 100      * Updates the UIs of all the known Frames.
 101      */
 102     private static void updateAllUIs() {
 103         invalidateStyle();
 104         Frame appFrames[] = Frame.getFrames();
 105         for (Frame appFrame : appFrames) {
 106             updateWindowUI(appFrame);
 107         }
 108     }
 109 
 110     /**
 111      * Invalidates the current style in WindowsLookAndFeel.
 112      */
 113     private static void invalidateStyle() {
 114         // Check if the current UI is WindowsLookAndfeel and flush the XP style map.
 115         // Note: Change the package test if this class is moved to a different package.
 116         Class uiClass = UIManager.getLookAndFeel().getClass();
 117         if (uiClass.getPackage().equals(DesktopProperty.class.getPackage())) {
 118             XPStyle.invalidateStyle();
 119         }




 120     }
 121 
 122     /**
 123      * Updates the UI of the passed in window and all its children.
 124      */
 125     private static void updateWindowUI(Window window) {
 126         SwingUtilities.updateComponentTreeUI(window);
 127         Window ownedWins[] = window.getOwnedWindows();
 128         for (Window ownedWin : ownedWins) {
 129             updateWindowUI(ownedWin);
 130         }
 131     }
 132 
 133 
 134     /**
 135      * Creates a DesktopProperty.
 136      *
 137      * @param key Key used in looking up desktop value.
 138      * @param fallback Value used if desktop property is null.
 139      */


 197     }
 198 
 199     /**
 200      * Invalides the current value so that the next invocation of
 201      * <code>createValue</code> will ask for the property again.
 202      */
 203     public void invalidate() {
 204         value = null;
 205     }
 206 
 207     /**
 208      * Requests that all components in the GUI hierarchy be updated
 209      * to reflect dynamic changes in this look&feel.  This update occurs
 210      * by uninstalling and re-installing the UI objects. Requests are
 211      * batched and collapsed into a single update pass because often
 212      * many desktop properties will change at once.
 213      */
 214     protected void updateUI() {
 215         if (!isUpdatePending()) {
 216             setUpdatePending(true);
 217             // JDK-8039383: invalidate the cached style as soon as possible
 218             invalidateStyle();
 219             Runnable uiUpdater = new Runnable() {
 220                 public void run() {
 221                     updateAllUIs();
 222                     setUpdatePending(false);
 223                 }
 224             };
 225             SwingUtilities.invokeLater(uiUpdater);
 226         }
 227     }
 228 
 229     /**
 230      * Configures the value as appropriate for a defaults property in
 231      * the UIDefaults table.
 232      */
 233     protected Object configureValue(Object value) {
 234         if (value != null) {
 235             if (value instanceof Color) {
 236                 return new ColorUIResource((Color)value);
 237             }
 238             else if (value instanceof Font) {