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