1 /* 2 * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 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} 48 * 49 * @param initialValue 50 * the initial value of the wrapped value 51 */ 52 public ReadOnlyDoubleWrapper(double initialValue) { 53 super(initialValue); 54 } 55 56 /** 57 * The constructor of {@code ReadOnlyDoubleWrapper} 58 * 59 * @param bean 60 * the bean of this {@code ReadOnlyDoubleProperty} 61 * @param name 62 * the name of this {@code ReadOnlyDoubleProperty} 63 */ 64 public ReadOnlyDoubleWrapper(Object bean, String name) { 65 super(bean, name); 66 } 67 68 /** 69 * The constructor of {@code ReadOnlyDoubleWrapper} 70 * 71 * @param bean 72 * the bean of this {@code ReadOnlyDoubleProperty} 73 * @param name 74 * the name of this {@code ReadOnlyDoubleProperty} 75 * @param initialValue 76 * the initial value of the wrapped value 77 */ 78 public ReadOnlyDoubleWrapper(Object bean, String name, 79 double initialValue) { 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(); 122 } 123 }; 124 }