Search in sources :

Example 1 with SimulatorEvent

use of com.cburch.logisim.circuit.SimulatorEvent in project logisim-evolution by reds-heig.

the class MenuSimulate method setCurrentState.

public void setCurrentState(Simulator sim, CircuitState value) {
    if (currentState == value) {
        return;
    }
    Simulator oldSim = currentSim;
    CircuitState oldState = currentState;
    currentSim = sim;
    currentState = value;
    if (bottomState == null) {
        bottomState = currentState;
    } else if (currentState == null) {
        bottomState = null;
    } else {
        CircuitState cur = bottomState;
        while (cur != null && cur != currentState) {
            cur = cur.getParentState();
        }
        if (cur == null) {
            bottomState = currentState;
        }
    }
    boolean oldPresent = oldState != null;
    boolean present = currentState != null;
    if (oldPresent != present) {
        computeEnabled();
    }
    if (currentSim != oldSim) {
        double freq = currentSim == null ? 1.0 : currentSim.getTickFrequency();
        for (int i = 0; i < tickFreqs.length; i++) {
            tickFreqs[i].setSelected(Math.abs(tickFreqs[i].freq - freq) < 0.001);
        }
        if (oldSim != null) {
            oldSim.removeSimulatorListener(myListener);
        }
        if (currentSim != null) {
            currentSim.addSimulatorListener(myListener);
        }
        myListener.simulatorStateChanged(new SimulatorEvent(sim));
    }
    clearItems(downStateItems);
    CircuitState cur = bottomState;
    while (cur != null && cur != currentState) {
        downStateItems.add(new CircuitStateMenuItem(cur));
        cur = cur.getParentState();
    }
    if (cur != null) {
        cur = cur.getParentState();
    }
    clearItems(upStateItems);
    while (cur != null) {
        upStateItems.add(0, new CircuitStateMenuItem(cur));
        cur = cur.getParentState();
    }
    recreateStateMenus();
}
Also used : CircuitState(com.cburch.logisim.circuit.CircuitState) SimulatorEvent(com.cburch.logisim.circuit.SimulatorEvent) Simulator(com.cburch.logisim.circuit.Simulator)

Aggregations

CircuitState (com.cburch.logisim.circuit.CircuitState)1 Simulator (com.cburch.logisim.circuit.Simulator)1 SimulatorEvent (com.cburch.logisim.circuit.SimulatorEvent)1