[fixes #358] Ignore component changes for configListeners
Otherwise, after every change, the fireComponentChanged would be called for every listener, as well as the current component. This was very inefficient...
This commit is contained in:
parent
9324d2a7ed
commit
117c0c76ca
@ -121,6 +121,9 @@ public abstract class RocketComponent implements ChangeSource, Cloneable, Iterab
|
|||||||
|
|
||||||
// The realistic appearance of this component
|
// The realistic appearance of this component
|
||||||
private Appearance appearance = null;
|
private Appearance appearance = null;
|
||||||
|
|
||||||
|
// If true, component change events will not be fired
|
||||||
|
private boolean ignoreComponentChange = false;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1832,7 +1835,7 @@ public abstract class RocketComponent implements ChangeSource, Cloneable, Iterab
|
|||||||
*/
|
*/
|
||||||
protected void fireComponentChangeEvent(ComponentChangeEvent e) {
|
protected void fireComponentChangeEvent(ComponentChangeEvent e) {
|
||||||
checkState();
|
checkState();
|
||||||
if (parent == null) {
|
if (parent == null || ignoreComponentChange) {
|
||||||
/* Ignore if root invalid. */
|
/* Ignore if root invalid. */
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -1851,6 +1854,14 @@ public abstract class RocketComponent implements ChangeSource, Cloneable, Iterab
|
|||||||
fireComponentChangeEvent(new ComponentChangeEvent(this, type));
|
fireComponentChangeEvent(new ComponentChangeEvent(this, type));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setIgnoreComponentChange(boolean newValue) {
|
||||||
|
this.ignoreComponentChange = newValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean getIgnoreComponentChange() {
|
||||||
|
return this.ignoreComponentChange;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a new config listener that will undergo the same configuration changes as this.component. Listener must be
|
* Add a new config listener that will undergo the same configuration changes as this.component. Listener must be
|
||||||
* of the same class as this.component.
|
* of the same class as this.component.
|
||||||
@ -1862,14 +1873,19 @@ public abstract class RocketComponent implements ChangeSource, Cloneable, Iterab
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
configListeners.add(listener);
|
configListeners.add(listener);
|
||||||
|
listener.setIgnoreComponentChange(true);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeConfigListener(RocketComponent listener) {
|
public void removeConfigListener(RocketComponent listener) {
|
||||||
configListeners.remove(listener);
|
configListeners.remove(listener);
|
||||||
|
listener.setIgnoreComponentChange(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clearConfigListeners() {
|
public void clearConfigListeners() {
|
||||||
|
for (RocketComponent listener : configListeners) {
|
||||||
|
listener.setIgnoreComponentChange(false);
|
||||||
|
}
|
||||||
configListeners.clear();
|
configListeners.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user