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

Last change on this file since 5590 was 5571, checked in by mdewsnip, 21 years ago

More small updates and tooltips added.

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