ResetableIntegerProperty.java
01 /*
02  * SPDX-License-Identifier: Apache-2.0
03  *
04  * Copyright 2008-2017 the original author or authors.
05  *
06  * Licensed under the Apache License, Version 2.0 (the "License");
07  * you may not use this file except in compliance with the License.
08  * You may obtain a copy of the License at
09  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 package griffon.javafx.beans.property;
19 
20 import javafx.beans.property.IntegerProperty;
21 import javafx.beans.property.Property;
22 import javafx.beans.property.ReadOnlyIntegerProperty;
23 import javafx.beans.property.ReadOnlyProperty;
24 import javafx.beans.property.SimpleIntegerProperty;
25 
26 import javax.annotation.Nonnull;
27 import javax.annotation.Nullable;
28 
29 /**
30  @author Andres Almiray
31  @since 2.10.0
32  */
33 public class ResetableIntegerProperty extends AbstractResetableProperty<Number> {
34     private IntegerProperty baseValue;
35     private IntegerProperty value;
36 
37     public ResetableIntegerProperty() {
38         super(null);
39     }
40 
41     public ResetableIntegerProperty(@Nullable Integer value) {
42         super(value);
43     }
44 
45     public ResetableIntegerProperty(@Nullable Object bean, @Nonnull String name) {
46         super(bean, name);
47     }
48 
49     public ResetableIntegerProperty(@Nullable Object bean, @Nonnull String name, @Nullable Integer baseValue) {
50         super(bean, name, baseValue);
51     }
52 
53     @Nonnull
54     @Override
55     protected Property<Number> writableBaseValueProperty() {
56         return writableBaseValueIntegerProperty();
57     }
58 
59     @Nonnull
60     protected IntegerProperty writableBaseValueIntegerProperty() {
61         if (baseValue == null) {
62             baseValue = new SimpleIntegerProperty(this, "baseValue");
63         }
64         return baseValue;
65     }
66 
67     @Nonnull
68     @Override
69     public ReadOnlyProperty<Number> baseValueProperty() {
70         return writableBaseValueProperty();
71     }
72 
73     @Nonnull
74     public ReadOnlyIntegerProperty baseValueIntegerProperty() {
75         return writableBaseValueIntegerProperty();
76     }
77 
78     @Nonnull
79     @Override
80     public Property<Number> valueProperty() {
81         return valueIntegerProperty();
82     }
83 
84     @Nonnull
85     public IntegerProperty valueIntegerProperty() {
86         if (value == null) {
87             value = new SimpleIntegerProperty(this, "value");
88         }
89         return value;
90     }
91 }