source: trunk/gsdl3/src/java/org/greenstone/admin/gui/LogPane.java@ 10929

Last change on this file since 10929 was 10929, checked in by kjdon, 18 years ago

merged Chi's admin stuff from ant install branch into main repository

  • Property svn:keywords set to Author Date Id Revision
File size: 13.7 KB
Line 
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 */
38package org.greenstone.admin.gui;
39
40import java.awt.*;
41import java.awt.event.*;
42import java.io.*;
43import java.util.*;
44import javax.swing.*;
45import javax.swing.event.*;
46import javax.swing.tree.*;
47
48import org.greenstone.admin.GAIManager;
49import org.greenstone.admin.GAI;
50import org.greenstone.core.Configuration;
51import org.greenstone.core.Dictionary;
52import org.greenstone.core.util.Utility;
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 */
58public class LogPane
59 extends JPanel
60 implements ActionListener {
61
62 /* The pane to demonstrate log information, including the log files being
63 *monitored and their content*/
64 protected JSplitPane main_log_pane = null;
65
66 /** The panel that contains a log_list */
67 private JPanel logList_pane = null;
68
69 /** The panel that contains the log content. */
70 private JPanel logContent_pane = null;
71
72 /** The List showing all the log files concerned. */
73 private JList log_list=null;
74
75 /** The scrollable area into which the log content is placed. */
76 private JScrollPane log_content = null;
77
78 /** The label at the top of the logList_pane. */
79 private JLabel logList_label = null;
80
81 /** The label shown at the top of the logContent Pane. */
82 private JLabel logContent_label = null;
83
84 /* Log TEXT AREA*/
85 private JTextArea log_textarea = null;
86
87 // The control buttons used to manipulate log Pane
88 protected JPanel button_pane = null;
89
90 /** Buttons */
91 private JButton reload_button = null;
92 private JButton clear_button = null;
93
94 /*The pane which contains the controls for log files */
95 private JPanel control_pane = null;
96
97 private File log_file = null;
98
99 /** The various sizes for the screen layout*/
100 static private Dimension MIN_SIZE = new Dimension( 90, 90);
101 static private Dimension LIST_SIZE = new Dimension(200, 450);
102 static private Dimension LOGPANE_SIZE = new Dimension (800,450);
103
104 //Constructor
105 public LogPane() {
106
107 // create all the necessary panes
108 control_pane = new JPanel();
109 button_pane = new JPanel();
110
111 // Log_Pane
112 main_log_pane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
113 main_log_pane.setPreferredSize(LOGPANE_SIZE);
114 //log_pane.setSize(LOGPANE_SIZE);
115
116 // Log_list
117 String[] log_files = { "Tomcat log file", "Log file 2", "Log file 3"};
118 log_list = new JList(log_files);
119 log_list.setBorder(BorderFactory.createLoweredBevelBorder());
120 log_list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
121 log_list.setVisibleRowCount(4);
122 log_list.setBackground (Configuration.getColor("coloring.workspace_tree_background", false));
123 log_list.setForeground (Configuration.getColor("coloring.workspace_tree_foreground", false));
124 log_list.addListSelectionListener(new LogListListener());
125
126 // Log_TextArea
127 log_textarea = new JTextArea();
128 log_textarea.setEditable(false);
129
130 // Buttons
131 ReloadButtonListener rbl = new ReloadButtonListener();
132 ClearButtonListener dbl = new ClearButtonListener();
133 ImageIcon reloadButtonIcon = new ImageIcon(GAI.images_path + "toolbarButtonGraphics/general/Refresh16.gif");
134 ImageIcon clearButtonIcon = new ImageIcon(GAI.images_path + "toolbarButtonGraphics/general/Delete16.gif");
135
136 //reload_button = new JButton("Reload", reloadButtonIcon);
137 reload_button = new JButton();
138 reload_button.addActionListener(rbl);
139 reload_button.setEnabled(false);
140 reload_button.setMnemonic(KeyEvent.VK_R);
141 Dictionary.registerBoth(reload_button, "LogPane.Reload_Log", "LogPane.Reload_Log_Tooltip");
142
143 clear_button = new JButton();
144 clear_button.addActionListener(dbl);
145 clear_button.setEnabled(false);
146 clear_button.setMnemonic(KeyEvent.VK_C);
147 Dictionary.registerBoth(clear_button, "LogPane.Clear_Log", "LogPane.Clear_Log_Tooltip");
148
149 rbl = null;
150 dbl = null;
151 }
152
153 /** Any implementation of ActionListener requires this method so that when an
154 **action is performed the appropriate effect can occur.*/
155
156 public void actionPerformed(ActionEvent event) {
157 }
158
159
160 /** This method is callsed to actually layout the components.*/
161 public void display() {
162 // Create Components.
163 //KeyListenerImpl key_listener = new KeyListenerImpl();
164 //MouseListenerImpl mouse_listener = new MouseListenerImpl();
165 //this.addKeyListener(key_listener);
166
167 // logList_Pane
168 logList_pane = new JPanel();
169 logList_pane.setBorder(BorderFactory.createLoweredBevelBorder());
170 logList_label = new JLabel();
171 logList_label.setOpaque(true);
172 logList_label.setBackground(Configuration.getColor("coloring.workspace_heading_background", false));
173 logList_label.setForeground(Configuration.getColor("coloring.workspace_heading_foreground", false));
174 Dictionary.registerText(logList_label, "LogPane.Log_List");
175
176 // logContent_Pane
177 logContent_pane = new JPanel();
178 logContent_pane.setBorder(BorderFactory.createLoweredBevelBorder());
179 logContent_pane.setBackground(Configuration.getColor("coloring.workspace_selection_background", false));
180 logContent_pane.setForeground(Configuration.getColor("coloring.workspace_selection_foreground", false));
181 logContent_label = new JLabel();
182 logContent_label.setOpaque(true);
183 logContent_label.setBackground(Configuration.getColor("coloring.workspace_selection_background", false));
184 logContent_label.setForeground(Configuration.getColor("coloring.workspace_selection_foreground", false));
185 Dictionary.registerText(logContent_label, "LogPane.Log_Content");
186
187 // TEXTAREA Layout
188 log_content = new JScrollPane(log_textarea);
189
190 // Button Layout
191 button_pane.setLayout (new GridLayout(1,3));
192 button_pane.add(reload_button);
193 button_pane.add(clear_button);
194
195 control_pane.setLayout (new BorderLayout());
196 //control_pane.setBorder(BorderFactory.createLoweredBevelBorder());
197 control_pane.setBorder(BorderFactory.createEmptyBorder(05,10,5,10));
198 control_pane.setPreferredSize(new Dimension(50,50));
199 control_pane.setSize(new Dimension(50,50));
200 control_pane.add (button_pane, BorderLayout.CENTER);
201
202 // Layout Components
203 logList_pane.setLayout(new BorderLayout());
204 logList_pane.add(log_list, BorderLayout.CENTER);
205 logList_pane.add(logList_label, BorderLayout.NORTH);
206
207 logContent_pane.setLayout(new BorderLayout());
208 logContent_pane.add(log_content,BorderLayout.CENTER);
209 logContent_pane.add(logContent_label, BorderLayout.NORTH);
210 logContent_pane.add(control_pane, BorderLayout.SOUTH);
211
212 main_log_pane.add(logList_pane, JSplitPane.LEFT);
213 main_log_pane.add(logContent_pane, JSplitPane.RIGHT);
214 main_log_pane.setDividerLocation(LIST_SIZE.width - 10);
215
216 this.setLayout(new BorderLayout());
217 this.add(main_log_pane, BorderLayout.CENTER);
218 //this.add(control_pane, BorderLayout.SOUTH);
219 }
220
221 /** Called whenever this pane gains focus, this method ensures that the various
222 **tree renderers are correctly colouring the tree (as these settings sometimes get lost).
223 * @param event A <strong>FocusEvent</strong> containing details about the focus action performed.
224 */
225 /*public void focusGained(FocusEvent event) {
226 DefaultTreeCellRenderer def = new DefaultTreeCellRenderer();
227 DefaultTreeCellRenderer w = (DefaultTreeCellRenderer)workspace_tree.getCellRenderer();
228 DefaultTreeCellRenderer c = (DefaultTreeCellRenderer)collection_tree.getCellRenderer();
229 if(event.getSource() == workspace_tree) {
230 w.setBackgroundSelectionColor(def.getBackgroundSelectionColor());
231 c.setBackgroundSelectionColor(Color.lightGray);
232 }
233 else if(event.getSource() == collection_tree) {
234 c.setBackgroundSelectionColor(def.getBackgroundSelectionColor());
235 w.setBackgroundSelectionColor(Color.lightGray);
236 }
237 repaint();
238 }*/
239
240 /** Implementation side-effect, not used in any way.
241 * @param event A <strong>FocusEvent</strong> containing details about the focus action performed.
242 */
243 /*public void focusLost(FocusEvent event) {
244 }*/
245
246 /** Called to inform this control panel that it has just gained focus as an effect of the user clicking on its tab.
247 */
248 public void gainFocus() {
249 // Update the meta-audit view to show the current selection, if any.
250 //Gatherer.g_man.meta_audit.setRecords(getCollectionTreeSelection());
251 }
252
253 /** Called whenever the detail mode changes to ensure the filters are at an appropriate
254 **level (ie only editable by those that understand regular expression matching)
255 * @param mode the mode level as an int
256 */
257 /* public void modeChanged(int mode) {
258 collection_filter.setEditable(mode > Configuration.LIBRARIAN_MODE);
259 workspace_filter.setEditable(mode > Configuration.LIBRARIAN_MODE);
260 }*/
261
262 private class KeyListenerImpl
263 extends KeyAdapter {
264 private boolean vk_left_pressed = false;
265 public void keyReleased(KeyEvent event) {
266 }
267 // we need to watch for left clicks on an unopened folder - should shift the focus to the
268 //parent folder. But because there is some other mysterious key listener that does opening and
269 //closing folders on right and left clicks, we must detect the situation before the other handler
270 //has done its job, and process it after.*/
271 public void keyPressed(KeyEvent event) {
272 if (event.getKeyCode() == KeyEvent.VK_LEFT) {
273
274 }
275 }
276 }
277
278 /** This class listens for mouse clicks and responds right mouse button clicks (popup menu)., left
279 ** mouse button:log file selected */
280 private class MouseListenerImpl
281 extends MouseAdapter {
282 /* Any subclass of MouseAdapter can override this method to respond to mouse click events.
283 *In this case we want to open a pop-up menu if we detect a right mouse click over one of our
284 *registered components, and start an external application if someone double clicks on a certain
285 *file record. */
286 public void mouseReleased(MouseEvent e) {}
287 public void mouseExited(MouseEvent e) {}
288 public void mousePressed(MouseEvent e) {}
289 public void mouseEntered(MouseEvent e) {}
290
291 }
292
293 /** This class serves as the listener for actions on the build button. */
294 private class ReloadButtonListener
295 implements ActionListener {
296 /** As the log files could be modified in the runtime environment
297 * This button is to reload the log file whenever user want to */
298 public void actionPerformed(ActionEvent event) {
299 // Remember that for lower thresholds the above doesn't work, so try this instead
300 reload_button.setEnabled(true);
301 clear_button.setEnabled(true);
302 updateLogsContent(log_file.getPath());
303 }
304 }
305
306 private class ClearButtonListener
307 implements ActionListener {
308 public void actionPerformed(ActionEvent event) {
309 if (!log_file.exists()){
310 JOptionPane.showMessageDialog((Component) null,log_file.getPath() + " log file does not exist");
311 return;
312 } else {
313 ClearLogFilePrompt cfp = new ClearLogFilePrompt();
314 boolean file_cleared = cfp.display(log_file);
315 if (file_cleared) {
316 log_textarea.setText("");
317 }
318 }
319 clear_button.setEnabled(false);
320 }
321 }
322
323 public void updateLogsContent(String filename){
324 if (!log_file.exists()){
325 log_textarea.setText("");
326 JOptionPane.showMessageDialog((Component) null, filename+" log file does not exist");
327 clear_button.setEnabled(false);
328 } else {
329 readFile(filename);
330 }
331 }
332
333 public void readFile (String filename) {
334 log_textarea.setText("");
335 String fileLine;
336 try {
337 BufferedReader in = new BufferedReader(new FileReader(filename));
338 while ((fileLine = in.readLine()) != null) {
339 log_textarea.append(fileLine);
340 log_textarea.append("\n");
341 }
342 } catch (Exception e) {
343 e.printStackTrace();
344 }
345 }
346
347 private class LogListListener implements ListSelectionListener {
348 public void valueChanged (ListSelectionEvent e){
349 if (e.getValueIsAdjusting() == false){
350 if (log_list.getSelectedIndex() == -1){
351 //no selection
352 } else if (log_list.getSelectedIndex () == 0 ) {
353 log_file = new File (GAI.tomcat_file_path+"catalina.out");
354 String filename = log_file.getPath();
355 updateLogsContent(filename);
356 reload_button.setEnabled(true);
357 clear_button.setEnabled(true);
358 } else if (log_list.getSelectedIndex () == 1) {
359 log_textarea.setText("");
360 JOptionPane.showMessageDialog((Component) null,"This file has not been defined yet");
361 clear_button.setEnabled(false);
362 reload_button.setEnabled(false);
363 } else if (log_list.getSelectedIndex () == 2) {
364 log_textarea.setText("");
365 JOptionPane.showMessageDialog((Component) null,"This file has not been defined yet");
366 clear_button.setEnabled(false);
367 reload_button.setEnabled(false);
368 }
369 }
370 }
371 }
372 public void modeChanged (int mode){
373 return;
374 }
375 public void afterDisplay() {
376 return;
377 }
378}
Note: See TracBrowser for help on using the repository browser.