Spinner in Lemur

Is there some example code for a Lemur Spinner for setting Integer values?

I now have this:

        SequenceModel model = SequenceModels.rangedSequence(new DefaultRangedValueModel(0, 100, 0), 1, 1);
        VersionedReference valueRef = model.createReference();
        DefaultValueRenderer<Integer> renderer = ValueRenderers.formattedRenderer("%d", "error");
        Spinner<Integer> spinner = new Spinner<>(model);
        //doubleSpinner.setLocalTranslation(200, 200, 0);

And it keeps complaining about this:

SEVERE: Uncaught exception thrown in Thread[jME3 Main,5,main]
java.lang.ClassCastException: class java.lang.Integer cannot be cast to class java.lang.Double (java.lang.Integer and java.lang.Double are in module java.base of loader 'bootstrap')
	at com.simsilica.lemur.SequenceModels$RangedSequence.setObject(SequenceModels.java:176)
	at com.simsilica.lemur.Spinner.setValue(Spinner.java:231)

And would it be an idea to add a constructor that acts as a wrapper for all these extra objects like DefaultValueRenders and SequenceModels? I think for many controls this would help to make Lemur easier to use.

900 constructors is bad but definitely some utility methods.

RangedValueModel is going to always be Double because RangedValueModel only deals in doubles.

Your options are to build a double spinner with no decimal places and then cast the value coming out… or to write a SequenceModel that does that automatically, perhaps forking the existing ranged sequence. Lemur really needs such a thing so if you write one I’d be interested in seeing it.

For my own “integer” spinner, I do the following:

    SequenceModel<Double> model 
                = SequenceModels.rangedSequence(
                        new DefaultRangedValueModel(min, max, 0), 
                        step, 1);
    DefaultValueRenderer<Double> renderer = ValueRenderers.formattedRenderer("%.0f", "error");
    editor = new Spinner<>(model, renderer);

And every time I write that another time I think “This time I will make a factory method…”

1 Like