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.WritableMapValue; 030import javafx.collections.ObservableMap; 031 032/** 033 * This class provides a full implementation of a {@link Property} wrapping a 034 * {@link javafx.collections.ObservableMap}. 035 * 036 * The value of a {@code MapProperty} can be get and set with {@link #get()}, 037 * {@link #getValue()}, {@link #set(Object)}, and {@link #setValue(javafx.collections.ObservableMap)}. 038 * 039 * A property can be bound and unbound unidirectional with 040 * {@link #bind(javafx.beans.value.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 MapProperty} can be read with {@link #getBean()} 045 * and {@link #getName()}. 046 * 047 * @see javafx.collections.ObservableMap 048 * @see javafx.beans.value.ObservableMapValue 049 * @see javafx.beans.value.WritableMapValue 050 * @see ReadOnlyMapProperty 051 * @see Property 052 * 053 * @param <K> the type of the key elements of the {@code Map} 054 * @param <V> the type of the value elements of the {@code Map} 055 */ 056public abstract class MapProperty<K, V> extends ReadOnlyMapProperty<K, V> implements 057 Property<ObservableMap<K, V>>, WritableMapValue<K, V> { 058 /** 059 * {@inheritDoc} 060 */ 061 @Override 062 public void setValue(ObservableMap<K, V> v) { 063 set(v); 064 } 065 066 /** 067 * {@inheritDoc} 068 */ 069 @Override 070 public void bindBidirectional(Property<ObservableMap<K, V>> other) { 071 Bindings.bindBidirectional(this, other); 072 } 073 074 /** 075 * {@inheritDoc} 076 */ 077 @Override 078 public void unbindBidirectional(Property<ObservableMap<K, V>> other) { 079 Bindings.unbindBidirectional(this, other); 080 } 081 082 /** 083 * Returns a string representation of this {@code MapProperty} object. 084 * @return a string representation of this {@code MapProperty} object. 085 */ 086 @Override 087 public String toString() { 088 final Object bean = getBean(); 089 final String name = getName(); 090 final StringBuilder result = new StringBuilder( 091 "MapProperty ["); 092 if (bean != null) { 093 result.append("bean: ").append(bean).append(", "); 094 } 095 if ((name != null) && (!name.equals(""))) { 096 result.append("name: ").append(name).append(", "); 097 } 098 result.append("value: ").append(get()).append("]"); 099 return result.toString(); 100 } 101}