/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
Possible License(s): BSD-3-Clause, AGPL-1.0, Apache-2.0, LGPL-2.0, LGPL-3.0, GPL-2.0, CC-BY-SA-3.0, LGPL-2.1, GPL-3.0, MPL-2.0-no-copyleft-exception, IPL-1.0
- /*
- * LogViewer.java
- * Copyright (C) 1999, 2000, 2001 Slava Pestov
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- */
- package org.gjt.sp.jedit.gui;
- import java.awt.BorderLayout;
- import java.awt.Component;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import javax.swing.*;
- import javax.swing.event.DocumentEvent;
- import javax.swing.event.DocumentListener;
- import org.gjt.sp.jedit.*;
- import org.gjt.sp.util.Log;
- public class LogViewer extends JPanel
- {
- public LogViewer()
- {
- super(new BorderLayout());
- Box captionBox = Box.createHorizontalBox();
- String settingsDirectory = jEdit.getSettingsDirectory();
- if(settingsDirectory != null)
- {
- String[] args = { MiscUtilities.constructPath(
- settingsDirectory, "activity.log") };
- JLabel label = new JLabel(jEdit.getProperty(
- "log-viewer.caption",args));
- captionBox.add(label);
- }
- captionBox.add(Box.createHorizontalGlue());
- tailIsOn = jEdit.getBooleanProperty("log-viewer.tail", false);
- tail = new JCheckBox(
- jEdit.getProperty("log-viewer.tail.label"),tailIsOn);
- tail.addActionListener(new ActionHandler());
- captionBox.add(tail);
- textArea = new JTextArea(24,80);
- textArea.setDocument(Log.getLogDocument());
- textArea.getDocument().addDocumentListener(
- new DocumentHandler());
- //textArea.setEditable(false);
- add(BorderLayout.NORTH,captionBox);
- add(BorderLayout.CENTER,new JScrollPane(textArea));
- }
- private JTextArea textArea;
- private JCheckBox tail;
- private boolean tailIsOn;
- class ActionHandler implements ActionListener
- {
- public void actionPerformed(ActionEvent e)
- {
- tailIsOn = !tailIsOn;
- jEdit.setBooleanProperty("log-viewer.tail",tailIsOn);
- if(tailIsOn)
- textArea.setCaretPosition(
- textArea.getDocument().getLength());
- }
- }
- class DocumentHandler implements DocumentListener
- {
- public void insertUpdate(DocumentEvent e)
- {
- if(tailIsOn)
- textArea.setCaretPosition(
- textArea.getDocument().getLength());
- }
- public void changedUpdate(DocumentEvent e) {}
- public void removeUpdate(DocumentEvent e) {}
- }
- }