spinner component
Tom Eugelink
tbee at tbee.org
Thu Dec 22 21:54:32 PST 2011
Thanks! I'll look into it.
Tom
On 2011-12-23 00:46, Jonathan Giles wrote:
> We've just made available the UX specs for Date Picker and Spinner here:
> http://openjdk.java.net/projects/openjfx/ux/index.html
>
> -- Jonathan
>
>
> On 17/12/2011 6:16 p.m., Tom Eugelink wrote:
>> I would like to propose the addition of a spinner control to OpenJFX.
>>
>> A spinner control for all means and purposes is a listview where only one cell is visible (rendered) at a time. Moving to the next and previous cell is done via clicking with the mouse on arrows or using keyboard presses. The control's API could look like:
>>
>> Class: *Spinner<T> extends Control*
>> T denotes the type it is holding; String, Integer, any bean.
>>
>> Properties:
>> *- ObjectProperty<T> valueProperty()
>> * The value property holds the currently displayed (selected) value
>> *
>> - ObjectProperty<Boolean> cyclicProperty()
>> * Cyclic means that the spinners cycles back to the beginning when the end of the list of values is reached, e.g. december -> next -> januari, or vice versa (januari -> previous -> december).
>>
>> Methods:
>> *- public void decrease()
>> * programatically select the previous value
>> *
>> - public void increase()
>> * programatically select the next value
>>
>> Events
>> *- ObjectProperty<EventHandler<CycleEvent>> onCycleProperty()
>> * OnCycle method gets called when the spinners cycles (see cyclic property).
>>
>> A value change event is not needed, since registering to the value property will take care of that. Detecting a cycle based on value changes is cumbersome, so hence the OnCycle event.
>>
>>
>> Implementation considerations:
>>
>> Since this actually is a list-with-just-one-cell, adopting a cell factory may be a good idea.
>>
>> Even though a spinner is a list-with-just-one-cell, using a list as its data source is restrictive, because lists always have a lower and upper bound. For example, take a spinner that selects a year: the value "year" has no natural lower and upper bound. It could have in certain situations, but as a concept it has not. Therefor I would like to propose the usage of a data provider, in this case a single-value-linear-data-provider. Such a data provider uses a BigInteger to represent the current value and can increment or decrement.
>>
>> Data provide API:
>> - *public BigInteger getPreviousIdx(BigInteger idx);*
>> Calculate the previous index given the provided one, returning null if there is no previous. (Spinner may cycle.)
>>
>> - *public BigInteger getNextIdx(BigInteger idx);*
>> Calculate the next index given the provided one, returning null if there is no next. (Spinner may cycle.)
>>
>> - *public T getValue(BigInteger idx);*
>> Return the value for the specified index, could return null as a valid value
>>
>> - *public BigInteger getIdx(T value);*
>> Return the idx for the specified value, returning null means the value does not exist
>>
>> The DataProvider can be based on an actual list, or on an implementation allowing the endless selection of a year.
>>
>> A initial (but fully working) implementation can be found at http://code.google.com/p/jfxtras/source/browse/controls/src/main/java/jfxtras/scene/control/SpinnerX.java (screenshot attached to the email).
>>
>> Tom
>>
>>
>>
>
More information about the openjfx-dev
mailing list