use of java.text.AttributedCharacterIterator in project eclipse.platform.swt by eclipse.
the class DateTime method updateField.
/**
* Returns a field with updated positionla data
*
* @param field
* @return
*/
private FieldPosition updateField(FieldPosition field) {
AttributedCharacterIterator iterator = dateFormat.formatToCharacterIterator(calendar.getTime());
while (iterator.current() != CharacterIterator.DONE) {
FieldPosition current = getFieldPosition(iterator);
iterator.setIndex(iterator.getRunLimit());
if (field == null || isSameField(current, field)) {
return current;
}
}
return field;
}
use of java.text.AttributedCharacterIterator in project eclipse.platform.swt by eclipse.
the class DateTime method onTextMouseClick.
void onTextMouseClick(GdkEventButton event) {
if (calendar == null) {
// Guard: Object not fully initialized yet.
return;
}
int clickPosition = getSelection().x;
AttributedCharacterIterator iterator = dateFormat.formatToCharacterIterator(calendar.getTime());
iterator.first();
int pos = 0;
do {
FieldPosition position = getFieldPosition(iterator);
iterator.setIndex(iterator.getRunLimit());
if (isSameField(position, currentField)) {
// use the current field instead then!
position = currentField;
}
int fieldWidth = position.getEndIndex() - position.getBeginIndex();
pos += fieldWidth;
if (position.getFieldAttribute() == null) {
continue;
}
if (pos >= clickPosition) {
FieldPosition selectField = new FieldPosition(position.getFieldAttribute());
selectField.setBeginIndex(pos - fieldWidth);
selectField.setEndIndex(pos);
selectField(selectField);
break;
}
} while (iterator.current() != CharacterIterator.DONE);
}
Aggregations