src/share/classes/javax/swing/text/PlainDocument.java

Print this page




  83     /**
  84      * Constructs a plain text document.  A default root element is created,
  85      * and the tab size set to 8.
  86      *
  87      * @param c  the container for the content
  88      */
  89     public PlainDocument(Content c) {
  90         super(c);
  91         putProperty(tabSizeAttribute, Integer.valueOf(8));
  92         defaultRoot = createDefaultRoot();
  93     }
  94 
  95     /**
  96      * Inserts some content into the document.
  97      * Inserting content causes a write lock to be held while the
  98      * actual changes are taking place, followed by notification
  99      * to the observers on the thread that grabbed the write lock.
 100      * <p>
 101      * This method is thread safe, although most Swing methods
 102      * are not. Please see
 103      * <A HREF="http://docs.oracle.com/javase/tutorial/uiswing/concurrency/index.html">Concurrency
 104      * in Swing</A> for more information.
 105      *
 106      * @param offs the starting offset &gt;= 0
 107      * @param str the string to insert; does nothing with null/empty strings
 108      * @param a the attributes for the inserted content
 109      * @exception BadLocationException  the given insert position is not a valid
 110      *   position within the document
 111      * @see Document#insertString
 112      */
 113     public void insertString(int offs, String str, AttributeSet a) throws BadLocationException {
 114         // fields don't want to have multiple lines.  We may provide a field-specific
 115         // model in the future in which case the filtering logic here will no longer
 116         // be needed.
 117         Object filterNewlines = getProperty("filterNewlines");
 118         if ((filterNewlines instanceof Boolean) && filterNewlines.equals(Boolean.TRUE)) {
 119             if ((str != null) && (str.indexOf('\n') >= 0)) {
 120                 StringBuilder filtered = new StringBuilder(str);
 121                 int n = filtered.length();
 122                 for (int i = 0; i < n; i++) {
 123                     if (filtered.charAt(i) == '\n') {




  83     /**
  84      * Constructs a plain text document.  A default root element is created,
  85      * and the tab size set to 8.
  86      *
  87      * @param c  the container for the content
  88      */
  89     public PlainDocument(Content c) {
  90         super(c);
  91         putProperty(tabSizeAttribute, Integer.valueOf(8));
  92         defaultRoot = createDefaultRoot();
  93     }
  94 
  95     /**
  96      * Inserts some content into the document.
  97      * Inserting content causes a write lock to be held while the
  98      * actual changes are taking place, followed by notification
  99      * to the observers on the thread that grabbed the write lock.
 100      * <p>
 101      * This method is thread safe, although most Swing methods
 102      * are not. Please see
 103      * <A HREF="https://docs.oracle.com/javase/tutorial/uiswing/concurrency/index.html">Concurrency
 104      * in Swing</A> for more information.
 105      *
 106      * @param offs the starting offset &gt;= 0
 107      * @param str the string to insert; does nothing with null/empty strings
 108      * @param a the attributes for the inserted content
 109      * @exception BadLocationException  the given insert position is not a valid
 110      *   position within the document
 111      * @see Document#insertString
 112      */
 113     public void insertString(int offs, String str, AttributeSet a) throws BadLocationException {
 114         // fields don't want to have multiple lines.  We may provide a field-specific
 115         // model in the future in which case the filtering logic here will no longer
 116         // be needed.
 117         Object filterNewlines = getProperty("filterNewlines");
 118         if ((filterNewlines instanceof Boolean) && filterNewlines.equals(Boolean.TRUE)) {
 119             if ((str != null) && (str.indexOf('\n') >= 0)) {
 120                 StringBuilder filtered = new StringBuilder(str);
 121                 int n = filtered.length();
 122                 for (int i = 0; i < n; i++) {
 123                     if (filtered.charAt(i) == '\n') {