Search in sources :

Example 1 with CircuitListener

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

the class Project method setCircuitState.

public void setCircuitState(CircuitState value) {
    if (value == null || circuitState == value)
        return;
    CircuitState old = circuitState;
    Circuit oldCircuit = old == null ? null : old.getCircuit();
    Circuit newCircuit = value.getCircuit();
    boolean circuitChanged = old == null || oldCircuit != newCircuit;
    if (circuitChanged) {
        Canvas canvas = frame == null ? null : frame.getCanvas();
        if (canvas != null) {
            if (tool != null)
                tool.deselect(canvas);
            Selection selection = canvas.getSelection();
            if (selection != null) {
                Action act = SelectionActions.dropAll(selection);
                if (act != null) {
                    doAction(act);
                }
            }
            if (tool != null)
                tool.select(canvas);
        }
        if (oldCircuit != null) {
            for (CircuitListener l : circuitListeners) {
                oldCircuit.removeCircuitListener(l);
            }
        }
    }
    circuitState = value;
    stateMap.put(circuitState.getCircuit(), circuitState);
    simulator.setCircuitState(circuitState);
    if (circuitChanged) {
        fireEvent(ProjectEvent.ACTION_SET_CURRENT, oldCircuit, newCircuit);
        if (newCircuit != null) {
            for (CircuitListener l : circuitListeners) {
                newCircuit.addCircuitListener(l);
            }
        }
    }
    fireEvent(ProjectEvent.ACTION_SET_STATE, old, circuitState);
}
Also used : CircuitState(com.cburch.logisim.circuit.CircuitState) CircuitListener(com.cburch.logisim.circuit.CircuitListener) Selection(com.cburch.logisim.gui.main.Selection) Canvas(com.cburch.logisim.gui.main.Canvas) Circuit(com.cburch.logisim.circuit.Circuit)

Aggregations

Circuit (com.cburch.logisim.circuit.Circuit)1 CircuitListener (com.cburch.logisim.circuit.CircuitListener)1 CircuitState (com.cburch.logisim.circuit.CircuitState)1 Canvas (com.cburch.logisim.gui.main.Canvas)1 Selection (com.cburch.logisim.gui.main.Selection)1