8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package javafx.beans.property;
27
28 import javafx.beans.InvalidationListener;
29 import javafx.beans.value.ChangeListener;
30
31 /**
32 * This class provides a convenient class to define read-only properties. It
33 * creates two properties that are synchronized. One property is read-only
34 * and can be passed to external users. The other property is read- and
35 * writable and should be used internally only.
36 *
37 * @since JavaFX 2.0
38 */
39 public class ReadOnlyDoubleWrapper extends SimpleDoubleProperty {
40
41 private ReadOnlyPropertyImpl readOnlyProperty;
42
43 /**
44 * The constructor of {@code ReadOnlyDoubleWrapper}
45 */
46 public ReadOnlyDoubleWrapper() {
47 }
48
49 /**
50 * The constructor of {@code ReadOnlyDoubleWrapper}
83 super(bean, name, initialValue);
84 }
85
86 /**
87 * Returns the read-only property, that is synchronized with this
88 * {@code ReadOnlyDoubleWrapper}.
89 *
90 * @return the read-only property
91 */
92 public ReadOnlyDoubleProperty getReadOnlyProperty() {
93 if (readOnlyProperty == null) {
94 readOnlyProperty = new ReadOnlyPropertyImpl();
95 }
96 return readOnlyProperty;
97 }
98
99 /**
100 * {@inheritDoc}
101 */
102 @Override
103 public void addListener(InvalidationListener listener) {
104 getReadOnlyProperty().addListener(listener);
105 }
106
107 /**
108 * {@inheritDoc}
109 */
110 @Override
111 public void removeListener(InvalidationListener listener) {
112 if (readOnlyProperty != null) {
113 readOnlyProperty.removeListener(listener);
114 }
115 }
116
117 /**
118 * {@inheritDoc}
119 */
120 @Override
121 public void addListener(ChangeListener<? super Number> listener) {
122 getReadOnlyProperty().addListener(listener);
123 }
124
125 /**
126 * {@inheritDoc}
127 */
128 @Override
129 public void removeListener(ChangeListener<? super Number> listener) {
130 if (readOnlyProperty != null) {
131 readOnlyProperty.removeListener(listener);
132 }
133 }
134
135 /**
136 * {@inheritDoc}
137 */
138 @Override
139 protected void fireValueChangedEvent() {
140 if (readOnlyProperty != null) {
141 readOnlyProperty.fireValueChangedEvent();
142 }
143 }
144
145 private class ReadOnlyPropertyImpl extends ReadOnlyDoublePropertyBase {
146
147 @Override
148 public double get() {
149 return ReadOnlyDoubleWrapper.this.get();
150 }
151
152 @Override
153 public Object getBean() {
154 return ReadOnlyDoubleWrapper.this.getBean();
155 }
156
157 @Override
158 public String getName() {
159 return ReadOnlyDoubleWrapper.this.getName();
|
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package javafx.beans.property;
27
28 /**
29 * This class provides a convenient class to define read-only properties. It
30 * creates two properties that are synchronized. One property is read-only
31 * and can be passed to external users. The other property is read- and
32 * writable and should be used internally only.
33 *
34 * @since JavaFX 2.0
35 */
36 public class ReadOnlyDoubleWrapper extends SimpleDoubleProperty {
37
38 private ReadOnlyPropertyImpl readOnlyProperty;
39
40 /**
41 * The constructor of {@code ReadOnlyDoubleWrapper}
42 */
43 public ReadOnlyDoubleWrapper() {
44 }
45
46 /**
47 * The constructor of {@code ReadOnlyDoubleWrapper}
80 super(bean, name, initialValue);
81 }
82
83 /**
84 * Returns the read-only property, that is synchronized with this
85 * {@code ReadOnlyDoubleWrapper}.
86 *
87 * @return the read-only property
88 */
89 public ReadOnlyDoubleProperty getReadOnlyProperty() {
90 if (readOnlyProperty == null) {
91 readOnlyProperty = new ReadOnlyPropertyImpl();
92 }
93 return readOnlyProperty;
94 }
95
96 /**
97 * {@inheritDoc}
98 */
99 @Override
100 protected void fireValueChangedEvent() {
101 super.fireValueChangedEvent();
102 if (readOnlyProperty != null) {
103 readOnlyProperty.fireValueChangedEvent();
104 }
105 }
106
107 private class ReadOnlyPropertyImpl extends ReadOnlyDoublePropertyBase {
108
109 @Override
110 public double get() {
111 return ReadOnlyDoubleWrapper.this.get();
112 }
113
114 @Override
115 public Object getBean() {
116 return ReadOnlyDoubleWrapper.this.getBean();
117 }
118
119 @Override
120 public String getName() {
121 return ReadOnlyDoubleWrapper.this.getName();
|