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

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

Added an additional file and modified an existing file for the GAI extension manager

  • Property svn:keywords set to Author Date Id Revision
File size: 13.8 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 File log_file = null;
96
97 /** The various sizes for the screen layout*/
98 static private Dimension MIN_SIZE = new Dimension( 90, 90);
99 static private Dimension LIST_SIZE = new Dimension(200, 450);
100 static private Dimension LOGPANE_SIZE = new Dimension (800,450);
101
102 //Constructor
103 public LogPane() {
104
105 // create all the necessary panes
106 control_pane = new JPanel();
107 button_pane = new JPanel();
108
109 // Log_Pane
110 main_log_pane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
111 main_log_pane.setPreferredSize(LOGPANE_SIZE);
112 //log_pane.setSize(LOGPANE_SIZE);
113
114 // Log_list
115 String[] log_files = { "Tomcat log file", "Extension log file", "Log file 3"};
116 log_list = new JList(log_files);
117 log_list.setBorder(BorderFactory.createLoweredBevelBorder());
118 log_list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
119 log_list.setVisibleRowCount(4);
120 log_list.setBackground (Configuration.getColor("coloring.workspace_tree_background"));
121 log_list.setForeground (Configuration.getColor("coloring.workspace_tree_foreground"));
122 log_list.addListSelectionListener(new LogListListener());
123
124 // Log_TextArea
125 log_textarea = new JTextArea();
126 log_textarea.setEditable(false);
127
128 // Buttons
129 ReloadButtonListener rbl = new ReloadButtonListener();
130 ClearButtonListener dbl = new ClearButtonListener();
131 ImageIcon reloadButtonIcon = new ImageIcon(GAI.images_path + "toolbarButtonGraphics/general/Refresh16.gif");
132 ImageIcon clearButtonIcon = new ImageIcon(GAI.images_path + "toolbarButtonGraphics/general/Delete16.gif");
133
134 //reload_button = new JButton("Reload", reloadButtonIcon);
135 reload_button = new JButton();
136 reload_button.addActionListener(rbl);
137 reload_button.setEnabled(false);
138 reload_button.setMnemonic(KeyEvent.VK_R);
139 reload_button.setText(GAI.dictionary.get("LogPane.Reload_Log"));
140 reload_button.setToolTipText(GAI.dictionary.get("LogPane.Reload_Log_Tooltip"));
141
142 clear_button = new JButton();
143 clear_button.addActionListener(dbl);
144 clear_button.setEnabled(false);
145 clear_button.setMnemonic(KeyEvent.VK_C);
146 clear_button.setText(GAI.dictionary.get("LogPane.Clear_Log"));
147 clear_button.setToolTipText(GAI.dictionary.get("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"));
173 logList_label.setForeground(Configuration.getColor("coloring.workspace_heading_foreground"));
174 logList_label.setText(GAI.dictionary.get("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"));
180 logContent_pane.setForeground(Configuration.getColor("coloring.workspace_selection_foreground"));
181 logContent_label = new JLabel();
182 logContent_label.setOpaque(true);
183 logContent_label.setBackground(Configuration.getColor("coloring.workspace_selection_background"));
184 logContent_label.setForeground(Configuration.getColor("coloring.workspace_selection_foreground"));
185 logContent_label.setText(GAI.dictionary.get("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_home+File.separatorChar+"logs"+File.separatorChar+"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_file = new File (GAI.getGSDL3ExtensionHome() + File.separatorChar + "logs" + File.separatorChar + "ext.log");
360 String filename = log_file.getPath();
361 updateLogsContent(filename);
362 clear_button.setEnabled(true);
363 reload_button.setEnabled(true);
364 } else if (log_list.getSelectedIndex () == 2) {
365 log_textarea.setText("");
366 JOptionPane.showMessageDialog((Component) null,"This file has not been defined yet");
367 clear_button.setEnabled(false);
368 reload_button.setEnabled(false);
369 }
370 }
371 }
372 }
373 public void modeChanged (int mode){
374 return;
375 }
376 public void afterDisplay() {
377 return;
378 }
379}
Note: See TracBrowser for help on using the repository browser.