diff options
author | Alexander Sulfrian <asulfrian@zedat.fu-berlin.de> | 2019-03-09 07:00:04 +0100 |
---|---|---|
committer | Alexander Sulfrian <asulfrian@zedat.fu-berlin.de> | 2019-03-09 07:00:04 +0100 |
commit | 5514a9a5a1fbf0204927300a5af73c251cdf3799 (patch) | |
tree | 9c9b9dff77fdb2aa5ee01e9dba10c8c5449fb911 /src/main/java/de/spline/kvm/StandaloneApplet.java | |
parent | b13d00e372b7731a87c8b4d81dfd5454214b8cfa (diff) | |
download | kvm-5514a9a5a1fbf0204927300a5af73c251cdf3799.tar.gz kvm-5514a9a5a1fbf0204927300a5af73c251cdf3799.tar.bz2 kvm-5514a9a5a1fbf0204927300a5af73c251cdf3799.zip |
Add first version of the applet launcher
Diffstat (limited to 'src/main/java/de/spline/kvm/StandaloneApplet.java')
-rw-r--r-- | src/main/java/de/spline/kvm/StandaloneApplet.java | 121 |
1 files changed, 121 insertions, 0 deletions
diff --git a/src/main/java/de/spline/kvm/StandaloneApplet.java b/src/main/java/de/spline/kvm/StandaloneApplet.java new file mode 100644 index 0000000..cf8a5d5 --- /dev/null +++ b/src/main/java/de/spline/kvm/StandaloneApplet.java @@ -0,0 +1,121 @@ +package de.spline.kvm; + +import java.awt.*; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.Locale; +import java.util.Map; + +import de.spline.kvm.events.EventMulticaster; +import de.spline.kvm.events.LifetimeListener; +import de.spline.kvm.utils.ReflectionUtils; +import nn.pp.rc.RemoteConsoleApplet; +import nn.pp.rc.ServerConsolePanelBase; + +/** + * This is a class, to run an applet without an browser. It just overrides the + * necessary methods to run the applet. The applet "window" displayed in tbe + * browser is not drawn, but the interesting stuff (aka. the remote console) + * is in a separate Frame. + */ +public class StandaloneApplet extends RemoteConsoleApplet +{ + protected String host; + protected Map<String, String> parameters; + + protected LifetimeListener lifetimeListener = null; + + public StandaloneApplet(String host, Map<String, String> parameters) + { + this.host = host; + this.parameters = parameters; + } + + /** + * Add a listener for the lifetime events of the applet. + * + * @param listener Listener instance to add + */ + public void addLifetimeListener(LifetimeListener listener) + { + lifetimeListener = EventMulticaster.add(listener, lifetimeListener); + } + + /** + * Remove a listener for the lifetime events of the applet. + * + * @param listener Listener instance to remove + */ + public void removeLifetimeListener(LifetimeListener listener) + { + lifetimeListener = EventMulticaster.remove(listener, lifetimeListener); + } + + @Override + public Image getImage(URL url) + { + return getToolkit().getImage(url); + } + + @Override + public URL getCodeBase() + { + URL url = null; + + try { + url = new URL("https", host, 443, ""); + } catch (MalformedURLException e) { + e.printStackTrace(); + } + + return url; + } + + @Override + public URL getDocumentBase() + { + return getCodeBase(); + } + + @Override + public Locale getLocale() + { + return Locale.getDefault(); + } + + /** + * This are the parameters of the applet. The applet usually get the values + * from html tags inside the applet tag. We have parsed this tags into a + * map and simply return these values here. + * + * @param name Name of the parameter to get + * @return Value of the parameter + */ + @Override + public String getParameter(String name) + { + return parameters.get(name.toUpperCase()); + } + + @Override + public void init() + { + super.init(); + + // The initial label is removed during init and this is causing + // NullPointerExceptions when the popup should be displayed, so we + // simply add the label again. + ServerConsolePanelBase consolePanel = ReflectionUtils.getConsolePanel(this); + PopupMenu menu = ReflectionUtils.getOptionMenu(consolePanel); + menu.setLabel("Options"); + } + + @Override + public void stop() + { + super.stop(); + destroy(); + + lifetimeListener.appletStopped(); + } +} |