PageRenderTime 66ms CodeModel.GetById 60ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/jEdit/tags/jedit-4-0-pre5/org/gjt/sp/jedit/gui/LogViewer.java

#
Java | 96 lines | 64 code | 13 blank | 19 comment | 4 complexity | 5cf5152ce0bfe2137f4023ef24a99111 MD5 | raw file
 1/*
 2 * LogViewer.java
 3 * Copyright (C) 1999, 2000, 2001 Slava Pestov
 4 *
 5 * This program is free software; you can redistribute it and/or
 6 * modify it under the terms of the GNU General Public License
 7 * as published by the Free Software Foundation; either version 2
 8 * of the License, or any later version.
 9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18 */
19
20package org.gjt.sp.jedit.gui;
21
22import java.awt.BorderLayout;
23import java.awt.Component;
24import java.awt.event.ActionEvent;
25import java.awt.event.ActionListener;
26import javax.swing.*;
27import javax.swing.event.DocumentEvent;
28import javax.swing.event.DocumentListener;
29import org.gjt.sp.jedit.*;
30import org.gjt.sp.util.Log;
31
32public class LogViewer extends JPanel
33{
34	public LogViewer()
35	{
36		super(new BorderLayout());
37
38		Box captionBox = Box.createHorizontalBox();
39
40		String settingsDirectory = jEdit.getSettingsDirectory();
41		if(settingsDirectory != null)
42		{
43			String[] args = { MiscUtilities.constructPath(
44				settingsDirectory, "activity.log") };
45			JLabel label = new JLabel(jEdit.getProperty(
46				"log-viewer.caption",args));
47			captionBox.add(label);
48		}
49
50		captionBox.add(Box.createHorizontalGlue());
51
52		tailIsOn = jEdit.getBooleanProperty("log-viewer.tail", false);
53		tail = new JCheckBox(
54			jEdit.getProperty("log-viewer.tail.label"),tailIsOn);
55		tail.addActionListener(new ActionHandler());
56		captionBox.add(tail);
57
58		textArea = new JTextArea(24,80);
59		textArea.setDocument(Log.getLogDocument());
60		textArea.getDocument().addDocumentListener(
61			new DocumentHandler());
62		//textArea.setEditable(false);
63
64		add(BorderLayout.NORTH,captionBox);
65		add(BorderLayout.CENTER,new JScrollPane(textArea));
66	}
67
68	private JTextArea textArea;
69	private JCheckBox tail;
70	private boolean tailIsOn;
71
72	class ActionHandler implements ActionListener
73	{
74		public void actionPerformed(ActionEvent e)
75		{
76			tailIsOn = !tailIsOn;
77			jEdit.setBooleanProperty("log-viewer.tail",tailIsOn);
78			if(tailIsOn)
79				textArea.setCaretPosition(
80					textArea.getDocument().getLength());
81		}
82	}
83
84	class DocumentHandler implements DocumentListener
85	{
86		public void insertUpdate(DocumentEvent e)
87		{
88			if(tailIsOn)
89				textArea.setCaretPosition(
90					textArea.getDocument().getLength());
91		}
92
93		public void changedUpdate(DocumentEvent e) {}
94		public void removeUpdate(DocumentEvent e) {}
95	}
96}