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
635 //formattedChars = 0;
636 collectStats = false;
637 }
638
639 /**
640 * Updates the {@code TextMeasurer} after a single character has
641 * been inserted
642 * into the paragraph currently represented by this
643 * {@code TextMeasurer}. After this call, this
644 * {@code TextMeasurer} is equivalent to a new
645 * {@code TextMeasurer} created from the text; however, it will
646 * usually be more efficient to update an existing
647 * {@code TextMeasurer} than to create a new one from scratch.
648 *
649 * @param newParagraph the text of the paragraph after performing
650 * the insertion. Cannot be null.
651 * @param insertPos the position in the text where the character was
652 * inserted. Must not be less than the start of
653 * {@code newParagraph}, and must be less than the end of
654 * {@code newParagraph}.
655 * @throws IndexOutOfBoundsException if {@code insertPos} is less
656 * than the start of {@code newParagraph} or greater than
657 * or equal to the end of {@code newParagraph}
658 * @throws NullPointerException if {@code newParagraph} is
659 * {@code null}
660 */
661 public void insertChar(AttributedCharacterIterator newParagraph, int insertPos) {
662
663 if (collectStats) {
664 printStats();
665 }
666 if (wantStats) {
667 collectStats = true;
668 }
669
670 fStart = newParagraph.getBeginIndex();
671 int end = newParagraph.getEndIndex();
672 if (end - fStart != fChars.length+1) {
673 initAll(newParagraph);
674 }
675
676 char[] newChars = new char[end-fStart];
677 int newCharIndex = insertPos - fStart;
678 System.arraycopy(fChars, 0, newChars, 0, newCharIndex);
679
680 char newChar = newParagraph.setIndex(insertPos);
681 newChars[newCharIndex] = newChar;
682 System.arraycopy(fChars,
683 newCharIndex,
684 newChars,
685 newCharIndex+1,
686 end-insertPos-1);
687 fChars = newChars;
688
689 if (fBidi != null || Bidi.requiresBidi(newChars, newCharIndex, newCharIndex + 1) ||
690 newParagraph.getAttribute(TextAttribute.BIDI_EMBEDDING) != null) {
691
692 fBidi = new Bidi(newParagraph);
693 if (fBidi.isLeftToRight()) {
694 fBidi = null;
695 }
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);
753 invalidateComponents();
754 }
|
1 /*
2 * Copyright (c) 1997, 2018, 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
635 //formattedChars = 0;
636 collectStats = false;
637 }
638
639 /**
640 * Updates the {@code TextMeasurer} after a single character has
641 * been inserted
642 * into the paragraph currently represented by this
643 * {@code TextMeasurer}. After this call, this
644 * {@code TextMeasurer} is equivalent to a new
645 * {@code TextMeasurer} created from the text; however, it will
646 * usually be more efficient to update an existing
647 * {@code TextMeasurer} than to create a new one from scratch.
648 *
649 * @param newParagraph the text of the paragraph after performing
650 * the insertion. Cannot be null.
651 * @param insertPos the position in the text where the character was
652 * inserted. Must not be less than the start of
653 * {@code newParagraph}, and must be less than the end of
654 * {@code newParagraph}.
655 * @throws IllegalArgumentException if multiple characters are inserted
656 * in the text represented by {@code newParagraph}
657 * @throws IndexOutOfBoundsException if {@code insertPos} is less
658 * than the start of {@code newParagraph} or greater than
659 * or equal to the end of {@code newParagraph}
660 * @throws NullPointerException if {@code newParagraph} is
661 * {@code null}
662 */
663 public void insertChar(AttributedCharacterIterator newParagraph, int insertPos) {
664
665 if (collectStats) {
666 printStats();
667 }
668 if (wantStats) {
669 collectStats = true;
670 }
671
672 int start = newParagraph.getBeginIndex();
673 int end = newParagraph.getEndIndex();
674 if (end - start != fChars.length+1) {
675 // The new paragraph attempts to insert multiple characters
676 throw new IllegalArgumentException("The new paragraph"
677 + " attempts to insert multiple characters into the text.");
678 }
679
680 fStart = start;
681 char[] newChars = new char[end-fStart];
682 int newCharIndex = insertPos - fStart;
683 System.arraycopy(fChars, 0, newChars, 0, newCharIndex);
684
685 char newChar = newParagraph.setIndex(insertPos);
686 newChars[newCharIndex] = newChar;
687 System.arraycopy(fChars,
688 newCharIndex,
689 newChars,
690 newCharIndex+1,
691 end-insertPos-1);
692 fChars = newChars;
693
694 if (fBidi != null || Bidi.requiresBidi(newChars, newCharIndex, newCharIndex + 1) ||
695 newParagraph.getAttribute(TextAttribute.BIDI_EMBEDDING) != null) {
696
697 fBidi = new Bidi(newParagraph);
698 if (fBidi.isLeftToRight()) {
699 fBidi = null;
700 }
706 fParagraph);
707 invalidateComponents();
708 }
709
710 /**
711 * Updates the {@code TextMeasurer} after a single character has
712 * been deleted
713 * from the paragraph currently represented by this
714 * {@code TextMeasurer}. After this call, this
715 * {@code TextMeasurer} is equivalent to a new {@code TextMeasurer}
716 * created from the text; however, it will usually be more efficient
717 * to update an existing {@code TextMeasurer} than to create a new one
718 * from scratch.
719 *
720 * @param newParagraph the text of the paragraph after performing
721 * the deletion. Cannot be null.
722 * @param deletePos the position in the text where the character was removed.
723 * Must not be less than
724 * the start of {@code newParagraph}, and must not be greater than the
725 * end of {@code newParagraph}.
726 * @throws IllegalArgumentException if multiple characters are deleted from
727 * the text represented by {@code newParagraph}
728 * @throws IndexOutOfBoundsException if {@code deletePos} is
729 * less than the start of {@code newParagraph} or greater
730 * than the end of {@code newParagraph}
731 * @throws NullPointerException if {@code newParagraph} is
732 * {@code null}
733 */
734 public void deleteChar(AttributedCharacterIterator newParagraph, int deletePos) {
735
736 int start = newParagraph.getBeginIndex();
737 int end = newParagraph.getEndIndex();
738 if (end - start != fChars.length-1) {
739 // The new paragraph attempts to delete multiple characters
740 throw new IllegalArgumentException("The new paragraph"
741 + " attempts to delete multiple characters from the text.");
742 }
743
744 fStart = start;
745 char[] newChars = new char[end-fStart];
746 int changedIndex = deletePos-fStart;
747
748 System.arraycopy(fChars, 0, newChars, 0, deletePos-fStart);
749 System.arraycopy(fChars, changedIndex+1, newChars, changedIndex, end-deletePos);
750 fChars = newChars;
751
752 if (fBidi != null) {
753 fBidi = new Bidi(newParagraph);
754 if (fBidi.isLeftToRight()) {
755 fBidi = null;
756 }
757 }
758
759 fParagraph = StyledParagraph.deleteChar(newParagraph,
760 fChars,
761 deletePos,
762 fParagraph);
763 invalidateComponents();
764 }
|