1 package org.splat.launcher;
3 import java.awt.GridLayout;
4 import java.awt.event.ActionEvent;
5 import java.awt.event.ActionListener;
6 import java.awt.ComponentOrientation;
7 import java.io.ObjectInputStream;
9 import java.net.URLConnection;
12 public class ToolbarApplet extends java.applet.Applet implements ActionListener {
17 private static final long serialVersionUID = 3243053622061086715L;
19 // ==============================================================================================================================
20 // Overridden functions
21 // ==============================================================================================================================
24 // -------------------
25 URL appurl = getCodeBase();
26 int hgap = 6; // Gap between icons
29 width = getSize().width;
30 height = getSize().height;
31 for (ntools = 0; ntools < (width+hgap)/(height+hgap); ntools++) {
32 String icon = this.getParameter("icon"+ntools);
33 String tool = this.getParameter("tool"+ntools);
34 String file = this.getParameter("file"+ntools); // May be null
35 if (icon != null && tool != null) {
36 ToolButton button = new ToolButton(height, getImage(appurl, "../skin/" + icon), tool, file);
37 add(button); // For displaying the button
38 button.addActionListener(this);
41 setLayout( new GridLayout(1, ntools, hgap, 0) ); // 1 row, {ntools} buttons
42 applyComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
45 public void actionPerformed (ActionEvent event) {
46 // -----------------------------------------------
47 if (event.getSource() instanceof ToolButton) {
48 ToolButton clicked = (ToolButton)event.getSource();
49 String module = clicked.getTool();
50 String target = clicked.getTarget();
51 launch(module, target);
55 // ==============================================================================================================================
56 // Public member functions
57 // ==============================================================================================================================
59 public void launch (String name, String filename) {
60 // -------------------------------------------------
64 // Opening a Web page in a new tab
65 if (module.startsWith("http")) {
66 getAppletContext().showDocument(new URL(module), "_blank");
69 // Opening a Web module in a new tab
70 if (module.startsWith("../") || module.startsWith("/")) {
71 module = getCodeBase().toString() + module;
72 if (filename != null) module = module + "?open=" + filename;
73 getAppletContext().showDocument(new URL(module), "_blank");
76 // Opening an application on the local machine
77 if (module.endsWith(".exe") || module.endsWith(".EXE")) {
78 String applikey = "HKEY_LOCAL_MACHINE\\SOFTWARE\\Classes\\Applications\\" + module;
79 String valkey = ""; // Default application and file keys
81 module = WindowsRegistry.readValue(applikey + "\\shell\\open\\command", valkey);
82 if (module == null) module = WindowsRegistry.readValue(applikey + "\\shell\\edit\\command", valkey);
83 // if (module == null) module = "\"C:\\Program Files (x86)\\Microsoft Office\\Office14\\WINWORD.EXE\"";
85 String[] parse = module.split("/");
86 String command = parse[0]; // Removing eventual options
87 if (filename != null) {
89 // Opening the application with a server side existing file
90 if (filename.startsWith("http")) {
91 path = " \"" + filename + "\"";
93 // Opening the application with a file previously created by the server
94 else if (filename.startsWith("/jsp")) { // Document created through a JSP
95 URL my = getDocumentBase();
96 String http = "http://" + my.getHost() + ":" + my.getPort() + "/";
97 String[] jsppath = my.getPath().split("/"); // Parses "/webapp/..."
98 String location = http + jsppath[1] + filename;
100 URLConnection connection = new URL(location).openConnection();
101 ObjectInputStream fromservlet = new ObjectInputStream(connection.getInputStream());
102 URL docurl = (URL)fromservlet.readObject();
105 if (docurl != null) path = " " + docurl.toString();
107 command = command + path;
109 Runtime.getRuntime().exec(command);
111 module = getCodeBase().toString() + "error.jsp?message=launch&value=" + name;
112 getAppletContext().showDocument(new URL(module));
115 } catch (Exception error) {
116 error.printStackTrace();