RawEditorKit.java |
1 /* 2 * RawEditorKit.java 3 * 4 * Copyright (c) 1998-2005, 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.11 2005/01/11 13:51:37 ian Exp $ 14 */ 15 16 package gate.util; 17 18 import java.io.IOException; 19 import java.io.Reader; 20 21 import javax.swing.text.*; 22 23 /** This class provides an editor kit that does not change \n\r to \n but 24 * instead it leaves the original text as is. 25 * Needed for GUI components 26 */ 27 public class RawEditorKit extends StyledEditorKit { 28 29 /** Debug flag */ 30 private static final boolean DEBUG = false; 31 32 /** 33 * Inserts content from the given stream, which will be 34 * treated as plain text. 35 * This insertion is done without checking \r or \r \n sequence. 36 * It takes the text from the Reader and place it into Document at position 37 * pos 38 */ 39 public void read(Reader in, Document doc, int pos) 40 throws IOException, BadLocationException { 41 42 char[] buff = new char[65536]; 43 int charsRead = 0; 44 45 while ((charsRead = in.read(buff, 0, buff.length)) != -1) { 46 doc.insertString(pos, new String(buff, 0, charsRead), null); 47 pos += charsRead; 48 }// while 49 50 }// read 51 52 }// class RawEditorKit 53