URLLauncherCertificatepublic class URLLauncher extends Object
This method is used to handle opening of URLs. All URLs are
opened with an external web browser via BrowserFactory, but
action: URLs are handled specially.
An action: URL activates an Actions actionPerformed
method, so it is equivalent to selecting a menu item or pressing a button.
Before an action can be called as URL, it must be made known using addAction(java.lang.String, javax.swing.Action),
for example:
It is then possible to launch the action by invoking
class CoolAction extends AbstractAction {
public CoolAction() {
super();
putValue(NAME, "Cool thing...");
URLLauncher.addAction("cool", this);
}
public void actionPerformed(ActionEvent e) {
System.out.println("Cool down "+e.getActionCommand());
}
}
URLLauncher.openURL("action:cool").
Actions can have an argument specified in brackets, which sets the
ActionEvent's command. So when
URLLauncher.openURL("action:cool(please)") would be invoked,
CoolAction's actionPerformed method would print
"Cool down please".
The API is compatible with BareBonesBrowserLaunch (original version), so this could be used as a drop-in replacement to add action-handling.
| Modifier and Type | Field | Description |
|---|---|---|
protected static HashMap<String,Action> |
actions |
list of registered actions
|
| Constructor | Description |
|---|---|
URLLauncher() |
| Modifier and Type | Method | Description |
|---|---|---|
static void |
addAction(String name,
Action a) |
Add an Action to the list of recognised actions.
|
static Action |
getAction(String name) |
Return a previously added action
|
static void |
openURL(String surl) |
Open a string URL
|
static void |
openURL(String surl,
Component parent) |
Open a string URL
|
static void |
openURL(URL url) |
Open an URL
|
static void |
openURL(URL url,
Component parent) |
Open a URL
|
static void |
performAction(String action,
Component parent) |
Perform an action.
|
protected static void |
runBrowser(String location,
Component parent) |
Open the URL in an external web browser.
|
protected static void runBrowser(String location, Component parent)
public static void openURL(URL url, Component parent)
url - url to openparent - parent component for error dialogpublic static void openURL(String surl, Component parent)
surl - url to open (as String)parent - parent component for error dialogpublic static void openURL(URL url)
This is equal to openURL(url, null)
so any error dialog will have no parent.
url - url to openpublic static void openURL(String surl)
This is equal to openURL(url, null)
so any error dialog will have no parent.
surl - url to open (as String)public static void performAction(String action, Component parent)
This method is called for each action: URL, it calls
ActionListener.actionPerformed(java.awt.event.ActionEvent) of the specified action.
If the action is not found in the list of known actions, an error dialog is shown.
action - name of action to performparent - parentpublic static void addAction(String name, Action a)
It is suggested to run this in an Action's constructor like this:
See also this class's description.
class MyAction extends AbstractAction {
public MyAction() {
super("MyAction");
ActionHandler.addAction("myaction", this);
}
public void actionPerformed(ActionEvent e) {
// ...
}
}
name - name in url, e.g. "myaction" to respond to url "action:myaction"a - Action to perform when url is openedCopyright © 2010-2018 Nikhef / Stichting FOM. All Rights Reserved.