diff options
author | dcherepanov <none@none> | 2008-08-25 19:15:37 +0400 |
---|---|---|
committer | dcherepanov <none@none> | 2008-08-25 19:15:37 +0400 |
commit | e076a103de4bc8da0b3118565060449565fc261f (patch) | |
tree | a9b6d7c26383a75abb8cff46e189b1bf5d8a9829 | |
parent | f998677359f58d7226585ff805b5d88a07a01573 (diff) |
6737722: api/java_awt/TrayIcon/index.html#TrayIconHeadlessMode
Summary: isSupported() should skip tray initialization in case of headless
Reviewed-by: art, ant
-rw-r--r-- | src/share/classes/java/awt/SystemTray.java | 19 | ||||
-rw-r--r-- | src/share/classes/java/awt/TrayIcon.java | 10 | ||||
-rw-r--r-- | test/java/awt/Toolkit/HeadlessTray/HeadlessTray.java | 49 |
3 files changed, 70 insertions, 8 deletions
diff --git a/src/share/classes/java/awt/SystemTray.java b/src/share/classes/java/awt/SystemTray.java index 7d193fc6e..2aa172108 100644 --- a/src/share/classes/java/awt/SystemTray.java +++ b/src/share/classes/java/awt/SystemTray.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2007 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 2005-2008 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -203,16 +203,18 @@ public class SystemTray { * functionality is supported for the current platform */ public static boolean isSupported() { - initializeSystemTrayIfNeeded(); - Toolkit toolkit = Toolkit.getDefaultToolkit(); - if (toolkit instanceof SunToolkit) { + // connecting tray to native resource + initializeSystemTrayIfNeeded(); return ((SunToolkit)toolkit).isTraySupported(); } else if (toolkit instanceof HeadlessToolkit) { + // skip initialization as the init routine + // throws HeadlessException return ((HeadlessToolkit)toolkit).isTraySupported(); + } else { + return false; } - return false; } /** @@ -476,7 +478,12 @@ public class SystemTray { synchronized void addNotify() { if (peer == null) { - peer = ((SunToolkit)Toolkit.getDefaultToolkit()).createSystemTray(this); + Toolkit toolkit = Toolkit.getDefaultToolkit(); + if (toolkit instanceof SunToolkit) { + peer = ((SunToolkit)Toolkit.getDefaultToolkit()).createSystemTray(this); + } else if (toolkit instanceof HeadlessToolkit) { + peer = ((HeadlessToolkit)Toolkit.getDefaultToolkit()).createSystemTray(this); + } } } diff --git a/src/share/classes/java/awt/TrayIcon.java b/src/share/classes/java/awt/TrayIcon.java index d3a6e570f..9fcdd2a6a 100644 --- a/src/share/classes/java/awt/TrayIcon.java +++ b/src/share/classes/java/awt/TrayIcon.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2006 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 2005-2008 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -38,6 +38,7 @@ import java.util.EventListener; import java.awt.peer.TrayIconPeer; import sun.awt.AppContext; import sun.awt.SunToolkit; +import sun.awt.HeadlessToolkit; import java.util.EventObject; /** @@ -659,7 +660,12 @@ public class TrayIcon { { synchronized (this) { if (peer == null) { - peer = ((SunToolkit)Toolkit.getDefaultToolkit()).createTrayIcon(this); + Toolkit toolkit = Toolkit.getDefaultToolkit(); + if (toolkit instanceof SunToolkit) { + peer = ((SunToolkit)Toolkit.getDefaultToolkit()).createTrayIcon(this); + } else if (toolkit instanceof HeadlessToolkit) { + peer = ((HeadlessToolkit)Toolkit.getDefaultToolkit()).createTrayIcon(this); + } } } peer.setToolTip(tooltip); diff --git a/test/java/awt/Toolkit/HeadlessTray/HeadlessTray.java b/test/java/awt/Toolkit/HeadlessTray/HeadlessTray.java new file mode 100644 index 000000000..2045052f6 --- /dev/null +++ b/test/java/awt/Toolkit/HeadlessTray/HeadlessTray.java @@ -0,0 +1,49 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +/* + @test + @bug 6737722 + @summary no tray support in headless mode + @author dmitry.cherepanov: area=awt.headless + @run main HeadlessTray +*/ + +import java.awt.*; + +public class HeadlessTray +{ + public static void main (String args[]) { + + System.setProperty("java.awt.headless", "true"); + + // We expect the method returns false and no exception thrown + boolean isSupported = SystemTray.isSupported(); + + if (isSupported) { + throw new RuntimeException("Tray shouldn't be supported in headless mode "); + } + + } + +} |