示例#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
        /**
         * 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);
                }
            }
        }
示例#3
0
 /**
  * Constructs an {@code AttributedString} from a range of the text contained
  * in the specified {@code AttributedCharacterIterator}, starting at {@code
  * start} and ending at {@code end}. All attributes will be copied to this
  * attributed string.
  *
  * @param iterator
  *            the {@code AttributedCharacterIterator} that contains the text
  *            for this attributed string.
  * @param start
  *            the start index of the range of the copied text.
  * @param end
  *            the end index of the range of the copied text.
  * @throws IllegalArgumentException
  *             if {@code start} is less than first index of
  *             {@code iterator}, {@code end} is greater than the last
  *             index + 1 in {@code iterator} or if {@code start > end}.
  */
 public AttributedString(AttributedCharacterIterator iterator, int start,
                         int end) : this(iterator, start, end, iterator.getAllAttributeKeys())
 {
 }
示例#4
0
 /**
  * Constructs an {@code AttributedString} from a range of the text contained
  * in the specified {@code AttributedCharacterIterator}, starting at {@code
  * start} and ending at {@code end}. All attributes will be copied to this
  * attributed string.
  *
  * @param iterator
  *            the {@code AttributedCharacterIterator} that contains the text
  *            for this attributed string.
  * @param start
  *            the start index of the range of the copied text.
  * @param end
  *            the end index of the range of the copied text.
  * @throws IllegalArgumentException
  *             if {@code start} is less than first index of
  *             {@code iterator}, {@code end} is greater than the last
  *             index + 1 in {@code iterator} or if {@code start > end}.
  */
 public AttributedString(AttributedCharacterIterator iterator, int start,
         int end)
     : this(iterator, start, end, iterator.getAllAttributeKeys())
 {
 }