001: /*
002: * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025:
026: package sun.awt;
027:
028: import java.awt.Window;
029:
030: import java.lang.reflect.Field;
031:
032: import java.util.logging.Logger;
033: import java.util.logging.Level;
034:
035: import java.security.AccessController;
036: import java.security.PrivilegedAction;
037:
038: public class WindowAccessor {
039:
040: private static Class windowClass;
041: private static Field fieldIsAutoRequestFocus;
042: private static Field fieldIsTrayIconWindow;
043:
044: private static final Logger log = Logger
045: .getLogger("sun.awt.WindowAccessor");
046:
047: private WindowAccessor() {
048: }
049:
050: static {
051: AccessController.doPrivileged(new PrivilegedAction() {
052: public Object run() {
053: try {
054: windowClass = Class.forName("java.awt.Window");
055: fieldIsAutoRequestFocus = windowClass
056: .getDeclaredField("autoRequestFocus");
057: fieldIsAutoRequestFocus.setAccessible(true);
058: fieldIsTrayIconWindow = windowClass
059: .getDeclaredField("isTrayIconWindow");
060: fieldIsTrayIconWindow.setAccessible(true);
061:
062: } catch (NoSuchFieldException e) {
063: log.log(Level.FINE,
064: "Unable to initialize WindowAccessor: ", e);
065: } catch (ClassNotFoundException e) {
066: log.log(Level.FINE,
067: "Unable to initialize WindowAccessor: ", e);
068: }
069: return null;
070: }
071: });
072: }
073:
074: public static boolean isAutoRequestFocus(Window w) {
075: try {
076: return fieldIsAutoRequestFocus.getBoolean(w);
077:
078: } catch (IllegalAccessException e) {
079: log
080: .log(Level.FINE,
081: "Unable to access the Window object", e);
082: }
083: return true;
084: }
085:
086: public static boolean isTrayIconWindow(Window w) {
087: try {
088: return fieldIsTrayIconWindow.getBoolean(w);
089:
090: } catch (IllegalAccessException e) {
091: log
092: .log(Level.FINE,
093: "Unable to access the Window object", e);
094: }
095: return false;
096: }
097:
098: public static void setTrayIconWindow(Window w,
099: boolean isTrayIconWindow) {
100: try {
101: fieldIsTrayIconWindow.set(w, isTrayIconWindow);
102:
103: } catch (IllegalAccessException e) {
104: log
105: .log(Level.FINE,
106: "Unable to access the Window object", e);
107: }
108: }
109: }
|