1 | /**
|
---|
2 | *#########################################################################
|
---|
3 | *
|
---|
4 | * A component of the Administration Tool (GAI) application, part of the
|
---|
5 | * Greenstone digital library suite from the New Zealand Digital Library
|
---|
6 | * Project at the University of Waikato, New Zealand.
|
---|
7 | *
|
---|
8 | * Copyright (C) 1999 New Zealand Digital Library Project
|
---|
9 | *
|
---|
10 | * This program is free software; you can redistribute it and/or modify
|
---|
11 | * it under the terms of the GNU General Public License as published by
|
---|
12 | * the Free Software Foundation; either version 2 of the License, or
|
---|
13 | * (at your option) any later version.
|
---|
14 | *
|
---|
15 | * This program is distributed in the hope that it will be useful,
|
---|
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
18 | * GNU General Public License for more details.
|
---|
19 | *
|
---|
20 | * You should have received a copy of the GNU General Public License
|
---|
21 | * along with this program; if not, write to the Free Software
|
---|
22 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
23 | *
|
---|
24 | * Author: Chi-Yu Huang, Greenstone Digital Library, University of Waikato
|
---|
25 | *
|
---|
26 | *########################################################################
|
---|
27 | */
|
---|
28 |
|
---|
29 | package org.greenstone.admin;
|
---|
30 |
|
---|
31 | import org.greenstone.admin.GAI;
|
---|
32 | import org.greenstone.admin.gui.TabbedPane;
|
---|
33 | import org.greenstone.admin.gui.MenuBar;
|
---|
34 | import org.greenstone.admin.gui.LogPane;
|
---|
35 | import org.greenstone.admin.gui.ConfPane;
|
---|
36 |
|
---|
37 | //import java AWT classes
|
---|
38 | import java.awt.*;
|
---|
39 | import java.awt.event.*;
|
---|
40 | import java.io.*;
|
---|
41 | import java.net.*;
|
---|
42 | import java.util.*;
|
---|
43 | import javax.swing.*;
|
---|
44 | import javax.swing.event.*;
|
---|
45 | import javax.swing.plaf.*;
|
---|
46 |
|
---|
47 | public class GAIManager
|
---|
48 | extends JFrame
|
---|
49 | implements ActionListener, ChangeListener{
|
---|
50 |
|
---|
51 | private Dimension size = null;
|
---|
52 | // The ConfPane contains the configuration details of Greenstone III build and installation
|
---|
53 | public ConfPane conf_pane = null;
|
---|
54 | // The LogPane contains the log details for Tomcat Server used by gsdl3
|
---|
55 | public LogPane log_pane = null;
|
---|
56 | // Not designed yet
|
---|
57 | public JPanel ext_pane = null;
|
---|
58 | // Not designed yet
|
---|
59 | public JPanel monitor_pane = null;
|
---|
60 |
|
---|
61 | static public ImageIcon CONF_ICON = null;
|
---|
62 | static public ImageIcon EXT_ICON = null;
|
---|
63 | static public ImageIcon MONITOR_ICON = null;
|
---|
64 | static public ImageIcon LOG_ICON = null;
|
---|
65 |
|
---|
66 | // Create a menu bar in the main Pane
|
---|
67 | public MenuBar menu_bar = null;
|
---|
68 |
|
---|
69 | // HelpFrame
|
---|
70 |
|
---|
71 | private JPanel previous_pane = null;
|
---|
72 | private JPanel content_pane = null;
|
---|
73 | private JTabbedPane tab_pane = null;
|
---|
74 |
|
---|
75 | /** A threaded tab changer to try and avoid NPE on exit. */
|
---|
76 | private TabUpdater tab_updater = null;
|
---|
77 |
|
---|
78 | //Contructor
|
---|
79 | public GAIManager(Dimension size){
|
---|
80 | super();
|
---|
81 | this.size = size;
|
---|
82 | this.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
|
---|
83 | this.setTitle("GreenStone 3 Administration Tool");
|
---|
84 | /* Add a focus listener to ourselves. Thus if we gain focus when a Modal Dialog should
|
---|
85 | * instead have it, we can try to bring the modal dialog to the front*/
|
---|
86 | //this.addFocusListener(new GAIGUIFocusListener());
|
---|
87 | //display();
|
---|
88 | }
|
---|
89 |
|
---|
90 | private class GAIGUIFocusListener
|
---|
91 | extends FocusAdapter {
|
---|
92 | public void focusGained(FocusEvent e) {
|
---|
93 | /* if (ModalDialog.current_modal != null) {
|
---|
94 | ModalDialog.current_modal.makeVisible();
|
---|
95 | ModalDialog.current_modal.toFront();
|
---|
96 | }*/
|
---|
97 | }
|
---|
98 | }
|
---|
99 |
|
---|
100 | public void display(){
|
---|
101 | CONF_ICON = new ImageIcon (GAI.images_path + "create.gif");
|
---|
102 | EXT_ICON = new ImageIcon (GAI.images_path + "information.gif");
|
---|
103 | MONITOR_ICON = new ImageIcon (GAI.images_path + "zoom.gif");
|
---|
104 | LOG_ICON = new ImageIcon (GAI.images_path + "history.gif");
|
---|
105 | content_pane = (JPanel) this.getContentPane();
|
---|
106 |
|
---|
107 | try {
|
---|
108 | this.setSize(size);
|
---|
109 | //create a menuBar
|
---|
110 | menu_bar = new MenuBar(new MenuListenerImpl());
|
---|
111 | this.setJMenuBar(menu_bar);
|
---|
112 |
|
---|
113 | //Create the tabbed pane and put it in the center
|
---|
114 | tab_pane = new JTabbedPane();
|
---|
115 | tab_pane.addChangeListener(this);
|
---|
116 |
|
---|
117 | //set up the Configuration Pane
|
---|
118 | if (Configuration.get("admin.conf")){
|
---|
119 | conf_pane = new ConfPane();
|
---|
120 | conf_pane.display();
|
---|
121 | tab_pane.addTab("Configuration", CONF_ICON, conf_pane);
|
---|
122 | tab_pane.setEnabledAt(tab_pane.indexOfComponent(conf_pane),Configuration.get("admin.conf"));
|
---|
123 | }
|
---|
124 |
|
---|
125 | //set up the ext Pane
|
---|
126 | if (Configuration.get("admin.ext")){
|
---|
127 | ext_pane = new JPanel();
|
---|
128 | //ext_pane.display();
|
---|
129 | tab_pane.addTab("Exts", EXT_ICON, ext_pane);
|
---|
130 | tab_pane.setEnabledAt(tab_pane.indexOfComponent(ext_pane),Configuration.get("admin.ext"));
|
---|
131 | }
|
---|
132 |
|
---|
133 | //set up the Monitor Pane
|
---|
134 | if (Configuration.get("admin.monitor")){
|
---|
135 | monitor_pane = new JPanel();
|
---|
136 | //monitor_pane.display();
|
---|
137 | tab_pane.addTab("Monitor", MONITOR_ICON, monitor_pane);
|
---|
138 | tab_pane.setEnabledAt(tab_pane.indexOfComponent(monitor_pane),Configuration.get("admin.monitor"));
|
---|
139 | }
|
---|
140 |
|
---|
141 | //set up the Log Pane
|
---|
142 | if (Configuration.get("admin.log")){
|
---|
143 | log_pane = new LogPane();
|
---|
144 | log_pane.display();
|
---|
145 | tab_pane.addTab("Log", LOG_ICON, log_pane);
|
---|
146 | tab_pane.setEnabledAt(tab_pane.indexOfComponent(log_pane),Configuration.get("admin.log"));
|
---|
147 | }
|
---|
148 | content_pane.setLayout(new BorderLayout());
|
---|
149 | content_pane.add(tab_pane, BorderLayout.CENTER);
|
---|
150 | pack();
|
---|
151 | setVisible(true);
|
---|
152 | } catch (Exception e){
|
---|
153 | e.printStackTrace();
|
---|
154 | System.exit(1);
|
---|
155 | }
|
---|
156 | }
|
---|
157 |
|
---|
158 | /** Any implementation of <i>ActionListener</i> must include this method so that we can be informed
|
---|
159 | * when an action has occured. In this case we are listening to actions from the menu-bar, and should
|
---|
160 | * react appropriately.
|
---|
161 | * @param event An <strong>ActionEvent</strong> containing information about the action that has occured.
|
---|
162 | */
|
---|
163 |
|
---|
164 | public void actionPerformed (ActionEvent event){
|
---|
165 | Object esrc = event.getSource();
|
---|
166 | if (esrc == menu_bar.file_exit){
|
---|
167 | if (conf_pane.configurationChanged()) {
|
---|
168 | // prompt users for save
|
---|
169 | int result = JOptionPane.showConfirmDialog((Component) null, "The Configuration files have been changed, do you want to save the change", "Save Confirmation", JOptionPane.YES_NO_OPTION);
|
---|
170 | if ( result == JOptionPane.YES_OPTION) {
|
---|
171 | conf_pane.save();
|
---|
172 | }
|
---|
173 | }
|
---|
174 | exit();
|
---|
175 | }
|
---|
176 | else if (esrc == menu_bar.file_save){
|
---|
177 | /* sliently and Globally save Project and Site configuration*/
|
---|
178 | conf_pane.save();
|
---|
179 | }
|
---|
180 | else if (esrc == menu_bar.help_conf){
|
---|
181 | }
|
---|
182 | else if (esrc == menu_bar.help_ext){
|
---|
183 | }
|
---|
184 | else if (esrc == menu_bar.help_monitor){
|
---|
185 | }
|
---|
186 | else if (esrc == menu_bar.help_log){
|
---|
187 | }
|
---|
188 | else if (esrc == menu_bar.help_about) {
|
---|
189 | }
|
---|
190 | }
|
---|
191 |
|
---|
192 |
|
---|
193 | public void destory (){
|
---|
194 | // Destroying create pane ensures the latest log has been closed
|
---|
195 | //if (status_pane != null) {
|
---|
196 | //}
|
---|
197 | }
|
---|
198 | /**Overridden from JFrame so we can exit safely when window is closed
|
---|
199 | *(or destroyed). @param event A <strong>WindowEvent</strong> containing
|
---|
200 | *information about the event that fired this call.
|
---|
201 | */
|
---|
202 | protected void processWindowEvent(WindowEvent event) {
|
---|
203 | if(event.getID() == WindowEvent.WINDOW_CLOSING) {
|
---|
204 | exit();
|
---|
205 | }
|
---|
206 | }
|
---|
207 |
|
---|
208 |
|
---|
209 | /** Listens to actions upon the menu bar, and if it detects a click over
|
---|
210 | *the help menu brings the help window to the front if it has become hidden.
|
---|
211 | */
|
---|
212 | private class MenuListenerImpl
|
---|
213 | implements MenuListener {
|
---|
214 | public void menuCanceled (MenuEvent e) {
|
---|
215 | }
|
---|
216 |
|
---|
217 | public void menuDeselected (MenuEvent e){
|
---|
218 | }
|
---|
219 |
|
---|
220 | public void menuSelected (MenuEvent e){
|
---|
221 | if (e.getSource() == menu_bar.file_exit) {
|
---|
222 | exit();
|
---|
223 | }
|
---|
224 |
|
---|
225 | if (e.getSource() == menu_bar.help){
|
---|
226 | if (menu_bar.help.isSelected()){
|
---|
227 | menu_bar.help.doClick(10);
|
---|
228 | }
|
---|
229 | }
|
---|
230 | }
|
---|
231 | }
|
---|
232 |
|
---|
233 |
|
---|
234 | /** This method ensures that all the things needing saving
|
---|
235 | * are saved before GAIManager.exit() is called.
|
---|
236 | */
|
---|
237 | public void exit() {
|
---|
238 | System.exit(0);
|
---|
239 | }
|
---|
240 |
|
---|
241 |
|
---|
242 | /** Any implementation of ChangeListener must include this method
|
---|
243 | **so we can be informed when the state of one of the registered
|
---|
244 | **objects changes. In this case we are listening to view changes
|
---|
245 | **within the tabbed pane.
|
---|
246 | * @param event A ChangeEvent containing information about the event that fired this call.
|
---|
247 | */
|
---|
248 | public void stateChanged(ChangeEvent event) {
|
---|
249 | if(previous_pane != null) {
|
---|
250 | }
|
---|
251 |
|
---|
252 | //menu_bar.tabSelected(tab_pane.getSelectedIndex());
|
---|
253 | int selected_index = tab_pane.getSelectedIndex();
|
---|
254 | if (selected_index == tab_pane.indexOfComponent(log_pane)) {
|
---|
255 | log_pane.gainFocus();
|
---|
256 | }
|
---|
257 | else if (selected_index == tab_pane.indexOfComponent(conf_pane)) {
|
---|
258 | conf_pane.gainFocus();
|
---|
259 | }
|
---|
260 | previous_pane = (JPanel) tab_pane.getSelectedComponent();
|
---|
261 | }
|
---|
262 |
|
---|
263 | public void modeChanged (int mode){
|
---|
264 | if (log_pane != null){
|
---|
265 | log_pane.modeChanged(mode);
|
---|
266 | }
|
---|
267 | if (conf_pane !=null) {
|
---|
268 | conf_pane.modeChanged(mode);
|
---|
269 | }
|
---|
270 | }
|
---|
271 |
|
---|
272 | // public void refresh (int refresh_reason, boolean collection_loaded)
|
---|
273 | public void refresh () {
|
---|
274 | if (log_pane != null ){
|
---|
275 | }
|
---|
276 | }
|
---|
277 |
|
---|
278 | public void returnToInitialPane(){
|
---|
279 | if (log_pane != null) {
|
---|
280 | tab_pane.setSelectedComponent(log_pane);
|
---|
281 | }
|
---|
282 | }
|
---|
283 | public void wait(boolean waiting) {
|
---|
284 | Component glass_pane = getGlassPane();
|
---|
285 | if(waiting) {
|
---|
286 | // Show wait cursor.
|
---|
287 | //glass_pane.addMouseListener(mouse_blocker_listener);
|
---|
288 | glass_pane.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
|
---|
289 | glass_pane.setVisible(true);
|
---|
290 | }
|
---|
291 | else {
|
---|
292 | // Hide wait cursor.
|
---|
293 | glass_pane.setVisible(false);
|
---|
294 | glass_pane.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
|
---|
295 | //glass_pane.removeMouseListener(mouse_blocker_listener);
|
---|
296 | }
|
---|
297 | glass_pane = null;
|
---|
298 | }
|
---|
299 |
|
---|
300 | private class TabUpdater
|
---|
301 | implements Runnable {
|
---|
302 | private boolean ready = false;
|
---|
303 | private int conf_pos = -1;
|
---|
304 | private int ext_pos = -1;
|
---|
305 | private int monitor_pos = -1;
|
---|
306 | private int log_pos = -1;
|
---|
307 | private JTabbedPane tab_pane = null;
|
---|
308 |
|
---|
309 | public TabUpdater (JTabbedPane tab_pane, boolean ready){
|
---|
310 | this.ready = ready;
|
---|
311 | this.tab_pane = tab_pane;
|
---|
312 | conf_pos = tab_pane.indexOfComponent(conf_pane);
|
---|
313 | ext_pos = tab_pane.indexOfComponent(ext_pane);
|
---|
314 | monitor_pos = tab_pane.indexOfComponent(monitor_pane);
|
---|
315 | log_pos = tab_pane.indexOfComponent(log_pane);
|
---|
316 | }
|
---|
317 |
|
---|
318 | public void run() {
|
---|
319 | if (conf_pos != -1){
|
---|
320 | if (ready) {
|
---|
321 | tab_pane.setEnabledAt (conf_pos,Configuration.get("admin.conf"));
|
---|
322 | } else {
|
---|
323 | tab_pane.setEnabledAt (conf_pos,false);
|
---|
324 | }
|
---|
325 | }
|
---|
326 | if (ext_pos != -1){
|
---|
327 | if (ready) {
|
---|
328 | tab_pane.setEnabledAt (ext_pos,Configuration.get("admin.ext"));
|
---|
329 | } else {
|
---|
330 | tab_pane.setEnabledAt (ext_pos,false);
|
---|
331 | }
|
---|
332 | }
|
---|
333 | if (monitor_pos != -1){
|
---|
334 | if (ready) {
|
---|
335 | tab_pane.setEnabledAt (monitor_pos,Configuration.get("admin.monitor"));
|
---|
336 | } else {
|
---|
337 | tab_pane.setEnabledAt (monitor_pos,false);
|
---|
338 | }
|
---|
339 | }
|
---|
340 | if (log_pos != -1){
|
---|
341 | if (ready) {
|
---|
342 | tab_pane.setEnabledAt (log_pos,Configuration.get("admin.log"));
|
---|
343 | } else {
|
---|
344 | tab_pane.setEnabledAt (log_pos,false);
|
---|
345 | }
|
---|
346 | }
|
---|
347 | }
|
---|
348 | public void setReady (boolean ready){
|
---|
349 |
|
---|
350 | this.ready = ready;
|
---|
351 | }
|
---|
352 | }
|
---|
353 | }
|
---|