View Javadoc

1   package org.devaki.nextobjects.util;
2   /*
3   
4   nextobjects Copyright (C) 2001-2005 Emmanuel Florent
5   
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by the
8   Free Software Foundation; either version 2 of the License, or (at your
9   option) any later version.
10  
11  This program is distributed in the hope that it will
12  be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
13  of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14  PURPOSE. See the GNU General Public License for more details.
15  
16  You should have received a copy of the GNU General Public License along
17  with this program; if not, write to the Free Software Foundation, Inc., 59
18  Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19  
20  */
21  import java.io.Writer;
22  import org.devaki.nextobjects.ui.components.JTextAreaOutputStream;
23      /***
24       * LogWriter has the ability to forward the log4j output to a LogFrame class
25       * Inspired by  Thomas Weber from OpenAI, http://openai.sourceforge.net/
26       */
27      public class LogWriter extends Writer
28      {
29          /*** Ref to the LogFrame instance that should receive the output */
30          private JTextAreaOutputStream jTextAreaOutputStream;
31          /***
32           * Constructs a new LogWriter and registers the LogFrame
33           * @param  pjTextAreaOutputStream the textarea
34           */
35          public LogWriter(final JTextAreaOutputStream pjTextAreaOutputStream)
36          {
37              this.jTextAreaOutputStream = pjTextAreaOutputStream;
38          }
39          /***
40           * Common flux write method
41           *
42           * @param parm1 char array to be written
43           * @param parm2 start offset to be written
44           * @param parm3 number of char to write
45           * @throws java.io.IOException a standard io exception
46           */
47          public final void write(
48              final char[] parm1,
49              final int parm2,
50              final int parm3)
51              throws java.io.IOException
52          {
53              write(String.valueOf(parm1, parm2, parm3));
54          }
55          /***
56           * Mandatory Method declaration
57           * @throws java.io.IOException  a standard io exception
58           */
59          public void flush() throws java.io.IOException
60          {
61          }
62          /***
63           * Mandatory close Method declaration
64           *
65           * @throws java.io.IOException  a standard io exception
66           */
67          public void close() throws java.io.IOException
68          {
69          }
70          /***
71           * Append 'text' to the LogFrame textarea
72           * @param text the text
73           */
74          public final void write(final String text)
75          {
76              jTextAreaOutputStream.write(text);
77          }
78      }