Example #1
0
  private AttributedCharacterIterator formatToCharacterIteratorImpl(Date date) {
    StringBuffer buffer = new StringBuffer();
    ArrayList<FieldPosition> fields = new ArrayList<FieldPosition>();

    // format the date, and find fields
    formatImpl(date, buffer, null, fields);

    // create and AttributedString with the formatted buffer
    AttributedString as = new AttributedString(buffer.toString());

    // add DateFormat field attributes to the AttributedString
    for (FieldPosition pos : fields) {
      Format.Field attribute = pos.getFieldAttribute();
      as.addAttribute(attribute, attribute, pos.getBeginIndex(), pos.getEndIndex());
    }

    // return the CharacterIterator from AttributedString
    return as.getIterator();
  }