1 18 package org.apache.batik.gvt.text; 19 20 import java.text.AttributedCharacterIterator ; 21 import java.text.CharacterIterator ; 22 import java.util.Map ; 23 import java.util.Set ; 24 25 35 36 public class AttributedCharacterSpanIterator implements 37 AttributedCharacterIterator { 38 39 private AttributedCharacterIterator aci; 40 private int begin; 41 private int end; 42 43 50 public AttributedCharacterSpanIterator(AttributedCharacterIterator aci, 51 int start, int stop) { 52 this.aci = aci; 53 end = Math.min(aci.getEndIndex(), stop); 54 begin = Math.max(aci.getBeginIndex(), start); 55 this.aci.setIndex(begin); 56 } 57 58 60 63 public Set getAllAttributeKeys() { 64 return aci.getAllAttributeKeys(); 65 } 67 68 72 public Object getAttribute(AttributedCharacterIterator.Attribute attribute) { 73 return aci.getAttribute(attribute); 74 } 75 76 80 public Map getAttributes() { 81 return aci.getAttributes(); 82 } 83 84 89 public int getRunLimit() { 90 return Math.min(aci.getRunLimit(), end); 91 } 92 93 98 public int getRunLimit(AttributedCharacterIterator.Attribute attribute) { 99 return Math.min(aci.getRunLimit(attribute), end); 100 } 101 102 107 public int getRunLimit(Set attributes) { 108 return Math.min(aci.getRunLimit(attributes), end); 109 } 110 111 115 public int getRunStart() { 116 return Math.max(aci.getRunStart(), begin); 117 } 118 119 125 public int getRunStart(AttributedCharacterIterator.Attribute attribute) { 126 return Math.max(aci.getRunStart(attribute), begin); 127 } 128 129 135 public int getRunStart(Set attributes) { 136 return Math.max(aci.getRunStart(attributes), begin); 137 } 138 139 141 144 public Object clone() { 145 return new AttributedCharacterSpanIterator( 146 (AttributedCharacterIterator ) aci.clone(), begin, end); 147 } 148 149 154 public char current() { 155 return aci.current(); 156 } 157 158 163 public char first() { 164 return aci.setIndex(begin); 165 } 166 167 171 public int getBeginIndex() { 172 return begin; 173 } 174 175 179 public int getEndIndex() { 180 return end; 181 } 182 183 187 public int getIndex() { 188 return aci.getIndex(); 189 } 190 191 196 public char last() { 197 return setIndex(end-1); 198 } 199 200 205 public char next() { 206 if (getIndex() < end-1 ) { 207 return aci.next(); 208 } else { 209 return setIndex(end); 210 } 211 } 212 213 218 public char previous() { 219 if (getIndex() > begin) { 220 return aci.previous(); 221 } else { 222 return CharacterIterator.DONE; 223 } 224 } 225 226 232 public char setIndex(int position) { 233 int ndx = Math.max(position, begin); 234 ndx = Math.min(ndx, end); 235 char c = aci.setIndex(ndx); 236 if (ndx == end) { 237 c = CharacterIterator.DONE; 238 } 239 return c; 240 } 241 } 242 243 244 245 246 247 248 | Popular Tags |