source: main/trunk/greenstone3/src/java/org/greenstone/admin/GAIManager.java@ 22085

Last change on this file since 22085 was 22085, checked in by sjm84, 14 years ago

Created a util package from classes that could be useful outside of their original packages

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