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 import javafx.beans.binding.Bindings; 29 import javafx.beans.value.ObservableValue; 30 import javafx.beans.value.WritableObjectValue; 31 32 /** 33 * This class provides a full implementation of a {@link Property} wrapping an 34 * arbitrary {@code Object}. 35 * 36 * The value of a {@code ObjectProperty} can be get and set with {@link #get()}, 37 * {@link #getValue()}, {@link #set(Object)}, and {@link #setValue(Object)}. 38 * 39 * A property can be bound and unbound unidirectional with 40 * {@link #bind(ObservableValue)} and {@link #unbind()}. Bidirectional bindings 41 * can be created and removed with {@link #bindBidirectional(Property)} and 42 * {@link #unbindBidirectional(Property)}. 43 * 44 * The context of a {@code ObjectProperty} can be read with {@link #getBean()} 45 * and {@link #getName()}. 46 * 47 * For specialized implementations for {@link ObservableList}, {@link ObservableSet} and 48 * {@link ObservableMap} that also report changes inside the collections, see 49 * {@link ListProperty}, {@link SetProperty} and {@link MapProperty}, respectively. 50 * 51 * @see javafx.beans.value.ObservableObjectValue 52 * @see javafx.beans.value.WritableObjectValue 53 * @see ReadOnlyObjectProperty 54 * @see Property 55 * 56 * 57 * @param <T> 58 * the type of the wrapped {@code Object} 59 * @since JavaFX 2.0 60 */ 61 public abstract class ObjectProperty<T> extends ReadOnlyObjectProperty<T> 62 implements Property<T>, WritableObjectValue<T> { 63 64 /** 65 * {@inheritDoc} 66 */ 67 @Override 68 public void setValue(T v) { 69 set(v); 70 } 71 72 /** 73 * {@inheritDoc} 74 */ 75 @Override 76 public void bindBidirectional(Property<T> other) { 77 Bindings.bindBidirectional(this, other); 78 } 79 80 /** 81 * {@inheritDoc} 82 */ 83 @Override 84 public void unbindBidirectional(Property<T> other) { 85 Bindings.unbindBidirectional(this, other); 86 } 87 88 /** 89 * Returns a string representation of this {@code ObjectProperty} object. 90 * @return a string representation of this {@code ObjectProperty} object. 91 */ 92 @Override 93 public String toString() { 94 final Object bean = getBean(); 95 final String name = getName(); 96 final StringBuilder result = new StringBuilder( 97 "ObjectProperty ["); 98 if (bean != null) { 99 result.append("bean: ").append(bean).append(", "); 100 } 101 if ((name != null) && (!name.equals(""))) { 102 result.append("name: ").append(name).append(", "); 103 } 104 result.append("value: ").append(get()).append("]"); 105 return result.toString(); 106 } 107 }