fixed a NOSYNC bug.

This commit is contained in:
hneemann 2020-04-09 23:29:37 +02:00
parent 395c3dd47d
commit d3bf273491
3 changed files with 13 additions and 24 deletions

View File

@ -41,7 +41,8 @@ public interface SyncAccess {
@Override @Override
public <A extends Runnable> A read(A run) { public <A extends Runnable> A read(A run) {
return null; run.run();
return run;
} }
}; };

View File

@ -978,10 +978,6 @@ public final class Main extends JFrame implements ClosingWindowListener.ConfirmS
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
try { try {
model.doMicroStep(false); model.doMicroStep(false);
circuitComponent.removeHighLighted();
modelCreator.addNodeElementsTo(model.nodesToUpdate(), circuitComponent.getHighLighted());
circuitComponent.graphicHasChanged();
checkMicroStepActions(model);
} catch (Exception e1) { } catch (Exception e1) {
showErrorAndStopModel(Lang.get("msg_errorCalculatingStep"), e1); showErrorAndStopModel(Lang.get("msg_errorCalculatingStep"), e1);
} }
@ -992,10 +988,6 @@ public final class Main extends JFrame implements ClosingWindowListener.ConfirmS
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
try { try {
model.runToBreakMicro(); model.runToBreakMicro();
circuitComponent.removeHighLighted();
modelCreator.addNodeElementsTo(model.nodesToUpdate(), circuitComponent.getHighLighted());
circuitComponent.graphicHasChanged();
checkMicroStepActions(model);
} catch (Exception e1) { } catch (Exception e1) {
showErrorAndStopModel(Lang.get("msg_errorCalculatingStep"), e1); showErrorAndStopModel(Lang.get("msg_errorCalculatingStep"), e1);
} }
@ -1011,7 +1003,6 @@ public final class Main extends JFrame implements ClosingWindowListener.ConfirmS
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
try { try {
Model.BreakInfo info = model.runToBreak(); Model.BreakInfo info = model.runToBreak();
circuitComponent.graphicHasChanged();
statusLabel.setText(Lang.get("stat_clocks", info.getSteps(), info.getLabel())); statusLabel.setText(Lang.get("stat_clocks", info.getSteps(), info.getLabel()));
} catch (NodeException | RuntimeException e1) { } catch (NodeException | RuntimeException e1) {
showErrorAndStopModel(Lang.get("msg_fastRunError"), e1); showErrorAndStopModel(Lang.get("msg_fastRunError"), e1);
@ -1404,7 +1395,7 @@ public final class Main extends JFrame implements ClosingWindowListener.ConfirmS
modelCreator.connectToGui(); modelCreator.connectToGui();
handleKeyboardComponent(updateEvent); handleKeyboardComponents();
doMicroStep.setEnabled(false); doMicroStep.setEnabled(false);
if (!realTimeClockRunning && model.isRunToBreakAllowed()) { if (!realTimeClockRunning && model.isRunToBreakAllowed()) {
@ -1457,17 +1448,11 @@ public final class Main extends JFrame implements ClosingWindowListener.ConfirmS
runToBreakMicroAction.setEnabled(needsUpdate); runToBreakMicroAction.setEnabled(needsUpdate);
} }
private void handleKeyboardComponent(ModelEvent updateEvent) { private void handleKeyboardComponents() {
KeyboardDialog.KeyPressedHandler handler = null; KeyboardDialog.KeyPressedHandler handler = null;
for (Keyboard k : model.findNode(Keyboard.class)) { for (Keyboard k : model.findNode(Keyboard.class)) {
if (handler == null) if (handler == null)
if (updateEvent == ModelEvent.MICROSTEP) handler = keyboard -> model.modify(keyboard::hasChanged);
handler = keyboard -> {
model.modify(keyboard::hasChanged);
checkMicroStepActions(model);
};
else
handler = keyboard -> model.modify(keyboard::hasChanged);
windowPosManager.register("keyboard_" + k.getLabel(), new KeyboardDialog(this, k, handler)); windowPosManager.register("keyboard_" + k.getLabel(), new KeyboardDialog(this, k, handler));
} }
@ -1499,8 +1484,9 @@ public final class Main extends JFrame implements ClosingWindowListener.ConfirmS
// To avoid such problems a lock is used. // To avoid such problems a lock is used.
synchronized (modelLock) { synchronized (modelLock) {
if (model != null) { if (model != null) {
model.modify(() -> model.close()); Model m = model;
model = null; model = null;
m.modify(m::close);
SwingUtilities.invokeLater(() -> showErrorWithoutARunningModel(message, cause)); SwingUtilities.invokeLater(() -> showErrorWithoutARunningModel(message, cause));
} }
} }
@ -1727,8 +1713,10 @@ public final class Main extends JFrame implements ClosingWindowListener.ConfirmS
case EXTERNALCHANGE: case EXTERNALCHANGE:
case MICROSTEP: case MICROSTEP:
case BREAK: case BREAK:
if (!realTimeClockRunning) if (!realTimeClockRunning) {
circuitComponent.removeHighLighted();
modelCreator.addNodeElementsTo(model.nodesToUpdate(), circuitComponent.getHighLighted()); modelCreator.addNodeElementsTo(model.nodesToUpdate(), circuitComponent.getHighLighted());
}
circuitComponent.graphicHasChanged(); circuitComponent.graphicHasChanged();
if (!realTimeClockRunning) if (!realTimeClockRunning)
checkMicroStepActions(model); checkMicroStepActions(model);
@ -1863,7 +1851,7 @@ public final class Main extends JFrame implements ClosingWindowListener.ConfirmS
try { try {
model.doStep(); model.doStep();
if (clkVal.getBool()) { if (clkVal.getBool()) {
clkVal.setBool(!clkVal.getBool()); model.modify(() -> clkVal.setBool(!clkVal.getBool()));
model.doStep(); model.doStep();
} }
circuitComponent.graphicHasChanged(); circuitComponent.graphicHasChanged();

View File

@ -434,7 +434,7 @@ public class TestInGUI extends TestCase {
.press("control typed a") .press("control typed a")
.typeTempFile("test") .typeTempFile("test")
.press("ENTER") .press("ENTER")
.delay(300) .delay(600)
.add(new GuiTester.WaitFor(() -> { .add(new GuiTester.WaitFor(() -> {
Window activeWindow = FocusManager.getCurrentManager().getActiveWindow(); Window activeWindow = FocusManager.getCurrentManager().getActiveWindow();
return !(activeWindow instanceof Main || activeWindow instanceof TableDialog); return !(activeWindow instanceof Main || activeWindow instanceof TableDialog);
@ -915,7 +915,7 @@ public class TestInGUI extends TestCase {
.press("RIGHT", 1) .press("RIGHT", 1)
.press("DOWN", 1) .press("DOWN", 1)
.press("ENTER", 1) .press("ENTER", 1)
.press("control TAB", 4) .press("control TAB", 7)
.press("RIGHT", 1) .press("RIGHT", 1)
.add(new GuiTester.SetFocusTo<>(AttributeDialog.class, .add(new GuiTester.SetFocusTo<>(AttributeDialog.class,
b -> b instanceof JButton && Lang.get("btn_edit").equals(((JButton) b).getText()))) b -> b instanceof JButton && Lang.get("btn_edit").equals(((JButton) b).getText())))