1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
|
/*
* Copyright (c) 2005, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.awt.peer;
import java.awt.Desktop.Action;
import java.awt.desktop.AboutHandler;
import java.awt.desktop.OpenFilesHandler;
import java.awt.desktop.OpenURIEvent;
import java.awt.desktop.OpenURIHandler;
import java.awt.desktop.PreferencesEvent;
import java.awt.desktop.PreferencesHandler;
import java.awt.desktop.PrintFilesHandler;
import java.awt.desktop.QuitHandler;
import java.awt.desktop.QuitStrategy;
import java.awt.desktop.SystemEventListener;
import java.io.File;
import java.io.IOException;
import java.net.URI;
import javax.swing.JMenuBar;
/**
* The {@code DesktopPeer} interface provides methods for the operation
* of open, edit, print, browse and mail with the given URL or file, by
* launching the associated application.
* <p>
* Each platform has an implementation class for this interface.
*
*/
public interface DesktopPeer {
/**
* Returns whether the given action is supported on the current platform.
* @param action the action type to be tested if it's supported on the
* current platform.
* @return {@code true} if the given action is supported on
* the current platform; {@code false} otherwise.
*/
boolean isSupported(Action action);
/**
* Launches the associated application to open the given file. The
* associated application is registered to be the default file viewer for
* the file type of the given file.
*
* @param file the given file.
* @throws IOException If the given file has no associated application,
* or the associated application fails to be launched.
*/
void open(File file) throws IOException;
/**
* Launches the associated editor and opens the given file for editing. The
* associated editor is registered to be the default editor for the file
* type of the given file.
*
* @param file the given file.
* @throws IOException If the given file has no associated editor, or
* the associated application fails to be launched.
*/
void edit(File file) throws IOException;
/**
* Prints the given file with the native desktop printing facility, using
* the associated application's print command.
*
* @param file the given file.
* @throws IOException If the given file has no associated application
* that can be used to print it.
*/
void print(File file) throws IOException;
/**
* Launches the mail composing window of the user default mail client,
* filling the message fields including to, cc, etc, with the values
* specified by the given mailto URL.
*
* @param mailtoURL represents a mailto URL with specified values of the message.
* The syntax of mailto URL is defined by
* <a href="http://www.ietf.org/rfc/rfc2368.txt">RFC2368: The mailto
* URL scheme</a>
* @throws IOException If the user default mail client is not found,
* or it fails to be launched.
*/
void mail(URI mailtoURL) throws IOException;
/**
* Launches the user default browser to display the given URI.
*
* @param uri the given URI.
* @throws IOException If the user default browser is not found,
* or it fails to be launched.
*/
void browse(URI uri) throws IOException;
/**
* Adds sub-types of {@link SystemEventListener} to listen for notifications
* from the native system.
*
* @param listener listener
* @see java.awt.desktop.AppForegroundListener
* @see java.awt.desktop.AppHiddenListener
* @see java.awt.desktop.AppReopenedListener
* @see java.awt.desktop.ScreenSleepListener
* @see java.awt.desktop.SystemSleepListener
* @see java.awt.desktop.UserSessionListener
*/
default void addAppEventListener(final SystemEventListener listener) {
}
/**
* Removes sub-types of {@link SystemEventListener} to listen for notifications
* from the native system.
*
* @param listener listener
* @see java.awt.desktop.AppForegroundListener
* @see java.awt.desktop.AppHiddenListener
* @see java.awt.desktop.AppReopenedListener
* @see java.awt.desktop.ScreenSleepListener
* @see java.awt.desktop.SystemSleepListener
* @see java.awt.desktop.UserSessionListener
*/
default void removeAppEventListener(final SystemEventListener listener) {
}
/**
* Installs a handler to show a custom About window for your application.
* <p>
* Setting the {@link AboutHandler} to {@code null} reverts it to the
* default behavior.
*
* @param aboutHandler the handler to respond to the
* {@link AboutHandler#handleAbout} )} message
*/
default void setAboutHandler(final AboutHandler aboutHandler) {
}
/**
* Installs a handler to show a custom Preferences window for your
* application.
* <p>
* Setting the {@link PreferencesHandler} to {@code null} reverts it to
* the default behavior
*
* @param preferencesHandler the handler to respond to the
* {@link java.awt.desktop.PreferencesHandler#handlePreferences(PreferencesEvent) }
*/
default void setPreferencesHandler(final PreferencesHandler preferencesHandler) {
}
/**
* Installs the handler which is notified when the application is asked to
* open a list of files.
*
* @param openFileHandler handler
*
*/
default void setOpenFileHandler(final OpenFilesHandler openFileHandler) {
}
/**
* Installs the handler which is notified when the application is asked to
* print a list of files.
*
* @param printFileHandler handler
*/
default void setPrintFileHandler(final PrintFilesHandler printFileHandler) {
}
/**
* Installs the handler which is notified when the application is asked to
* open a URL.
*
* Setting the handler to {@code null} causes all
* {@link OpenURIHandler#openURI(OpenURIEvent)} requests to be
* enqueued until another handler is set.
*
* @param openURIHandler handler
*/
default void setOpenURIHandler(final OpenURIHandler openURIHandler) {
}
/**
* Installs the handler which determines if the application should quit.
*
* @param quitHandler the handler that is called when the application is
* asked to quit
* @see java.awt.Desktop#setQuitHandler(java.awt.desktop.QuitHandler)
*/
default void setQuitHandler(final QuitHandler quitHandler) {
}
/**
* Sets the default strategy used to quit this application. The default is
* calling SYSTEM_EXIT_0.
*
* @param strategy the way this application should be shutdown
*/
default void setQuitStrategy(final QuitStrategy strategy) {
}
/**
* Enables this application to be suddenly terminated.
*
* @see java.awt.Desktop#disableSuddenTermination()
*/
default void enableSuddenTermination() {
}
/**
* Prevents this application from being suddenly terminated.
*
* @see java.awt.Desktop#enableSuddenTermination()
*/
default void disableSuddenTermination() {
}
/**
* Requests this application to move to the foreground.
*
* @param allWindows if all windows of this application should be moved to
* the foreground, or only the foremost one
*/
default void requestForeground(final boolean allWindows) {
}
/**
* Opens the native help viewer application.
*/
default void openHelpViewer() {
}
/**
* Sets the default menu bar to use when there are no active frames.
*
* @param menuBar to use when no other frames are active
*/
default void setDefaultMenuBar(final JMenuBar menuBar) {
}
/**
* Opens a folder containing the {@code file} in a default system file manager.
* @param file the file
* @return returns true if successfully opened
*/
default boolean browseFileDirectory(File file) {
return false;
}
/**
* Moves the specified file to the trash.
*
* @param file the file
* @return returns true if successfully moved the file to the trash.
*/
default boolean moveToTrash(File file) {
return false;
}
}
|