Example usage for javax.swing SpinnerNumberModel getValue

List of usage examples for javax.swing SpinnerNumberModel getValue

Introduction

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

Prototype

public Object getValue() 

Source Link

Document

Returns the value of the current element of the sequence.

Usage

From source file:Main.java

public static double getDouble(SpinnerNumberModel model) {
    return (double) model.getValue();
}

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

/**
 * @return the text to display for given {@link Property}.
 *///  ww  w  .  j a  v  a  2s  . 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;
}