示例#1
0
        /**
         * Constructs an {@code AttributedString} from an {@code
         * AttributedCharacterIterator}, which represents attributed text.
         *
         * @param iterator
         *            the {@code AttributedCharacterIterator} that contains the text
         *            for this attributed string.
         */
        public AttributedString(AttributedCharacterIterator iterator)
        {
            if (iterator.getBeginIndex() > iterator.getEndIndex()) {
                // text.0A=Invalid substring range
                throw new java.lang.IllegalArgumentException("Invalid substring range"); //$NON-NLS-1$
            }
            StringBuilder buffer = new StringBuilder();
            for (int i = iterator.getBeginIndex(); i < iterator.getEndIndex(); i++) {
                buffer.Append(iterator.current());
                iterator.next();
            }
            text = buffer.ToString();
            java.util.Set<AttributedCharacterIteratorNS.Attribute> attributes = iterator
                    .getAllAttributeKeys();
            if (attributes == null) {
                return;
            }
            attributeMap = new java.util.HashMap<AttributedCharacterIteratorNS.Attribute, java.util.List<IAC_Range>>();//(attributes.size() * 4 / 3) + 1);

            java.util.Iterator<AttributedCharacterIteratorNS.Attribute> it = attributes.iterator();
            while (it.hasNext()) {
                AttributedCharacterIteratorNS.Attribute attribute = it.next();
                iterator.setIndex(0);
                while (iterator.current() != CharacterIteratorConstants.DONE) {
                    int start = iterator.getRunStart(attribute);
                    int limit = iterator.getRunLimit(attribute);
                    System.Object value = iterator.getAttribute(attribute);
                    if (value != null) {
                        addAttribute(attribute, value, start, limit);
                    }
                    iterator.setIndex(limit);
                }
            }
        }
示例#2
0
        private AttributedString(AttributedCharacterIterator iterator, int start,
                                 int end, java.util.Set <AttributedCharacterIteratorNS.Attribute> attributes)
        {
            if (start < iterator.getBeginIndex() || end > iterator.getEndIndex() ||
                start > end)
            {
                throw new java.lang.IllegalArgumentException();
            }

            if (attributes == null)
            {
                return;
            }

            StringBuilder buffer = new StringBuilder();

            iterator.setIndex(start);
            while (iterator.getIndex() < end)
            {
                buffer.Append(iterator.current());
                iterator.next();
            }
            text         = buffer.ToString();
            attributeMap = new java.util.HashMap <AttributedCharacterIteratorNS.Attribute, java.util.List <IAC_Range> >();//(attributes.size() * 4 / 3) + 1);

            java.util.Iterator <AttributedCharacterIteratorNS.Attribute> it = attributes.iterator();
            while (it.hasNext())
            {
                AttributedCharacterIteratorNS.Attribute attribute = it.next();
                iterator.setIndex(start);
                while (iterator.getIndex() < end)
                {
                    System.Object value    = iterator.getAttribute(attribute);
                    int           runStart = iterator.getRunStart(attribute);
                    int           limit    = iterator.getRunLimit(attribute);
                    if ((value is java.lang.annotation.Annotation && runStart >= start && limit <= end) ||
                        (value != null && !(value is java.lang.annotation.Annotation)))
                    {
                        addAttribute(attribute, value, (runStart < start ? start
                                : runStart)
                                     - start, (limit > end ? end : limit) - start);
                    }
                    iterator.setIndex(limit);
                }
            }
        }
示例#3
0
        /**
         * Constructs an {@code AttributedString} from an {@code
         * AttributedCharacterIterator}, which represents attributed text.
         *
         * @param iterator
         *            the {@code AttributedCharacterIterator} that contains the text
         *            for this attributed string.
         */
        public AttributedString(AttributedCharacterIterator iterator)
        {
            if (iterator.getBeginIndex() > iterator.getEndIndex())
            {
                // text.0A=Invalid substring range
                throw new java.lang.IllegalArgumentException("Invalid substring range"); //$NON-NLS-1$
            }
            StringBuilder buffer = new StringBuilder();

            for (int i = iterator.getBeginIndex(); i < iterator.getEndIndex(); i++)
            {
                buffer.Append(iterator.current());
                iterator.next();
            }
            text = buffer.ToString();
            java.util.Set <AttributedCharacterIteratorNS.Attribute> attributes = iterator
                                                                                 .getAllAttributeKeys();
            if (attributes == null)
            {
                return;
            }
            attributeMap = new java.util.HashMap <AttributedCharacterIteratorNS.Attribute, java.util.List <IAC_Range> >();//(attributes.size() * 4 / 3) + 1);

            java.util.Iterator <AttributedCharacterIteratorNS.Attribute> it = attributes.iterator();
            while (it.hasNext())
            {
                AttributedCharacterIteratorNS.Attribute attribute = it.next();
                iterator.setIndex(0);
                while (iterator.current() != CharacterIteratorConstants.DONE)
                {
                    int           start = iterator.getRunStart(attribute);
                    int           limit = iterator.getRunLimit(attribute);
                    System.Object value = iterator.getAttribute(attribute);
                    if (value != null)
                    {
                        addAttribute(attribute, value, start, limit);
                    }
                    iterator.setIndex(limit);
                }
            }
        }
示例#4
0
        /// <summary>
        /// Return a StyledParagraph reflecting the insertion of a single character
        /// into the text.  This method will attempt to reuse the given paragraph,
        /// but may create a new paragraph. </summary>
        /// <param name="aci"> an iterator over the text.  The text should be the same as the
        ///     text used to create (or most recently update) oldParagraph, with
        ///     the exception of inserting a single character at insertPos. </param>
        /// <param name="chars"> the characters in aci </param>
        /// <param name="insertPos"> the index of the new character in aci </param>
        /// <param name="oldParagraph"> a StyledParagraph for the text in aci before the
        ///     insertion </param>
        public static StyledParagraph InsertChar(AttributedCharacterIterator aci, char[] chars, int insertPos, StyledParagraph oldParagraph)
        {
            // If the styles at insertPos match those at insertPos-1,
            // oldParagraph will be reused.  Otherwise we create a new
            // paragraph.

            char ch          = aci.setIndex(insertPos);
            int  relativePos = System.Math.Max(insertPos - aci.BeginIndex - 1, 0);

//JAVA TO C# CONVERTER TODO TASK: Java wildcard generics are not converted to .NET:
//ORIGINAL LINE: java.util.Map<? extends java.text.AttributedCharacterIterator_Attribute, ?> attributes = addInputMethodAttrs(aci.getAttributes());
            IDictionary <?, ?> attributes = AddInputMethodAttrs(aci.Attributes);
            Decoration         d          = Decoration.getDecoration(attributes);

            if (!oldParagraph.GetDecorationAt(relativePos).Equals(d))
            {
                return(new StyledParagraph(aci, chars));
            }
            Object f = GetGraphicOrFont(attributes);

            if (f == null)
            {
                FontResolver resolver  = FontResolver.Instance;
                int          fontIndex = resolver.getFontIndex(ch);
                f = resolver.getFont(fontIndex, attributes);
            }
            if (!oldParagraph.GetFontOrGraphicAt(relativePos).Equals(f))
            {
                return(new StyledParagraph(aci, chars));
            }

            // insert into existing paragraph
            oldParagraph.Length += 1;
            if (oldParagraph.Decorations != null)
            {
                InsertInto(relativePos, oldParagraph.DecorationStarts, oldParagraph.Decorations.Count);
            }
            if (oldParagraph.Fonts != null)
            {
                InsertInto(relativePos, oldParagraph.FontStarts, oldParagraph.Fonts.Count);
            }
            return(oldParagraph);
        }
示例#5
0
        /// <summary>
        /// Updates the <code>TextMeasurer</code> after a single character has
        /// been inserted
        /// into 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 insertion.  Cannot be null. </param>
        /// <param name="insertPos"> the position in the text where the character was
        /// inserted.  Must not be less than the start of
        /// <code>newParagraph</code>, and must be less than the end of
        /// <code>newParagraph</code>. </param>
        /// <exception cref="IndexOutOfBoundsException"> if <code>insertPos</code> is less
        ///         than the start of <code>newParagraph</code> or greater than
        ///         or equal to the end of <code>newParagraph</code> </exception>
        /// <exception cref="NullPointerException"> if <code>newParagraph</code> is
        ///         <code>null</code> </exception>
        public void InsertChar(AttributedCharacterIterator newParagraph, int insertPos)
        {
            if (CollectStats)
            {
                PrintStats();
            }
            if (WantStats)
            {
                CollectStats = true;
            }

            FStart = newParagraph.BeginIndex;
            int end = newParagraph.EndIndex;

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

            char[] newChars     = new char[end - FStart];
            int    newCharIndex = insertPos - FStart;

            System.Array.Copy(FChars, 0, newChars, 0, newCharIndex);

            char newChar = newParagraph.setIndex(insertPos);

            newChars[newCharIndex] = newChar;
            System.Array.Copy(FChars, newCharIndex, newChars, newCharIndex + 1, end - insertPos - 1);
            FChars = newChars;

            if (FBidi != null || Bidi.RequiresBidi(newChars, newCharIndex, newCharIndex + 1) || newParagraph.GetAttribute(TextAttribute.BIDI_EMBEDDING) != null)
            {
                FBidi = new Bidi(newParagraph);
                if (FBidi.LeftToRight)
                {
                    FBidi = null;
                }
            }

            FParagraph = StyledParagraph.InsertChar(newParagraph, FChars, insertPos, FParagraph);
            InvalidateComponents();
        }
示例#6
0
        private AttributedString(AttributedCharacterIterator iterator, int start,
                int end, java.util.Set<AttributedCharacterIteratorNS.Attribute> attributes)
        {
            if (start < iterator.getBeginIndex() || end > iterator.getEndIndex()
                    || start > end) {
                throw new java.lang.IllegalArgumentException();
            }

            if (attributes == null) {
                return;
            }

            StringBuilder buffer = new StringBuilder();
            iterator.setIndex(start);
            while (iterator.getIndex() < end) {
                buffer.Append(iterator.current());
                iterator.next();
            }
            text = buffer.ToString();
            attributeMap = new java.util.HashMap<AttributedCharacterIteratorNS.Attribute, java.util.List<IAC_Range>>();//(attributes.size() * 4 / 3) + 1);

            java.util.Iterator<AttributedCharacterIteratorNS.Attribute> it = attributes.iterator();
            while (it.hasNext()) {
                AttributedCharacterIteratorNS.Attribute attribute = it.next();
                iterator.setIndex(start);
                while (iterator.getIndex() < end) {
                    System.Object value = iterator.getAttribute(attribute);
                    int runStart = iterator.getRunStart(attribute);
                    int limit = iterator.getRunLimit(attribute);
                    if ((value is java.lang.annotation.Annotation && runStart >= start && limit <= end)
                            || (value != null && !(value is java.lang.annotation.Annotation))) {
                        addAttribute(attribute, value, (runStart < start ? start
                                : runStart)
                                - start, (limit > end ? end : limit) - start);
                    }
                    iterator.setIndex(limit);
                }
            }
        }