Package com.cburch.logisim.circuit

Examples of com.cburch.logisim.circuit.Simulator


    //
    // ChangeListener methods
    //
    @Override
    public void stateChanged(ChangeEvent e) {
        Simulator sim = project.getSimulator();
        boolean running = sim != null && sim.isRunning();
        boolean ticking = sim != null && sim.isTicking();
        simEnable.setIcon(running ? "simstop.svg" : "simplay.svg");
        simEnable.setToolTip(running ? getFromLocale("simulateDisableStepsTip")
                : getFromLocale("simulateEnableStepsTip"));
        tickEnable.setIcon(ticking ? "simtstop.svg" : "simtplay.svg");
        tickEnable.setToolTip(ticking ? getFromLocale("simulateDisableTicksTip")
View Full Code Here


    //
    @Override
    public void projectChanged(ProjectEvent event) {
        int action = event.getAction();
        if (action == ProjectEvent.ACTION_SET_STATE) {
            Simulator sim = project.getSimulator();
            CircuitState root = sim.getCircuitState();
            if (model.getRootState() != root) {
                model = new SimulationTreeModel(root);
                tree.setModel(model);
            }
            model.setCurrentView(project.getCircuitState());
View Full Code Here

        computeEnabled();
    }
   
    public void tick() {
      Project proj = menubar.getProject();
        Simulator sim = proj == null ? null : proj.getSimulator();
        if (sim != null)
          sim.tick();
    }
View Full Code Here

    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);
            }
View Full Code Here

    }

    @Override
    void computeEnabled() {
        boolean present = currentState != null;
        Simulator sim = this.currentSim;
        boolean simRunning = sim != null && sim.isRunning();
        setEnabled(present);
        run.setEnabled(present);
        reset.setEnabled(present);
        step.setEnabled(present && !simRunning);
        upStateMenu.setEnabled(present);
View Full Code Here

    private class MyListener implements ActionListener, SimulatorListener, ChangeListener {  
        @Override
        public void actionPerformed(ActionEvent e) {
            Object src = e.getSource();
            Project proj = menubar.getProject();
            Simulator sim = proj == null ? null : proj.getSimulator();
            if (src == run || src == LogisimMenuBar.SIMULATE_ENABLE) {
                if (sim != null) {
                    sim.setIsRunning(!sim.isRunning());
                    proj.repaintCanvas();
                }
            } else if (src == reset) {
                if (sim != null) {
                    sim.requestReset();
                }

            } else if (src == step || src == LogisimMenuBar.SIMULATE_STEP) {
                if (sim != null) {
                    sim.step();
                }

            } else if (src == tickOnce || src == LogisimMenuBar.TICK_STEP) {
                if (sim != null) {
                    sim.tick();
                }

            } else if (src == ticksEnabled || src == LogisimMenuBar.TICK_ENABLE) {
                if (sim != null) {
                    sim.setIsTicking(!sim.isTicking());
                }

            } else if (src == log) {
                LogFrame frame = menubar.getProject().getLogFrame(true);
                frame.setVisible(true);
View Full Code Here

        public void propagationCompleted(SimulatorEvent e) { }
        @Override
        public void tickCompleted(SimulatorEvent e) { }
        @Override
        public void simulatorStateChanged(SimulatorEvent e) {
            Simulator sim = e.getSource();
            if (sim != currentSim) {
                return;
            }

            computeEnabled();
            run.setSelected(sim.isRunning());
            ticksEnabled.setSelected(sim.isTicking());
            double freq = sim.getTickFrequency();
            for (int i = 0; i < tickFreqs.length; i++) {
                TickFrequencyChoice item = tickFreqs[i];
                item.setSelected(freq == item.freq);
            }
        }
View Full Code Here

TOP

Related Classes of com.cburch.logisim.circuit.Simulator

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.