Example usage for javax.swing SpinnerDateModel getValue

List of usage examples for javax.swing SpinnerDateModel getValue

Introduction

In this page you can find the example usage for javax.swing SpinnerDateModel getValue.

Prototype

public Object getValue() 

Source Link

Document

Returns the current element in this sequence of Dates.

Usage

From source file:org.eclipse.wb.internal.swing.model.property.editor.models.spinner.DateSpinnerComposite.java

@Override
public boolean setModel(SpinnerModel model) {
    if (model instanceof SpinnerDateModel) {
        SpinnerDateModel dateModel = (SpinnerDateModel) model;
        // values
        setValue(m_valueField, dateModel.getValue());
        setValue(m_minField, dateModel.getStart());
        setValue(m_maxField, dateModel.getEnd());
        // step/* w w w  .jav  a2 s .com*/
        for (int i = 0; i < CALENDAR_FIELDS.length; i++) {
            String field = CALENDAR_FIELDS[i];
            if (ReflectionUtils.getFieldInt(Calendar.class, field) == dateModel.getCalendarField()) {
                m_stepCombo.select(i);
                break;
            }
        }
        // enable/disable min/max fields
        updateCheckField(m_minButton, m_minField, dateModel.getStart() != null);
        updateCheckField(m_maxButton, m_maxField, dateModel.getEnd() != null);
        // OK, this is our model
        return true;
    } else {
        // values
        m_valueField.setSelection(DEFAULT_DATE);
        m_minField.setSelection(DEFAULT_DATE);
        m_maxField.setSelection(DEFAULT_DATE);
        // disable min/max fields
        updateCheckField(m_minButton, m_minField, false);
        updateCheckField(m_maxButton, m_maxField, false);
        // no, we don't know this model
        return false;
    }
}

From source file:org.eclipse.wb.internal.swing.model.property.editor.models.spinner.SpinnerModelPropertyEditor.java

/**
 * @return the text to display for given {@link Property}.
 *//*from ww  w.  j  ava2 s.  c om*/
private String getText(Property property, boolean forTooltip) throws Exception {
    Object value = property.getValue();
    if (value instanceof SpinnerModel) {
        SpinnerModel model = (SpinnerModel) value;
        // analyze known models
        if (model instanceof SpinnerNumberModel) {
            SpinnerNumberModel numberModel = (SpinnerNumberModel) model;
            // prepare labels
            String typeLabel = forTooltip ? "type=" : "";
            String valueLabel = forTooltip ? " value=" : ", ";
            String startLabel = forTooltip ? " start=" : ", ";
            String endLabel = forTooltip ? " end=" : ", ";
            String stepLabel = forTooltip ? " step=" : ", ";
            // text
            String typeText = typeLabel + CodeUtils.getShortClass(numberModel.getValue().getClass().getName());
            String valueText = valueLabel + numberModel.getValue();
            String startText = startLabel + numberModel.getMinimum();
            String endText = endLabel + numberModel.getMaximum();
            String stepText = stepLabel + numberModel.getStepSize();
            return typeText + valueText + startText + endText + stepText;
        } else if (model instanceof SpinnerListModel) {
            SpinnerListModel listModel = (SpinnerListModel) model;
            String separator = forTooltip ? "\n" : ", ";
            return StringUtils.join(listModel.getList().iterator(), separator);
        } else if (model instanceof SpinnerDateModel) {
            SpinnerDateModel dateModel = (SpinnerDateModel) model;
            // prepare labels
            String valueLabel = forTooltip ? "value=" : "";
            String startLabel = forTooltip ? "\nstart=" : ", ";
            String endLabel = forTooltip ? "\nend=" : ", ";
            String stepLabel = forTooltip ? "\nstep=" : ", ";
            // text
            String valueText = valueLabel + getDateText(dateModel.getValue());
            String startText = startLabel + getDateText(dateModel.getStart());
            String endText = endLabel + getDateText(dateModel.getEnd());
            String stepText = stepLabel + getDateStep(dateModel.getCalendarField());
            return valueText + startText + endText + stepText;
        } else {
            return model.toString();
        }
    }
    // unknown value
    return null;
}