src/java.desktop/share/classes/java/awt/Desktop.java
author serb
Wed, 31 Jan 2018 18:13:13 -0800
changeset 51152 edd69f959190
parent 50835 aaf263fe7eba
child 51363 a6fa2016cff1
permissions -rw-r--r--
8191239: Improve desktop file usage Reviewed-by: prr, rhalade, aghaisas
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
51152
edd69f959190 8191239: Improve desktop file usage
serb
parents: 50835
diff changeset
     2
 * Copyright (c) 2005, 2018, 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
44655
06871a50a4b5 8177461: Wrong references are used in the javadoc in the java.desktop module
serb
parents: 43833
diff changeset
    28
import java.awt.desktop.AboutEvent;
36903
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
    29
import java.awt.desktop.AboutHandler;
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
    30
import java.awt.desktop.OpenFilesHandler;
44655
06871a50a4b5 8177461: Wrong references are used in the javadoc in the java.desktop module
serb
parents: 43833
diff changeset
    31
import java.awt.desktop.OpenURIEvent;
36903
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
    32
import java.awt.desktop.OpenURIHandler;
44655
06871a50a4b5 8177461: Wrong references are used in the javadoc in the java.desktop module
serb
parents: 43833
diff changeset
    33
import java.awt.desktop.PreferencesEvent;
36903
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
    34
import java.awt.desktop.PreferencesHandler;
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
    35
import java.awt.desktop.PrintFilesHandler;
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
    36
import java.awt.desktop.QuitHandler;
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
    37
import java.awt.desktop.QuitStrategy;
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
    38
import java.awt.desktop.SystemEventListener;
30471
c1568a2416a8 8074757: Remove java.awt.Toolkit methods which return peer types
serb
parents: 26749
diff changeset
    39
import java.awt.peer.DesktopPeer;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.io.File;
30471
c1568a2416a8 8074757: Remove java.awt.Toolkit methods which return peer types
serb
parents: 26749
diff changeset
    41
import java.io.FilePermission;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.io.IOException;
30471
c1568a2416a8 8074757: Remove java.awt.Toolkit methods which return peer types
serb
parents: 26749
diff changeset
    43
import java.net.URI;
c1568a2416a8 8074757: Remove java.awt.Toolkit methods which return peer types
serb
parents: 26749
diff changeset
    44
import java.net.URISyntaxException;
51152
edd69f959190 8191239: Improve desktop file usage
serb
parents: 50835
diff changeset
    45
import java.net.URL;
edd69f959190 8191239: Improve desktop file usage
serb
parents: 50835
diff changeset
    46
import java.security.AccessController;
edd69f959190 8191239: Improve desktop file usage
serb
parents: 50835
diff changeset
    47
import java.security.PrivilegedAction;
50835
aaf263fe7eba 8205324: Part of java.awt.Desktop.browse(URI) spec is outdated after support of applets was removed
serb
parents: 48715
diff changeset
    48
import java.util.Objects;
30471
c1568a2416a8 8074757: Remove java.awt.Toolkit methods which return peer types
serb
parents: 26749
diff changeset
    49
44655
06871a50a4b5 8177461: Wrong references are used in the javadoc in the java.desktop module
serb
parents: 43833
diff changeset
    50
import javax.swing.JMenuBar;
06871a50a4b5 8177461: Wrong references are used in the javadoc in the java.desktop module
serb
parents: 43833
diff changeset
    51
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
import sun.awt.SunToolkit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
import sun.security.util.SecurityConstants;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
/**
36903
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
    56
 * The {@code Desktop} class allows interact with various desktop capabilities.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * <p> Supported operations include:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 *   <li>launching the user-default browser to show a specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 *       URI;</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 *   <li>launching the user-default mail client with an optional
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 *       {@code mailto} URI;</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 *   <li>launching a registered application to open, edit or print a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 *       specified file.</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * <p> This class provides methods corresponding to these
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * operations. The methods look for the associated application
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * registered on the current platform, and launch it to handle a URI
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * or file. If there is no associated application or the associated
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * application fails to be launched, an exception is thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 *
36903
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
    74
 * Please see {@link Desktop.Action} for the full list of supported operations
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
    75
 * and capabilities.
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
    76
 *
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
    77
 * <p> An application is registered to a URI or file type.
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
    78
 * The mechanism of registering, accessing, and
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * launching the associated application is platform-dependent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * <p> Each operation is an action type represented by the {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * Desktop.Action} class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 * <p> Note: when some action is invoked and the associated
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 * application is executed, it will be executed on the same system as
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 * the one on which the Java application was launched.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 *
48715
4b62b815b4f4 8195852: The usage of permissions in Desktop API should be clarified
serb
parents: 47497
diff changeset
    88
 * <p> Note: the methods in the {@code Desktop} class may require
4b62b815b4f4 8195852: The usage of permissions in Desktop API should be clarified
serb
parents: 47497
diff changeset
    89
 * platform-dependent permissions in addition to those described in the
4b62b815b4f4 8195852: The usage of permissions in Desktop API should be clarified
serb
parents: 47497
diff changeset
    90
 * specification.
4b62b815b4f4 8195852: The usage of permissions in Desktop API should be clarified
serb
parents: 47497
diff changeset
    91
 *
36903
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
    92
 * @see Action
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
    93
 *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 * @author Armin Chen
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 * @author George Zhang
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
public class Desktop {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * Represents an action type.  Each platform supports a different
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * set of actions.  You may use the {@link Desktop#isSupported}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * method to determine if the given action is supported by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * current platform.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * @see java.awt.Desktop#isSupported(java.awt.Desktop.Action)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    public static enum Action {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
         * Represents an "open" action.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
         * @see Desktop#open(java.io.File)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        OPEN,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
         * Represents an "edit" action.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
         * @see Desktop#edit(java.io.File)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        EDIT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
         * Represents a "print" action.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
         * @see Desktop#print(java.io.File)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        PRINT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
         * Represents a "mail" action.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
         * @see Desktop#mail()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
         * @see Desktop#mail(java.net.URI)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        MAIL,
36903
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   130
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
         * Represents a "browse" action.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
         * @see Desktop#browse(java.net.URI)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
         */
36903
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   135
        BROWSE,
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   136
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   137
        /**
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   138
         * Represents an AppForegroundListener
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   139
         * @see java.awt.desktop.AppForegroundListener
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   140
         * @since 9
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   141
         */
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   142
        APP_EVENT_FOREGROUND,
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   143
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   144
        /**
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   145
         * Represents an AppHiddenListener
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   146
         * @see java.awt.desktop.AppHiddenListener
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   147
         * @since 9
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   148
         */
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   149
        APP_EVENT_HIDDEN,
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   150
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   151
        /**
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   152
         * Represents an AppReopenedListener
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   153
         * @see java.awt.desktop.AppReopenedListener
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   154
         * @since 9
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   155
         */
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   156
        APP_EVENT_REOPENED,
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   157
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   158
        /**
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   159
         * Represents a ScreenSleepListener
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   160
         * @see java.awt.desktop.ScreenSleepListener
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   161
         * @since 9
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   162
         */
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   163
        APP_EVENT_SCREEN_SLEEP,
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   164
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   165
        /**
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   166
         * Represents a SystemSleepListener
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   167
         * @see java.awt.desktop.SystemSleepListener
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   168
         * @since 9
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   169
         */
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   170
        APP_EVENT_SYSTEM_SLEEP,
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   171
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   172
        /**
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   173
         * Represents a UserSessionListener
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   174
         * @see java.awt.desktop.UserSessionListener
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   175
         * @since 9
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   176
         */
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   177
        APP_EVENT_USER_SESSION,
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   178
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   179
        /**
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   180
         * Represents an AboutHandler
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   181
         * @see #setAboutHandler(java.awt.desktop.AboutHandler)
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   182
         * @since 9
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   183
         */
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   184
        APP_ABOUT,
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   185
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   186
        /**
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   187
         * Represents a PreferencesHandler
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   188
         * @see #setPreferencesHandler(java.awt.desktop.PreferencesHandler)
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   189
         * @since 9
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   190
         */
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   191
        APP_PREFERENCES,
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   192
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   193
        /**
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   194
         * Represents an OpenFilesHandler
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   195
         * @see #setOpenFileHandler(java.awt.desktop.OpenFilesHandler)
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   196
         * @since 9
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   197
         */
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   198
        APP_OPEN_FILE,
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   199
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   200
        /**
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   201
         * Represents a PrintFilesHandler
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   202
         * @see #setPrintFileHandler(java.awt.desktop.PrintFilesHandler)
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   203
         * @since 9
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   204
         */
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   205
        APP_PRINT_FILE,
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   206
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   207
        /**
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   208
         * Represents an OpenURIHandler
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   209
         * @see #setOpenURIHandler(java.awt.desktop.OpenURIHandler)
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   210
         * @since 9
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   211
         */
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   212
        APP_OPEN_URI,
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   213
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   214
        /**
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   215
         * Represents a QuitHandler
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   216
         * @see #setQuitHandler(java.awt.desktop.QuitHandler)
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   217
         * @since 9
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   218
         */
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   219
        APP_QUIT_HANDLER,
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   220
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   221
        /**
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   222
         * Represents a QuitStrategy
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   223
         * @see #setQuitStrategy(java.awt.desktop.QuitStrategy)
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   224
         * @since 9
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   225
         */
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   226
        APP_QUIT_STRATEGY,
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   227
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   228
        /**
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   229
         * Represents a SuddenTermination
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   230
         * @see #enableSuddenTermination()
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   231
         * @since 9
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   232
         */
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   233
        APP_SUDDEN_TERMINATION,
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   234
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   235
        /**
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   236
         * Represents a requestForeground
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   237
         * @see #requestForeground(boolean)
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   238
         * @since 9
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   239
         */
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   240
        APP_REQUEST_FOREGROUND,
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   241
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   242
        /**
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   243
         * Represents a HelpViewer
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   244
         * @see #openHelpViewer()
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   245
         * @since 9
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   246
         */
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   247
        APP_HELP_VIEWER,
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   248
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   249
        /**
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   250
         * Represents a menu bar
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   251
         * @see #setDefaultMenuBar(javax.swing.JMenuBar)
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   252
         * @since 9
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   253
         */
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   254
        APP_MENU_BAR,
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   255
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   256
        /**
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   257
         * Represents a browse file directory
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   258
         * @see #browseFileDirectory(java.io.File)
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   259
         * @since 9
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   260
         */
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   261
        BROWSE_FILE_DIR,
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   262
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   263
        /**
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   264
         * Represents a move to trash
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   265
         * @see #moveToTrash(java.io.File)
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   266
         * @since 9
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   267
         */
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   268
        MOVE_TO_TRASH
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    private DesktopPeer peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * Suppresses default constructor for noninstantiability.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    private Desktop() {
30471
c1568a2416a8 8074757: Remove java.awt.Toolkit methods which return peer types
serb
parents: 26749
diff changeset
   277
        Toolkit defaultToolkit = Toolkit.getDefaultToolkit();
c1568a2416a8 8074757: Remove java.awt.Toolkit methods which return peer types
serb
parents: 26749
diff changeset
   278
        // same cast as in isDesktopSupported()
c1568a2416a8 8074757: Remove java.awt.Toolkit methods which return peer types
serb
parents: 26749
diff changeset
   279
        if (defaultToolkit instanceof SunToolkit) {
c1568a2416a8 8074757: Remove java.awt.Toolkit methods which return peer types
serb
parents: 26749
diff changeset
   280
            peer = ((SunToolkit) defaultToolkit).createDesktopPeer(this);
c1568a2416a8 8074757: Remove java.awt.Toolkit methods which return peer types
serb
parents: 26749
diff changeset
   281
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
41402
9ff91b2cd7a7 8164536: enableSuddenTermination() - Not throws SecurityException if a security manager exists and it will not allow the caller to invoke System.exit
azvegint
parents: 39838
diff changeset
   284
    private void checkEventsProcessingPermission() {
9ff91b2cd7a7 8164536: enableSuddenTermination() - Not throws SecurityException if a security manager exists and it will not allow the caller to invoke System.exit
azvegint
parents: 39838
diff changeset
   285
        SecurityManager sm = System.getSecurityManager();
9ff91b2cd7a7 8164536: enableSuddenTermination() - Not throws SecurityException if a security manager exists and it will not allow the caller to invoke System.exit
azvegint
parents: 39838
diff changeset
   286
        if (sm != null) {
9ff91b2cd7a7 8164536: enableSuddenTermination() - Not throws SecurityException if a security manager exists and it will not allow the caller to invoke System.exit
azvegint
parents: 39838
diff changeset
   287
            sm.checkPermission(new RuntimePermission(
9ff91b2cd7a7 8164536: enableSuddenTermination() - Not throws SecurityException if a security manager exists and it will not allow the caller to invoke System.exit
azvegint
parents: 39838
diff changeset
   288
                    "canProcessApplicationEvents"));
9ff91b2cd7a7 8164536: enableSuddenTermination() - Not throws SecurityException if a security manager exists and it will not allow the caller to invoke System.exit
azvegint
parents: 39838
diff changeset
   289
        }
9ff91b2cd7a7 8164536: enableSuddenTermination() - Not throws SecurityException if a security manager exists and it will not allow the caller to invoke System.exit
azvegint
parents: 39838
diff changeset
   290
    }
9ff91b2cd7a7 8164536: enableSuddenTermination() - Not throws SecurityException if a security manager exists and it will not allow the caller to invoke System.exit
azvegint
parents: 39838
diff changeset
   291
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    /**
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 30471
diff changeset
   293
     * Returns the {@code Desktop} instance of the current
36903
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   294
     * desktop context. On some platforms the Desktop API may not be
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     * supported; use the {@link #isDesktopSupported} method to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     * determine if the current desktop is supported.
36903
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   297
     * @return the Desktop instance
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     * @throws HeadlessException if {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     * GraphicsEnvironment#isHeadless()} returns {@code true}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     * @throws UnsupportedOperationException if this class is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     * supported on the current platform
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     * @see #isDesktopSupported()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     * @see java.awt.GraphicsEnvironment#isHeadless
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    public static synchronized Desktop getDesktop(){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        if (GraphicsEnvironment.isHeadless()) throw new HeadlessException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        if (!Desktop.isDesktopSupported()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
            throw new UnsupportedOperationException("Desktop API is not " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
                                                    "supported on the current platform");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        sun.awt.AppContext context = sun.awt.AppContext.getAppContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        Desktop desktop = (Desktop)context.get(Desktop.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        if (desktop == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
            desktop = new Desktop();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
            context.put(Desktop.class, desktop);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        return desktop;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * Tests whether this class is supported on the current platform.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     * If it's supported, use {@link #getDesktop()} to retrieve an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     * instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     *
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 30471
diff changeset
   328
     * @return {@code true} if this class is supported on the
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 30471
diff changeset
   329
     *         current platform; {@code false} otherwise
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     * @see #getDesktop()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
    public static boolean isDesktopSupported(){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        Toolkit defaultToolkit = Toolkit.getDefaultToolkit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        if (defaultToolkit instanceof SunToolkit) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
            return ((SunToolkit)defaultToolkit).isDesktopSupported();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     * Tests whether an action is supported on the current platform.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     * <p>Even when the platform supports an action, a file or URI may
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     * not have a registered application for the action.  For example,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     * most of the platforms support the {@link Desktop.Action#OPEN}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     * action.  But for a specific file, there may not be an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     * application registered to open it.  In this case, {@link
43833
205cd5dd58a9 8166313: JavaDoc mentions AppEvent subclasses as inner class of AppEvent
azvegint
parents: 41402
diff changeset
   348
     * #isSupported(Action)} may return {@code true}, but the corresponding
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     * action method will throw an {@link IOException}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     * @param action the specified {@link Action}
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 30471
diff changeset
   352
     * @return {@code true} if the specified action is supported on
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 30471
diff changeset
   353
     *         the current platform; {@code false} otherwise
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     * @see Desktop.Action
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    public boolean isSupported(Action action) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        return peer.isSupported(action);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     * Checks if the file is a valid file and readable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     * @throws SecurityException If a security manager exists and its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     *         {@link SecurityManager#checkRead(java.lang.String)} method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     *         denies read access to the file
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     * @throws NullPointerException if file is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     * @throws IllegalArgumentException if file doesn't exist
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     */
51152
edd69f959190 8191239: Improve desktop file usage
serb
parents: 50835
diff changeset
   369
    private static void checkFileValidation(File file) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
        if (!file.exists()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
            throw new IllegalArgumentException("The file: "
36903
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   372
                    + file.getPath() + " doesn't exist.");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     * Checks if the action type is supported.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     * @param actionType the action type in question
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     * @throws UnsupportedOperationException if the specified action type is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
     *         supported on the current platform
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
    private void checkActionSupport(Action actionType){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        if (!isSupported(actionType)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
            throw new UnsupportedOperationException("The " + actionType.name()
36903
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   386
                    + " action is not supported on the current platform!");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
    /**
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 30471
diff changeset
   392
     *  Calls to the security manager's {@code checkPermission} method with
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 30471
diff changeset
   393
     *  an {@code AWTPermission("showWindowWithoutWarningBanner")}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     *  permission.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
    private void checkAWTPermission(){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        SecurityManager sm = System.getSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        if (sm != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
            sm.checkPermission(new AWTPermission(
36903
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   400
                    "showWindowWithoutWarningBanner"));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     * Launches the associated application to open the file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     * <p> If the specified file is a directory, the file manager of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     * the current platform is launched to open it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     * @param file the file to be opened with the associated application
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     * @throws NullPointerException if {@code file} is {@code null}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     * @throws IllegalArgumentException if the specified file doesn't
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     * exist
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     * @throws UnsupportedOperationException if the current platform
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     * does not support the {@link Desktop.Action#OPEN} action
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     * @throws IOException if the specified file has no associated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
     * application or the associated application fails to be launched
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     * @throws SecurityException if a security manager exists and its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     * {@link java.lang.SecurityManager#checkRead(java.lang.String)}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     * method denies read access to the file, or it denies the
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 30471
diff changeset
   421
     * {@code AWTPermission("showWindowWithoutWarningBanner")}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
     * permission, or the calling thread is not allowed to create a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
     * subprocess
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
     * @see java.awt.AWTPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
    public void open(File file) throws IOException {
51152
edd69f959190 8191239: Improve desktop file usage
serb
parents: 50835
diff changeset
   427
        file = new File(file.getPath());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
        checkAWTPermission();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        checkExec();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        checkActionSupport(Action.OPEN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        checkFileValidation(file);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        peer.open(file);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     * Launches the associated editor application and opens a file for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     * editing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
     * @param file the file to be opened for editing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
     * @throws NullPointerException if the specified file is {@code null}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
     * @throws IllegalArgumentException if the specified file doesn't
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
     * exist
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
     * @throws UnsupportedOperationException if the current platform
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
     * does not support the {@link Desktop.Action#EDIT} action
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
     * @throws IOException if the specified file has no associated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
     * editor, or the associated application fails to be launched
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
     * @throws SecurityException if a security manager exists and its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
     * {@link java.lang.SecurityManager#checkRead(java.lang.String)}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
     * method denies read access to the file, or {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
     * java.lang.SecurityManager#checkWrite(java.lang.String)} method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
     * denies write access to the file, or it denies the
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 30471
diff changeset
   453
     * {@code AWTPermission("showWindowWithoutWarningBanner")}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
     * permission, or the calling thread is not allowed to create a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
     * subprocess
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
     * @see java.awt.AWTPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
    public void edit(File file) throws IOException {
51152
edd69f959190 8191239: Improve desktop file usage
serb
parents: 50835
diff changeset
   459
        file = new File(file.getPath());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
        checkAWTPermission();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
        checkExec();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
        checkActionSupport(Action.EDIT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
        file.canWrite();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        checkFileValidation(file);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        peer.edit(file);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
     * Prints a file with the native desktop printing facility, using
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
     * the associated application's print command.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
     * @param file the file to be printed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
     * @throws NullPointerException if the specified file is {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
     * null}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
     * @throws IllegalArgumentException if the specified file doesn't
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
     * exist
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
     * @throws UnsupportedOperationException if the current platform
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
     *         does not support the {@link Desktop.Action#PRINT} action
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
     * @throws IOException if the specified file has no associated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
     * application that can be used to print it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
     * @throws SecurityException if a security manager exists and its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
     * {@link java.lang.SecurityManager#checkRead(java.lang.String)}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
     * method denies read access to the file, or its {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
     * java.lang.SecurityManager#checkPrintJobAccess()} method denies
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
     * the permission to print the file, or the calling thread is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
     * allowed to create a subprocess
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
    public void print(File file) throws IOException {
51152
edd69f959190 8191239: Improve desktop file usage
serb
parents: 50835
diff changeset
   490
        file = new File(file.getPath());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
        checkExec();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
        SecurityManager sm = System.getSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
        if (sm != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
            sm.checkPrintJobAccess();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
        checkActionSupport(Action.PRINT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
        checkFileValidation(file);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
        peer.print(file);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
     * Launches the default browser to display a {@code URI}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
     * If the default browser is not able to handle the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
     * {@code URI}, the application registered for handling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
     * {@code URIs} of the specified type is invoked. The application
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
     * is determined from the protocol and path of the {@code URI}, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
     * defined by the {@code URI} class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
     * @param uri the URI to be displayed in the user default browser
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
     * @throws NullPointerException if {@code uri} is {@code null}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
     * @throws UnsupportedOperationException if the current platform
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
     * does not support the {@link Desktop.Action#BROWSE} action
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
     * @throws IOException if the user default browser is not found,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
     * or it fails to be launched, or the default handler application
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
     * failed to be launched
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
     * @throws SecurityException if a security manager exists and it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
     * denies the
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 30471
diff changeset
   519
     * {@code AWTPermission("showWindowWithoutWarningBanner")}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
     * permission, or the calling thread is not allowed to create a
50835
aaf263fe7eba 8205324: Part of java.awt.Desktop.browse(URI) spec is outdated after support of applets was removed
serb
parents: 48715
diff changeset
   521
     * subprocess
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
     * @see java.net.URI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
     * @see java.awt.AWTPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
    public void browse(URI uri) throws IOException {
50835
aaf263fe7eba 8205324: Part of java.awt.Desktop.browse(URI) spec is outdated after support of applets was removed
serb
parents: 48715
diff changeset
   526
        checkAWTPermission();
aaf263fe7eba 8205324: Part of java.awt.Desktop.browse(URI) spec is outdated after support of applets was removed
serb
parents: 48715
diff changeset
   527
        checkExec();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
        checkActionSupport(Action.BROWSE);
50835
aaf263fe7eba 8205324: Part of java.awt.Desktop.browse(URI) spec is outdated after support of applets was removed
serb
parents: 48715
diff changeset
   529
        Objects.requireNonNull(uri);
aaf263fe7eba 8205324: Part of java.awt.Desktop.browse(URI) spec is outdated after support of applets was removed
serb
parents: 48715
diff changeset
   530
        peer.browse(uri);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
     * Launches the mail composing window of the user default mail
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
     * client.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
     * @throws UnsupportedOperationException if the current platform
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
     * does not support the {@link Desktop.Action#MAIL} action
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
     * @throws IOException if the user default mail client is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
     * found, or it fails to be launched
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
     * @throws SecurityException if a security manager exists and it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
     * denies the
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 30471
diff changeset
   543
     * {@code AWTPermission("showWindowWithoutWarningBanner")}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
     * permission, or the calling thread is not allowed to create a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
     * subprocess
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
     * @see java.awt.AWTPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
    public void mail() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
        checkAWTPermission();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
        checkExec();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
        checkActionSupport(Action.MAIL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
        URI mailtoURI = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
        try{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
            mailtoURI = new URI("mailto:?");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
            peer.mail(mailtoURI);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
        } catch (URISyntaxException e){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
            // won't reach here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
     * Launches the mail composing window of the user default mail
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
     * client, filling the message fields specified by a {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
     * mailto:} URI.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
     *
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 30471
diff changeset
   566
     * <p> A {@code mailto:} URI can specify message fields
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
     * including <i>"to"</i>, <i>"cc"</i>, <i>"subject"</i>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
     * <i>"body"</i>, etc.  See <a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
     * href="http://www.ietf.org/rfc/rfc2368.txt">The mailto URL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
     * scheme (RFC 2368)</a> for the {@code mailto:} URI specification
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
     * details.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
     * @param mailtoURI the specified {@code mailto:} URI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
     * @throws NullPointerException if the specified URI is {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
     * null}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
     * @throws IllegalArgumentException if the URI scheme is not
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 30471
diff changeset
   577
     *         {@code "mailto"}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
     * @throws UnsupportedOperationException if the current platform
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
     * does not support the {@link Desktop.Action#MAIL} action
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
     * @throws IOException if the user default mail client is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
     * found or fails to be launched
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
     * @throws SecurityException if a security manager exists and it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
     * denies the
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 30471
diff changeset
   584
     * {@code AWTPermission("showWindowWithoutWarningBanner")}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
     * permission, or the calling thread is not allowed to create a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
     * subprocess
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
     * @see java.net.URI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
     * @see java.awt.AWTPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
    public  void mail(URI mailtoURI) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
        checkAWTPermission();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
        checkExec();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
        checkActionSupport(Action.MAIL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
        if (mailtoURI == null) throw new NullPointerException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
        if (!"mailto".equalsIgnoreCase(mailtoURI.getScheme())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
            throw new IllegalArgumentException("URI scheme is not \"mailto\"");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
        peer.mail(mailtoURI);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
    private void checkExec() throws SecurityException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
        SecurityManager sm = System.getSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
        if (sm != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
            sm.checkPermission(new FilePermission("<<ALL FILES>>",
36903
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   607
                    SecurityConstants.FILE_EXECUTE_ACTION));
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   608
        }
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   609
    }
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   610
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   611
    private void checkRead() throws SecurityException {
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   612
        SecurityManager sm = System.getSecurityManager();
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   613
        if (sm != null) {
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   614
            sm.checkPermission(new FilePermission("<<ALL FILES>>",
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   615
                    SecurityConstants.FILE_READ_ACTION));
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   616
        }
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   617
    }
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   618
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   619
    private void checkQuitPermission() {
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   620
        SecurityManager sm = System.getSecurityManager();
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   621
        if (sm != null) {
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   622
            sm.checkExit(0);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
    }
36903
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   625
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   626
    /**
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   627
     * Adds sub-types of {@link SystemEventListener} to listen for notifications
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   628
     * from the native system.
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   629
     *
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   630
     * Has no effect if SystemEventListener's sub-type is unsupported on the current
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   631
     * platform.
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   632
     *
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   633
     * @param listener listener
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   634
     *
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   635
     * @throws SecurityException if a security manager exists and it
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   636
     * denies the
41402
9ff91b2cd7a7 8164536: enableSuddenTermination() - Not throws SecurityException if a security manager exists and it will not allow the caller to invoke System.exit
azvegint
parents: 39838
diff changeset
   637
     * {@code RuntimePermission("canProcessApplicationEvents")}
36903
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   638
     * permission
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   639
     *
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   640
     * @see java.awt.desktop.AppForegroundListener
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   641
     * @see java.awt.desktop.AppHiddenListener
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   642
     * @see java.awt.desktop.AppReopenedListener
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   643
     * @see java.awt.desktop.ScreenSleepListener
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   644
     * @see java.awt.desktop.SystemSleepListener
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   645
     * @see java.awt.desktop.UserSessionListener
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   646
     * @since 9
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   647
     */
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   648
    public void addAppEventListener(final SystemEventListener listener) {
41402
9ff91b2cd7a7 8164536: enableSuddenTermination() - Not throws SecurityException if a security manager exists and it will not allow the caller to invoke System.exit
azvegint
parents: 39838
diff changeset
   649
        checkEventsProcessingPermission();
36903
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   650
        peer.addAppEventListener(listener);
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   651
    }
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   652
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   653
    /**
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   654
     * Removes sub-types of {@link SystemEventListener} to listen for notifications
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   655
     * from the native system.
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   656
     *
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   657
     * Has no effect if SystemEventListener's sub-type is unsupported on  the current
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   658
     * platform.
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   659
     *
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   660
     * @param listener listener
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   661
     *
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   662
     * @throws SecurityException if a security manager exists and it
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   663
     * denies the
41402
9ff91b2cd7a7 8164536: enableSuddenTermination() - Not throws SecurityException if a security manager exists and it will not allow the caller to invoke System.exit
azvegint
parents: 39838
diff changeset
   664
     * {@code RuntimePermission("canProcessApplicationEvents")}
36903
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   665
     * permission
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   666
     *
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   667
     * @see java.awt.desktop.AppForegroundListener
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   668
     * @see java.awt.desktop.AppHiddenListener
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   669
     * @see java.awt.desktop.AppReopenedListener
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   670
     * @see java.awt.desktop.ScreenSleepListener
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   671
     * @see java.awt.desktop.SystemSleepListener
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   672
     * @see java.awt.desktop.UserSessionListener
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   673
     * @since 9
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   674
     */
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   675
    public void removeAppEventListener(final SystemEventListener listener) {
41402
9ff91b2cd7a7 8164536: enableSuddenTermination() - Not throws SecurityException if a security manager exists and it will not allow the caller to invoke System.exit
azvegint
parents: 39838
diff changeset
   676
        checkEventsProcessingPermission();
36903
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   677
        peer.removeAppEventListener(listener);
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   678
    }
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   679
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   680
    /**
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   681
     * Installs a handler to show a custom About window for your application.
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   682
     * <p>
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   683
     * Setting the {@link java.awt.desktop.AboutHandler} to {@code null} reverts it to the
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   684
     * default behavior.
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   685
     *
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   686
     * @param aboutHandler the handler to respond to the
43833
205cd5dd58a9 8166313: JavaDoc mentions AppEvent subclasses as inner class of AppEvent
azvegint
parents: 41402
diff changeset
   687
     * {@link java.awt.desktop.AboutHandler#handleAbout(AboutEvent)} message
36903
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   688
     *
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   689
     * @throws SecurityException if a security manager exists and it
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   690
     * denies the
41402
9ff91b2cd7a7 8164536: enableSuddenTermination() - Not throws SecurityException if a security manager exists and it will not allow the caller to invoke System.exit
azvegint
parents: 39838
diff changeset
   691
     * {@code RuntimePermission("canProcessApplicationEvents")}
36903
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   692
     * permission
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   693
     * @throws UnsupportedOperationException if the current platform
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   694
     * does not support the {@link Desktop.Action#APP_ABOUT} action
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   695
     *
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   696
     * @since 9
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   697
     */
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   698
    public void setAboutHandler(final AboutHandler aboutHandler) {
41402
9ff91b2cd7a7 8164536: enableSuddenTermination() - Not throws SecurityException if a security manager exists and it will not allow the caller to invoke System.exit
azvegint
parents: 39838
diff changeset
   699
        checkEventsProcessingPermission();
36903
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   700
        checkActionSupport(Action.APP_ABOUT);
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   701
        peer.setAboutHandler(aboutHandler);
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   702
    }
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   703
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   704
    /**
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   705
     * Installs a handler to show a custom Preferences window for your
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   706
     * application.
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   707
     * <p>
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   708
     * Setting the {@link PreferencesHandler} to {@code null} reverts it to
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   709
     * the default behavior
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   710
     *
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   711
     * @param preferencesHandler the handler to respond to the
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   712
     * {@link PreferencesHandler#handlePreferences(PreferencesEvent)}
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   713
     *
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   714
     * @throws SecurityException if a security manager exists and it
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   715
     * denies the
41402
9ff91b2cd7a7 8164536: enableSuddenTermination() - Not throws SecurityException if a security manager exists and it will not allow the caller to invoke System.exit
azvegint
parents: 39838
diff changeset
   716
     * {@code RuntimePermission("canProcessApplicationEvents")} permission
36903
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   717
     * @throws UnsupportedOperationException if the current platform
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   718
     * does not support the {@link Desktop.Action#APP_PREFERENCES} action
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   719
     * @since 9
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   720
     */
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   721
    public void setPreferencesHandler(final PreferencesHandler preferencesHandler) {
41402
9ff91b2cd7a7 8164536: enableSuddenTermination() - Not throws SecurityException if a security manager exists and it will not allow the caller to invoke System.exit
azvegint
parents: 39838
diff changeset
   722
        checkEventsProcessingPermission();
36903
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   723
        checkActionSupport(Action.APP_PREFERENCES);
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   724
        peer.setPreferencesHandler(preferencesHandler);
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   725
    }
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   726
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   727
    /**
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   728
     * Installs the handler which is notified when the application is asked to
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   729
     * open a list of files.
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   730
     *
47497
328167c4ef32 8187399: Different problems in the javadoc's links in java.desktop package
serb
parents: 47216
diff changeset
   731
     * @implNote Please note that for macOS, notifications
36903
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   732
     * are only sent if the Java app is a bundled application,
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   733
     * with a {@code CFBundleDocumentTypes} array present in its
47497
328167c4ef32 8187399: Different problems in the javadoc's links in java.desktop package
serb
parents: 47216
diff changeset
   734
     * {@code Info.plist}. Check the
328167c4ef32 8187399: Different problems in the javadoc's links in java.desktop package
serb
parents: 47216
diff changeset
   735
     * <a href="https://developer.apple.com/documentation">
328167c4ef32 8187399: Different problems in the javadoc's links in java.desktop package
serb
parents: 47216
diff changeset
   736
     * Apple Developer Documentation</a> for more information about
328167c4ef32 8187399: Different problems in the javadoc's links in java.desktop package
serb
parents: 47216
diff changeset
   737
     * {@code Info.plist}.
36903
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   738
     *
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   739
     * @param openFileHandler handler
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   740
     *
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   741
     * @throws SecurityException if a security manager exists and its
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   742
     * {@link java.lang.SecurityManager#checkRead(java.lang.String)}
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   743
     * method denies read access to the files, or it denies the
41402
9ff91b2cd7a7 8164536: enableSuddenTermination() - Not throws SecurityException if a security manager exists and it will not allow the caller to invoke System.exit
azvegint
parents: 39838
diff changeset
   744
     * {@code RuntimePermission("canProcessApplicationEvents")}
36903
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   745
     * permission, or the calling thread is not allowed to create a
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   746
     * subprocess
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   747
     * @throws UnsupportedOperationException if the current platform
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   748
     * does not support the {@link Desktop.Action#APP_OPEN_FILE} action
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   749
     * @since 9
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   750
     */
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   751
    public void setOpenFileHandler(final OpenFilesHandler openFileHandler) {
41402
9ff91b2cd7a7 8164536: enableSuddenTermination() - Not throws SecurityException if a security manager exists and it will not allow the caller to invoke System.exit
azvegint
parents: 39838
diff changeset
   752
        checkEventsProcessingPermission();
36903
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   753
        checkExec();
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   754
        checkRead();
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   755
        checkActionSupport(Action.APP_OPEN_FILE);
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   756
        peer.setOpenFileHandler(openFileHandler);
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   757
    }
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   758
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   759
    /**
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   760
     * Installs the handler which is notified when the application is asked to
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   761
     * print a list of files.
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   762
     *
47497
328167c4ef32 8187399: Different problems in the javadoc's links in java.desktop package
serb
parents: 47216
diff changeset
   763
     * @implNote Please note that for macOS, notifications
36903
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   764
     * are only sent if the Java app is a bundled application,
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   765
     * with a {@code CFBundleDocumentTypes} array present in its
47497
328167c4ef32 8187399: Different problems in the javadoc's links in java.desktop package
serb
parents: 47216
diff changeset
   766
     * {@code Info.plist}. Check the
328167c4ef32 8187399: Different problems in the javadoc's links in java.desktop package
serb
parents: 47216
diff changeset
   767
     * <a href="https://developer.apple.com/documentation">
328167c4ef32 8187399: Different problems in the javadoc's links in java.desktop package
serb
parents: 47216
diff changeset
   768
     * Apple Developer Documentation</a> for more information about
328167c4ef32 8187399: Different problems in the javadoc's links in java.desktop package
serb
parents: 47216
diff changeset
   769
     * {@code Info.plist}.
36903
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   770
     *
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   771
     * @param printFileHandler handler
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   772
     * @throws SecurityException if a security manager exists and its
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   773
     * {@link java.lang.SecurityManager#checkPrintJobAccess()} method denies
41402
9ff91b2cd7a7 8164536: enableSuddenTermination() - Not throws SecurityException if a security manager exists and it will not allow the caller to invoke System.exit
azvegint
parents: 39838
diff changeset
   774
     * the permission to print or it denies the
9ff91b2cd7a7 8164536: enableSuddenTermination() - Not throws SecurityException if a security manager exists and it will not allow the caller to invoke System.exit
azvegint
parents: 39838
diff changeset
   775
     * {@code RuntimePermission("canProcessApplicationEvents")} permission
36903
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   776
     * @throws UnsupportedOperationException if the current platform
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   777
     * does not support the {@link Desktop.Action#APP_PRINT_FILE} action
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   778
     * @since 9
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   779
     */
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   780
    public void setPrintFileHandler(final PrintFilesHandler printFileHandler) {
41402
9ff91b2cd7a7 8164536: enableSuddenTermination() - Not throws SecurityException if a security manager exists and it will not allow the caller to invoke System.exit
azvegint
parents: 39838
diff changeset
   781
        checkEventsProcessingPermission();
36903
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   782
        SecurityManager sm = System.getSecurityManager();
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   783
        if (sm != null) {
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   784
            sm.checkPrintJobAccess();
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   785
        }
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   786
        checkActionSupport(Action.APP_PRINT_FILE);
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   787
        peer.setPrintFileHandler(printFileHandler);
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   788
    }
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   789
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   790
    /**
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   791
     * Installs the handler which is notified when the application is asked to
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   792
     * open a URL.
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   793
     *
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   794
     * Setting the handler to {@code null} causes all
43833
205cd5dd58a9 8166313: JavaDoc mentions AppEvent subclasses as inner class of AppEvent
azvegint
parents: 41402
diff changeset
   795
     * {@link OpenURIHandler#openURI(OpenURIEvent)} requests to be
36903
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   796
     * enqueued until another handler is set.
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   797
     *
47497
328167c4ef32 8187399: Different problems in the javadoc's links in java.desktop package
serb
parents: 47216
diff changeset
   798
     * @implNote Please note that for macOS, notifications
36903
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   799
     * are only sent if the Java app is a bundled application,
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   800
     * with a {@code CFBundleDocumentTypes} array present in its
47497
328167c4ef32 8187399: Different problems in the javadoc's links in java.desktop package
serb
parents: 47216
diff changeset
   801
     * {@code Info.plist}. Check the
328167c4ef32 8187399: Different problems in the javadoc's links in java.desktop package
serb
parents: 47216
diff changeset
   802
     * <a href="https://developer.apple.com/documentation">
328167c4ef32 8187399: Different problems in the javadoc's links in java.desktop package
serb
parents: 47216
diff changeset
   803
     * Apple Developer Documentation</a> for more information about
328167c4ef32 8187399: Different problems in the javadoc's links in java.desktop package
serb
parents: 47216
diff changeset
   804
     * {@code Info.plist}.
36903
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   805
     *
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   806
     * @param openURIHandler handler
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   807
     *
41402
9ff91b2cd7a7 8164536: enableSuddenTermination() - Not throws SecurityException if a security manager exists and it will not allow the caller to invoke System.exit
azvegint
parents: 39838
diff changeset
   808
     * {@code RuntimePermission("canProcessApplicationEvents")}
36903
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   809
     * permission, or the calling thread is not allowed to create a
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   810
     * subprocess
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   811
     * @throws UnsupportedOperationException if the current platform
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   812
     * does not support the {@link Desktop.Action#APP_OPEN_URI} action
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   813
     * @since 9
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   814
     */
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   815
    public void setOpenURIHandler(final OpenURIHandler openURIHandler) {
41402
9ff91b2cd7a7 8164536: enableSuddenTermination() - Not throws SecurityException if a security manager exists and it will not allow the caller to invoke System.exit
azvegint
parents: 39838
diff changeset
   816
        checkEventsProcessingPermission();
36903
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   817
        checkExec();
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   818
        checkActionSupport(Action.APP_OPEN_URI);
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   819
        peer.setOpenURIHandler(openURIHandler);
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   820
    }
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   821
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   822
    /**
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   823
     * Installs the handler which determines if the application should quit. The
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   824
     * handler is passed a one-shot {@link java.awt.desktop.QuitResponse} which can cancel or
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   825
     * proceed with the quit. Setting the handler to {@code null} causes
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   826
     * all quit requests to directly perform the default {@link QuitStrategy}.
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   827
     *
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   828
     * @param quitHandler the handler that is called when the application is
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   829
     * asked to quit
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   830
     *
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   831
     * @throws SecurityException if a security manager exists and it
41402
9ff91b2cd7a7 8164536: enableSuddenTermination() - Not throws SecurityException if a security manager exists and it will not allow the caller to invoke System.exit
azvegint
parents: 39838
diff changeset
   832
     * will not allow the caller to invoke {@code System.exit} or it denies the
9ff91b2cd7a7 8164536: enableSuddenTermination() - Not throws SecurityException if a security manager exists and it will not allow the caller to invoke System.exit
azvegint
parents: 39838
diff changeset
   833
     * {@code RuntimePermission("canProcessApplicationEvents")} permission
36903
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   834
     * @throws UnsupportedOperationException if the current platform
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   835
     * does not support the {@link Desktop.Action#APP_QUIT_HANDLER} action
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   836
     * @since 9
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   837
     */
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   838
    public void setQuitHandler(final QuitHandler quitHandler) {
41402
9ff91b2cd7a7 8164536: enableSuddenTermination() - Not throws SecurityException if a security manager exists and it will not allow the caller to invoke System.exit
azvegint
parents: 39838
diff changeset
   839
        checkEventsProcessingPermission();
36903
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   840
        checkQuitPermission();
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   841
        checkActionSupport(Action.APP_QUIT_HANDLER);
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   842
        peer.setQuitHandler(quitHandler);
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   843
    }
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   844
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   845
    /**
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   846
     * Sets the default strategy used to quit this application. The default is
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   847
     * calling SYSTEM_EXIT_0.
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   848
     *
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   849
     * @param strategy the way this application should be shutdown
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   850
     *
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   851
     * @throws SecurityException if a security manager exists and it
41402
9ff91b2cd7a7 8164536: enableSuddenTermination() - Not throws SecurityException if a security manager exists and it will not allow the caller to invoke System.exit
azvegint
parents: 39838
diff changeset
   852
     * will not allow the caller to invoke {@code System.exit} or it denies the
9ff91b2cd7a7 8164536: enableSuddenTermination() - Not throws SecurityException if a security manager exists and it will not allow the caller to invoke System.exit
azvegint
parents: 39838
diff changeset
   853
     * {@code RuntimePermission("canProcessApplicationEvents")} permission
36903
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   854
     * @throws UnsupportedOperationException if the current platform
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   855
     * does not support the {@link Desktop.Action#APP_QUIT_STRATEGY} action
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   856
     * @see QuitStrategy
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   857
     * @since 9
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   858
     */
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   859
    public void setQuitStrategy(final QuitStrategy strategy) {
41402
9ff91b2cd7a7 8164536: enableSuddenTermination() - Not throws SecurityException if a security manager exists and it will not allow the caller to invoke System.exit
azvegint
parents: 39838
diff changeset
   860
        checkEventsProcessingPermission();
36903
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   861
        checkQuitPermission();
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   862
        checkActionSupport(Action.APP_QUIT_STRATEGY);
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   863
        peer.setQuitStrategy(strategy);
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   864
    }
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   865
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   866
    /**
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   867
     * Enables this application to be suddenly terminated.
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   868
     *
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   869
     * Call this method to indicate your application's state is saved, and
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   870
     * requires no notification to be terminated. Letting your application
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   871
     * remain terminatable improves the user experience by avoiding re-paging in
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   872
     * your application when it's asked to quit.
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   873
     *
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   874
     * <b>Note: enabling sudden termination will allow your application to be
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   875
     * quit without notifying your QuitHandler, or running any shutdown
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   876
     * hooks.</b>
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   877
     * E.g. user-initiated Cmd-Q, logout, restart, or shutdown requests will
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   878
     * effectively "kill -KILL" your application.
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   879
     *
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   880
     * @throws SecurityException if a security manager exists and it
41402
9ff91b2cd7a7 8164536: enableSuddenTermination() - Not throws SecurityException if a security manager exists and it will not allow the caller to invoke System.exit
azvegint
parents: 39838
diff changeset
   881
     * will not allow the caller to invoke {@code System.exit} or it denies the
9ff91b2cd7a7 8164536: enableSuddenTermination() - Not throws SecurityException if a security manager exists and it will not allow the caller to invoke System.exit
azvegint
parents: 39838
diff changeset
   882
     * {@code RuntimePermission("canProcessApplicationEvents")} permission
36903
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   883
     * @throws UnsupportedOperationException if the current platform
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   884
     * does not support the {@link Desktop.Action#APP_SUDDEN_TERMINATION} action
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   885
     * @see #disableSuddenTermination()
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   886
     * @since 9
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   887
     */
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   888
    public void enableSuddenTermination() {
41402
9ff91b2cd7a7 8164536: enableSuddenTermination() - Not throws SecurityException if a security manager exists and it will not allow the caller to invoke System.exit
azvegint
parents: 39838
diff changeset
   889
        checkEventsProcessingPermission();
36903
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   890
        checkQuitPermission();
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   891
        checkActionSupport(Action.APP_SUDDEN_TERMINATION);
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   892
        peer.enableSuddenTermination();
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   893
    }
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   894
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   895
    /**
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   896
     * Prevents this application from being suddenly terminated.
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   897
     *
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   898
     * Call this method to indicate that your application has unsaved state, and
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   899
     * may not be terminated without notification.
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   900
     *
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   901
     * @throws SecurityException if a security manager exists and it
41402
9ff91b2cd7a7 8164536: enableSuddenTermination() - Not throws SecurityException if a security manager exists and it will not allow the caller to invoke System.exit
azvegint
parents: 39838
diff changeset
   902
     * will not allow the caller to invoke {@code System.exit} or it denies the
9ff91b2cd7a7 8164536: enableSuddenTermination() - Not throws SecurityException if a security manager exists and it will not allow the caller to invoke System.exit
azvegint
parents: 39838
diff changeset
   903
     * {@code RuntimePermission("canProcessApplicationEvents")} permission
36903
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   904
     * @throws UnsupportedOperationException if the current platform
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   905
     * does not support the {@link Desktop.Action#APP_SUDDEN_TERMINATION} action
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   906
     * @see #enableSuddenTermination()
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   907
     * @since 9
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   908
     */
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   909
    public void disableSuddenTermination() {
41402
9ff91b2cd7a7 8164536: enableSuddenTermination() - Not throws SecurityException if a security manager exists and it will not allow the caller to invoke System.exit
azvegint
parents: 39838
diff changeset
   910
        checkEventsProcessingPermission();
36903
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   911
        checkQuitPermission();
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   912
        checkActionSupport(Action.APP_SUDDEN_TERMINATION);
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   913
        peer.disableSuddenTermination();
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   914
    }
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   915
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   916
    /**
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   917
     * Requests this application to move to the foreground.
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   918
     *
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   919
     * @param allWindows if all windows of this application should be moved to
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   920
     * the foreground, or only the foremost one
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   921
     * @throws SecurityException if a security manager exists and it denies the
41402
9ff91b2cd7a7 8164536: enableSuddenTermination() - Not throws SecurityException if a security manager exists and it will not allow the caller to invoke System.exit
azvegint
parents: 39838
diff changeset
   922
     * {@code RuntimePermission("canProcessApplicationEvents")} permission.
36903
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   923
     * @throws UnsupportedOperationException if the current platform
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   924
     * does not support the {@link Desktop.Action#APP_REQUEST_FOREGROUND} action
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   925
     * @since 9
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   926
     */
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   927
    public void requestForeground(final boolean allWindows) {
41402
9ff91b2cd7a7 8164536: enableSuddenTermination() - Not throws SecurityException if a security manager exists and it will not allow the caller to invoke System.exit
azvegint
parents: 39838
diff changeset
   928
        checkEventsProcessingPermission();
36903
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   929
        checkActionSupport(Action.APP_REQUEST_FOREGROUND);
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   930
        peer.requestForeground(allWindows);
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   931
    }
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   932
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   933
    /**
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   934
     * Opens the native help viewer application.
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   935
     *
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   936
     * @implNote Please note that for Mac OS, it opens the native help viewer
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   937
     * application if a Help Book has been added to the application bundler
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   938
     * and registered in the Info.plist with CFBundleHelpBookFolder
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   939
     *
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   940
     * @throws SecurityException if a security manager exists and it denies the
41402
9ff91b2cd7a7 8164536: enableSuddenTermination() - Not throws SecurityException if a security manager exists and it will not allow the caller to invoke System.exit
azvegint
parents: 39838
diff changeset
   941
     * {@code RuntimePermission("canProcessApplicationEvents")} permission.
36903
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   942
     * @throws UnsupportedOperationException if the current platform
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   943
     * does not support the {@link Desktop.Action#APP_HELP_VIEWER} action
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   944
     * @since 9
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   945
     */
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   946
    public void openHelpViewer() {
51152
edd69f959190 8191239: Improve desktop file usage
serb
parents: 50835
diff changeset
   947
        checkAWTPermission();
edd69f959190 8191239: Improve desktop file usage
serb
parents: 50835
diff changeset
   948
        checkExec();
41402
9ff91b2cd7a7 8164536: enableSuddenTermination() - Not throws SecurityException if a security manager exists and it will not allow the caller to invoke System.exit
azvegint
parents: 39838
diff changeset
   949
        checkEventsProcessingPermission();
36903
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   950
        checkActionSupport(Action.APP_HELP_VIEWER);
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   951
        peer.openHelpViewer();
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   952
    }
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   953
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   954
    /**
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   955
     * Sets the default menu bar to use when there are no active frames.
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   956
     *
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   957
     * @param menuBar to use when no other frames are active
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   958
     * @throws SecurityException if a security manager exists and it denies the
41402
9ff91b2cd7a7 8164536: enableSuddenTermination() - Not throws SecurityException if a security manager exists and it will not allow the caller to invoke System.exit
azvegint
parents: 39838
diff changeset
   959
     * {@code RuntimePermission("canProcessApplicationEvents")} permission.
36903
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   960
     * @throws UnsupportedOperationException if the current platform
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   961
     * does not support the {@link Desktop.Action#APP_MENU_BAR} action
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   962
     * @since 9
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   963
     */
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   964
    public void setDefaultMenuBar(final JMenuBar menuBar) {
41402
9ff91b2cd7a7 8164536: enableSuddenTermination() - Not throws SecurityException if a security manager exists and it will not allow the caller to invoke System.exit
azvegint
parents: 39838
diff changeset
   965
        checkEventsProcessingPermission();
36903
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   966
        checkActionSupport(Action.APP_MENU_BAR);
47173
948b0623c6d6 8178448: MenuBar item handler fired twice
azvegint
parents: 44768
diff changeset
   967
948b0623c6d6 8178448: MenuBar item handler fired twice
azvegint
parents: 44768
diff changeset
   968
        if (menuBar != null) {
948b0623c6d6 8178448: MenuBar item handler fired twice
azvegint
parents: 44768
diff changeset
   969
            Container parent = menuBar.getParent();
948b0623c6d6 8178448: MenuBar item handler fired twice
azvegint
parents: 44768
diff changeset
   970
            if (parent != null) {
948b0623c6d6 8178448: MenuBar item handler fired twice
azvegint
parents: 44768
diff changeset
   971
                parent.remove(menuBar);
948b0623c6d6 8178448: MenuBar item handler fired twice
azvegint
parents: 44768
diff changeset
   972
                menuBar.updateUI();
948b0623c6d6 8178448: MenuBar item handler fired twice
azvegint
parents: 44768
diff changeset
   973
            }
948b0623c6d6 8178448: MenuBar item handler fired twice
azvegint
parents: 44768
diff changeset
   974
        }
948b0623c6d6 8178448: MenuBar item handler fired twice
azvegint
parents: 44768
diff changeset
   975
36903
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   976
        peer.setDefaultMenuBar(menuBar);
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   977
    }
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   978
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   979
    /**
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   980
     * Opens a folder containing the {@code file} and selects it
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   981
     * in a default system file manager.
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   982
     * @param file the file
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   983
     * @throws SecurityException If a security manager exists and its
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   984
     *         {@link SecurityManager#checkRead(java.lang.String)} method
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   985
     *         denies read access to the file
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   986
     * @throws UnsupportedOperationException if the current platform
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   987
     *         does not support the {@link Desktop.Action#BROWSE_FILE_DIR} action
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   988
     * @throws NullPointerException if {@code file} is {@code null}
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   989
     * @throws IllegalArgumentException if the specified file doesn't
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   990
     * exist
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   991
     * @since 9
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   992
     */
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   993
    public void browseFileDirectory(File file) {
51152
edd69f959190 8191239: Improve desktop file usage
serb
parents: 50835
diff changeset
   994
        file = new File(file.getPath());
edd69f959190 8191239: Improve desktop file usage
serb
parents: 50835
diff changeset
   995
        checkAWTPermission();
edd69f959190 8191239: Improve desktop file usage
serb
parents: 50835
diff changeset
   996
        checkExec();
36903
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   997
        checkActionSupport(Action.BROWSE_FILE_DIR);
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
   998
        checkFileValidation(file);
51152
edd69f959190 8191239: Improve desktop file usage
serb
parents: 50835
diff changeset
   999
        File parentFile = file.getParentFile();
edd69f959190 8191239: Improve desktop file usage
serb
parents: 50835
diff changeset
  1000
        if (parentFile == null || !parentFile.exists()) {
edd69f959190 8191239: Improve desktop file usage
serb
parents: 50835
diff changeset
  1001
            throw new IllegalArgumentException("Parent folder doesn't exist");
edd69f959190 8191239: Improve desktop file usage
serb
parents: 50835
diff changeset
  1002
        }
36903
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
  1003
        peer.browseFileDirectory(file);
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
  1004
    }
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
  1005
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
  1006
    /**
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
  1007
     * Moves the specified file to the trash.
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
  1008
     *
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
  1009
     * @param file the file
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
  1010
     * @return returns true if successfully moved the file to the trash.
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
  1011
     * @throws SecurityException If a security manager exists and its
39838
69e15ad7f51a 8155515: Desktop.moveToTrash() javadoc issue
azvegint
parents: 36903
diff changeset
  1012
     *         {@link SecurityManager#checkDelete(java.lang.String)} method
69e15ad7f51a 8155515: Desktop.moveToTrash() javadoc issue
azvegint
parents: 36903
diff changeset
  1013
     *         denies deletion of the file
36903
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
  1014
     * @throws UnsupportedOperationException if the current platform
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
  1015
     *         does not support the {@link Desktop.Action#MOVE_TO_TRASH} action
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
  1016
     * @throws NullPointerException if {@code file} is {@code null}
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
  1017
     * @throws IllegalArgumentException if the specified file doesn't
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
  1018
     * exist
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
  1019
     *
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
  1020
     * @since 9
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
  1021
     */
51152
edd69f959190 8191239: Improve desktop file usage
serb
parents: 50835
diff changeset
  1022
    public boolean moveToTrash(File file) {
edd69f959190 8191239: Improve desktop file usage
serb
parents: 50835
diff changeset
  1023
        file = new File(file.getPath());
edd69f959190 8191239: Improve desktop file usage
serb
parents: 50835
diff changeset
  1024
        SecurityManager sm = System.getSecurityManager();
edd69f959190 8191239: Improve desktop file usage
serb
parents: 50835
diff changeset
  1025
        if (sm != null) {
edd69f959190 8191239: Improve desktop file usage
serb
parents: 50835
diff changeset
  1026
            sm.checkDelete(file.getPath());
edd69f959190 8191239: Improve desktop file usage
serb
parents: 50835
diff changeset
  1027
        }
36903
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
  1028
        checkActionSupport(Action.MOVE_TO_TRASH);
51152
edd69f959190 8191239: Improve desktop file usage
serb
parents: 50835
diff changeset
  1029
        final File finalFile = file;
edd69f959190 8191239: Improve desktop file usage
serb
parents: 50835
diff changeset
  1030
        AccessController.doPrivileged((PrivilegedAction<?>) () -> {
edd69f959190 8191239: Improve desktop file usage
serb
parents: 50835
diff changeset
  1031
            checkFileValidation(finalFile);
edd69f959190 8191239: Improve desktop file usage
serb
parents: 50835
diff changeset
  1032
            return null;
edd69f959190 8191239: Improve desktop file usage
serb
parents: 50835
diff changeset
  1033
        });
36903
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
  1034
        return peer.moveToTrash(file);
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents: 35667
diff changeset
  1035
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
}