示例#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);
                }
            }
        }
示例#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);
                }
            }
        }
示例#3
0
 /// <summary>
 /// Constructs an <see cref="AttributedString"/> from a range of the text contained
 /// in the specified <see cref="AttributedCharacterIterator"/>, starting at
 /// <paramref name="start"/>, ending at <paramref name="end"/> and it will copy the attributes defined in
 /// the specified set. If the set is <c>null</c> then all attributes are
 /// copied.
 /// </summary>
 /// <param name="iterator">The <see cref="AttributedCharacterIterator"/> that contains the text
 /// for this attributed string.</param>
 /// <param name="start">The start index of the range of the copied text.</param>
 /// <param name="end">The end index of the range of the copied text.</param>
 /// <param name="attributes">The set of attributes that will be copied, or all if it is
 /// <c>null</c>.</param>
 /// <exception cref="ArgumentException">if <paramref name="start"/> is less than first index of
 /// <paramref name="iterator"/>, <paramref name="end"/> is greater than the last index +
 /// 1 in <paramref name="iterator"/> or if <paramref name="start"/> &gt; <paramref name="end"/>.</exception>
 public AttributedString(AttributedCharacterIterator iterator, int start,
                         int end, AttributedCharacterIteratorAttribute[] attributes)
     : this(iterator, start, end, new HashSet <AttributedCharacterIteratorAttribute>(attributes))
 {
 }
示例#4
0
 /// <summary>
 /// Constructs an <see cref="AttributedString"/> from a range of the text contained
 /// in the specified <see cref="AttributedCharacterIterator"/>, starting at
 /// <paramref name="start"/> and ending at <paramref name="end"/>. All attributes will be copied to this
 /// attributed string.
 /// </summary>
 /// <param name="iterator">The <see cref="AttributedCharacterIterator"/> that contains the text
 /// for this attributed string.</param>
 /// <param name="start">the start index of the range of the copied text.</param>
 /// <param name="end">the end index of the range of the copied text.</param>
 /// <exception cref="ArgumentException">if <paramref name="start"/> is less than first index of
 /// <paramref name="iterator"/>, <paramref name="end"/> is greater than the last index +
 /// 1 in <paramref name="iterator"/> or if <paramref name="start"/> &gt; <paramref name="end"/>.</exception>
 public AttributedString(AttributedCharacterIterator iterator, int start,
                         int end)
     : this(iterator, start, end, iterator.GetAllAttributeKeys())
 {
 }