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: Chi-Yu Huang, Greenstone Digital Library, University of Waikato
|
---|
11 | * Modified: 03.2005
|
---|
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 | */
|
---|
38 | package org.greenstone.admin.gui;
|
---|
39 |
|
---|
40 | import java.awt.*;
|
---|
41 | import java.awt.event.*;
|
---|
42 | import java.io.*;
|
---|
43 | import java.util.*;
|
---|
44 | import javax.swing.*;
|
---|
45 | import javax.swing.event.*;
|
---|
46 | import javax.swing.tree.*;
|
---|
47 |
|
---|
48 | import org.greenstone.core.Configuration;
|
---|
49 | import org.greenstone.core.Dictionary;
|
---|
50 | import org.greenstone.core.util.Utility;
|
---|
51 | import org.greenstone.admin.GAIManager;
|
---|
52 | import org.greenstone.admin.GAI;
|
---|
53 |
|
---|
54 | /** The Log pane is to view the status of relevant log files in GSIII
|
---|
55 | * @author Chi-Yu Huang, Greenstone Digital Library, University of Waikato
|
---|
56 | * @version
|
---|
57 | */
|
---|
58 | public class LogPane
|
---|
59 | extends JPanel
|
---|
60 | implements ActionListener {
|
---|
61 |
|
---|
62 | // Main Pane
|
---|
63 | //protected JSplitPane main_pane = null;
|
---|
64 |
|
---|
65 | /* The pane to demonstrate log information, including the log files being
|
---|
66 | *monitored and their content*/
|
---|
67 | protected JSplitPane main_log_pane = null;
|
---|
68 |
|
---|
69 | /** The panel that contains a log_list */
|
---|
70 | private JPanel logList_pane = null;
|
---|
71 |
|
---|
72 | /** The panel that contains the log content. */
|
---|
73 | private JPanel logContent_pane = null;
|
---|
74 |
|
---|
75 | /** The List showing all the log files concerned. */
|
---|
76 | private JList log_list=null;
|
---|
77 |
|
---|
78 | /** The scrollable area into which the log content is placed. */
|
---|
79 | private JScrollPane log_content = null;
|
---|
80 |
|
---|
81 | /** The label at the top of the logList_pane. */
|
---|
82 | private JLabel logList_label = null;
|
---|
83 |
|
---|
84 | /** The label shown at the top of the logContent Pane. */
|
---|
85 | private JLabel logContent_label = null;
|
---|
86 |
|
---|
87 | /* Log TEXT AREA*/
|
---|
88 | private JTextArea log_textarea = null;
|
---|
89 |
|
---|
90 | // The control buttons used to manipulate log Pane
|
---|
91 | protected JPanel button_pane = null;
|
---|
92 |
|
---|
93 | /** Buttons */
|
---|
94 | private JButton reload_button = null;
|
---|
95 | private JButton delete_button = null;
|
---|
96 | private JButton exit_button = null;
|
---|
97 |
|
---|
98 | /*The pane which contains the controls for log files */
|
---|
99 | private JPanel control_pane = null;
|
---|
100 |
|
---|
101 | private File log_file = null;
|
---|
102 |
|
---|
103 | /** The various sizes for the screen layout*/
|
---|
104 | static private Dimension MIN_SIZE = new Dimension( 90, 90);
|
---|
105 | static private Dimension LIST_SIZE = new Dimension(200, 450);
|
---|
106 | static private Dimension LOGPANE_SIZE = new Dimension (800,450);
|
---|
107 |
|
---|
108 | //Constructor
|
---|
109 | public LogPane() {
|
---|
110 |
|
---|
111 | // create all the necessary panes
|
---|
112 | control_pane = new JPanel();
|
---|
113 | button_pane = new JPanel();
|
---|
114 |
|
---|
115 | // Log_Pane
|
---|
116 | main_log_pane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
|
---|
117 | main_log_pane.setPreferredSize(LOGPANE_SIZE);
|
---|
118 | //log_pane.setSize(LOGPANE_SIZE);
|
---|
119 |
|
---|
120 | // Log_list
|
---|
121 | String[] log_files = { "Tomcat log file", "Log file 2", "Log file 3"};
|
---|
122 | log_list = new JList(log_files);
|
---|
123 | log_list.setBorder(BorderFactory.createLoweredBevelBorder());
|
---|
124 | log_list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
---|
125 | log_list.setVisibleRowCount(4);
|
---|
126 | log_list.setBackground (Configuration.getColor("coloring.workspace_tree_background", false));
|
---|
127 | log_list.setForeground (Configuration.getColor("coloring.workspace_tree_foreground", false));
|
---|
128 | log_list.addListSelectionListener(new LogListListener());
|
---|
129 |
|
---|
130 | // Log_TextArea
|
---|
131 | log_textarea = new JTextArea();
|
---|
132 | log_textarea.setEditable(false);
|
---|
133 |
|
---|
134 | // Buttons
|
---|
135 | ReloadButtonListener rbl = new ReloadButtonListener();
|
---|
136 | DeleteButtonListener dbl = new DeleteButtonListener();
|
---|
137 | //ExitButtonListener ebl = new ExitButtonListener();
|
---|
138 | ImageIcon reloadButtonIcon = new ImageIcon(GAI.admin_path + "images/toolbarButtonGraphics/general/Refresh16.gif");
|
---|
139 | ImageIcon deleteButtonIcon = new ImageIcon(GAI.admin_path + "images/toolbarButtonGraphics/general/Delete16.gif");
|
---|
140 | ImageIcon exitButtonIcon = new ImageIcon(GAI.admin_path + "images/exit16.gif");
|
---|
141 |
|
---|
142 | reload_button = new JButton("Reload", reloadButtonIcon);
|
---|
143 | reload_button.addActionListener(rbl);
|
---|
144 | reload_button.setMnemonic(KeyEvent.VK_R);
|
---|
145 | reload_button.setToolTipText("Click this button to reload the log file");
|
---|
146 | //Dictionary.registerBoth(build_button, "CreatePane.Build_Collection", "CreatePane.Build_Collection_Tooltip");
|
---|
147 |
|
---|
148 | delete_button = new JButton("Delete", deleteButtonIcon);
|
---|
149 | delete_button.addActionListener(dbl);
|
---|
150 | delete_button.setEnabled(false);
|
---|
151 | delete_button.setMnemonic(KeyEvent.VK_D);
|
---|
152 | delete_button.setToolTipText("Click this button to delete the log file");
|
---|
153 | //Dictionary.registerBoth(cancel_button, "CreatePane.Cancel_Build", "CreatePane.Cancel_Build_Tooltip");*/
|
---|
154 |
|
---|
155 | /*exit_button = new JButton("Exit", exitButtonIcon);
|
---|
156 | exit_button.setToolTipText("Click this button to exit the viewing");
|
---|
157 | exit_button.addActionListener(ebl);
|
---|
158 | exit_button.setEnabled(true);
|
---|
159 | exit_button.setMnemonic(KeyEvent.VK_E);*/
|
---|
160 |
|
---|
161 | rbl = null;
|
---|
162 | dbl = null;
|
---|
163 | //ebl = null;
|
---|
164 | }
|
---|
165 |
|
---|
166 | /** Any implementation of ActionListener requires this method so that when an
|
---|
167 | **action is performed the appropriate effect can occur.*/
|
---|
168 |
|
---|
169 | public void actionPerformed(ActionEvent event) {
|
---|
170 | }
|
---|
171 |
|
---|
172 |
|
---|
173 | /** This method is callsed to actually layout the components.*/
|
---|
174 | public void display() {
|
---|
175 | // Create Components.
|
---|
176 | //KeyListenerImpl key_listener = new KeyListenerImpl();
|
---|
177 | //MouseListenerImpl mouse_listener = new MouseListenerImpl();
|
---|
178 | //this.addKeyListener(key_listener);
|
---|
179 |
|
---|
180 | // logList_Pane
|
---|
181 | logList_pane = new JPanel();
|
---|
182 | logList_pane.setBorder(BorderFactory.createLoweredBevelBorder());
|
---|
183 | logList_label = new JLabel("Log Files");
|
---|
184 | logList_label.setOpaque(true);
|
---|
185 | logList_label.setBackground(Configuration.getColor("coloring.workspace_heading_background", false));
|
---|
186 | logList_label.setForeground(Configuration.getColor("coloring.workspace_heading_foreground", false));
|
---|
187 | //Dictionary.registerText(logList_label, "Log.List");
|
---|
188 |
|
---|
189 | // logContent_Pane
|
---|
190 | logContent_pane = new JPanel();
|
---|
191 | logContent_pane.setBorder(BorderFactory.createLoweredBevelBorder());
|
---|
192 | logContent_pane.setBackground(Configuration.getColor("coloring.workspace_selection_background", false));
|
---|
193 | logContent_pane.setForeground(Configuration.getColor("coloring.workspace_selection_foreground", false));
|
---|
194 | logContent_label = new JLabel("Log Content");
|
---|
195 | logContent_label.setOpaque(true);
|
---|
196 | logContent_label.setBackground(Configuration.getColor("coloring.workspace_heading_background", false));
|
---|
197 | logContent_label.setForeground(Configuration.getColor("coloring.workspace_heading_foreground", false));
|
---|
198 | //Dictionary.registerText(logContent_label, "Log.Content");
|
---|
199 |
|
---|
200 | // TEXTAREA Layout
|
---|
201 | log_content = new JScrollPane(log_textarea);
|
---|
202 |
|
---|
203 | // Button Layout
|
---|
204 | button_pane.setLayout (new GridLayout(1,3));
|
---|
205 | button_pane.add(reload_button);
|
---|
206 | button_pane.add(delete_button);
|
---|
207 | //button_pane.add(exit_button);
|
---|
208 |
|
---|
209 | control_pane.setLayout (new BorderLayout());
|
---|
210 | //control_pane.setBorder(BorderFactory.createLoweredBevelBorder());
|
---|
211 | control_pane.setBorder(BorderFactory.createEmptyBorder(05,10,5,10));
|
---|
212 | control_pane.setPreferredSize(new Dimension(50,50));
|
---|
213 | control_pane.setSize(new Dimension(50,50));
|
---|
214 | control_pane.add (button_pane, BorderLayout.CENTER);
|
---|
215 |
|
---|
216 | // Layout Components
|
---|
217 | logList_pane.setLayout(new BorderLayout());
|
---|
218 | logList_pane.add(log_list, BorderLayout.CENTER);
|
---|
219 | logList_pane.add(logList_label, BorderLayout.NORTH);
|
---|
220 |
|
---|
221 | logContent_pane.setLayout(new BorderLayout());
|
---|
222 | logContent_pane.add(log_content,BorderLayout.CENTER);
|
---|
223 | logContent_pane.add(logContent_label, BorderLayout.NORTH);
|
---|
224 | logContent_pane.add(control_pane, BorderLayout.SOUTH);
|
---|
225 |
|
---|
226 | main_log_pane.add(logList_pane, JSplitPane.LEFT);
|
---|
227 | main_log_pane.add(logContent_pane, JSplitPane.RIGHT);
|
---|
228 | main_log_pane.setDividerLocation(LIST_SIZE.width - 10);
|
---|
229 |
|
---|
230 | this.setLayout(new BorderLayout());
|
---|
231 | this.add(main_log_pane, BorderLayout.CENTER);
|
---|
232 | //this.add(control_pane, BorderLayout.SOUTH);
|
---|
233 | }
|
---|
234 |
|
---|
235 | /** Called whenever this pane gains focus, this method ensures that the various
|
---|
236 | **tree renderers are correctly colouring the tree (as these settings sometimes get lost).
|
---|
237 | * @param event A <strong>FocusEvent</strong> containing details about the focus action performed.
|
---|
238 | */
|
---|
239 | /*public void focusGained(FocusEvent event) {
|
---|
240 | DefaultTreeCellRenderer def = new DefaultTreeCellRenderer();
|
---|
241 | DefaultTreeCellRenderer w = (DefaultTreeCellRenderer)workspace_tree.getCellRenderer();
|
---|
242 | DefaultTreeCellRenderer c = (DefaultTreeCellRenderer)collection_tree.getCellRenderer();
|
---|
243 | if(event.getSource() == workspace_tree) {
|
---|
244 | w.setBackgroundSelectionColor(def.getBackgroundSelectionColor());
|
---|
245 | c.setBackgroundSelectionColor(Color.lightGray);
|
---|
246 | }
|
---|
247 | else if(event.getSource() == collection_tree) {
|
---|
248 | c.setBackgroundSelectionColor(def.getBackgroundSelectionColor());
|
---|
249 | w.setBackgroundSelectionColor(Color.lightGray);
|
---|
250 | }
|
---|
251 | repaint();
|
---|
252 | }*/
|
---|
253 |
|
---|
254 | /** Implementation side-effect, not used in any way.
|
---|
255 | * @param event A <strong>FocusEvent</strong> containing details about the focus action performed.
|
---|
256 | */
|
---|
257 | /*public void focusLost(FocusEvent event) {
|
---|
258 | }*/
|
---|
259 |
|
---|
260 | /** Called to inform this control panel that it has just gained focus as an effect of the user clicking on its tab.
|
---|
261 | */
|
---|
262 | public void gainFocus() {
|
---|
263 | // Update the meta-audit view to show the current selection, if any.
|
---|
264 | //Gatherer.g_man.meta_audit.setRecords(getCollectionTreeSelection());
|
---|
265 | }
|
---|
266 |
|
---|
267 | /** Called whenever the detail mode changes to ensure the filters are at an appropriate
|
---|
268 | **level (ie only editable by those that understand regular expression matching)
|
---|
269 | * @param mode the mode level as an int
|
---|
270 | */
|
---|
271 | /* public void modeChanged(int mode) {
|
---|
272 | collection_filter.setEditable(mode > Configuration.LIBRARIAN_MODE);
|
---|
273 | workspace_filter.setEditable(mode > Configuration.LIBRARIAN_MODE);
|
---|
274 | }*/
|
---|
275 |
|
---|
276 |
|
---|
277 | /** Refresh this pane, depending on what has just happened (refresh_reason). */
|
---|
278 | /*public void refresh(int refresh_reason, boolean collection_loaded)
|
---|
279 | {
|
---|
280 | if (collection_loaded) {
|
---|
281 | // Update collection label
|
---|
282 | Dictionary.registerText(collection_label, "Collection.Collection");
|
---|
283 | collection_label.setBackground(Configuration.getColor("coloring.collection_heading_background", false));
|
---|
284 | collection_label.setForeground(Configuration.getColor("coloring.collection_heading_foreground", false));
|
---|
285 |
|
---|
286 | // Update collection tree
|
---|
287 | if (refresh_reason == Gatherer.COLLECTION_OPENED) {
|
---|
288 | collection_tree.setModel(Gatherer.c_man.getCollectionTreeModel());
|
---|
289 | }
|
---|
290 | // Update collection filter
|
---|
291 | collection_filter.setBackground(Configuration.getColor("coloring.collection_heading_background", false));
|
---|
292 | }
|
---|
293 | else {
|
---|
294 | // Update collection label
|
---|
295 | String[] args = new String[1];
|
---|
296 | args[0] = Dictionary.get("Collection.No_Collection");
|
---|
297 | Dictionary.registerText(collection_label, "Collection.Collection", args);
|
---|
298 | collection_label.setBackground(Color.lightGray);
|
---|
299 | collection_label.setForeground(Color.black);
|
---|
300 |
|
---|
301 | // Update collection tree
|
---|
302 | collection_tree.setModel(new DefaultTreeModel(new DefaultMutableTreeNode("Error")));
|
---|
303 |
|
---|
304 | // Update collection filter
|
---|
305 | collection_filter.setBackground(Color.lightGray);
|
---|
306 | }
|
---|
307 |
|
---|
308 | // Enable or disable the controls
|
---|
309 | workspace_tree.setEnabled(true);
|
---|
310 | collection_tree.setEnabled(collection_loaded);
|
---|
311 | collection_filter.setEnabled(collection_loaded);
|
---|
312 | bin_button.setEnabled(collection_loaded);
|
---|
313 | new_folder.setEnabled(collection_loaded);
|
---|
314 |
|
---|
315 | // Ensure that this collection tree view is synchronized with all others
|
---|
316 | collection_tree_sync.add(collection_tree);
|
---|
317 | }*/
|
---|
318 |
|
---|
319 | private class KeyListenerImpl
|
---|
320 | extends KeyAdapter {
|
---|
321 | private boolean vk_left_pressed = false;
|
---|
322 | public void keyReleased(KeyEvent event) {
|
---|
323 | }
|
---|
324 |
|
---|
325 | // we need to watch for left clicks on an unopened folder - should shift the focus to the
|
---|
326 | //parent folder. But because there is some other mysterious key listener that does opening and
|
---|
327 | //closing folders on right and left clicks, we must detect the situation before the other handler
|
---|
328 | //has done its job, and process it after.*/
|
---|
329 |
|
---|
330 | public void keyPressed(KeyEvent event) {
|
---|
331 | if (event.getKeyCode() == KeyEvent.VK_LEFT) {
|
---|
332 |
|
---|
333 | }
|
---|
334 | }
|
---|
335 | }
|
---|
336 |
|
---|
337 | /** This class listens for mouse clicks and responds right mouse button clicks (popup menu)., left
|
---|
338 | ** mouse button:log file selected */
|
---|
339 | private class MouseListenerImpl
|
---|
340 | extends MouseAdapter {
|
---|
341 | /* Any subclass of MouseAdapter can override this method to respond to mouse click events.
|
---|
342 | *In this case we want to open a pop-up menu if we detect a right mouse click over one of our
|
---|
343 | *registered components, and start an external application if someone double clicks on a certain
|
---|
344 | *file record. */
|
---|
345 |
|
---|
346 | /*public void mouseReleased(MouseEvent e) {}
|
---|
347 | public void mouseExited(MouseEvent e) {}
|
---|
348 | public void mousePressed(MouseEvent e) {}
|
---|
349 | public void mouseEntered(MouseEvent e) {}*/
|
---|
350 |
|
---|
351 | }
|
---|
352 |
|
---|
353 | /** This class serves as the listener for actions on the build button. */
|
---|
354 | private class ReloadButtonListener
|
---|
355 | implements ActionListener {
|
---|
356 | /** As the log files could be modified in the runtime environment
|
---|
357 | * This button is to reload the log file whenever user want to */
|
---|
358 | public void actionPerformed(ActionEvent event) {
|
---|
359 | // Remember that for lower thresholds the above doesn't work, so try this instead
|
---|
360 | reload_button.setEnabled(true);
|
---|
361 | delete_button.setEnabled(true);
|
---|
362 | updateLogsContent(log_file.getPath());
|
---|
363 | }
|
---|
364 | }
|
---|
365 |
|
---|
366 | private class DeleteButtonListener
|
---|
367 | implements ActionListener {
|
---|
368 | public void actionPerformed(ActionEvent event) {
|
---|
369 | //log_file.
|
---|
370 | if (!log_file.exists()){
|
---|
371 | JOptionPane.showMessageDialog((Component) null,log_file.getPath() + " log file does not exist");
|
---|
372 | return;
|
---|
373 | } else {
|
---|
374 | DeleteLogFilePrompt dfp = new DeleteLogFilePrompt();
|
---|
375 | boolean file_deleted = dfp.display(log_file);
|
---|
376 | if (file_deleted) {
|
---|
377 | log_textarea.setText("");
|
---|
378 | }
|
---|
379 | }
|
---|
380 | delete_button.setEnabled(true);
|
---|
381 | }
|
---|
382 | }
|
---|
383 |
|
---|
384 | /* private class ExitButtonListener
|
---|
385 | implements ActionListener {
|
---|
386 | // Exit the Adminstration tool
|
---|
387 | public void actionPerformed(ActionEvent event) {
|
---|
388 | System.exit(1);
|
---|
389 | }
|
---|
390 | }*/
|
---|
391 |
|
---|
392 | public void updateLogsContent(String filename){
|
---|
393 | if (!log_file.exists()){
|
---|
394 | log_textarea.setText("");
|
---|
395 | JOptionPane.showMessageDialog((Component) null, filename+" log file does not exist");
|
---|
396 | delete_button.setEnabled(false);
|
---|
397 | } else {
|
---|
398 | readFile(filename);
|
---|
399 | }
|
---|
400 | }
|
---|
401 |
|
---|
402 | public void readFile (String filename) {
|
---|
403 | log_textarea.setText("");
|
---|
404 | String fileLine;
|
---|
405 | int line_number = 0;
|
---|
406 | try {
|
---|
407 | BufferedReader in = new BufferedReader(new FileReader(filename));
|
---|
408 | while ((fileLine = in.readLine()) != null) {
|
---|
409 | log_textarea.append(fileLine);
|
---|
410 | log_textarea.append("\n");
|
---|
411 | line_number =line_number + 1;
|
---|
412 | }
|
---|
413 | } catch (Exception e) {
|
---|
414 | e.printStackTrace();
|
---|
415 | }
|
---|
416 | }
|
---|
417 |
|
---|
418 | private class LogListListener implements ListSelectionListener {
|
---|
419 | public void valueChanged (ListSelectionEvent e){
|
---|
420 | if (e.getValueIsAdjusting() == false){
|
---|
421 | if (log_list.getSelectedIndex() == -1){
|
---|
422 | //no selection
|
---|
423 | } else if (log_list.getSelectedIndex () == 0 ) {
|
---|
424 | log_file = new File (GAI.tomcat_file_path+"catalina.out");
|
---|
425 | String filename = log_file.getPath();
|
---|
426 | updateLogsContent(filename);
|
---|
427 | reload_button.setEnabled(true);
|
---|
428 | delete_button.setEnabled(true);
|
---|
429 | } else if (log_list.getSelectedIndex () == 1) {
|
---|
430 | /*log_file = new File (GAI.gsdl3_path+"/ant_out.log");
|
---|
431 | String filename = log_file.getPath();
|
---|
432 | updateLogsContent(filename);
|
---|
433 | delete_button.setEnabled(true);*/
|
---|
434 | log_textarea.setText("");
|
---|
435 | JOptionPane.showMessageDialog((Component) null,"This file has not been defined yet");
|
---|
436 | delete_button.setEnabled(false);
|
---|
437 | reload_button.setEnabled(false);
|
---|
438 | } else if (log_list.getSelectedIndex () == 2) {
|
---|
439 | log_textarea.setText("");
|
---|
440 | JOptionPane.showMessageDialog((Component) null,"This file has not been defined yet");
|
---|
441 | delete_button.setEnabled(false);
|
---|
442 | reload_button.setEnabled(false);
|
---|
443 | }
|
---|
444 | }
|
---|
445 | }
|
---|
446 | }
|
---|
447 | public void modeChanged (int mode){
|
---|
448 | return;
|
---|
449 | }
|
---|
450 | }
|
---|