Fixed "concurrent modification exception" if input value dialog is opened.

This commit is contained in:
hneemann 2017-11-18 14:45:24 +01:00
parent e65635ef0e
commit 916e86403e
3 changed files with 17 additions and 3 deletions

View File

@ -15,6 +15,7 @@ HEAD, planned as v0.16
- It was not possible to use constants with 32 bits or more. Now it is.
- Fixed a bug that caused the exported VHDL code not to work if a signal was connected
to multiple outputs.
- Fixed "concurrent modification exception" if input value dialog is opened.
v0.15, released on 30. Oct 2017
- Added the possibility to use custom, java implemented components in Digital.

View File

@ -1,5 +1,6 @@
package de.neemann.digital.draw.shapes;
import de.neemann.digital.core.Model;
import de.neemann.digital.core.ObservableValue;
import de.neemann.digital.core.Observer;
import de.neemann.digital.core.element.Element;
@ -74,8 +75,8 @@ public class InputShape implements Shape {
return true;
} else {
if (dialog == null) {
dialog = new SingleValueDialog(pos, label, value, cc, modelSync);
((In) element).getModel().addObserver(dialog);
Model model = ((In) element).getModel();
dialog = new SingleValueDialog(pos, label, value, cc, model, modelSync);
}
dialog.setVisible(true);
return false;

View File

@ -1,5 +1,6 @@
package de.neemann.digital.gui.components;
import de.neemann.digital.core.Model;
import de.neemann.digital.core.ModelEvent;
import de.neemann.digital.core.ModelStateObserver;
import de.neemann.digital.core.ObservableValue;
@ -13,6 +14,8 @@ import javax.swing.event.DocumentListener;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.Arrays;
/**
@ -71,9 +74,10 @@ public final class SingleValueDialog extends JDialog implements ModelStateObserv
* @param label the name of the value
* @param value the value to edit
* @param circuitComponent the component which contains the circuit
* @param model the model
* @param modelSync used to access the running model
*/
public SingleValueDialog(Point pos, String label, ObservableValue value, CircuitComponent circuitComponent, Sync modelSync) {
public SingleValueDialog(Point pos, String label, ObservableValue value, CircuitComponent circuitComponent, Model model, Sync modelSync) {
super((Frame) null, Lang.get("win_valueInputTitle_N", label), false);
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
this.value = value;
@ -93,6 +97,14 @@ public final class SingleValueDialog extends JDialog implements ModelStateObserv
setLongToDialog(editValue);
});
modelSync.access(() -> model.addObserver(this));
addWindowListener(new WindowAdapter() {
@Override
public void windowClosed(WindowEvent windowEvent) {
modelSync.access(() -> model.removeObserver(SingleValueDialog.this));
}
});
JPanel panel = new JPanel(new GridBagLayout());
ConstraintsBuilder constr = new ConstraintsBuilder().inset(3).fill();
panel.add(formatComboBox, constr);