Spec-Zone .ru
спецификации, руководства, описания, API
|
001/* 002 * Copyright (c) 2010, 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.binding; 027 028import javafx.beans.value.ObservableValue; 029import javafx.collections.ObservableList; 030import com.sun.javafx.collections.annotations.ReturnsUnmodifiableCollection; 031 032/** 033 * A {@code Binding} calculates a value that depends on one or more sources. The 034 * sources are usually called the dependency of a binding. A binding observes 035 * its dependencies for changes and updates its value automatically. 036 * <p> 037 * While a dependency of a binding can be anything, it is almost always an 038 * implementation of {@link javafx.beans.value.ObservableValue}. {@code Binding} 039 * implements {@code ObservableValue} allowing to use it in another binding. 040 * With that one can assemble very complex bindings from simple bindings. 041 * <p> 042 * All bindings in the JavaFX 2.0 runtime are calculated lazily. That means, if 043 * a dependency changes, the result of a binding is not immediately 044 * recalculated, but it is marked as invalid. Next time the value of an invalid 045 * binding is requested, it is recalculated. 046 * <p> 047 * It is recommended to use one of the base classes defined in this package 048 * (e.g. {@link DoubleBinding}) to define a custom binding, because these 049 * classes already provide most of the needed functionality. See 050 * {@link DoubleBinding} for an example. 051 * 052 * @see DoubleBinding 053 * 054 * 055 */ 056public interface Binding<T> extends ObservableValue<T> { 057 058 /** 059 * Checks if a binding is valid. 060 * 061 * @return {@code true} if the {@code Binding} is valid, {@code false} 062 * otherwise 063 */ 064 boolean isValid(); 065 066 /** 067 * Mark a binding as invalid. This forces the recalculation of the value of 068 * the {@code Binding} next time it is request. 069 */ 070 void invalidate(); 071 072 /** 073 * Returns the dependencies of a binding in an unmodifiable 074 * {@link javafx.collections.ObservableList}. The implementation is 075 * optional. The main purpose of this method is to support developers during 076 * development. It allows to explore and monitor dependencies of a binding 077 * during runtime. 078 * <p> 079 * Because this method should not be used in production code, it is 080 * recommended to implement this functionality as sparse as possible. For 081 * example if the dependencies do not change, each call can generate a new 082 * {@code ObservableList}, avoiding the necessity to store the result. 083 * 084 * @return an unmodifiable {@code} ObservableList of the dependencies 085 */ 086 @ReturnsUnmodifiableCollection 087 ObservableList<?> getDependencies(); 088 089 /** 090 * Signals to the {@code Binding} that it will not be used anymore and any 091 * references can be removed. A call of this method usually results in the 092 * binding stopping to observe its dependencies by unregistering its 093 * listener(s). The implementation is optional. 094 * <p> 095 * All bindings in our implementation use instances of 096 * {@link javafx.beans.WeakInvalidationListener}, which means usually 097 * a binding does not need to be disposed. But if you plan to use your 098 * application in environments that do not support {@code WeakReferences} 099 * you have to dispose unused {@code Bindings} to avoid memory leaks. 100 */ 101 void dispose(); 102 103}