src/java.desktop/share/classes/java/awt/HeadlessException.java
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--
8187443: Forest Consolidation: Move files to unified layout Reviewed-by: darcy, ihse
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     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
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package java.awt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * Thrown when code that is dependent on a keyboard, display, or mouse
90ce3da70b43 Initial load
duke
parents:
diff changeset
    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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
    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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
public class HeadlessException extends UnsupportedOperationException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
     * JDK 1.4 serialVersionUID
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    private static final long serialVersionUID = 167183644944358563L;
25162
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 5506
diff changeset
    45
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 5506
diff changeset
    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
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 5506
diff changeset
    54
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    public HeadlessException() {}
25162
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 5506
diff changeset
    56
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 5506
diff changeset
    57
    /**
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 5506
diff changeset
    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
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 5506
diff changeset
    65
     *
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 5506
diff changeset
    66
     * @param  msg the error message
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 5506
diff changeset
    67
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    public HeadlessException(String msg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        super(msg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    }
25162
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 5506
diff changeset
    71
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 5506
diff changeset
    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
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 5506
diff changeset
    83
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    public String getMessage() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        String superMessage = super.getMessage();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        String headlessMessage = GraphicsEnvironment.getHeadlessMessage();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        if (superMessage == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
            return headlessMessage;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        } else if (headlessMessage == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
            return superMessage;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
            return superMessage + headlessMessage;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
}