1   /*
2    *  RawEditorKit.java
3    *
4    *  Copyright (c) 1998-2001, The University of Sheffield.
5    *
6    *  This file is part of GATE (see http://gate.ac.uk/), and is free
7    *  software, licenced under the GNU Library General Public License,
8    *  Version 2, June 1991 (in the distribution as file licence.html,
9    *  and also available at http://gate.ac.uk/gate/licence.html).
10   *  
11   *  Valentin Tablan, Nov/1999
12   *
13   *  $Id: RawEditorKit.java,v 1.8 2000/11/08 16:35:11 hamish Exp $
14   */
15  
16  package gate.util;
17  
18  import javax.swing.text.*;
19  import java.io.Reader;
20  import java.io.IOException;
21  
22  /** This class provides an editor kit that does not change \n\r to \n but
23    * instead it leaves the original text as is.
24    * Needed for GUI components
25    */
26  public class RawEditorKit extends StyledEditorKit {
27  
28    /** Debug flag */
29    private static final boolean DEBUG = false;
30  
31    /**
32      * Inserts content from the given stream, which will be
33      * treated as plain text.
34      * This insertion is done without checking \r or \r \n sequence.
35      * It takes the text from the Reader and place it into Document at position
36      * pos
37      */
38    public void read(Reader in, Document doc, int pos)
39                throws IOException, BadLocationException {
40  
41      char[] buff = new char[65536];
42      int charsRead = 0;
43  
44      while ((charsRead = in.read(buff, 0, buff.length)) != -1) {
45            doc.insertString(pos, new String(buff, 0, charsRead), null);
46            pos += charsRead;
47      }// while
48  
49    }// read
50  
51  }// class RawEditorKit 
52