mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-22 12:04:39 +02:00
6737722: api/java_awt/TrayIcon/index.html#TrayIconHeadlessMode
IsSupported() should skip tray initialization in case of headless Reviewed-by: art, ant
This commit is contained in:
parent
f5cc909878
commit
a16656700d
3 changed files with 70 additions and 8 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
49
jdk/test/java/awt/Toolkit/HeadlessTray/HeadlessTray.java
Normal file
49
jdk/test/java/awt/Toolkit/HeadlessTray/HeadlessTray.java
Normal file
|
@ -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 ");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue