1 /*
2 * Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
741 }
742
743 Vector<UndoPosRef> placeIn = (v == null) ?
744 new Vector<>(Math.max(1, endIndex - startIndex)) :
745 v;
746
747 for (int counter = startIndex; counter < endIndex; counter++) {
748 placeIn.addElement(new UndoPosRef(marks.elementAt(counter)));
749 }
750 return placeIn;
751 }
752
753 /**
754 * Resets the location for all the UndoPosRef instances
755 * in <code>positions</code>.
756 * <p>
757 * This is meant for internal usage, and is generally not of interest
758 * to subclasses.
759 *
760 * @param positions the UndoPosRef instances to reset
761 */
762 @SuppressWarnings("rawtypes") // UndoPosRef type cannot be exposed
763 protected void updateUndoPositions(Vector positions, int offset,
764 int length) {
765 // Find the indexs of the end points.
766 int endOffset = offset + length;
767 int g1 = getGapEnd();
768 int startIndex;
769 int endIndex = findMarkAdjustIndex(g1 + 1);
770
771 if (offset != 0) {
772 startIndex = findMarkAdjustIndex(g1);
773 }
774 else {
775 startIndex = 0;
776 }
777
778 // Reset the location of the refenences.
779 for(int counter = positions.size() - 1; counter >= 0; counter--) {
780 UndoPosRef ref = (UndoPosRef) positions.elementAt(counter);
|
1 /*
2 * Copyright (c) 1998, 2015, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
741 }
742
743 Vector<UndoPosRef> placeIn = (v == null) ?
744 new Vector<>(Math.max(1, endIndex - startIndex)) :
745 v;
746
747 for (int counter = startIndex; counter < endIndex; counter++) {
748 placeIn.addElement(new UndoPosRef(marks.elementAt(counter)));
749 }
750 return placeIn;
751 }
752
753 /**
754 * Resets the location for all the UndoPosRef instances
755 * in <code>positions</code>.
756 * <p>
757 * This is meant for internal usage, and is generally not of interest
758 * to subclasses.
759 *
760 * @param positions the UndoPosRef instances to reset
761 * @param offset where the string was inserted
762 * @param length length of inserted string
763 */
764 @SuppressWarnings("rawtypes") // UndoPosRef type cannot be exposed
765 protected void updateUndoPositions(Vector positions, int offset,
766 int length) {
767 // Find the indexs of the end points.
768 int endOffset = offset + length;
769 int g1 = getGapEnd();
770 int startIndex;
771 int endIndex = findMarkAdjustIndex(g1 + 1);
772
773 if (offset != 0) {
774 startIndex = findMarkAdjustIndex(g1);
775 }
776 else {
777 startIndex = 0;
778 }
779
780 // Reset the location of the refenences.
781 for(int counter = positions.size() - 1; counter >= 0; counter--) {
782 UndoPosRef ref = (UndoPosRef) positions.elementAt(counter);
|