Example #1
0
        /// <summary>
        /// Updates the <code>TextMeasurer</code> after a single character has
        /// been deleted
        /// from the paragraph currently represented by this
        /// <code>TextMeasurer</code>.  After this call, this
        /// <code>TextMeasurer</code> is equivalent to a new <code>TextMeasurer</code>
        /// created from the text;  however, it will usually be more efficient
        /// to update an existing <code>TextMeasurer</code> than to create a new one
        /// from scratch.
        /// </summary>
        /// <param name="newParagraph"> the text of the paragraph after performing
        /// the deletion.  Cannot be null. </param>
        /// <param name="deletePos"> the position in the text where the character was removed.
        /// Must not be less than
        /// the start of <code>newParagraph</code>, and must not be greater than the
        /// end of <code>newParagraph</code>. </param>
        /// <exception cref="IndexOutOfBoundsException"> if <code>deletePos</code> is
        ///         less than the start of <code>newParagraph</code> or greater
        ///         than the end of <code>newParagraph</code> </exception>
        /// <exception cref="NullPointerException"> if <code>newParagraph</code> is
        ///         <code>null</code> </exception>
        public void DeleteChar(AttributedCharacterIterator newParagraph, int deletePos)
        {
            FStart = newParagraph.BeginIndex;
            int end = newParagraph.EndIndex;

            if (end - FStart != FChars.Length - 1)
            {
                InitAll(newParagraph);
            }

            char[] newChars     = new char[end - FStart];
            int    changedIndex = deletePos - FStart;

            System.Array.Copy(FChars, 0, newChars, 0, deletePos - FStart);
            System.Array.Copy(FChars, changedIndex + 1, newChars, changedIndex, end - deletePos);
            FChars = newChars;

            if (FBidi != null)
            {
                FBidi = new Bidi(newParagraph);
                if (FBidi.LeftToRight)
                {
                    FBidi = null;
                }
            }

            FParagraph = StyledParagraph.DeleteChar(newParagraph, FChars, deletePos, FParagraph);
            InvalidateComponents();
        }