1 /*
2 * Copyright (c) 1997, 2011, 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
701 fParagraph);
702 invalidateComponents();
703 }
704
705 /**
706 * Updates the {@code TextMeasurer} after a single character has
707 * been deleted
708 * from the paragraph currently represented by this
709 * {@code TextMeasurer}. After this call, this
710 * {@code TextMeasurer} is equivalent to a new {@code TextMeasurer}
711 * created from the text; however, it will usually be more efficient
712 * to update an existing {@code TextMeasurer} than to create a new one
713 * from scratch.
714 *
715 * @param newParagraph the text of the paragraph after performing
716 * the deletion. Cannot be null.
717 * @param deletePos the position in the text where the character was removed.
718 * Must not be less than
719 * the start of {@code newParagraph}, and must not be greater than the
720 * end of {@code newParagraph}.
721 * @throws IndexOutOfBoundsException if {@code deletePos} is
722 * less than the start of {@code newParagraph} or greater
723 * than the end of {@code newParagraph}
724 * @throws NullPointerException if {@code newParagraph} is
725 * {@code null}
726 */
727 public void deleteChar(AttributedCharacterIterator newParagraph, int deletePos) {
728
729 fStart = newParagraph.getBeginIndex();
730 int end = newParagraph.getEndIndex();
731 if (end - fStart != fChars.length-1) {
732 initAll(newParagraph);
733 }
734
735 char[] newChars = new char[end-fStart];
736 int changedIndex = deletePos-fStart;
737
738 System.arraycopy(fChars, 0, newChars, 0, deletePos-fStart);
739 System.arraycopy(fChars, changedIndex+1, newChars, changedIndex, end-deletePos);
740 fChars = newChars;
741
742 if (fBidi != null) {
743 fBidi = new Bidi(newParagraph);
744 if (fBidi.isLeftToRight()) {
745 fBidi = null;
746 }
747 }
748
749 fParagraph = StyledParagraph.deleteChar(newParagraph,
750 fChars,
751 deletePos,
752 fParagraph);
|
1 /*
2 * Copyright (c) 1997, 2017, 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
701 fParagraph);
702 invalidateComponents();
703 }
704
705 /**
706 * Updates the {@code TextMeasurer} after a single character has
707 * been deleted
708 * from the paragraph currently represented by this
709 * {@code TextMeasurer}. After this call, this
710 * {@code TextMeasurer} is equivalent to a new {@code TextMeasurer}
711 * created from the text; however, it will usually be more efficient
712 * to update an existing {@code TextMeasurer} than to create a new one
713 * from scratch.
714 *
715 * @param newParagraph the text of the paragraph after performing
716 * the deletion. Cannot be null.
717 * @param deletePos the position in the text where the character was removed.
718 * Must not be less than
719 * the start of {@code newParagraph}, and must not be greater than the
720 * end of {@code newParagraph}.
721 * @throws IllegalArgumentException if multiple characters are deleted from
722 * the text represented by {@code newParagraph}
723 * @throws IndexOutOfBoundsException if {@code deletePos} is
724 * less than the start of {@code newParagraph} or greater
725 * than the end of {@code newParagraph}
726 * @throws NullPointerException if {@code newParagraph} is
727 * {@code null}
728 */
729 public void deleteChar(AttributedCharacterIterator newParagraph, int deletePos) {
730
731 fStart = newParagraph.getBeginIndex();
732 int end = newParagraph.getEndIndex();
733 if (end - fStart != fChars.length-1) {
734 // The new paragraph attempts to delete multiple characters
735 throw new IllegalArgumentException("The new paragraph"
736 + " attempts to delete multiple characters from the text.");
737 }
738
739 char[] newChars = new char[end-fStart];
740 int changedIndex = deletePos-fStart;
741
742 System.arraycopy(fChars, 0, newChars, 0, deletePos-fStart);
743 System.arraycopy(fChars, changedIndex+1, newChars, changedIndex, end-deletePos);
744 fChars = newChars;
745
746 if (fBidi != null) {
747 fBidi = new Bidi(newParagraph);
748 if (fBidi.isLeftToRight()) {
749 fBidi = null;
750 }
751 }
752
753 fParagraph = StyledParagraph.deleteChar(newParagraph,
754 fChars,
755 deletePos,
756 fParagraph);
|