jdk/src/share/classes/javax/swing/text/StringContent.java
author darcy
Fri, 24 Jan 2014 07:16:53 -0800
changeset 22574 7f8ce0c8c20a
parent 20458 f2423fb3fd19
child 25193 187a455af8f8
permissions -rw-r--r--
8032627: Add @SuppressWarnings("serial") to appropriate javax.swing classes Reviewed-by: alexsch, alanb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
22574
7f8ce0c8c20a 8032627: Add @SuppressWarnings("serial") to appropriate javax.swing classes
darcy
parents: 20458
diff changeset
     2
 * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1639
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1639
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1639
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1639
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1639
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
package javax.swing.text;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import java.util.Vector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.Serializable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import javax.swing.undo.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import javax.swing.SwingUtilities;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * An implementation of the AbstractDocument.Content interface that is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * a brute force implementation that is useful for relatively small
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * documents and/or debugging.  It manages the character content
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * as a simple character array.  It is also quite inefficient.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * It is generally recommended that the gap buffer or piece table
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * implementations be used instead.  This buffer does not scale up
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * to large sizes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * future Swing releases. The current serialization support is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * appropriate for short term storage or RMI between applications running
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * the same version of Swing.  As of 1.4, support for long term storage
20458
f2423fb3fd19 8025840: Fix all the doclint warnings about trademark
cl
parents: 20158
diff changeset
    47
 * of all JavaBeans&trade;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * has been added to the <code>java.beans</code> package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * Please see {@link java.beans.XMLEncoder}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * @author  Timothy Prinzing
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 */
22574
7f8ce0c8c20a 8032627: Add @SuppressWarnings("serial") to appropriate javax.swing classes
darcy
parents: 20458
diff changeset
    53
@SuppressWarnings("serial") // Same-version serialization only
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
public final class StringContent implements AbstractDocument.Content, Serializable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
     * Creates a new StringContent object.  Initial size defaults to 10.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    public StringContent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        this(10);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     * Creates a new StringContent object, with the initial
20158
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 5506
diff changeset
    65
     * size specified.  If the length is &lt; 1, a size of 1 is used.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     * @param initialLength the initial size
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    public StringContent(int initialLength) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        if (initialLength < 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
            initialLength = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        data = new char[initialLength];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        data[0] = '\n';
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        count = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * Returns the length of the content.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     *
20158
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 5506
diff changeset
    81
     * @return the length &gt;= 1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * @see AbstractDocument.Content#length
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    public int length() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        return count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * Inserts a string into the content.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     *
20158
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 5506
diff changeset
    91
     * @param where the starting position &gt;= 0 &amp;&amp; &lt; length()
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * @param str the non-null string to insert
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * @return an UndoableEdit object for undoing
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * @exception BadLocationException if the specified position is invalid
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * @see AbstractDocument.Content#insertString
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    public UndoableEdit insertString(int where, String str) throws BadLocationException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        if (where >= count || where < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
            throw new BadLocationException("Invalid location", count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        char[] chars = str.toCharArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        replace(where, 0, chars, 0, chars.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        if (marks != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
            updateMarksForInsert(where, str.length());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        return new InsertUndo(where, str.length());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    /**
20158
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 5506
diff changeset
   110
     * Removes part of the content.  where + nitems must be &lt; length().
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     *
20158
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 5506
diff changeset
   112
     * @param where the starting position &gt;= 0
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 5506
diff changeset
   113
     * @param nitems the number of characters to remove &gt;= 0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * @return an UndoableEdit object for undoing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * @exception BadLocationException if the specified position is invalid
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * @see AbstractDocument.Content#remove
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    public UndoableEdit remove(int where, int nitems) throws BadLocationException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        if (where + nitems >= count) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
            throw new BadLocationException("Invalid range", count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        String removedString = getString(where, nitems);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        UndoableEdit edit = new RemoveUndo(where, removedString);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        replace(where, nitems, empty, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        if (marks != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
            updateMarksForRemove(where, nitems);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        return edit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    /**
20158
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 5506
diff changeset
   133
     * Retrieves a portion of the content.  where + len must be &lt;= length().
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     *
20158
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 5506
diff changeset
   135
     * @param where the starting position &gt;= 0
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 5506
diff changeset
   136
     * @param len the length to retrieve &gt;= 0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * @return a string representing the content; may be empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * @exception BadLocationException if the specified position is invalid
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * @see AbstractDocument.Content#getString
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    public String getString(int where, int len) throws BadLocationException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        if (where + len > count) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            throw new BadLocationException("Invalid range", count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        return new String(data, where, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    /**
20158
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 5506
diff changeset
   149
     * Retrieves a portion of the content.  where + len must be &lt;= length()
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     *
20158
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 5506
diff changeset
   151
     * @param where the starting position &gt;= 0
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 5506
diff changeset
   152
     * @param len the number of characters to retrieve &gt;= 0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * @param chars the Segment object to return the characters in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * @exception BadLocationException if the specified position is invalid
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * @see AbstractDocument.Content#getChars
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    public void getChars(int where, int len, Segment chars) throws BadLocationException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        if (where + len > count) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
            throw new BadLocationException("Invalid location", count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        chars.array = data;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        chars.offset = where;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        chars.count = len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * Creates a position within the content that will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * track change as the content is mutated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     *
20158
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 5506
diff changeset
   170
     * @param offset the offset to create a position for &gt;= 0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * @return the position
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * @exception BadLocationException if the specified position is invalid
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    public Position createPosition(int offset) throws BadLocationException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        // some small documents won't have any sticky positions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        // at all, so the buffer is created lazily.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        if (marks == null) {
1287
a04aca99c77a 6722802: Code improvement and warnings removing from the javax.swing.text package
rupashka
parents: 2
diff changeset
   178
            marks = new Vector<PosRec>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        return new StickyPosition(offset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    // --- local methods ---------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * Replaces some of the characters in the array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * @param offset  offset into the array to start the replace
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * @param length  number of characters to remove
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * @param replArray replacement array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * @param replOffset offset into the replacement array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * @param replLength number of character to use from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     *   replacement array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    void replace(int offset, int length,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                 char[] replArray, int replOffset, int replLength) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        int delta = replLength - length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        int src = offset + length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        int nmove = count - src;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        int dest = src + delta;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        if ((count + delta) >= data.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
            // need to grow the array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            int newLength = Math.max(2*data.length, count + delta);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            char[] newData = new char[newLength];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
            System.arraycopy(data, 0, newData, 0, offset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
            System.arraycopy(replArray, replOffset, newData, offset, replLength);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            System.arraycopy(data, src, newData, dest, nmove);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
            data = newData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            // patch the existing array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            System.arraycopy(data, src, data, dest, nmove);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
            System.arraycopy(replArray, replOffset, data, offset, replLength);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        count = count + delta;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    void resize(int ncount) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        char[] ndata = new char[ncount];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        System.arraycopy(data, 0, ndata, 0, Math.min(ncount, count));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        data = ndata;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    synchronized void updateMarksForInsert(int offset, int length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        if (offset == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            // zero is a special case where we update only
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            // marks after it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            offset = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        int n = marks.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        for (int i = 0; i < n; i++) {
1287
a04aca99c77a 6722802: Code improvement and warnings removing from the javax.swing.text package
rupashka
parents: 2
diff changeset
   230
            PosRec mark = marks.elementAt(i);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            if (mark.unused) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                // this record is no longer used, get rid of it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                marks.removeElementAt(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
                i -= 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
                n -= 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            } else if (mark.offset >= offset) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                mark.offset += length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    synchronized void updateMarksForRemove(int offset, int length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        int n = marks.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        for (int i = 0; i < n; i++) {
1287
a04aca99c77a 6722802: Code improvement and warnings removing from the javax.swing.text package
rupashka
parents: 2
diff changeset
   245
            PosRec mark = marks.elementAt(i);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            if (mark.unused) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                // this record is no longer used, get rid of it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                marks.removeElementAt(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
                i -= 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                n -= 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
            } else if (mark.offset >= (offset + length)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                mark.offset -= length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            } else if (mark.offset >= offset) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
                mark.offset = offset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * Returns a Vector containing instances of UndoPosRef for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * Positions in the range
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * <code>offset</code> to <code>offset</code> + <code>length</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * If <code>v</code> is not null the matching Positions are placed in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * there. The vector with the resulting Positions are returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * This is meant for internal usage, and is generally not of interest
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * to subclasses.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * @param v the Vector to use, with a new one created on null
20158
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 5506
diff changeset
   270
     * @param offset the starting offset &gt;= 0
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 5506
diff changeset
   271
     * @param length the length &gt;= 0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * @return the set of instances
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    protected Vector getPositionsInRange(Vector v, int offset,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
                                                      int length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        int n = marks.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        int end = offset + length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        Vector placeIn = (v == null) ? new Vector() : v;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        for (int i = 0; i < n; i++) {
1287
a04aca99c77a 6722802: Code improvement and warnings removing from the javax.swing.text package
rupashka
parents: 2
diff changeset
   280
            PosRec mark = marks.elementAt(i);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
            if (mark.unused) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
                // this record is no longer used, get rid of it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
                marks.removeElementAt(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
                i -= 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
                n -= 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
            } else if(mark.offset >= offset && mark.offset <= end)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
                placeIn.addElement(new UndoPosRef(mark));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        return placeIn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     * Resets the location for all the UndoPosRef instances
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     * in <code>positions</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     * This is meant for internal usage, and is generally not of interest
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     * to subclasses.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     * @param positions the positions of the instances
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    protected void updateUndoPositions(Vector positions) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        for(int counter = positions.size() - 1; counter >= 0; counter--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
            UndoPosRef ref = (UndoPosRef)positions.elementAt(counter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
            // Check if the Position is still valid.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
            if(ref.rec.unused) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
                positions.removeElementAt(counter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
                ref.resetLocation();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    private static final char[] empty = new char[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    private char[] data;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    private int count;
1287
a04aca99c77a 6722802: Code improvement and warnings removing from the javax.swing.text package
rupashka
parents: 2
diff changeset
   316
    transient Vector<PosRec> marks;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     * holds the data for a mark... separately from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     * the real mark so that the real mark can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     * collected if there are no more references to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     * it.... the update table holds only a reference
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * to this grungy thing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
    final class PosRec {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        PosRec(int offset) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
            this.offset = offset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        int offset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        boolean unused;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     * This really wants to be a weak reference but
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     * in 1.1 we don't have a 100% pure solution for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     * this... so this class trys to hack a solution
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     * to causing the marks to be collected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    final class StickyPosition implements Position {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        StickyPosition(int offset) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
            rec = new PosRec(offset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
            marks.addElement(rec);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        public int getOffset() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
            return rec.offset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        protected void finalize() throws Throwable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
            // schedule the record to be removed later
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
            // on another thread.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
            rec.unused = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
            return Integer.toString(getOffset());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
        PosRec rec;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     * Used to hold a reference to a Position that is being reset as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     * result of removing from the content.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
    final class UndoPosRef {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
        UndoPosRef(PosRec rec) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
            this.rec = rec;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
            this.undoLocation = rec.offset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
         * Resets the location of the Position to the offset when the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
         * receiver was instantiated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        protected void resetLocation() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
            rec.offset = undoLocation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        /** Location to reset to when resetLocatino is invoked. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        protected int undoLocation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        /** Position to reset offset. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        protected PosRec rec;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     * UnoableEdit created for inserts.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
    class InsertUndo extends AbstractUndoableEdit {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        protected InsertUndo(int offset, int length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
            super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
            this.offset = offset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
            this.length = length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        public void undo() throws CannotUndoException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
            super.undo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
                synchronized(StringContent.this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
                    // Get the Positions in the range being removed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
                    if(marks != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
                        posRefs = getPositionsInRange(null, offset, length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
                    string = getString(offset, length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
                    remove(offset, length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
            } catch (BadLocationException bl) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
              throw new CannotUndoException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        public void redo() throws CannotRedoException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
            super.redo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
                synchronized(StringContent.this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
                    insertString(offset, string);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
                    string = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
                    // Update the Positions that were in the range removed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
                    if(posRefs != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
                        updateUndoPositions(posRefs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
                        posRefs = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
            } catch (BadLocationException bl) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
              throw new CannotRedoException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        // Where the string goes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        protected int offset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        // Length of the string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        protected int length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
        // The string that was inserted. To cut down on space needed this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
        // will only be valid after an undo.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
        protected String string;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        // An array of instances of UndoPosRef for the Positions in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
        // range that was removed, valid after undo.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
        protected Vector posRefs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
     * UndoableEdit created for removes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
    class RemoveUndo extends AbstractUndoableEdit {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
        protected RemoveUndo(int offset, String string) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
            super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
            this.offset = offset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
            this.string = string;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
            this.length = string.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
            if(marks != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
                posRefs = getPositionsInRange(null, offset, length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
        public void undo() throws CannotUndoException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
            super.undo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
                synchronized(StringContent.this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
                    insertString(offset, string);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
                    // Update the Positions that were in the range removed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
                    if(posRefs != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
                        updateUndoPositions(posRefs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
                        posRefs = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
                    string = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
            } catch (BadLocationException bl) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
              throw new CannotUndoException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
        public void redo() throws CannotRedoException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
            super.redo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
                synchronized(StringContent.this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
                    string = getString(offset, length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
                    // Get the Positions in the range being removed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
                    if(marks != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
                        posRefs = getPositionsInRange(null, offset, length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
                    remove(offset, length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
            } catch (BadLocationException bl) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
              throw new CannotRedoException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
        // Where the string goes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
        protected int offset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
        // Length of the string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
        protected int length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
        // The string that was inserted. This will be null after an undo.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
        protected String string;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
        // An array of instances of UndoPosRef for the Positions in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
        // range that was removed, valid before undo.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
        protected Vector posRefs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
}