source: trunk/gli/src/org/greenstone/gatherer/gui/PreviewPane.java@ 4560

Last change on this file since 4560 was 4560, checked in by jmt12, 21 years ago

2030123: Have now (successfully) told CalPane not to cache pages. After the first 'a=config&cmd=release-collection' the page returned was being cached and so the index files weren't released for subsequent builds.

  • Property svn:keywords set to Author Date Id Revision
File size: 9.1 KB
Line 
1package org.greenstone.gatherer.gui;
2/**
3 *#########################################################################
4 *
5 * A component of the Gatherer application, part of the Greenstone digital
6 * library suite from the New Zealand Digital Library Project at the
7 * University of Waikato, New Zealand.
8 *
9 * <BR><BR>
10 *
11 * Author: John Thompson, Greenstone Digital Library, University of Waikato
12 *
13 * <BR><BR>
14 *
15 * Copyright (C) 1999 New Zealand Digital Library Project
16 *
17 * <BR><BR>
18 *
19 * This program is free software; you can redistribute it and/or modify
20 * it under the terms of the GNU General Public License as published by
21 * the Free Software Foundation; either version 2 of the License, or
22 * (at your option) any later version.
23 *
24 * <BR><BR>
25 *
26 * This program is distributed in the hope that it will be useful,
27 * but WITHOUT ANY WARRANTY; without even the implied warranty of
28 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29 * GNU General Public License for more details.
30 *
31 * <BR><BR>
32 *
33 * You should have received a copy of the GNU General Public License
34 * along with this program; if not, write to the Free Software
35 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
36 *########################################################################
37 */
38import calpa.html.*;
39import java.awt.*;
40import java.awt.event.*;
41import java.net.*;
42import javax.swing.*;
43import org.greenstone.gatherer.Gatherer;
44import org.greenstone.gatherer.util.GURL;
45import org.greenstone.gatherer.util.Utility;
46
47public class PreviewPane
48 extends JPanel {
49
50 private CalHTMLPane view = null;
51 private int back_count = 0;
52 private int forward_count = 0;
53 private JButton back = null;
54 private JButton forward = null;
55 private JButton home = null;
56 private JButton reload = null;
57 private JLabel status = null;
58 private Observer observer = null;
59 private URL homepage = null;
60
61 static final public String BLANK_PAGE = "<html><head><title>No Page</title></head><body></body></html>";
62
63 public PreviewPane() {
64 super();
65
66 CalHTMLManager.setCacheDocuments(false);
67
68 // Create components
69 back = new JButton(get("Back"), Utility.getImage("back.gif"));
70 back.addActionListener(new BackListener());
71 back.setEnabled(false);
72
73 home = new JButton(get("Home"), Utility.getImage("home.gif"));
74 home.addActionListener(new HomeListener());
75 home.setEnabled(false);
76
77 forward = new JButton(get("Forward"), Utility.getImage("forward.gif"));
78 forward.addActionListener(new ForwardListener());
79 forward.setEnabled(false);
80
81 reload = new JButton(get("Reload"), Utility.getImage("reload.gif"));
82 reload.addActionListener(new ReloadListener());
83 reload.setEnabled(false);
84
85 CalHTMLPreferences prefs = new CalHTMLPreferences();
86 observer = new Observer();
87 view = new CalHTMLPane(prefs, observer, "Default");
88
89 status = new JLabel(get("Ready"));
90 }
91
92 public void collectionChanged(boolean ready) {
93 // If we were showing a page, but that page is no longer available, then return to a blank page
94 if(!ready && homepage != null) {
95 homepage = null;
96 view.showHTMLDocument(BLANK_PAGE);
97 }
98 }
99
100 public void display() {
101 JPanel control_pane = new JPanel();
102 control_pane.setBorder(BorderFactory.createEmptyBorder(0,0,5,0));
103 control_pane.setLayout(new GridLayout(1,4));
104 control_pane.add(back);
105 control_pane.add(reload);
106 control_pane.add(home);
107 control_pane.add(forward);
108
109 JPanel a_panel = new JPanel(new BorderLayout());
110 a_panel.setSize(new Dimension(770, 440));
111 a_panel.add(view, BorderLayout.CENTER);
112
113 setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
114 setLayout(new BorderLayout());
115 add(control_pane, BorderLayout.NORTH);
116 add(a_panel, BorderLayout.CENTER);
117 add(status, BorderLayout.SOUTH);
118 }
119
120 /** This method is called when the user selects the 'Preview' tab from the views bar. Can be used to display a particular page or perform some other relevant tests (ensure internet connection to specified server maybe?)
121 */
122 public void gainFocus() {
123 if(Gatherer.c_man.ready() && Gatherer.c_man.built()) {
124 if(homepage == null) {
125 try {
126 // Now load the collection
127 homepage = new URL(Gatherer.config.exec_address.toString() + "?a=p&p=about&c=" + Gatherer.c_man.getCollection().getName());
128 ///atherer.println("Loading " + url);
129 status.setText(get("Loading", homepage.toString()));
130 view.showHTMLDocument(homepage);
131 }
132 catch (MalformedURLException exception) {
133 Gatherer.printStackTrace(exception);
134 }
135 }
136 }
137 validate();
138 }
139
140 /** Used to retrieve the phrase that matches the given key from the loaded dictionary.
141 */
142 public String get(String key) {
143 return get(key, null);
144 }
145
146 public String get(String key, String arg) {
147 if(key.indexOf(".") == -1) {
148 key = "Browser." + key;
149 }
150 return Gatherer.dictionary.get(key, arg);
151 }
152
153 public void configServer(String command) {
154 try {
155 String url = Gatherer.config.exec_address.toString() + command;
156 ///ystem.err.println("Action: " + url);
157 view.setLoadSynchronously(true);
158 view.showHTMLDocument(new URL(url));
159 view.setLoadSynchronously(false);
160 ///ystem.err.println("Complete.");
161 url = null;
162 }
163 catch(MalformedURLException error) {
164 ///ystem.err.println("Bad URL.");
165 }
166 }
167
168 public void validate() {
169 back.setEnabled(back_count > 0);
170 home.setEnabled(homepage != null);
171 forward.setEnabled(forward_count > 0);
172 reload.setEnabled(homepage != null);
173 }
174
175 private class BackListener
176 implements ActionListener {
177 public void actionPerformed(ActionEvent event) {
178 view.goBack();
179 back_count--;
180 forward_count++;
181 validate();
182 }
183 }
184
185 private class ForwardListener
186 implements ActionListener {
187 public void actionPerformed(ActionEvent event) {
188 view.goForward();
189 back_count++;
190 forward_count--;
191 validate();
192 }
193 }
194
195 private class HomeListener
196 implements ActionListener {
197 public void actionPerformed(ActionEvent event) {
198 view.showHTMLDocument(homepage);
199 back_count++;
200 forward_count = 0;
201 validate();
202 }
203 }
204
205 private class ReloadListener
206 implements ActionListener {
207 public void actionPerformed(ActionEvent event) {
208 view.reloadDocument();
209 }
210 }
211
212 private class Observer
213 extends DefaultCalHTMLObserver {
214 public int state = CalCons.DOC_LOADED;
215 public void linkActivatedUpdate(CalHTMLPane pane, URL url, String target_frame, String j_name) {
216 back_count++;
217 forward_count = 0;
218 validate();
219 }
220 public void linkFocusUpdate(CalHTMLPane pane, URL url) {
221 ///ystem.err.println("Link in focus " + url.toString());
222 status.setText(get("Follow", url.toString()));
223 }
224 public void statusUpdate(CalHTMLPane pane, int state, URL url, int value, String message) {
225 this.state = state;
226 switch(state) {
227 // The Pane is attempting to connect to the given URL to receive data.
228 case CalCons.PRE_CONNECT:
229 ///ystem.err.println("Preconnect: " + state + " - " + message);
230 break;
231 // The Pane was unable to connect to the given URL or was unable to parse the content. Most likely this will be due to an incorrectly specified URL. The message argument may contain further details of the reason for failure.
232 case CalCons.PARSE_FAILED:
233 ///ystem.err.println("Parse Failed: " + state + " - " + message);
234 status.setText(get("CannotConnect", url.toString()));
235 break;
236 // The Pane has established a connection to the given URL and is receiving any content.
237 case CalCons.CONNECTED:
238 ///ystem.err.println("Connected: " + state + " - " + message);
239 status.setText(get("Loading", url.toString()));
240 break;
241 // The size of the content at the given URL is known and is contained in the value argument.
242 case CalCons.DOC_LENGTH:
243 ///ystem.err.println("Doc Length: " + state + " - " + message);
244 break;
245 // The title of the document for the given URL is known and is contained in the message argument. Only the title of a document in the Pane's top level frame will be sent to this method. If the document has no name, the message will be null, unless the document is a Frameset document in which case the message "Frameset" will be sent.
246 case CalCons.TITLE:
247 ///ystem.err.println("Title: " + state + " - " + message);
248 break;
249 // An exception has been thrown during parsing of the data from the URL. This will most likely be an IOException such as a server time-out.
250 case CalCons.PARSE_FAILED_POST_CONNECT:
251 ///ystem.err.println("Parse Failed Post Connect: " + state + " - " + message);
252 status.setText(get("TimedOut", url.toString()));
253 break;
254 // The document has been parsed but formatting cannot be completed because the document contains images of unspecified size. The parsing thread is waiting for image updates to give it the information it needs to format and display the document.
255 case CalCons.WAITING_FOR_IMAGES:
256 ///ystem.err.println("Waiting For Images: " + state + " - " + message + " - " + url.toString());
257 break;
258 // All text and image data has been received, parsed and the document structure determined.
259 case CalCons.DOC_LOADED:
260 ///ystem.err.println("Doc Loaded: " + state + " - " + message);
261 status.setText(get("Ready"));
262 break;
263 }
264 }
265 }
266}
Note: See TracBrowser for help on using the repository browser.