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.Property;
19 import javafx.beans.property.ReadOnlyProperty;
20 import javafx.beans.property.ReadOnlyStringProperty;
21 import javafx.beans.property.SimpleStringProperty;
22 import javafx.beans.property.StringProperty;
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 ResetableStringProperty extends AbstractResetableProperty<String> {
32 private StringProperty baseValue;
33 private StringProperty value;
34
35 public ResetableStringProperty() {
36 super(null);
37 }
38
39 public ResetableStringProperty(@Nullable String value) {
40 super(value);
41 }
42
43 public ResetableStringProperty(@Nullable Object bean, @Nonnull String name) {
44 super(bean, name);
45 }
46
47 public ResetableStringProperty(@Nullable Object bean, @Nonnull String name, @Nullable String baseValue) {
48 super(bean, name, baseValue);
49 }
50
51 @Nonnull
52 @Override
53 protected Property<String> writableBaseValueProperty() {
54 return writableBaseValueStringProperty();
55 }
56
57 @Nonnull
58 protected StringProperty writableBaseValueStringProperty() {
59 if (baseValue == null) {
60 baseValue = new SimpleStringProperty(this, "baseValue");
61 }
62 return baseValue;
63 }
64
65 @Nonnull
66 @Override
67 public ReadOnlyProperty<String> baseValueProperty() {
68 return writableBaseValueProperty();
69 }
70
71 @Nonnull
72 public ReadOnlyStringProperty baseValueStringProperty() {
73 return writableBaseValueStringProperty();
74 }
75
76 @Nonnull
77 @Override
78 public Property<String> valueProperty() {
79 return valueStringProperty();
80 }
81
82 @Nonnull
83 public StringProperty valueStringProperty() {
84 if (value == null) {
85 value = new SimpleStringProperty(this, "value");
86 }
87 return value;
88 }
89 }
|