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.WritableStringValue;
031import javafx.util.StringConverter;
032
033import java.text.Format;
034
035/**
036 * This class provides a full implementation of a {@link Property} wrapping a
037 * {@code String} value.
038 * 
039 * The value of a {@code StringProperty} can be get and set with {@link #get()},
040 * {@link #getValue()}, {@link #set(Object)}, and {@link #setValue(String)}.
041 * 
042 * A property can be bound and unbound unidirectional with
043 * {@link #bind(ObservableValue)} and {@link #unbind()}. Bidirectional bindings
044 * can be created and removed with {@link #bindBidirectional(Property)} and
045 * {@link #unbindBidirectional(Property)}.
046 * 
047 * The context of a {@code StringProperty} can be read with {@link #getBean()}
048 * and {@link #getName()}.
049 * 
050 * @see javafx.beans.value.ObservableStringValue
051 * @see javafx.beans.value.WritableStringValue
052 * @see ReadOnlyStringProperty
053 * @see Property
054 * 
055 */
056public abstract class StringProperty extends ReadOnlyStringProperty implements
057        Property<String>, WritableStringValue {
058
059    /**
060     * {@inheritDoc}
061     */
062    @Override
063    public void setValue(String v) {
064        set(v);
065    }
066
067    /**
068     * {@inheritDoc}
069     */
070    @Override
071    public void bindBidirectional(Property<String> other) {
072        Bindings.bindBidirectional(this, other);
073    }
074
075    /**
076     * Create a bidirectional binding between this {@code StringProperty} and another
077     * arbitrary property. Relies on an implementation of {@code Format} for conversion.
078     *
079     * @param other
080     *            the other {@code Property}
081     * @param format
082     *            the {@code Format} used to convert between this {@code StringProperty}
083     *            and the other {@code Property}
084     * @throws NullPointerException
085     *             if {@code other} or {@code format} is {@code null}
086     * @throws IllegalArgumentException
087     *             if {@code other} is {@code this}
088     */
089    public void bindBidirectional(Property<?> other, Format format) {
090        Bindings.bindBidirectional(this, other, format);
091    }
092
093    /**
094     * Create a bidirectional binding between this {@code StringProperty} and another
095     * arbitrary property. Relies on an implementation of {@link StringConverter} for conversion.
096     *
097     * @param other
098     *            the other {@code Property}
099     * @param converter
100     *            the {@code StringConverter} used to convert between this {@code StringProperty}
101     *            and the other {@code Property}
102     * @throws NullPointerException
103     *             if {@code other} or {@code converter} is {@code null}
104     * @throws IllegalArgumentException
105     *             if {@code other} is {@code this}
106     */
107    public <T> void bindBidirectional(Property<T> other, StringConverter<T> converter) {
108        Bindings.bindBidirectional(this, other, converter);
109    }
110
111    /**
112     * {@inheritDoc}
113     */
114    @Override
115    public void unbindBidirectional(Property<String> other) {
116        Bindings.unbindBidirectional(this, other);
117    }
118
119    /**
120     * Remove a bidirectional binding between this {@code Property} and another
121     * one.
122     *
123     * If no bidirectional binding between the properties exists, calling this
124     * method has no effect.
125     *
126     * @param other
127     *            the other {@code Property}
128     * @throws NullPointerException
129     *             if {@code other} is {@code null}
130     * @throws IllegalArgumentException
131     *             if {@code other} is {@code this}
132     */
133    public void unbindBidirectional(Object other) {
134        Bindings.unbindBidirectional(this, other);
135    }
136
137    /**
138     * Returns a string representation of this {@code StringProperty} object.
139     * @return a string representation of this {@code StringProperty} object.
140     */ 
141    @Override
142    public String toString() {
143        final Object bean = getBean();
144        final String name = getName();
145        final StringBuilder result = new StringBuilder(
146                "StringProperty [");
147        if (bean != null) {
148            result.append("bean: ").append(bean).append(", ");
149        }
150        if ((name != null) && (!name.equals(""))) {
151            result.append("name: ").append(name).append(", ");
152        }
153        result.append("value: ").append(get()).append("]");
154        return result.toString();
155    }
156}