jdk/src/share/classes/sun/awt/WindowAccessor.java
changeset 3938 ef327bd847c0
parent 2 90ce3da70b43
equal deleted inserted replaced
3934:487e1aa949c4 3938:ef327bd847c0
    27 
    27 
    28 import java.awt.Window;
    28 import java.awt.Window;
    29 
    29 
    30 import java.lang.reflect.Field;
    30 import java.lang.reflect.Field;
    31 
    31 
    32 import java.util.logging.Logger;
    32 import sun.util.logging.PlatformLogger;
    33 import java.util.logging.Level;
       
    34 
    33 
    35 import java.security.AccessController;
    34 import java.security.AccessController;
    36 import java.security.PrivilegedAction;
    35 import java.security.PrivilegedAction;
    37 
    36 
    38 public class WindowAccessor {
    37 public class WindowAccessor {
    39 
    38 
    40     private static Class windowClass;
    39     private static Class windowClass;
    41     private static Field fieldIsAutoRequestFocus;
    40     private static Field fieldIsAutoRequestFocus;
    42     private static Field fieldIsTrayIconWindow;
    41     private static Field fieldIsTrayIconWindow;
    43 
    42 
    44     private static final Logger log = Logger.getLogger("sun.awt.WindowAccessor");
    43     private static final PlatformLogger log = PlatformLogger.getLogger("sun.awt.WindowAccessor");
    45 
    44 
    46     private WindowAccessor() {
    45     private WindowAccessor() {
    47     }
    46     }
    48 
    47 
    49     static {
    48     static {
    55                         fieldIsAutoRequestFocus.setAccessible(true);
    54                         fieldIsAutoRequestFocus.setAccessible(true);
    56                         fieldIsTrayIconWindow = windowClass.getDeclaredField("isTrayIconWindow");
    55                         fieldIsTrayIconWindow = windowClass.getDeclaredField("isTrayIconWindow");
    57                         fieldIsTrayIconWindow.setAccessible(true);
    56                         fieldIsTrayIconWindow.setAccessible(true);
    58 
    57 
    59                     } catch (NoSuchFieldException e) {
    58                     } catch (NoSuchFieldException e) {
    60                         log.log(Level.FINE, "Unable to initialize WindowAccessor: ", e);
    59                         log.fine("Unable to initialize WindowAccessor: ", e);
    61                     } catch (ClassNotFoundException e) {
    60                     } catch (ClassNotFoundException e) {
    62                         log.log(Level.FINE, "Unable to initialize WindowAccessor: ", e);
    61                         log.fine("Unable to initialize WindowAccessor: ", e);
    63                     }
    62                     }
    64                     return null;
    63                     return null;
    65                 }
    64                 }
    66             });
    65             });
    67     }
    66     }
    69     public static boolean isAutoRequestFocus(Window w) {
    68     public static boolean isAutoRequestFocus(Window w) {
    70         try {
    69         try {
    71             return fieldIsAutoRequestFocus.getBoolean(w);
    70             return fieldIsAutoRequestFocus.getBoolean(w);
    72 
    71 
    73         } catch (IllegalAccessException e) {
    72         } catch (IllegalAccessException e) {
    74             log.log(Level.FINE, "Unable to access the Window object", e);
    73             log.fine("Unable to access the Window object", e);
    75         }
    74         }
    76         return true;
    75         return true;
    77     }
    76     }
    78 
    77 
    79     public static boolean isTrayIconWindow(Window w) {
    78     public static boolean isTrayIconWindow(Window w) {
    80         try {
    79         try {
    81             return fieldIsTrayIconWindow.getBoolean(w);
    80             return fieldIsTrayIconWindow.getBoolean(w);
    82 
    81 
    83         } catch (IllegalAccessException e) {
    82         } catch (IllegalAccessException e) {
    84             log.log(Level.FINE, "Unable to access the Window object", e);
    83             log.fine("Unable to access the Window object", e);
    85         }
    84         }
    86         return false;
    85         return false;
    87     }
    86     }
    88 
    87 
    89     public static void setTrayIconWindow(Window w, boolean isTrayIconWindow) {
    88     public static void setTrayIconWindow(Window w, boolean isTrayIconWindow) {
    90         try {
    89         try {
    91             fieldIsTrayIconWindow.set(w, isTrayIconWindow);
    90             fieldIsTrayIconWindow.set(w, isTrayIconWindow);
    92 
    91 
    93         } catch (IllegalAccessException e) {
    92         } catch (IllegalAccessException e) {
    94             log.log(Level.FINE, "Unable to access the Window object", e);
    93             log.fine("Unable to access the Window object", e);
    95         }
    94         }
    96     }
    95     }
    97 }
    96 }