Example usage for java.text FieldPosition getField

List of usage examples for java.text FieldPosition getField

Introduction

In this page you can find the example usage for java.text FieldPosition getField.

Prototype

public int getField() 

Source Link

Document

Retrieves the field identifier.

Usage

From source file:DateTimeEditor.java

private int getFieldBeginIndex(int fieldNum) {
    int beginIndex = -1;
    for (Iterator iter = m_fieldPositions.iterator(); iter.hasNext();) {
        FieldPosition fieldPos = (FieldPosition) iter.next();
        if (fieldPos.getField() == fieldNum) {
            beginIndex = fieldPos.getBeginIndex();
            break;
        }/*from   w w w. j av  a 2  s.  c om*/
    }
    return (beginIndex);
}

From source file:DateTimeEditor.java

private FieldPosition getFieldPosition(int fieldNum) {
    FieldPosition result = null;//from www  .j  ava  2  s.c  o m
    for (Iterator iter = m_fieldPositions.iterator(); iter.hasNext();) {
        FieldPosition fieldPosition = (FieldPosition) iter.next();
        if (fieldPosition.getField() == fieldNum) {
            result = fieldPosition;
            break;
        }
    }
    return (result);
}

From source file:DateTimeEditor.java

private void setCurField() {
    FieldPosition fieldPosition = getField(m_caret.getDot());
    if (fieldPosition != null) {
        if (m_caret.getDot() != fieldPosition.getBeginIndex())
            m_caret.setDot(fieldPosition.getBeginIndex());
    } else {/*from   ww  w.  ja  v a2s.  co m*/
        fieldPosition = getPrevField(m_caret.getDot());
        if (fieldPosition != null)
            m_caret.setDot(fieldPosition.getBeginIndex());
        else {
            fieldPosition = getFirstField();
            if (fieldPosition != null)
                m_caret.setDot(fieldPosition.getBeginIndex());
        }
    }

    if (fieldPosition != null)
        m_curField = fieldPosition.getField();
    else
        m_curField = -1;
}

From source file:org.osaf.cosmo.eim.schema.text.TriageStatusFormat.java

public StringBuffer format(Object obj, StringBuffer toAppendTo, FieldPosition pos) {
    if (obj == null)
        return toAppendTo;
    if (!(obj instanceof TriageStatus))
        throw new IllegalArgumentException("object not a TriageStatus");
    TriageStatus ts = (TriageStatus) obj;

    int begin = -1;
    int end = -1;

    Integer code = ts.getCode();//from   www .  j  a  v a 2 s  .  com
    if (code != null)
        // validate that this is a known code; throws
        // IllegalArgumentException if not
        TriageStatusUtil.label(code);
    else
        code = new Integer(-1);

    if (pos.getField() == CODE_FIELD)
        begin = toAppendTo.length();
    toAppendTo.append(code);
    if (pos.getField() == CODE_FIELD)
        end = toAppendTo.length() - 1;

    toAppendTo.append(" ");

    BigDecimal rank = ts.getRank();
    if (rank == null)
        rank = BigDecimal.ZERO;
    rank.setScale(2);

    if (pos.getField() == RANK_FIELD)
        begin = toAppendTo.length();
    toAppendTo.append(rank);
    if (pos.getField() == RANK_FIELD)
        end = toAppendTo.length() - 1;

    toAppendTo.append(" ");

    String autoTriage = BooleanUtils.isTrue(ts.getAutoTriage()) ? AUTOTRIAGE_ON : AUTOTRIAGE_OFF;

    if (pos.getField() == AUTOTRIAGE_FIELD)
        begin = toAppendTo.length();
    toAppendTo.append(autoTriage);
    if (pos.getField() == AUTOTRIAGE_FIELD)
        end = toAppendTo.length() - 1;

    if (pos != null) {
        pos.setBeginIndex(begin);
        pos.setEndIndex(end);
    }

    return toAppendTo;
}