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

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

Initial revision

  • Property svn:keywords set to Author Date Id Revision
File size: 7.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 String args[] = null;
59 private String current_url = null;
60 private String page_showing = null;
61 private URL homepage = null;
62
63 public PreviewPane() {
64 // Create components
65 back = new JButton(get("Back"), Utility.getImage("back.gif"));
66 back.addActionListener(new BackListener());
67 back.setEnabled(false);
68
69 home = new JButton(get("Home"), Utility.getImage("home.gif"));
70 home.addActionListener(new HomeListener());
71 home.setEnabled(false);
72
73 forward = new JButton(get("Forward"), Utility.getImage("forward.gif"));
74 forward.addActionListener(new ForwardListener());
75 forward.setEnabled(false);
76
77 reload = new JButton(get("Reload"), Utility.getImage("reload.gif"));
78 reload.addActionListener(new ReloadListener());
79 reload.setEnabled(false);
80
81 CalHTMLPreferences prefs = new CalHTMLPreferences();
82 Observer observer = new Observer();
83 view = new CalHTMLPane(prefs, observer, "Default");
84 //view.setSize(new Dimension(770, 440));
85
86 status = new JLabel(get("Ready"));
87 }
88
89 public void collectionChanged(boolean ready) {
90 if(ready && Gatherer.c_man.built()) {
91 String url = Gatherer.config.exec_path + "?a=p&p=about&c=" + Gatherer.c_man.getCollection().getName();
92 Gatherer.println("Loading " + url);
93 args = new String[1];
94 args[0] = url;
95 status.setText(get("Loading", args));
96 args = null;
97 view.showHTMLDocument((new GURL(url)).getURL());
98 }
99 validate();
100 }
101
102 public void display() {
103 JPanel control_pane = new JPanel();
104 control_pane.setBorder(BorderFactory.createEmptyBorder(0,0,5,0));
105 control_pane.setLayout(new GridLayout(1,4));
106 control_pane.add(back);
107 control_pane.add(reload);
108 control_pane.add(home);
109 control_pane.add(forward);
110
111 JPanel a_panel = new JPanel(new BorderLayout());
112 a_panel.setSize(new Dimension(770, 440));
113 a_panel.add(view, BorderLayout.CENTER);
114
115 setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
116 setLayout(new BorderLayout());
117 add(control_pane, BorderLayout.NORTH);
118 add(a_panel, BorderLayout.CENTER);
119 add(status, BorderLayout.SOUTH);
120 }
121
122 /** 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?)
123 */
124 public void gainFocus() {
125 if(Gatherer.c_man.ready() && Gatherer.c_man.built()) {
126 String url = Gatherer.config.exec_path + "?a=p&p=about&c=" + Gatherer.c_man.getCollection().getName();
127 if(page_showing != null && page_showing.equals(url)) {
128 view.reloadDocument();
129 }
130 else {
131 Gatherer.println("Loading " + url);
132 args = new String[1];
133 args[0] = url;
134 status.setText(get("Loading", args));
135 args = null;
136 view.showHTMLDocument((new GURL(url)).getURL());
137 page_showing = url;
138 homepage = (new GURL(url)).getURL();
139 }
140 }
141 validate();
142 }
143
144 /** Used to retrieve the phrase that matches the given key from the loaded dictionary.
145 */
146 public String get(String key) {
147 return get(key, null);
148 }
149
150 public String get(String key, String args[]) {
151 if(key.indexOf(".") == -1) {
152 key = "Browser." + key;
153 }
154 return Gatherer.dictionary.get(key, args);
155 }
156
157 public void validate() {
158 if(back_count > 0) {
159 back.setEnabled(true);
160 }
161 else {
162 back.setEnabled(false);
163 }
164 if(homepage != null) {
165 home.setEnabled(true);
166 }
167 else {
168 home.setEnabled(false);
169 }
170 if(forward_count > 0) {
171 forward.setEnabled(true);
172 }
173 else {
174 forward.setEnabled(false);
175 }
176 reload.setEnabled(true);
177 }
178
179 private class BackListener
180 implements ActionListener {
181 public void actionPerformed(ActionEvent event) {
182 view.goBack();
183 back_count--;
184 forward_count++;
185 validate();
186 }
187 }
188
189 private class ForwardListener
190 implements ActionListener {
191 public void actionPerformed(ActionEvent event) {
192 view.goForward();
193 back_count++;
194 forward_count--;
195 validate();
196 }
197 }
198
199 private class HomeListener
200 implements ActionListener {
201 public void actionPerformed(ActionEvent event) {
202 if(homepage != null) {
203 view.showHTMLDocument(homepage);
204 back_count++;
205 validate();
206 }
207 }
208 }
209
210 private class ReloadListener
211 implements ActionListener {
212 public void actionPerformed(ActionEvent event) {
213 view.reloadDocument();
214 }
215 }
216
217 private class Observer
218 extends DefaultCalHTMLObserver {
219 public void linkActivatedUpdate(CalHTMLPane pane, URL url, String target_frame, String j_name) {
220 if(!url.toString().equals(current_url)) {
221 back_count++;
222 forward_count = 0;
223 validate();
224 }
225 }
226 public void linkFocusUpdate(CalHTMLPane pane, URL url) {
227 ///ystem.err.println("Link in focus " + url.toString());
228 args = new String[1];
229 args[0] = url.toString();
230 status.setText(get("Follow"));
231 args = null;
232 }
233 public void statusUpdate(CalHTMLPane pane, int state, URL url, int value, String message) {
234 switch(state) {
235 case 11:
236 args = new String[1];
237 args[0] = url.toString();
238 status.setText(get("Loading", args));
239 args = null;
240 break;
241 case 14:
242 // Rendering complete.
243 status.setText(get("Ready"));
244 break;
245 }
246 }
247 }
248}
Note: See TracBrowser for help on using the repository browser.