Beispiel #1
0
        private AttributedString(AttributedCharacterIterator iterator, int start,
                                 int end, ICollection <AttributedCharacterIteratorAttribute> attributes)
        {
            if (start < iterator.BeginIndex || end > iterator.EndIndex ||
                start > end)
            {
                throw new ArgumentException();
            }

            if (attributes == null)
            {
                return;
            }

            StringBuilder buffer = new StringBuilder();

            iterator.SetIndex(start);
            while (iterator.Index < end)
            {
                buffer.Append(iterator.Current);
                iterator.Next();
            }
            text         = buffer.ToString();
            attributeMap = new Dictionary <AttributedCharacterIteratorAttribute, IList <Range> >(
                /*(attributes.size() * 4 / 3) + 1*/);

            //Iterator<Attribute> it = attributes.iterator();
            //while (it.hasNext())
            //{
            //    AttributedCharacterIterator.Attribute attribute = it.next();
            foreach (var attribute in attributes)
            {
                iterator.SetIndex(start);
                while (iterator.Index < end)
                {
                    Object value    = iterator.GetAttribute(attribute);
                    int    runStart = iterator.GetRunStart(attribute);
                    int    limit    = iterator.GetRunLimit(attribute);
                    if (/*(value is Annotation && runStart >= start && limit <= end)
                         ||*/(value != null /*&& !(value instanceof Annotation)*/))
                    {
                        AddAttribute(attribute, value, (runStart < start ? start
                                : runStart)
                                     - start, (limit > end ? end : limit) - start);
                    }
                    iterator.SetIndex(limit);
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Constructs an <see cref="AttributedString"/> from an
        /// <see cref="AttributedCharacterIterator"/>, which represents attributed text.
        /// </summary>
        /// <param name="iterator">The <see cref="AttributedCharacterIterator"/> that contains the text
        /// for this attributed string.</param>
        public AttributedString(AttributedCharacterIterator iterator)
        {
            if (iterator.BeginIndex > iterator.EndIndex)
            {
                // text.0A=Invalid substring range
                throw new ArgumentException(/*Messages.getString("text.0A")*/); //$NON-NLS-1$
            }
            StringBuilder buffer = new StringBuilder();

            for (int i = iterator.BeginIndex; i < iterator.EndIndex; i++)
            {
                buffer.Append(iterator.Current);
                iterator.Next();
            }
            text = buffer.ToString();
            var attributes = iterator
                             .GetAllAttributeKeys();

            if (attributes == null)
            {
                return;
            }
            attributeMap = new Dictionary <AttributedCharacterIteratorAttribute, IList <Range> >(
                /*(attributes.size() * 4 / 3) + 1*/);

            //Iterator<Attribute> it = attributes.iterator();
            //while (it.hasNext())
            //{
            //    AttributedCharacterIterator.Attribute attribute = it.next();
            foreach (var attribute in attributes)
            {
                iterator.SetIndex(0);
                while (iterator.Current != CharacterIterator.Done)
                {
                    int    start = iterator.GetRunStart(attribute);
                    int    limit = iterator.GetRunLimit(attribute);
                    object value = iterator.GetAttribute(attribute);
                    if (value != null)
                    {
                        AddAttribute(attribute, value, start, limit);
                    }
                    iterator.SetIndex(limit);
                }
            }
        }