PageRenderTime 50ms CodeModel.GetById 18ms 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
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
  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. package org.gjt.sp.jedit.gui;
  20. import java.awt.BorderLayout;
  21. import java.awt.Component;
  22. import java.awt.event.ActionEvent;
  23. import java.awt.event.ActionListener;
  24. import javax.swing.*;
  25. import javax.swing.event.DocumentEvent;
  26. import javax.swing.event.DocumentListener;
  27. import org.gjt.sp.jedit.*;
  28. import org.gjt.sp.util.Log;
  29. public class LogViewer extends JPanel
  30. {
  31. public LogViewer()
  32. {
  33. super(new BorderLayout());
  34. Box captionBox = Box.createHorizontalBox();
  35. String settingsDirectory = jEdit.getSettingsDirectory();
  36. if(settingsDirectory != null)
  37. {
  38. String[] args = { MiscUtilities.constructPath(
  39. settingsDirectory, "activity.log") };
  40. JLabel label = new JLabel(jEdit.getProperty(
  41. "log-viewer.caption",args));
  42. captionBox.add(label);
  43. }
  44. captionBox.add(Box.createHorizontalGlue());
  45. tailIsOn = jEdit.getBooleanProperty("log-viewer.tail", false);
  46. tail = new JCheckBox(
  47. jEdit.getProperty("log-viewer.tail.label"),tailIsOn);
  48. tail.addActionListener(new ActionHandler());
  49. captionBox.add(tail);
  50. textArea = new JTextArea(24,80);
  51. textArea.setDocument(Log.getLogDocument());
  52. textArea.getDocument().addDocumentListener(
  53. new DocumentHandler());
  54. //textArea.setEditable(false);
  55. add(BorderLayout.NORTH,captionBox);
  56. add(BorderLayout.CENTER,new JScrollPane(textArea));
  57. }
  58. private JTextArea textArea;
  59. private JCheckBox tail;
  60. private boolean tailIsOn;
  61. class ActionHandler implements ActionListener
  62. {
  63. public void actionPerformed(ActionEvent e)
  64. {
  65. tailIsOn = !tailIsOn;
  66. jEdit.setBooleanProperty("log-viewer.tail",tailIsOn);
  67. if(tailIsOn)
  68. textArea.setCaretPosition(
  69. textArea.getDocument().getLength());
  70. }
  71. }
  72. class DocumentHandler implements DocumentListener
  73. {
  74. public void insertUpdate(DocumentEvent e)
  75. {
  76. if(tailIsOn)
  77. textArea.setCaretPosition(
  78. textArea.getDocument().getLength());
  79. }
  80. public void changedUpdate(DocumentEvent e) {}
  81. public void removeUpdate(DocumentEvent e) {}
  82. }
  83. }