-
Notifications
You must be signed in to change notification settings - Fork 68
/
Spinner.scala
209 lines (183 loc) · 9.16 KB
/
Spinner.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
/*
* Copyright (c) 2011-2014, ScalaFX Project
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the ScalaFX Project nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE SCALAFX PROJECT OR ITS CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package scalafx.scene.control
import javafx.scene.{control => jfxsc}
import scala.language.implicitConversions
import scalafx.Includes._
import scalafx.beans.property.{BooleanProperty, ObjectProperty, ReadOnlyObjectProperty}
import scalafx.collections.ObservableBuffer
import scalafx.delegate.SFXDelegate
object Spinner {
implicit def sfxSpinner2jfx[T](v: Spinner[T]): jfxsc.Spinner[T] = if (v != null) v.delegate else null
/** The arrows are placed on the right of the Spinner, pointing horizontally (i.e. left and right). */
val StyleClassArrowsOnRightHorizontal = jfxsc.Spinner.STYLE_CLASS_ARROWS_ON_RIGHT_HORIZONTAL
/** The arrows are placed on the left of the Spinner, pointing vertically (i.e. up and down). */
val StyleClassArrowsOnLeftVertical = jfxsc.Spinner.STYLE_CLASS_ARROWS_ON_LEFT_VERTICAL
/** The arrows are placed on the left of the Spinner, pointing horizontally (i.e. left and right). */
val StyleClassArrowsOnLeftHorizontal = jfxsc.Spinner.STYLE_CLASS_ARROWS_ON_LEFT_HORIZONTAL
/** The arrows are placed above and beneath the spinner, stretching to take the entire width. */
val StyleClassSplitArrowsVertical = jfxsc.Spinner.STYLE_CLASS_SPLIT_ARROWS_VERTICAL
/** The decrement arrow is placed on the left of the Spinner, and the increment on the right. */
val StyleClassSplitArrowsHorizontal = jfxsc.Spinner.STYLE_CLASS_SPLIT_ARROWS_HORIZONTAL
}
/**
* A single line text field that lets the user select a number or an object
* value from an ordered sequence.
*
* Wraps a $JFX [[http://docs.oracle.com/javase/8/javafx/api/javafx/scene/control/Spinner.html]].
*
* @constructor Constructs a default Spinner instance, with the default 'spinner' style class and a non-editable editor.
* @param delegate A JavaFX Spinner to be wrapped. Its default value is a new JavaFX Spinner.
* @tparam T The type of all values that can be iterated through in the Spinner. Common types include Integer and String.
*
*/
class Spinner[T](override val delegate: jfxsc.Spinner[T] = new jfxsc.Spinner[T])
extends Control(delegate)
with SFXDelegate[jfxsc.Spinner[T]] {
/**
* Creates a Spinner instance with the value factory set to be an instance
* of `IntegerSpinnerValueFactory`. Note that
* if this constructor is called, the only valid generic type for the
* Spinner instance is Integer, i.e. Spinner[Integer].
*
* @param min The minimum allowed integer value for the Spinner.
* @param max The maximum allowed integer value for the Spinner.
* @param initialValue The value of the Spinner when first instantiated, must
* be within the bounds of the min and max arguments, or
* else the min value will be used.
*/
def this(min: Int, max: Int, initialValue: Int) {
this(new jfxsc.Spinner[T](min, max, initialValue))
}
/**
* Creates a Spinner instance with the value factory set to be an instance
* of `IntegerSpinnerValueFactory`. Note that
* if this constructor is called, the only valid generic type for the
* Spinner instance is Integer, i.e. Spinner[Integer].
*
* @param min The minimum allowed integer value for the Spinner.
* @param max The maximum allowed integer value for the Spinner.
* @param initialValue The value of the Spinner when first instantiated, must
* be within the bounds of the min and max arguments, or
* else the min value will be used.
* @param amountToStepBy The amount to increment or decrement by, per step.
*/
def this(min: Int, max: Int, initialValue: Int, amountToStepBy: Int) {
this(new jfxsc.Spinner[T](min, max, initialValue, amountToStepBy))
}
/**
* Creates a Spinner instance with the value factory set to be an instance
* of `DoubleSpinnerValueFactory`. Note that
* if this constructor is called, the only valid generic type for the
* Spinner instance is Double, i.e. Spinner[Double].
*
* @param min The minimum allowed double value for the Spinner.
* @param max The maximum allowed double value for the Spinner.
* @param initialValue The value of the Spinner when first instantiated, must
* be within the bounds of the min and max arguments, or
* else the min value will be used.
*/
def this(min: Double, max: Double, initialValue: Double) {
this(new jfxsc.Spinner[T](min, max, initialValue))
}
/**
* Creates a Spinner instance with the value factory set to be an instance
* of `DoubleSpinnerValueFactory`. Note that
* if this constructor is called, the only valid generic type for the
* Spinner instance is Double, i.e. Spinner[Double].
*
* @param min The minimum allowed double value for the Spinner.
* @param max The maximum allowed double value for the Spinner.
* @param initialValue The value of the Spinner when first instantiated, must
* be within the bounds of the min and max arguments, or
* else the min value will be used.
* @param amountToStepBy The amount to increment or decrement by, per step.
*/
def this(min: Double, max: Double, initialValue: Double, amountToStepBy: Double) {
this(new jfxsc.Spinner[T](min, max, initialValue, amountToStepBy))
}
/**
* Creates a Spinner instance with the value factory set to be an instance
* of `ListSpinnerValueFactory`. The
* Spinner `value` property will be set to the first
* element of the list, if an element exists, or null otherwise.
*
* @param items A list of items that will be stepped through in the Spinner.
*/
def this(items: ObservableBuffer[T]) {
this(new jfxsc.Spinner[T](items))
}
/**
* Creates a Spinner instance with the given value factory set.
*
* @param valueFactory The value factory to use.
*/
def this(valueFactory: SpinnerValueFactory[T]) {
this(new jfxsc.Spinner[T](valueFactory.delegate))
}
/**
* The value property on Spinner is a read-only property, as it is bound to
* the SpinnerValueFactoryvalue property. Should the
* value factory change, this value property
* will be unbound from the old value factory and bound to the new one.
*
* <p>If developers wish to modify the value property, they may do so with
* code in the following form:
*
* {{{
* val newValue = ...;
* spinner.valueFactory().value = newValue
* }}}
*/
def value: ReadOnlyObjectProperty[T] = delegate.valueProperty()
/**
* The value factory is the model behind the JavaFX Spinner control - without
* a value factory installed a Spinner is unusable. It is the role of the
* value factory to handle almost all aspects of the Spinner.
*
*/
def valueFactory: ObjectProperty[jfxsc.SpinnerValueFactory[T]] = delegate.valueFactoryProperty()
def valueFactory_=(value: SpinnerValueFactory[T]) {
valueFactory() = value
}
/**
* The editable property is used to specify whether user input is able to
* be typed into the Spinner `editor`. If editable
* is true, user input will be received once the user types and presses
* the Enter key. At this point the input is passed to the
* SpinnerValueFactory `converter` StringConverter#fromString(String) method.
* The returned value from this call (of type T) is then sent to the
* `SpinnerValueFactory#setValue(Object)` method. If the value
* is valid, it will remain as the value. If it is invalid, the value factory
* will need to react accordingly and back out this change.
*/
def editable: BooleanProperty = delegate.editableProperty()
def editable_=(value: Boolean): Unit = {
editable() = value
}
def editor: ReadOnlyObjectProperty[jfxsc.TextField] = delegate.editorProperty()
}