Search in sources :

Example 56 with AttributedCharacterIterator

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;
}
Also used : AttributedCharacterIterator(java.text.AttributedCharacterIterator)

Example 57 with AttributedCharacterIterator

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);
}
Also used : AttributedCharacterIterator(java.text.AttributedCharacterIterator)

Aggregations

AttributedCharacterIterator (java.text.AttributedCharacterIterator)57 AttributedString (java.text.AttributedString)35 TextLayout (java.awt.font.TextLayout)17 LineBreakMeasurer (java.awt.font.LineBreakMeasurer)15 Point (java.awt.Point)8 Font (java.awt.Font)7 Paint (java.awt.Paint)7 FontRenderContext (java.awt.font.FontRenderContext)7 Graphics2D (java.awt.Graphics2D)6 Color (java.awt.Color)5 ArrayList (java.util.ArrayList)5 WeakHashMap (java.util.WeakHashMap)5 Rectangle (java.awt.Rectangle)4 Attribute (java.text.AttributedCharacterIterator.Attribute)4 DecimalFormat (java.text.DecimalFormat)4 BigDecimal (java.math.BigDecimal)3 BigInteger (java.math.BigInteger)3 HashSet (java.util.HashSet)3 Dimension (java.awt.Dimension)2 Image (java.awt.Image)2