Class Launcher
mailto: to the mail program, a file to the program registered for its type, or a file
to the file manager, shown selected in its folder. Reached from a window,
NativeWindow.launcher(), because the system is told which window asked and brings what
it opens in front of it.
window.launcher().openAddress(URI.create("https://example.org/docs"));
window.launcher().openFile(report);
window.launcher().showInFolder(report);
Each call returns at once and its stage completes on the UI thread. true
means the system took what it was handed, which is all a system tells a caller: not that a
program opened, nor that the user saw it. false means it was not handed over (an
address this class refuses, a file that is not there, no program registered, a window with no
desktop under it), and the reason is logged as a warning. UI thread only.
Which addresses. An address often comes from data, and handed to a system as it is,
text can start a program. So openAddress(java.net.URI) takes an absolute address whose scheme is
http, https or mailto, and refuses the rest until the application says,
once and for the process, that its addresses may be of another kind: allowScheme(java.lang.String). A
file: address is never taken: a file is opened by openFile(java.nio.file.Path), whose argument is a
path the application built.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionLauncher(LauncherPeer peer) For a backend: the launcher of one of its windows. -
Method Summary
Modifier and TypeMethodDescriptionstatic voidallowScheme(String scheme) LetsopenAddress(java.net.URI)take addresses of one more scheme, for the whole process: atel:number, the application's own protocol.static booleanWhetheropenAddress(java.net.URI)would hand this address to the system: it is absolute, its scheme is allowed, and a web address names a host.openAddress(URI address) Opens an address in the program the system has for it.Opens a file in the program registered for its type, as a double click in the file manager does.showInFolder(Path file) Shows a file in the file manager, selected in the folder it is in.
-
Field Details
-
NONE
The launcher of a window with no desktop under it (headless, embedded): alwaysfalse.
-
-
Constructor Details
-
Launcher
For a backend: the launcher of one of its windows.- Parameters:
peer- what hands things to the system
-
-
Method Details
-
allowScheme
LetsopenAddress(java.net.URI)take addresses of one more scheme, for the whole process: atel:number, the application's own protocol. Said once where the application starts, since it is a fact about the application and not about one call. Any thread.- Parameters:
scheme- the scheme, without its colon; case does not matter- Throws:
IllegalArgumentException- forfile, whichopenFile(java.nio.file.Path)opens, and for a text that is not a scheme
-
isAllowed
WhetheropenAddress(java.net.URI)would hand this address to the system: it is absolute, its scheme is allowed, and a web address names a host. Says nothing of whether a program is registered for it. Any thread.- Parameters:
address- the address- Returns:
- whether it is one this class takes
-
openAddress
Opens an address in the program the system has for it.- Parameters:
address- an absolute address of an allowed scheme- Returns:
- whether the system took it;
falseat once for an address this class refuses
-
openFile
Opens a file in the program registered for its type, as a double click in the file manager does. For a program file that means running it.- Parameters:
file- the file, or a folder, which opens in the file manager- Returns:
- whether the system took it;
falseat once for a path that does not exist
-
showInFolder
Shows a file in the file manager, selected in the folder it is in. Where the system can open the folder but not select in it, the folder opens and the answer is stilltrue.- Parameters:
file- the file or folder to show- Returns:
- whether the file manager was asked;
falseat once for a path that does not exist
-