source: main/trunk/greenstone3/src/java/org/greenstone/admin/gui/LogPane.java@ 21934

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

Added a filter box to the GAI log pane

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