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