Skip to content

Commit

Permalink
Fixed selection bug overwriting settigns
Browse files Browse the repository at this point in the history
  • Loading branch information
breiler committed May 24, 2024
1 parent f6ad4fc commit 37a5383
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ This file is part of Universal Gcode Sender (UGS).
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicBoolean;


/**
Expand All @@ -51,8 +52,8 @@ This file is part of Universal Gcode Sender (UGS).
*/
public class FieldEventDispatcher {
private final Set<FieldEventListener> listeners = ConcurrentHashMap.newKeySet();

private final EnumMap<EntitySetting, JComponent> componentsMap = new EnumMap<>(EntitySetting.class);
private AtomicBoolean enabled = new AtomicBoolean(false);

/**
* Installs a listener to receive notification when the text of any
Expand Down Expand Up @@ -151,7 +152,9 @@ private void valueUpdated(PropertyChangeEvent propertyChangeEvent) {


public void updateValue(EntitySetting entitySetting, Object object) {
listeners.forEach(l -> l.onFieldUpdate(entitySetting, object));
if (this.enabled.get()) {
listeners.forEach(l -> l.onFieldUpdate(entitySetting, object));
}
}

public void addListener(FieldEventListener listener) {
Expand All @@ -162,4 +165,8 @@ public void registerListener(EntitySetting entitySetting, JSlider slider) {
componentsMap.put(entitySetting, slider);
slider.addChangeListener(l -> updateValue(entitySetting, slider.getValue()));
}

public void setEnabled(boolean enabled) {
this.enabled.set(enabled);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,10 @@ public void setEnabled(boolean enabled) {

@Override
public void onSelectionEvent(SelectionEvent selectionEvent) {
// Temporarily disable the field event dispatcher so that it won't triggers updates on select
fieldEventDispatcher.setEnabled(false);
onEvent(new EntityEvent(controller.getSelectionManager(), EventType.SELECTED));
fieldEventDispatcher.setEnabled(true);
}

@Override
Expand Down

0 comments on commit 37a5383

Please sign in to comment.