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.WritableMapValue; 30 import javafx.collections.ObservableMap; 31 32 /** 33 * This class provides a full implementation of a {@link Property} wrapping an 34 * {@link javafx.collections.ObservableMap}. 35 * 36 * The value of a {@code MapProperty} can be get and set with {@link #get()}, 37 * {@link #getValue()}, {@link #set(Object)}, and {@link #setValue(javafx.collections.ObservableMap)}. 38 * 39 * A property can be bound and unbound unidirectional with 40 * {@link #bind(javafx.beans.value.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 MapProperty} can be read with {@link #getBean()} 45 * and {@link #getName()}. 46 * 47 * @see javafx.collections.ObservableMap 48 * @see javafx.beans.value.ObservableMapValue 49 * @see javafx.beans.value.WritableMapValue 50 * @see ReadOnlyMapProperty 51 * @see Property 52 * 53 * @param <K> the type of the key elements of the {@code Map} 54 * @param <V> the type of the value elements of the {@code Map} 55 * @since JavaFX 2.1 56 */ 57 public abstract class MapProperty<K, V> extends ReadOnlyMapProperty<K, V> implements 58 Property<ObservableMap<K, V>>, WritableMapValue<K, V> { 59 /** 60 * {@inheritDoc} 61 */ 62 @Override 63 public void setValue(ObservableMap<K, V> v) { 64 set(v); 65 } 66 67 /** 68 * {@inheritDoc} 69 */ 70 @Override 71 public void bindBidirectional(Property<ObservableMap<K, V>> other) { 72 Bindings.bindBidirectional(this, other); 73 } 74 75 /** 76 * {@inheritDoc} 77 */ 78 @Override 79 public void unbindBidirectional(Property<ObservableMap<K, V>> other) { 80 Bindings.unbindBidirectional(this, other); 81 } 82 83 /** 84 * Returns a string representation of this {@code MapProperty} object. 85 * @return a string representation of this {@code MapProperty} object. 86 */ 87 @Override 88 public String toString() { 89 final Object bean = getBean(); 90 final String name = getName(); 91 final StringBuilder result = new StringBuilder( 92 "MapProperty ["); 93 if (bean != null) { 94 result.append("bean: ").append(bean).append(", "); 95 } 96 if ((name != null) && (!name.equals(""))) { 97 result.append("name: ").append(name).append(", "); 98 } 99 result.append("value: ").append(get()).append("]"); 100 return result.toString(); 101 } 102 }