fix: check if property is bound before setting value of ReadWriteComposedProperty

This commit is contained in:
Haowei Wen
2021-09-01 16:41:07 +08:00
parent 832c029db6
commit e428cc7117

View File

@@ -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());
} }