author | erikj |
Tue, 12 Sep 2017 19:03:39 +0200 | |
changeset 47216 | 71c04702a3d5 |
parent 40163 | jdk/src/java.desktop/share/classes/java/awt/HeadlessException.java@be5de84c54a7 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
40163
be5de84c54a7
8016313: java.awt.Headless exception has no spec since its creation
ssadetsky
parents:
25859
diff
changeset
|
2 |
* Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved. |
2 | 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 |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 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 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
package java.awt; |
|
27 |
||
28 |
/** |
|
29 |
* Thrown when code that is dependent on a keyboard, display, or mouse |
|
30 |
* is called in an environment that does not support a keyboard, display, |
|
40163
be5de84c54a7
8016313: java.awt.Headless exception has no spec since its creation
ssadetsky
parents:
25859
diff
changeset
|
31 |
* or mouse. Any code that depends on any of those devices should firstly |
be5de84c54a7
8016313: java.awt.Headless exception has no spec since its creation
ssadetsky
parents:
25859
diff
changeset
|
32 |
* ensure their availability using the {@code GraphicsEnvironment.isHeadless()} |
be5de84c54a7
8016313: java.awt.Headless exception has no spec since its creation
ssadetsky
parents:
25859
diff
changeset
|
33 |
* method and throw {@code HeadlessException} if the latter returns |
be5de84c54a7
8016313: java.awt.Headless exception has no spec since its creation
ssadetsky
parents:
25859
diff
changeset
|
34 |
* {@code true}. |
2 | 35 |
* |
36 |
* @since 1.4 |
|
37 |
* @author Michael Martak |
|
40163
be5de84c54a7
8016313: java.awt.Headless exception has no spec since its creation
ssadetsky
parents:
25859
diff
changeset
|
38 |
* @see GraphicsEnvironment#isHeadless |
2 | 39 |
*/ |
40 |
public class HeadlessException extends UnsupportedOperationException { |
|
41 |
/* |
|
42 |
* JDK 1.4 serialVersionUID |
|
43 |
*/ |
|
44 |
private static final long serialVersionUID = 167183644944358563L; |
|
25162 | 45 |
|
46 |
/** |
|
40163
be5de84c54a7
8016313: java.awt.Headless exception has no spec since its creation
ssadetsky
parents:
25859
diff
changeset
|
47 |
* Constructs new {@code HeadlessException} with empty message. |
be5de84c54a7
8016313: java.awt.Headless exception has no spec since its creation
ssadetsky
parents:
25859
diff
changeset
|
48 |
* For such {@code HeadlessException} the default headless error message |
be5de84c54a7
8016313: java.awt.Headless exception has no spec since its creation
ssadetsky
parents:
25859
diff
changeset
|
49 |
* may be auto-generated for some platforms. |
be5de84c54a7
8016313: java.awt.Headless exception has no spec since its creation
ssadetsky
parents:
25859
diff
changeset
|
50 |
* The text of the default headless message may depend on |
be5de84c54a7
8016313: java.awt.Headless exception has no spec since its creation
ssadetsky
parents:
25859
diff
changeset
|
51 |
* whether the GraphicsEnvironment is in fact headless. |
be5de84c54a7
8016313: java.awt.Headless exception has no spec since its creation
ssadetsky
parents:
25859
diff
changeset
|
52 |
* That is, the default headless message is both system and environmentally |
be5de84c54a7
8016313: java.awt.Headless exception has no spec since its creation
ssadetsky
parents:
25859
diff
changeset
|
53 |
* dependent. |
25162 | 54 |
*/ |
2 | 55 |
public HeadlessException() {} |
25162 | 56 |
|
57 |
/** |
|
58 |
* Create a new instance with the specified detailed error message. |
|
40163
be5de84c54a7
8016313: java.awt.Headless exception has no spec since its creation
ssadetsky
parents:
25859
diff
changeset
|
59 |
* For some platforms the default headless error message may be |
be5de84c54a7
8016313: java.awt.Headless exception has no spec since its creation
ssadetsky
parents:
25859
diff
changeset
|
60 |
* added at the end of the specified message. |
be5de84c54a7
8016313: java.awt.Headless exception has no spec since its creation
ssadetsky
parents:
25859
diff
changeset
|
61 |
* The text of the default headless message may depend on |
be5de84c54a7
8016313: java.awt.Headless exception has no spec since its creation
ssadetsky
parents:
25859
diff
changeset
|
62 |
* whether the GraphicsEnvironment is in fact headless. |
be5de84c54a7
8016313: java.awt.Headless exception has no spec since its creation
ssadetsky
parents:
25859
diff
changeset
|
63 |
* That is, the default headless message is both system and environmentally |
be5de84c54a7
8016313: java.awt.Headless exception has no spec since its creation
ssadetsky
parents:
25859
diff
changeset
|
64 |
* dependent. |
25162 | 65 |
* |
66 |
* @param msg the error message |
|
67 |
*/ |
|
2 | 68 |
public HeadlessException(String msg) { |
69 |
super(msg); |
|
70 |
} |
|
25162 | 71 |
|
72 |
/** |
|
40163
be5de84c54a7
8016313: java.awt.Headless exception has no spec since its creation
ssadetsky
parents:
25859
diff
changeset
|
73 |
* Returns the detail message string of this {@code HeadlessException}. |
be5de84c54a7
8016313: java.awt.Headless exception has no spec since its creation
ssadetsky
parents:
25859
diff
changeset
|
74 |
* Depending on the platform the message specified in the constructor may |
be5de84c54a7
8016313: java.awt.Headless exception has no spec since its creation
ssadetsky
parents:
25859
diff
changeset
|
75 |
* be followed by the default headless error message. |
be5de84c54a7
8016313: java.awt.Headless exception has no spec since its creation
ssadetsky
parents:
25859
diff
changeset
|
76 |
* The text of the default headless message may depend on |
be5de84c54a7
8016313: java.awt.Headless exception has no spec since its creation
ssadetsky
parents:
25859
diff
changeset
|
77 |
* whether the GraphicsEnvironment is in fact headless. |
be5de84c54a7
8016313: java.awt.Headless exception has no spec since its creation
ssadetsky
parents:
25859
diff
changeset
|
78 |
* That is, the default headless message is both system and environmentally |
be5de84c54a7
8016313: java.awt.Headless exception has no spec since its creation
ssadetsky
parents:
25859
diff
changeset
|
79 |
* dependent. |
be5de84c54a7
8016313: java.awt.Headless exception has no spec since its creation
ssadetsky
parents:
25859
diff
changeset
|
80 |
* |
be5de84c54a7
8016313: java.awt.Headless exception has no spec since its creation
ssadetsky
parents:
25859
diff
changeset
|
81 |
* @return the detail message string of this {@code HeadlessException} |
be5de84c54a7
8016313: java.awt.Headless exception has no spec since its creation
ssadetsky
parents:
25859
diff
changeset
|
82 |
* instance (which may be {@code null}). |
25162 | 83 |
*/ |
2 | 84 |
public String getMessage() { |
85 |
String superMessage = super.getMessage(); |
|
86 |
String headlessMessage = GraphicsEnvironment.getHeadlessMessage(); |
|
87 |
||
88 |
if (superMessage == null) { |
|
89 |
return headlessMessage; |
|
90 |
} else if (headlessMessage == null) { |
|
91 |
return superMessage; |
|
92 |
} else { |
|
93 |
return superMessage + headlessMessage; |
|
94 |
} |
|
95 |
} |
|
96 |
} |