001 /*
002 * Copyright 2008-2017 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package griffon.javafx.beans.binding;
017
018 import javafx.beans.InvalidationListener;
019 import javafx.beans.property.Property;
020 import javafx.beans.value.ChangeListener;
021 import javafx.beans.value.ObservableValue;
022
023 import javax.annotation.Nonnull;
024
025 import static java.util.Objects.requireNonNull;
026
027 /**
028 * @author Andres Almiray
029 * @since 2.11.0
030 */
031 public class PropertyDecorator<T> implements Property<T> {
032 private final Property<T> delegate;
033
034 public PropertyDecorator(@Nonnull Property<T> delegate) {
035 this.delegate = requireNonNull(delegate, "Argument 'delegate' must not be null");
036 }
037
038 @Nonnull
039 protected final Property<T> getDelegate() {
040 return delegate;
041 }
042
043 @Override
044 public void bind(ObservableValue<? extends T> observable) {
045 delegate.bind(observable);
046 }
047
048 @Override
049 public void unbind() {
050 delegate.unbind();
051 }
052
053 @Override
054 public boolean isBound() {
055 return delegate.isBound();
056 }
057
058 @Override
059 public void bindBidirectional(Property<T> other) {
060 delegate.bindBidirectional(other);
061 }
062
063 @Override
064 public void unbindBidirectional(Property<T> other) {
065 delegate.unbindBidirectional(other);
066 }
067
068 @Override
069 public Object getBean() {
070 return delegate.getBean();
071 }
072
073 @Override
074 public String getName() {
075 return delegate.getName();
076 }
077
078 @Override
079 public void addListener(ChangeListener<? super T> listener) {
080 delegate.addListener(listener);
081 }
082
083 @Override
084 public void removeListener(ChangeListener<? super T> listener) {
085 delegate.removeListener(listener);
086 }
087
088 @Override
089 public T getValue() {
090 return delegate.getValue();
091 }
092
093 @Override
094 public void addListener(InvalidationListener listener) {
095 delegate.addListener(listener);
096 }
097
098 @Override
099 public void removeListener(InvalidationListener listener) {
100 delegate.removeListener(listener);
101 }
102
103 @Override
104 public void setValue(T value) {
105 delegate.setValue(value);
106 }
107
108 @Override
109 public boolean equals(Object o) {
110 return this == o || delegate.equals(o);
111 }
112
113 @Override
114 public int hashCode() {
115 return delegate.hashCode();
116 }
117
118 @Override
119 public String toString() {
120 return getClass().getName() + ":" + delegate.toString();
121 }
122 }
|