UIThreadAwareBooleanBinding.java
01 /*
02  * SPDX-License-Identifier: Apache-2.0
03  *
04  * Copyright 2008-2017 the original author or authors.
05  *
06  * Licensed under the Apache License, Version 2.0 (the "License");
07  * you may not use this file except in compliance with the License.
08  * You may obtain a copy of the License at
09  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 package griffon.javafx.beans.binding;
19 
20 import javafx.beans.InvalidationListener;
21 import javafx.beans.binding.BooleanBinding;
22 import javafx.beans.value.ChangeListener;
23 
24 import javax.annotation.Nonnull;
25 
26 /**
27  @author Andres Almiray
28  @since 2.13.0
29  */
30 class UIThreadAwareBooleanBinding extends BooleanBindingDecorator implements UIThreadAware {
31     UIThreadAwareBooleanBinding(@Nonnull BooleanBinding delegate) {
32         super(delegate);
33     }
34 
35     @Override
36     public void addListener(ChangeListener<? super Boolean> listener) {
37         if (listener instanceof UIThreadAware) {
38             getDelegate().addListener(listener);
39         else {
40             getDelegate().addListener(new UIThreadAwareChangeListener<>(listener));
41         }
42     }
43 
44     @Override
45     public void removeListener(ChangeListener<? super Boolean> listener) {
46         if (listener instanceof UIThreadAware) {
47             getDelegate().removeListener(listener);
48         else {
49             getDelegate().removeListener(new UIThreadAwareChangeListener<>(listener));
50         }
51     }
52 
53     @Override
54     public void addListener(InvalidationListener listener) {
55         if (listener instanceof UIThreadAware) {
56             getDelegate().addListener(listener);
57         else {
58             getDelegate().addListener(new UIThreadAwareInvalidationListener(listener));
59         }
60     }
61 
62     @Override
63     public void removeListener(InvalidationListener listener) {
64         if (listener instanceof UIThreadAware) {
65             getDelegate().removeListener(listener);
66         else {
67             getDelegate().removeListener(new UIThreadAwareInvalidationListener(listener));
68         }
69     }
70 }