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 org.greenstone.core.Configuration;
|
---|
38 | import org.greenstone.core.Dictionary;
|
---|
39 | import org.greenstone.core.DebugStream;
|
---|
40 | import org.greenstone.core.util.Utility;
|
---|
41 |
|
---|
42 | //import java AWT classes
|
---|
43 | import java.awt.*;
|
---|
44 | import java.awt.event.*;
|
---|
45 | import java.io.*;
|
---|
46 | import java.net.*;
|
---|
47 | import java.util.*;
|
---|
48 | import javax.swing.*;
|
---|
49 | import javax.swing.event.*;
|
---|
50 | import javax.swing.plaf.*;
|
---|
51 |
|
---|
52 | public class GAIManager
|
---|
53 | extends JFrame
|
---|
54 | implements ActionListener, ChangeListener{
|
---|
55 |
|
---|
56 | //private static final Dimension SIZE = new Dimension (800, 600);
|
---|
57 | private Dimension size = null;
|
---|
58 | //public static String gsdl3_path = null;
|
---|
59 |
|
---|
60 | private JTabbedPane tab_pane = null;
|
---|
61 |
|
---|
62 | // Call the ConfPane
|
---|
63 | public ConfPane conf_pane = null;
|
---|
64 |
|
---|
65 | public JPanel ext_pane = null;
|
---|
66 |
|
---|
67 | public JPanel monitor_pane = null;
|
---|
68 |
|
---|
69 | // Call the LogPane
|
---|
70 | public LogPane log_pane = null;
|
---|
71 |
|
---|
72 | static public ImageIcon CONF_ICON = null;
|
---|
73 | static public ImageIcon EXT_ICON = null;
|
---|
74 | static public ImageIcon MONITOR_ICON = null;
|
---|
75 | static public ImageIcon LOG_ICON = null;
|
---|
76 |
|
---|
77 | // Create a menu bar in the main Pane
|
---|
78 | public MenuBar menu_bar = null;
|
---|
79 | // Setting up the MenuItem
|
---|
80 | public JMenu menu = null;
|
---|
81 |
|
---|
82 | private JPanel previous_pane = null;
|
---|
83 | private JPanel content_pane = null;
|
---|
84 | //public static String admin_path = null;
|
---|
85 |
|
---|
86 | //Contructor
|
---|
87 | public GAIManager(Dimension size){
|
---|
88 | super();
|
---|
89 | this.size = size;
|
---|
90 | this.setDefaultCloseOperation(EXIT_ON_CLOSE);
|
---|
91 | this.setTitle("GreenStone 3 Administration Tool");
|
---|
92 |
|
---|
93 | display();
|
---|
94 | }
|
---|
95 |
|
---|
96 | //private createMenuEvent (){
|
---|
97 |
|
---|
98 | public void actionPerformed (ActionEvent event){
|
---|
99 | Object esrc = event.getSource();
|
---|
100 | // File Options
|
---|
101 | if (esrc == menu_bar.file_exit){
|
---|
102 | System.exit(1);
|
---|
103 | }
|
---|
104 | //Edit Options
|
---|
105 | //Help Options
|
---|
106 | else if (esrc == menu_bar.help_conf){
|
---|
107 | }
|
---|
108 | else if (esrc == menu_bar.help_ext){
|
---|
109 | }
|
---|
110 | else if (esrc == menu_bar.help_monitor){
|
---|
111 | }
|
---|
112 | else if (esrc == menu_bar.help_log){
|
---|
113 | }
|
---|
114 | else if (esrc == menu_bar.help_about) {
|
---|
115 | }
|
---|
116 | }
|
---|
117 |
|
---|
118 | public void destory (){
|
---|
119 | // Destroying create pane ensures the latest log has been closed
|
---|
120 | //if (status_pane != null) {
|
---|
121 | //}
|
---|
122 | }
|
---|
123 |
|
---|
124 | // Listens to actions upon the menu bar
|
---|
125 | private class MenuListenerImpl
|
---|
126 | implements MenuListener {
|
---|
127 |
|
---|
128 | public void menuCanceled (MenuEvent e) {
|
---|
129 | }
|
---|
130 |
|
---|
131 | public void menuDeselected (MenuEvent e){
|
---|
132 | }
|
---|
133 |
|
---|
134 | public void menuSelected (MenuEvent e){
|
---|
135 | if (e.getSource() == menu_bar.help){
|
---|
136 | if (menu_bar.help.isSelected()){
|
---|
137 | menu_bar.help.doClick(10);
|
---|
138 | }
|
---|
139 | }
|
---|
140 | }
|
---|
141 | }
|
---|
142 |
|
---|
143 | public void display(){
|
---|
144 | CONF_ICON = new ImageIcon (GAI.admin_path+"images/properties24.gif");
|
---|
145 | EXT_ICON = new ImageIcon ("");
|
---|
146 | MONITOR_ICON = new ImageIcon (GAI.admin_path+ "images/examine.gif");
|
---|
147 | LOG_ICON = new ImageIcon (GAI.admin_path+"images/collection.gif");
|
---|
148 |
|
---|
149 | content_pane = (JPanel) this.getContentPane();
|
---|
150 |
|
---|
151 | try {
|
---|
152 | this.setSize(size);
|
---|
153 |
|
---|
154 | //create a menuBar
|
---|
155 | menu_bar = new MenuBar();
|
---|
156 |
|
---|
157 | this.setJMenuBar(menu_bar);
|
---|
158 | //Create the tabbed pane and put it in the center
|
---|
159 | tab_pane = new JTabbedPane();
|
---|
160 | tab_pane.addChangeListener(this);
|
---|
161 |
|
---|
162 | //set up the Configuration Pane
|
---|
163 | if (Configuration.get("admin.conf", true)){
|
---|
164 | conf_pane = new ConfPane();
|
---|
165 | conf_pane.display();
|
---|
166 | tab_pane.addTab("Configuration", CONF_ICON, conf_pane);
|
---|
167 | tab_pane.setEnabledAt(tab_pane.indexOfComponent(conf_pane),Configuration.get("admin.conf", false));
|
---|
168 | }
|
---|
169 |
|
---|
170 | //set up the ext Pane
|
---|
171 | if (Configuration.get("admin.ext", true)){
|
---|
172 | ext_pane = new JPanel();
|
---|
173 | //ext_pane.display();
|
---|
174 | tab_pane.addTab("Exts", EXT_ICON, ext_pane);
|
---|
175 | tab_pane.setEnabledAt(tab_pane.indexOfComponent(ext_pane),Configuration.get("admin.ext", false));
|
---|
176 | }
|
---|
177 |
|
---|
178 | //set up the Monitor Pane
|
---|
179 | if (Configuration.get("admin.monitor", true)){
|
---|
180 | monitor_pane = new JPanel();
|
---|
181 | //monitor_pane.display();
|
---|
182 | tab_pane.addTab("Monitor", MONITOR_ICON, monitor_pane);
|
---|
183 | tab_pane.setEnabledAt(tab_pane.indexOfComponent(monitor_pane),Configuration.get("admin.monitor", false));
|
---|
184 | }
|
---|
185 |
|
---|
186 | //set up the Log Pane
|
---|
187 | if (Configuration.get("admin.log", true)){
|
---|
188 | log_pane = new LogPane();
|
---|
189 | log_pane.display();
|
---|
190 | tab_pane.addTab("Log", LOG_ICON, log_pane);
|
---|
191 | tab_pane.setEnabledAt(tab_pane.indexOfComponent(log_pane),Configuration.get("admin.log", false));
|
---|
192 | }
|
---|
193 | content_pane.setLayout(new BorderLayout());
|
---|
194 | content_pane.add(tab_pane, BorderLayout.CENTER);
|
---|
195 | pack();
|
---|
196 | setVisible(true);
|
---|
197 | } catch (Exception e){
|
---|
198 | DebugStream.printStackTrace(e);
|
---|
199 | e.printStackTrace();
|
---|
200 | System.exit(1);
|
---|
201 | }
|
---|
202 | }
|
---|
203 |
|
---|
204 | /** Any implementation of ChangeListener must include this method
|
---|
205 | **so we can be informed when the state of one of the registered
|
---|
206 | **objects changes. In this case we are listening to view changes
|
---|
207 | **within the tabbed pane.
|
---|
208 | * @param event A ChangeEvent containing information about the event that fired this call.
|
---|
209 | */
|
---|
210 | public void stateChanged(ChangeEvent event) {
|
---|
211 | if(previous_pane != null) {
|
---|
212 | }
|
---|
213 |
|
---|
214 | //menu_bar.tabSelected(tab_pane.getSelectedIndex());
|
---|
215 | int selected_index = tab_pane.getSelectedIndex();
|
---|
216 | if (selected_index == tab_pane.indexOfComponent(log_pane)) {
|
---|
217 | log_pane.gainFocus();
|
---|
218 | }
|
---|
219 | else if (selected_index == tab_pane.indexOfComponent(conf_pane)) {
|
---|
220 | conf_pane.gainFocus();
|
---|
221 | }
|
---|
222 | previous_pane = (JPanel) tab_pane.getSelectedComponent();
|
---|
223 | }
|
---|
224 |
|
---|
225 | public void exit(){
|
---|
226 | DebugStream.println("****exit called");
|
---|
227 | System.exit(1);
|
---|
228 | }
|
---|
229 |
|
---|
230 | public void modeChanged (int mode){
|
---|
231 | if (log_pane != null){
|
---|
232 | log_pane.modeChanged(mode);
|
---|
233 | }
|
---|
234 | if (conf_pane !=null) {
|
---|
235 | conf_pane.modeChanged(mode);
|
---|
236 | }
|
---|
237 | }
|
---|
238 |
|
---|
239 | // public void refresh (int refresh_reason, boolean collection_loaded)
|
---|
240 | public void refresh () {
|
---|
241 | if (log_pane != null ){
|
---|
242 | }
|
---|
243 | //if (status_pane != null) {
|
---|
244 | //}
|
---|
245 | }
|
---|
246 |
|
---|
247 | public void returnToInitialPane(){
|
---|
248 | if (log_pane != null) {
|
---|
249 | tab_pane.setSelectedComponent(log_pane);
|
---|
250 | }
|
---|
251 | }
|
---|
252 | private class TabUpdater
|
---|
253 | implements Runnable {
|
---|
254 | private boolean ready = false;
|
---|
255 | private int conf_pos = -1;
|
---|
256 | private int ext_pos = -1;
|
---|
257 | private int monitor_pos = -1;
|
---|
258 | private int log_pos = -1;
|
---|
259 | private JTabbedPane tab_pane = null;
|
---|
260 |
|
---|
261 | public TabUpdater (JTabbedPane tab_pane, boolean ready){
|
---|
262 | this.ready = ready;
|
---|
263 | this.tab_pane = tab_pane;
|
---|
264 | conf_pos = tab_pane.indexOfComponent(conf_pane);
|
---|
265 | ext_pos = tab_pane.indexOfComponent(ext_pane);
|
---|
266 | monitor_pos = tab_pane.indexOfComponent(monitor_pane);
|
---|
267 | log_pos = tab_pane.indexOfComponent(log_pane);
|
---|
268 | }
|
---|
269 |
|
---|
270 | public void run() {
|
---|
271 | if (conf_pos != -1){
|
---|
272 | if (ready) {
|
---|
273 | tab_pane.setEnabledAt (conf_pos,Configuration.get("admin.conf", false));
|
---|
274 | } else {
|
---|
275 | tab_pane.setEnabledAt (conf_pos,Configuration.get("admin.conf",true));
|
---|
276 | }
|
---|
277 | }
|
---|
278 | if (ext_pos != -1){
|
---|
279 | if (ready) {
|
---|
280 | tab_pane.setEnabledAt (ext_pos,Configuration.get("admin.ext", false));
|
---|
281 | } else {
|
---|
282 | tab_pane.setEnabledAt (ext_pos,Configuration.get("admin.ext",true));
|
---|
283 | }
|
---|
284 | }
|
---|
285 | if (monitor_pos != -1){
|
---|
286 | if (ready) {
|
---|
287 | tab_pane.setEnabledAt (monitor_pos,Configuration.get("admin.monitor", false));
|
---|
288 | } else {
|
---|
289 | tab_pane.setEnabledAt (monitor_pos,Configuration.get("admin.monitor",true));
|
---|
290 | }
|
---|
291 | }
|
---|
292 | if (log_pos != -1){
|
---|
293 | if (ready) {
|
---|
294 | tab_pane.setEnabledAt (log_pos,Configuration.get("admin.log", false));
|
---|
295 | } else {
|
---|
296 | tab_pane.setEnabledAt (log_pos,Configuration.get("admin.log",true));
|
---|
297 | }
|
---|
298 | }
|
---|
299 | }
|
---|
300 | public void setReady (boolean ready){
|
---|
301 |
|
---|
302 | this.ready = ready;
|
---|
303 | }
|
---|
304 | }
|
---|
305 | }
|
---|
306 |
|
---|
307 |
|
---|