Spec-Zone .ru
спецификации, руководства, описания, API
|
001/* 002 * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. 003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 004 * 005 * This code is free software; you can redistribute it and/or modify it 006 * under the terms of the GNU General Public License version 2 only, as 007 * published by the Free Software Foundation. Oracle designates this 008 * particular file as subject to the "Classpath" exception as provided 009 * by Oracle in the LICENSE file that accompanied this code. 010 * 011 * This code is distributed in the hope that it will be useful, but WITHOUT 012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 013 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 014 * version 2 for more details (a copy is included in the LICENSE file that 015 * accompanied this code). 016 * 017 * You should have received a copy of the GNU General Public License version 018 * 2 along with this work; if not, write to the Free Software Foundation, 019 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 020 * 021 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 022 * or visit www.oracle.com if you need additional information or have any 023 * questions. 024 */ 025 026package javafx.beans.property; 027 028import javafx.beans.binding.Bindings; 029import javafx.beans.value.ObservableValue; 030import javafx.beans.value.WritableObjectValue; 031 032/** 033 * This class provides a full implementation of a {@link Property} wrapping an 034 * arbitrary {@code Object}. 035 * 036 * The value of a {@code ObjectProperty} can be get and set with {@link #get()}, 037 * {@link #getValue()}, {@link #set(Object)}, and {@link #setValue(Object)}. 038 * 039 * A property can be bound and unbound unidirectional with 040 * {@link #bind(ObservableValue)} and {@link #unbind()}. Bidirectional bindings 041 * can be created and removed with {@link #bindBidirectional(Property)} and 042 * {@link #unbindBidirectional(Property)}. 043 * 044 * The context of a {@code ObjectProperty} can be read with {@link #getBean()} 045 * and {@link #getName()}. 046 * 047 * For specialized implementations for {@link ObservableList}, {@link ObservableSet} and 048 * {@link ObservableMap} that also report changes inside the collections, see 049 * {@link ListProperty}, {@link SetProperty} and {@link MapProperty}, respectively. 050 * 051 * @see javafx.beans.value.ObservableObjectValue 052 * @see javafx.beans.value.WritableObjectValue 053 * @see ReadOnlyObjectProperty 054 * @see Property 055 * 056 * 057 * @param <T> 058 * the type of the wrapped {@code Object} 059 */ 060public abstract class ObjectProperty<T> extends ReadOnlyObjectProperty<T> 061 implements Property<T>, WritableObjectValue<T> { 062 063 /** 064 * {@inheritDoc} 065 */ 066 @Override 067 public void setValue(T v) { 068 set(v); 069 } 070 071 /** 072 * {@inheritDoc} 073 */ 074 @Override 075 public void bindBidirectional(Property<T> other) { 076 Bindings.bindBidirectional(this, other); 077 } 078 079 /** 080 * {@inheritDoc} 081 */ 082 @Override 083 public void unbindBidirectional(Property<T> other) { 084 Bindings.unbindBidirectional(this, other); 085 } 086 087 /** 088 * Returns a string representation of this {@code ObjectProperty} object. 089 * @return a string representation of this {@code ObjectProperty} object. 090 */ 091 @Override 092 public String toString() { 093 final Object bean = getBean(); 094 final String name = getName(); 095 final StringBuilder result = new StringBuilder( 096 "ObjectProperty ["); 097 if (bean != null) { 098 result.append("bean: ").append(bean).append(", "); 099 } 100 if ((name != null) && (!name.equals(""))) { 101 result.append("name: ").append(name).append(", "); 102 } 103 result.append("value: ").append(get()).append("]"); 104 return result.toString(); 105 } 106}