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; 027 028 029/** 030 * An {@code Observable} is an entity that wraps content and allows to 031 * observe the content for invalidations. 032 * <p> 033 * An implementation of {@code Observable} may support lazy evaluation, 034 * which means that the content is not immediately recomputed after changes, but 035 * lazily the next time it is requested. All bindings and properties in 036 * this library support lazy evaluation. 037 * <p> 038 * Implementations of this class should strive to generate as few events as 039 * possible to avoid wasting too much time in event handlers. Implementations in 040 * this library mark themselves as invalid when the first invalidation event 041 * occurs. They do not generate anymore invalidation events until their value is 042 * recomputed and valid again. 043 * 044 * @see javafx.beans.value.ObservableValue 045 * @see javafx.collections.ObservableList 046 * @see javafx.collections.ObservableMap 047 * 048 * 049 */ 050public interface Observable { 051 052 /** 053 * Adds an {@link InvalidationListener} which will be notified whenever the 054 * {@code Observable} becomes invalid. If the same 055 * listener is added more than once, then it will be notified more than 056 * once. That is, no check is made to ensure uniqueness. 057 * <p> 058 * Note that the same actual {@code InvalidationListener} instance may be 059 * safely registered for different {@code Observables}. 060 * <p> 061 * The {@code Observable} stores a strong reference to the listener 062 * which will prevent the listener from being garbage collected and may 063 * result in a memory leak. It is recommended to either unregister a 064 * listener by calling {@link #removeListener(InvalidationListener) 065 * removeListener} after use or to use an instance of 066 * {@link WeakInvalidationListener} avoid this situation. 067 * 068 * @see #removeListener(InvalidationListener) 069 * 070 * @param listener 071 * The listener to register 072 * @throws NullPointerException 073 * if the listener is null 074 */ 075 void addListener(InvalidationListener listener); 076 077 /** 078 * Removes the given listener from the list of listeners, that are notified 079 * whenever the value of the {@code Observable} becomes invalid. 080 * <p> 081 * If the given listener has not been previously registered (i.e. it was 082 * never added) then this method call is a no-op. If it had been previously 083 * added then it will be removed. If it had been added more than once, then 084 * only the first occurrence will be removed. 085 * 086 * @see #addListener(InvalidationListener) 087 * 088 * @param listener 089 * The listener to remove 090 * @throws NullPointerException 091 * if the listener is null 092 */ 093 void removeListener(InvalidationListener listener); 094 095}