source: trunk/gli/src/org/greenstone/gatherer/GathererApplet.java@ 10242

Last change on this file since 10242 was 10242, checked in by mdewsnip, 19 years ago

Moved a lot of the duplicated code out of GathererProg and GathererApplet and into Gatherer.

  • Property svn:keywords set to Author Date Id Revision
File size: 4.6 KB
Line 
1/**
2 *#########################################################################
3 *
4 * A component of the Gatherer application, part of the Greenstone digital
5 * library suite from the New Zealand Digital Library Project at the
6 * University of Waikato, New Zealand.
7 *
8 * Author: John Thompson, Greenstone Digital Library, University of Waikato
9 *
10 * Copyright (C) 1999 New Zealand Digital Library Project
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 *########################################################################
26 */
27
28package org.greenstone.gatherer;
29
30import java.applet.*;
31import java.awt.event.ActionEvent;
32import java.awt.event.ActionListener;
33import java.net.*;
34import javax.swing.JApplet;
35
36import java.io.*;
37import javax.swing.*;
38import org.greenstone.gatherer.util.Utility;
39
40
41public class GathererApplet extends JApplet implements ActionListener
42{
43 private Gatherer gatherer = null;
44
45
46 protected String fullLibraryURL(String address)
47 {
48 String full_address = "";
49
50 // make sure the URL has protocol, host, and file
51 if (address.startsWith("http:")) {
52 // the address has all the necessary components
53 full_address = address;
54 }
55 else if (address.startsWith("/")) {
56 // there is not protocol and host
57 URL document = getDocumentBase();
58 int port_no = document.getPort();
59
60 String port = (port_no>0) ? ":" + port_no : "";
61 full_address = "http://" + document.getHost() + port + address;
62 }
63
64 return full_address;
65 }
66
67
68 /* This is the entry point for the GLI applet */
69 public void init()
70 {
71 // Check if the user has agreed to the requested security settings
72 try {
73 // Work-around to reduce number of
74 // 'Could not lock user prefs' error messages.
75 // Thanks to Walter Schatz from the java forums.
76 System.setProperty("java.util.prefs.syncInterval","2000000");
77 }
78 catch (Exception exception) {
79 getContentPane().add(new JLabel("Greenstone Librarian Interface Applet deactivated", JLabel.CENTER));
80 return;
81 }
82
83 // Ensure platform specific LAF
84 try {
85 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
86 }
87 catch (Exception exception) {
88 exception.printStackTrace();
89 }
90
91 // Ensure the GLI user directory exists
92 File gli_user_directory = Utility.setGLIUserFolder(getParameter("windowsHome"));
93 if (!gli_user_directory.exists() && !gli_user_directory.mkdirs()) {
94 System.err.println("Error: Unable to make directory: " + gli_user_directory.toString());
95 }
96
97 // Set some global variables so we know how we're running
98 Gatherer.isApplet = true;
99 Gatherer.isGsdlRemote = true;
100 String library_cgi = fullLibraryURL(getParameter("gwcgi"));
101 Gatherer.cgiBase = library_cgi.substring(0, library_cgi.lastIndexOf('/') + 1);
102
103 // String debug_param = getParameter("debug");
104 // if ((debug_param != null) && (debug_param.matches("true"))) {
105 // go.debug = true;
106 // }
107
108 String[] args = { "-gsdl", gli_user_directory.toString(),
109 "-library_url", library_cgi,
110 };
111
112 // Create an instance of the Gatherer class, which will parse the args and prepare the rest of the GLI
113 gatherer = new Gatherer(args);
114
115 // Create a button for the user to press to open the GLI GUI
116 JButton launch_GLI_button = new JButton("Launch Greenstone Librarian Interface ...");
117 launch_GLI_button.addActionListener(this);
118 getContentPane().add(launch_GLI_button);
119 }
120
121
122
123 public void start()
124 {
125 System.err.println("Start called");
126 }
127
128
129
130 public void stop()
131 {
132 System.err.println("Stop called");
133
134 }
135
136 public void destroy()
137 {
138 System.err.println("Destroy called");
139 gatherer.exit();
140 System.err.println("Done gatherer exit.");
141 }
142
143
144 public void actionPerformed(ActionEvent e)
145 {
146 gatherer.openGUI();
147
148 // If there was an open collection last session, reopen it
149 if (Gatherer.open_collection_file_path != null) {
150 Gatherer.c_man.loadCollection(Gatherer.open_collection_file_path);
151 }
152 }
153}
Note: See TracBrowser for help on using the repository browser.