mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-24 04:42:51 -04:00
avoids swing event queue flodding
This commit is contained in:
parent
14f71687a9
commit
3e06dd5d71
@ -374,7 +374,7 @@ public class Model implements Iterable<Node>, SyncAccess {
|
||||
brVal = new ArrayList<>();
|
||||
for (Break b : breaks)
|
||||
brVal.add(new BreakDetector(b));
|
||||
fireEvent(ModelEvent.FASTRUN);
|
||||
fireEvent(ModelEvent.RUN_TO_BREAK);
|
||||
}
|
||||
|
||||
ObservableValue clkVal = clocks.get(0).getClockOutput();
|
||||
@ -392,10 +392,12 @@ public class Model implements Iterable<Node>, SyncAccess {
|
||||
|
||||
if (timeout > 0) {
|
||||
timeout--;
|
||||
if (timeout == 0)
|
||||
if (timeout == 0) {
|
||||
fireEvent(ModelEvent.RUN_TO_BREAK_TIMEOUT);
|
||||
return new BreakInfo(timeout);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
errorOccurred(e);
|
||||
}
|
||||
@ -418,7 +420,7 @@ public class Model implements Iterable<Node>, SyncAccess {
|
||||
if (clocks.size() == 1)
|
||||
clkVal = clocks.get(0).getClockOutput();
|
||||
|
||||
fireEvent(ModelEvent.FASTRUN);
|
||||
fireEvent(ModelEvent.RUN_TO_BREAK);
|
||||
final boolean[] wasBreak = {false};
|
||||
while (!wasBreak[0] && state != State.CLOSED) {
|
||||
if (!needsUpdate()) {
|
||||
|
@ -36,9 +36,13 @@ public class ModelEvent {
|
||||
*/
|
||||
public static final ModelEvent MICROSTEP = new ModelEvent(ModelEventType.MICROSTEP);
|
||||
/**
|
||||
* Shorthand for a ModelEventType.FASTRUN event
|
||||
* Shorthand for a ModelEventType.RUN_TO_BREAK event
|
||||
*/
|
||||
public static final ModelEvent FASTRUN = new ModelEvent(ModelEventType.FASTRUN);
|
||||
public static final ModelEvent RUN_TO_BREAK = new ModelEvent(ModelEventType.RUN_TO_BREAK);
|
||||
/**
|
||||
* Shorthand for a ModelEventType.RUN_TO_BREAK_TIMEOUT event
|
||||
*/
|
||||
public static final ModelEvent RUN_TO_BREAK_TIMEOUT = new ModelEvent(ModelEventType.RUN_TO_BREAK_TIMEOUT);
|
||||
/**
|
||||
* Shorthand for a ModelEventType.BREAK event
|
||||
*/
|
||||
|
@ -35,7 +35,12 @@ public enum ModelEventType {
|
||||
/**
|
||||
* Fast run is started.
|
||||
*/
|
||||
FASTRUN,
|
||||
RUN_TO_BREAK,
|
||||
|
||||
/**
|
||||
* Fast run timeout has occurred.
|
||||
*/
|
||||
RUN_TO_BREAK_TIMEOUT,
|
||||
|
||||
/**
|
||||
* A break is detected.
|
||||
@ -58,5 +63,4 @@ public enum ModelEventType {
|
||||
* Used to notify an error
|
||||
*/
|
||||
ERROR_OCCURRED
|
||||
|
||||
}
|
||||
|
@ -1733,15 +1733,26 @@ public final class Main extends JFrame implements ClosingWindowListener.ConfirmS
|
||||
* Updates the graphic at every modification.
|
||||
*/
|
||||
private class UpdateViewAtEvent implements ModelStateObserverTyped {
|
||||
private boolean stepUpdateEnabled;
|
||||
|
||||
UpdateViewAtEvent() {
|
||||
stepUpdateEnabled = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleEvent(ModelEvent event) {
|
||||
switch (event.getType()) {
|
||||
case RUN_TO_BREAK:
|
||||
stepUpdateEnabled = false;
|
||||
break;
|
||||
case CHECKBURN:
|
||||
case STEP:
|
||||
case BREAK:
|
||||
stepUpdateEnabled = true;
|
||||
case STEP:
|
||||
if (stepUpdateEnabled)
|
||||
circuitComponent.graphicHasChanged();
|
||||
break;
|
||||
case RUN_TO_BREAK_TIMEOUT:
|
||||
circuitComponent.graphicHasChanged();
|
||||
break;
|
||||
}
|
||||
@ -2238,8 +2249,11 @@ public final class Main extends JFrame implements ClosingWindowListener.ConfirmS
|
||||
long time = System.currentTimeMillis();
|
||||
Model.BreakInfo info = model.runToBreak(steps);
|
||||
time = System.currentTimeMillis() - time;
|
||||
System.out.println(time + ", " + steps);
|
||||
if (time > 0) {
|
||||
int newSteps = (int) (steps * 250 / time);
|
||||
steps = (steps + newSteps) / 2;
|
||||
}
|
||||
|
||||
if (info != null) {
|
||||
if (info.isTimeout() && model.isRunning())
|
||||
|
@ -120,7 +120,7 @@ public class ProbeDialog extends JDialog implements ModelStateObserverTyped {
|
||||
}
|
||||
}
|
||||
switch (event.getType()) {
|
||||
case FASTRUN:
|
||||
case RUN_TO_BREAK:
|
||||
tableUpdateEnable = false;
|
||||
break;
|
||||
case BREAK:
|
||||
@ -133,7 +133,7 @@ public class ProbeDialog extends JDialog implements ModelStateObserverTyped {
|
||||
|
||||
@Override
|
||||
public ModelEventType[] getEvents() {
|
||||
return new ModelEventType[]{type, ModelEventType.CHECKBURN, ModelEventType.FASTRUN, ModelEventType.BREAK, ModelEventType.CLOSED};
|
||||
return new ModelEventType[]{type, ModelEventType.CHECKBURN, ModelEventType.RUN_TO_BREAK, ModelEventType.BREAK, ModelEventType.CLOSED};
|
||||
}
|
||||
|
||||
private static class SignalTableModel implements TableModel {
|
||||
|
Loading…
x
Reference in New Issue
Block a user