fix: check if property is bound before setting value of ReadWriteComposedProperty
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Hello Minecraft! Launcher
|
* Hello Minecraft! Launcher
|
||||||
* Copyright (C) 2020 huangyuhui <huanghongxun2008@126.com> and contributors
|
* Copyright (C) 2021 huangyuhui <huanghongxun2008@126.com> and contributors
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@@ -44,7 +44,11 @@ public class ReadWriteComposedProperty<T> extends SimpleObjectProperty<T> {
|
|||||||
this.readSource = readSource;
|
this.readSource = readSource;
|
||||||
this.writeTarget = writeTarget;
|
this.writeTarget = writeTarget;
|
||||||
|
|
||||||
this.listener = (observable, oldValue, newValue) -> set(newValue);
|
this.listener = (observable, oldValue, newValue) -> {
|
||||||
|
if (!isBound()) {
|
||||||
|
set(newValue);
|
||||||
|
}
|
||||||
|
};
|
||||||
readSource.addListener(new WeakChangeListener<>(listener));
|
readSource.addListener(new WeakChangeListener<>(listener));
|
||||||
set(readSource.getValue());
|
set(readSource.getValue());
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user