Пример #1
0
 public int getRunStart(AttributedCharacterIteratorNS.Attribute attribute)
 {
     if (attributesAllowed != null
             && !attributesAllowed.contains(attribute)) {
         return begin;
     }
     java.util.ArrayList<IAC_Range> ranges = (java.util.ArrayList<IAC_Range>) attrString.attributeMap
             .get(attribute);
     if (ranges == null) {
         return begin;
     }
     return runStart(ranges);
 }
Пример #2
0
 internal AttributedIterator(AttributedString attrString,
         AttributedCharacterIteratorNS.Attribute[] attributes, int begin,
         int end)
 {
     if (begin < 0 || end > attrString.text.Length || begin > end) {
         throw new java.lang.IllegalArgumentException();
     }
     this.begin = begin;
     this.end = end;
     offset = begin;
     this.attrString = attrString;
     if (attributes != null) {
         java.util.HashSet<AttributedCharacterIteratorNS.Attribute> set = new java.util.HashSet<AttributedCharacterIteratorNS.Attribute>(
                 (attributes.Length * 4 / 3) + 1);
         for (int i = attributes.Length; --i >= 0;) {
             set.add(attributes[i]);
         }
         attributesAllowed = set;
     }
 }
Пример #3
0
 public System.Object getAttribute(
         AttributedCharacterIteratorNS.Attribute attribute)
 {
     if (attributesAllowed != null
             && !attributesAllowed.contains(attribute)) {
         return null;
     }
     java.util.ArrayList<IAC_Range> ranges = (java.util.ArrayList<IAC_Range>) attrString.attributeMap
             .get(attribute);
     if (ranges == null) {
         return null;
     }
     return currentValue(ranges);
 }
Пример #4
0
 /**
  * Returns an {@code AttributedCharacterIterator} that gives access to the
  * contents of this attributed string starting at index {@code start} up to
  * index {@code end}. Only attributes contained in {@code attributes} are
  * available from this iterator if they are defined for this text.
  *
  * @param attributes
  *            the array containing attributes that will be in the new
  *            iterator if they are defined for this text.
  * @param start
  *            the start index of the iterator on the underlying text.
  * @param end
  *            the end index of the iterator on the underlying text.
  * @return the newly created {@code AttributedCharacterIterator}.
  */
 public AttributedCharacterIterator getIterator(
         AttributedCharacterIteratorNS.Attribute[] attributes, int start,
         int end)
 {
     return new AttributedIterator(this, attributes, start, end);
 }
Пример #5
0
 /**
  * Returns an {@code AttributedCharacterIterator} that gives access to the
  * complete content of this attributed string. Only attributes contained in
  * {@code attributes} are available from this iterator if they are defined
  * for this text.
  *
  * @param attributes
  *            the array containing attributes that will be in the new
  *            iterator if they are defined for this text.
  * @return the newly created {@code AttributedCharacterIterator}.
  */
 public AttributedCharacterIterator getIterator(
         AttributedCharacterIteratorNS.Attribute[] attributes)
 {
     return new AttributedIterator(this, attributes, 0, text.Length);
 }
Пример #6
0
        /**
         * Applies a given attribute to the given range of this string.
         *
         * @param attribute
         *            the attribute that will be applied to this string.
         * @param value
         *            the value of the attribute that will be applied to this
         *            string.
         * @param start
         *            the start of the range where the attribute will be applied.
         * @param end
         *            the end of the range where the attribute will be applied.
         * @throws IllegalArgumentException
         *             if {@code start < 0}, {@code end} is greater than the length
         *             of this string, or if {@code start >= end}.
         * @throws NullPointerException
         *             if {@code attribute} is {@code null}.
         */
        public void addAttribute(AttributedCharacterIteratorNS.Attribute attribute,
                System.Object value, int start, int end)
        {
            if (null == attribute) {
                throw new java.lang.NullPointerException();
            }
            if (start < 0 || end > text.Length || start >= end) {
                throw new java.lang.IllegalArgumentException();
            }

            if (value == null) {
                return;
            }

            java.util.List<IAC_Range> ranges = attributeMap.get(attribute);
            if (ranges == null) {
                ranges = new java.util.ArrayList<IAC_Range>(1);
                ranges.add(new IAC_Range(start, end, value));
                attributeMap.put(attribute, ranges);
                return;
            }
            java.util.ListIterator<IAC_Range> it = ranges.listIterator();
            while (it.hasNext()) {
                IAC_Range range = it.next();
                if (end <= range.start) {
                    it.previous();
                    break;
                } else if (start < range.end
                        || (start == range.end && value.Equals(range.value))) {
                    IAC_Range r1 = null, r3;
                    it.remove();
                    r1 = new IAC_Range(range.start, start, range.value);
                    r3 = new IAC_Range(end, range.end, range.value);

                    while (end > range.end && it.hasNext()) {
                        range = it.next();
                        if (end <= range.end) {
                            if (end > range.start
                                    || (end == range.start && value.Equals(range.value))) {
                                it.remove();
                                r3 = new IAC_Range(end, range.end, range.value);
                                break;
                            }
                        } else {
                            it.remove();
                        }
                    }

                    if (value.Equals(r1.value)) {
                        if (value.Equals(r3.value)) {
                            it.add(new IAC_Range(r1.start < start ? r1.start : start,
                                    r3.end > end ? r3.end : end, r1.value));
                        } else {
                            it.add(new IAC_Range(r1.start < start ? r1.start : start,
                                    end, r1.value));
                            if (r3.start < r3.end) {
                                it.add(r3);
                            }
                        }
                    } else {
                        if (value.Equals(r3.value)) {
                            if (r1.start < r1.end) {
                                it.add(r1);
                            }
                            it.add(new IAC_Range(start, r3.end > end ? r3.end : end,
                                    r3.value));
                        } else {
                            if (r1.start < r1.end) {
                                it.add(r1);
                            }
                            it.add(new IAC_Range(start, end, value));
                            if (r3.start < r3.end) {
                                it.add(r3);
                            }
                        }
                    }
                    return;
                }
            }
            it.add(new IAC_Range(start, end, value));
        }
Пример #7
0
        /**
         * Applies a given attribute to this string.
         *
         * @param attribute
         *            the attribute that will be applied to this string.
         * @param value
         *            the value of the attribute that will be applied to this
         *            string.
         * @throws IllegalArgumentException
         *             if the length of this attributed string is 0.
         * @throws NullPointerException
         *             if {@code attribute} is {@code null}.
         */
        public void addAttribute(AttributedCharacterIteratorNS.Attribute attribute,
                System.Object value)
        {
            if (null == attribute) {
                throw new java.lang.NullPointerException();
            }
            if (text.Length == 0) {
                throw new java.lang.IllegalArgumentException();
            }

            java.util.List<IAC_Range> ranges = attributeMap.get(attribute);
            if (ranges == null) {
                ranges = new java.util.ArrayList<IAC_Range>(1);
                attributeMap.put(attribute, ranges);
            } else {
                ranges.clear();
            }
            ranges.add(new IAC_Range(0, text.Length, value));
        }
Пример #8
0
 /**
  * Constructs an {@code AttributedString} from a range of the text contained
  * in the specified {@code AttributedCharacterIterator}, starting at {@code
  * start}, ending at {@code end} and it will copy the attributes defined in
  * the specified set. If the set is {@code null} then all attributes are
  * copied.
  *
  * @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.
  * @param attributes
  *            the set of attributes that will be copied, or all if it is
  *            {@code null}.
  * @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, AttributedCharacterIteratorNS.Attribute[] attributes)
     : this(iterator, start, end, new java.util.HashSet<AttributedCharacterIteratorNS.Attribute>(java.util.Arrays<System.Object>.asList(attributes)))
 {
 }