jdk/src/share/classes/sun/awt/WindowAccessor.java
changeset 4422 ade55a65b0f2
parent 4421 fcbbd4d49581
parent 4408 80dcc8ac5696
child 4423 4061c66ba1af
equal deleted inserted replaced
4421:fcbbd4d49581 4422:ade55a65b0f2
     1 /*
       
     2  * Copyright 2007 Sun Microsystems, Inc.  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.  Sun designates this
       
     8  * particular file as subject to the "Classpath" exception as provided
       
     9  * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
       
    22  * CA 95054 USA or visit www.sun.com if you need additional information or
       
    23  * have any questions.
       
    24  */
       
    25 
       
    26 package sun.awt;
       
    27 
       
    28 import java.awt.Window;
       
    29 
       
    30 import java.lang.reflect.Field;
       
    31 
       
    32 import sun.util.logging.PlatformLogger;
       
    33 
       
    34 import java.security.AccessController;
       
    35 import java.security.PrivilegedAction;
       
    36 
       
    37 public class WindowAccessor {
       
    38 
       
    39     private static Class windowClass;
       
    40     private static Field fieldIsAutoRequestFocus;
       
    41     private static Field fieldIsTrayIconWindow;
       
    42 
       
    43     private static final PlatformLogger log = PlatformLogger.getLogger("sun.awt.WindowAccessor");
       
    44 
       
    45     private WindowAccessor() {
       
    46     }
       
    47 
       
    48     static {
       
    49         AccessController.doPrivileged( new PrivilegedAction() {
       
    50                 public Object run() {
       
    51                     try {
       
    52                         windowClass = Class.forName("java.awt.Window");
       
    53                         fieldIsAutoRequestFocus = windowClass.getDeclaredField("autoRequestFocus");
       
    54                         fieldIsAutoRequestFocus.setAccessible(true);
       
    55                         fieldIsTrayIconWindow = windowClass.getDeclaredField("isTrayIconWindow");
       
    56                         fieldIsTrayIconWindow.setAccessible(true);
       
    57 
       
    58                     } catch (NoSuchFieldException e) {
       
    59                         log.fine("Unable to initialize WindowAccessor: ", e);
       
    60                     } catch (ClassNotFoundException e) {
       
    61                         log.fine("Unable to initialize WindowAccessor: ", e);
       
    62                     }
       
    63                     return null;
       
    64                 }
       
    65             });
       
    66     }
       
    67 
       
    68     public static boolean isAutoRequestFocus(Window w) {
       
    69         try {
       
    70             return fieldIsAutoRequestFocus.getBoolean(w);
       
    71 
       
    72         } catch (IllegalAccessException e) {
       
    73             log.fine("Unable to access the Window object", e);
       
    74         }
       
    75         return true;
       
    76     }
       
    77 
       
    78     public static boolean isTrayIconWindow(Window w) {
       
    79         try {
       
    80             return fieldIsTrayIconWindow.getBoolean(w);
       
    81 
       
    82         } catch (IllegalAccessException e) {
       
    83             log.fine("Unable to access the Window object", e);
       
    84         }
       
    85         return false;
       
    86     }
       
    87 
       
    88     public static void setTrayIconWindow(Window w, boolean isTrayIconWindow) {
       
    89         try {
       
    90             fieldIsTrayIconWindow.set(w, isTrayIconWindow);
       
    91 
       
    92         } catch (IllegalAccessException e) {
       
    93             log.fine("Unable to access the Window object", e);
       
    94         }
       
    95     }
       
    96 }