1 package org.splat.launcher;
3 import java.awt.ComponentOrientation;
4 import java.awt.GridLayout;
5 import java.awt.event.ActionEvent;
6 import java.awt.event.ActionListener;
7 import java.io.ObjectInputStream;
9 import java.net.URLConnection;
11 public class ToolbarApplet extends java.applet.Applet implements ActionListener {
13 private static final long serialVersionUID = 3243053622061086715L;
15 // ==============================================================================================================================
16 // Overridden functions
17 // ==============================================================================================================================
21 URL appurl = getCodeBase();
22 int hgap = 6; // Gap between icons
25 int width = getSize().width;
26 int height = getSize().height;
27 for (ntools = 0; ntools < (width + hgap) / (height + hgap); ntools++) {
28 String icon = this.getParameter("icon" + ntools);
29 String tool = this.getParameter("tool" + ntools);
30 String file = this.getParameter("file" + ntools); // May be null
31 if (icon != null && tool != null) {
32 ToolButton button = new ToolButton(height, getImage(appurl,
33 "../skin/" + icon), tool, file);
34 add(button); // For displaying the button
35 button.addActionListener(this);
38 setLayout(new GridLayout(1, ntools, hgap, 0)); // 1 row, {ntools} buttons
39 applyComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
42 public void actionPerformed(final ActionEvent event) {
43 // -----------------------------------------------
44 if (event.getSource() instanceof ToolButton) {
45 ToolButton clicked = (ToolButton) event.getSource();
46 String module = clicked.getTool();
47 String target = clicked.getTarget();
48 launch(module, target);
52 // ==============================================================================================================================
53 // Public member functions
54 // ==============================================================================================================================
56 public void launch(final String name, final String filename) {
57 // -------------------------------------------------
61 // Opening a Web page in a new tab
62 if (module.startsWith("http")) {
63 getAppletContext().showDocument(new URL(module), "_blank");
66 // Opening a Web module in a new tab
67 if (module.startsWith("../") || module.startsWith("/")) {
68 module = getCodeBase().toString() + module;
69 if (filename != null) {
70 module = module + "?open=" + filename;
72 getAppletContext().showDocument(new URL(module), "_blank");
75 // Opening an application on the local machine
76 if (module.endsWith(".exe") || module.endsWith(".EXE")) {
77 String applikey = "HKEY_LOCAL_MACHINE\\SOFTWARE\\Classes\\Applications\\"
79 String valkey = ""; // Default application and file keys
81 module = WindowsRegistry.readValue(applikey
82 + "\\shell\\open\\command", valkey);
84 module = WindowsRegistry.readValue(applikey
85 + "\\shell\\edit\\command", valkey);
87 // if (module == null) module = "\"C:\\Program Files (x86)\\Microsoft Office\\Office14\\WINWORD.EXE\"";
89 module = getCodeBase().toString()
90 + "error.jsp?message=launch&value=" + name;
91 getAppletContext().showDocument(new URL(module));
93 String[] parse = module.split("/");
94 String command = parse[0]; // Removing eventual options
95 if (filename != null) {
97 // Opening the application with a server side existing file
98 if (filename.startsWith("http")) {
99 path = " \"" + filename + "\"";
101 // Opening the application with a file previously created by the server
102 else if (filename.startsWith("/jsp")) { // Document created through a JSP
103 URL my = getDocumentBase();
104 String http = "http://" + my.getHost() + ":"
105 + my.getPort() + "/";
106 String[] jsppath = my.getPath().split("/"); // Parses "/webapp/..."
107 String location = http + jsppath[1] + filename;
109 URLConnection connection = new URL(location)
111 ObjectInputStream fromservlet = new ObjectInputStream(
112 connection.getInputStream());
113 URL docurl = (URL) fromservlet.readObject();
116 if (docurl != null) {
117 path = " " + docurl.toString();
120 command = command + path;
122 Runtime.getRuntime().exec(command);
125 } catch (Exception error) {
126 error.printStackTrace(); // RKV: NOPMD: TODO: try to use logger