/[classpath]/classpath/java/text/AttributedStringIterator.java
ViewVC logotype

Diff of /classpath/java/text/AttributedStringIterator.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.10 by trebligd, Thu Jul 28 09:27:39 2005 UTC revision 1.11 by trebligd, Mon Oct 24 10:04:22 2005 UTC
# Line 188  class AttributedStringIterator implement Line 188  class AttributedStringIterator implement
188      return(getRunLimit(s));      return(getRunLimit(s));
189    }    }
190    
191    public synchronized int getRunLimit(Set attribute_set)    public synchronized int getRunLimit(Set attributeSet)
192    {    {
193      boolean hit = false;      if (attributeSet == null)
194      int runLimit = ci.getEndIndex ();        return ci.getEndIndex();
195      int pos = ci.getIndex ();      
196        int current = ci.getIndex();
197      for (int i = 0; i < attribs.length; ++i)      int end = ci.getEndIndex();
198        int limit = current;
199        if (current == end)
200          return end;
201        Map runValues = getAttributes();
202        while (limit < end)
203        {
204          Iterator iterator = attributeSet.iterator();
205          while (iterator.hasNext())
206        {        {
207          if (pos >= attribs[i].begin_index &&          Attribute attributeKey = (Attribute) iterator.next();
208              pos < attribs[i].end_index)          Object v1 = runValues.get(attributeKey);
209            Object v2 = getAttribute(attributeKey, limit + 1);
210            boolean changed = false;
211            // check for equal or both null, if NO return start
212            if (v1 != null)
213              {
214                changed = !v1.equals(v2);
215              }
216            else
217            {            {
218              Iterator iter = attribute_set.iterator();              changed = (v2 != null);  
             while(iter.hasNext())  
               if (attribs[i].attribs.containsKey(iter.next()))  
                 {  
                   hit = true;  
                   runLimit = Math.min(runLimit, attribs[i].end_index);  
                 }  
219            }            }
220            if (changed)
221              return limit + 1;
222        }        }
223      if (hit)        // no differences, so increment limit and next and loop again
224        return runLimit;        limit++;
225      else      }
226        return ci.getEndIndex();      return end;
227    }    }
228    
229    /*************************************************************************/    /*************************************************************************/
# Line 221  class AttributedStringIterator implement Line 233  class AttributedStringIterator implement
233     * attribute combinations.     * attribute combinations.
234     */     */
235    
236      /**
237       * Returns the index of the first character in the run containing the current
238       * character and defined by all the attributes defined for that character
239       * position.
240       *
241       * @return The run start index.
242       */
243    public int getRunStart()    public int getRunStart()
244    {    {
245      return(getRunStart(getAttributes().keySet()));      return(getRunStart(getAttributes().keySet()));
246    }    }
247    
248      /**
249       * Returns the index of the first character in the run, defined by the
250       * specified attribute, that contains the current character.
251       *
252       * @param attrib  the attribute (<code>null</code> permitted).
253       *
254       * return The index of the first character in the run.
255       */
256    public int getRunStart(AttributedCharacterIterator.Attribute attrib)    public int getRunStart(AttributedCharacterIterator.Attribute attrib)
257    {    {
258        if (attrib == null)
259          return ci.getBeginIndex();
260      HashSet s = new HashSet();      HashSet s = new HashSet();
261      s.add(attrib);      s.add(attrib);
   
262      return(getRunStart(s));      return(getRunStart(s));
263    }    }
264    
265    public int getRunStart(Set attribute_set)    /**
266       * Returns the index of the first character in the run, defined by the
267       * specified attribute set, that contains the current character.
268       *
269       * @param attributeSet  the attribute set (<code>null</code> permitted).
270       *
271       * return The index of the first character in the run.
272       */
273      public int getRunStart(Set attributeSet)
274    {    {
275      boolean hit = false;      if (attributeSet == null)
276      int runBegin = 0;        return ci.getBeginIndex();
277      int pos = ci.getIndex();      
278        int current = ci.getIndex();
279      for (int i = 0; i < attribs.length; ++i)      int begin = ci.getBeginIndex();
280        int start = current;
281        if (start == begin)
282          return begin;
283        Map runValues = getAttributes();
284        int prev = start - 1;
285        while (start > begin)
286        {
287          Iterator iterator = attributeSet.iterator();
288          while (iterator.hasNext())
289        {        {
290          if (pos >= attribs[i].begin_index &&          Attribute attributeKey = (Attribute) iterator.next();
291              pos <= attribs[i].end_index)          Object v1 = runValues.get(attributeKey);
292            Object v2 = getAttribute(attributeKey, prev);
293            boolean changed = false;
294            // check for equal or both null, if NO return start
295            if (v1 != null)
296              {
297                changed = !v1.equals(v2);
298              }
299            else
300            {            {
301              Iterator iter = attribute_set.iterator();              changed = (v2 != null);  
             while(iter.hasNext())  
               if (attribs[i].attribs.containsKey(iter.next()))  
                 {  
                   hit = true;  
                   runBegin = Math.max(runBegin, attribs[i].begin_index);  
                 }  
302            }            }
303            if (changed)
304              return start;
305        }        }
306      if (hit)        // no differences, so decrement start and prev and loop again
307        return runBegin;        start--;
308      else        prev--;
309        return -1;      }
310        return start;
311    }    }
312    
313    /*************************************************************************/    /*************************************************************************/
314    
315    public Object getAttribute(AttributedCharacterIterator.Attribute attrib)    /**
316       * Returns the value for an attribute at the specified position.  If the
317       * attribute key (<code>key</code>) is <code>null</code>, the method returns
318       * <code>null</code>.
319       *
320       * @param key  the key (<code>null</code> permitted).
321       * @param pos  the character position.
322       *
323       * @return The attribute value (possibly <code>null</code>).
324       */
325      private Object getAttribute(AttributedCharacterIterator.Attribute key,
326              int pos)
327    {    {
328      if (attribs == null)      if (attribs == null)
329        return(null);        return null;
330        for (int i = attribs.length - 1; i >= 0; i--)
     for (int i = 0; i < attribs.length; i++)  
331        {        {
332          Set key_set = attribs[i].attribs.keySet();          if (pos >= attribs[i].begin_index && pos < attribs[i].end_index)
         Iterator iter = key_set.iterator();  
         while (iter.hasNext())  
333            {            {
334              Object obj = iter.next();              Set keys = attribs[i].attribs.keySet();
335                if (keys.contains(key))
336              // Check for attribute match and range match                {
337              if (obj.equals(attrib))                  return attribs[i].attribs.get(key);
338                if ((ci.getIndex() >= attribs[i].begin_index) &&                }
                   (ci.getIndex() < attribs[i].end_index))  
                 return(attribs[i].attribs.get(obj));  
339            }            }
340        }        }
341        return null;  
342      return(null);    }
343      
344      /**
345       * Returns the value for an attribute at the current position.  If the
346       * attribute key (<code>key</code>) is <code>null</code>, the method returns
347       * <code>null</code>.
348       *
349       * @param key  the key (<code>null</code> permitted).
350       *
351       * @return The attribute value (possibly <code>null</code>).
352       */
353      public Object getAttribute(AttributedCharacterIterator.Attribute key)
354      {
355        return getAttribute(key, ci.getIndex());
356    }    }
357    
358    /*************************************************************************/    /*************************************************************************/

Legend:
Removed from v.1.10  
changed lines
  Added in v.1.11

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26