Package com.cburch.logisim.circuit

Examples of com.cburch.logisim.circuit.Circuit


    }

    public void addCircuitListener(CircuitListener value) {
        circuitListeners.add(value);
        Circuit current = getCurrentCircuit();
        if (current != null) {
            current.addCircuitListener(value);
        }

    }
View Full Code Here


    }

    public void removeCircuitListener(CircuitListener value) {
        circuitListeners.remove(value);
        Circuit current = getCurrentCircuit();
        if (current != null) {
            current.removeCircuitListener(value);
        }

    }
View Full Code Here

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

        return c == null ? Location.create(0, 0) : c.getLocation();
    }

    @Override
    public boolean isPortConnected(int index) {
        Circuit circ = context.getCircuit();
        Location loc = comp.getEnd(index).getLocation();
        return circ.isConnected(loc, comp);
    }
View Full Code Here

            proj.addProjectListener(this);
            proj.addLibraryListener(this);
            frame.addPropertyChangeListener(Frame.EDITOR_VIEW, this);
            frame.addPropertyChangeListener(Frame.EXPLORER_VIEW, this);
            Circuit circ = proj.getCurrentCircuit();
            if (circ != null) {
                circ.getAppearance().addCanvasModelListener(this);
            }

            menubar.addActionListener(LogisimMenuBar.ADD_CIRCUIT, this);
            menubar.addActionListener(LogisimMenuBar.MOVE_CIRCUIT_UP, this);
            menubar.addActionListener(LogisimMenuBar.MOVE_CIRCUIT_DOWN, this);
View Full Code Here

        @Override
        public void projectChanged(ProjectEvent event) {
            int action = event.getAction();
            if (action == ProjectEvent.ACTION_SET_CURRENT) {
                Circuit old = (Circuit) event.getOldData();
                if (old != null) {
                    old.getAppearance().removeCanvasModelListener(this);
                }
                Circuit circ = (Circuit) event.getData();
                if (circ != null) {
                    circ.getAppearance().addCanvasModelListener(this);
                }
                computeEnabled();
            } else if (action == ProjectEvent.ACTION_SET_FILE) {
                computeEnabled();
            }
View Full Code Here

        @Override
        public void actionPerformed(ActionEvent event) {
            Object src = event.getSource();
            Project proj = frame.getProject();
            Circuit cur = proj == null ? null : proj.getCurrentCircuit();
            if (src == LogisimMenuBar.ADD_CIRCUIT) {
                ProjectCircuitActions.doAddCircuit(proj);
            } else if (src == LogisimMenuBar.MOVE_CIRCUIT_UP) {
                ProjectCircuitActions.doMoveCircuit(proj, cur, -1);
            } else if (src == LogisimMenuBar.MOVE_CIRCUIT_DOWN) {
View Full Code Here

        }

        private void computeEnabled() {
            Project proj = frame.getProject();
            LogisimFile file = proj.getLogisimFile();
            Circuit cur = proj.getCurrentCircuit();
            int curIndex = file.getCircuits().indexOf(cur);
            boolean isProjectCircuit = curIndex >= 0;
            String editorView = frame.getEditorView();
            String explorerView = frame.getExplorerView();
            boolean canSetMain = false;
            boolean canMoveUp = false;
            boolean canMoveDown = false;
            boolean canRemove = false;
            boolean canRevert = false;
            boolean viewAppearance = editorView.equals(Frame.EDIT_APPEARANCE);
            boolean viewLayout = editorView.equals(Frame.EDIT_LAYOUT);
            boolean viewToolbox = explorerView.equals(Frame.VIEW_TOOLBOX);
            boolean viewSimulation = explorerView.equals(Frame.VIEW_SIMULATION);
            if (isProjectCircuit) {
                List<?> tools = proj.getLogisimFile().getTools();

                canSetMain = proj.getLogisimFile().getMainCircuit() != cur;
                canMoveUp = curIndex > 0;
                canMoveDown = curIndex < tools.size() - 1;
                canRemove = tools.size() > 1;
                canRevert = viewAppearance
                    && !cur.getAppearance().isDefaultAppearance();
            }

            menubar.setEnabled(LogisimMenuBar.ADD_CIRCUIT, true);
            menubar.setEnabled(LogisimMenuBar.MOVE_CIRCUIT_UP, canMoveUp);
            menubar.setEnabled(LogisimMenuBar.MOVE_CIRCUIT_DOWN, canMoveDown);
View Full Code Here

        private void computeRevertEnabled() {
            // do this separately since it can happen rather often
            Project proj = frame.getProject();
            LogisimFile file = proj.getLogisimFile();
            Circuit cur = proj.getCurrentCircuit();
            boolean isProjectCircuit = file.contains(cur);
            boolean viewAppearance = frame.getEditorView().equals(Frame.EDIT_APPEARANCE);
            boolean canRevert = isProjectCircuit && viewAppearance
                && !cur.getAppearance().isDefaultAppearance();
            boolean oldValue = menubar.isEnabled(LogisimMenuBar.REVERT_APPEARANCE);
            if (canRevert != oldValue) {
                menubar.setEnabled(LogisimMenuBar.REVERT_APPEARANCE, canRevert);
                fireEnableChanged();
            }
View Full Code Here

            if (pageIndex >= circuits.size()) {
                return Printable.NO_SUCH_PAGE;
            }


            Circuit circ = circuits.get(pageIndex);
            CircuitState circState = proj.getCircuitState(circ);
            Graphics g = base.create();
            Graphics2D g2 = g instanceof Graphics2D ? (Graphics2D) g : null;
            FontMetrics fm = g.getFontMetrics();
            String head = (header != null && !header.equals(""))
                ? format(header, pageIndex + 1, circuits.size(),
                        circ.getName())
                : null;
            int headHeight = (head == null ? 0 : fm.getHeight());

            // Compute image size
            double imWidth = format.getImageableWidth();
            double imHeight = format.getImageableHeight();

            // Correct coordinate system for page, including
            // translation and possible rotation.
            Bounds bds = circ.getBounds(g).expand(4);
            double scale = Math.min(imWidth / bds.getWidth(),
                    (imHeight - headHeight) / bds.getHeight());
            if (g2 != null) {
                g2.translate(format.getImageableX(), format.getImageableY());
                if (rotateToFit && scale < 1.0 / 1.1) {
                    double scale2 = Math.min(imHeight / bds.getWidth(),
                            (imWidth - headHeight) / bds.getHeight());
                    // will rotate
                    if (scale2 >= scale * 1.1) {
                        scale = scale2;
                        // portrait -> landscape
                        if (imHeight > imWidth) {
                            g2.translate(0, imHeight);
                            g2.rotate(-Math.PI / 2);
                        // landscape -> portrait
                        } else {
                            g2.translate(imWidth, 0);
                            g2.rotate(Math.PI / 2);
                        }
                        double t = imHeight;
                        imHeight = imWidth;
                        imWidth = t;
                    }
                }
            }

            // Draw the header line if appropriate
            if (head != null) {
                g.drawString(head,
                        (int) Math.round((imWidth - fm.stringWidth(head)) / 2),
                        fm.getAscent());
                if (g2 != null) {
                    imHeight -= headHeight;
                    g2.translate(0, headHeight);
                }
            }

            // Now change coordinate system for circuit, including
            // translation and possible scaling
            if (g2 != null) {
                if (scale < 1.0) {
                    g2.scale(scale, scale);
                    imWidth /= scale;
                    imHeight /= scale;
                }
                double dx = Math.max(0.0, (imWidth - bds.getWidth()) / 2);
                g2.translate(-bds.getX() + dx, -bds.getY());
            }

            // Ensure that the circuit is eligible to be drawn
            Rectangle clip = g.getClipBounds();
            clip.add(bds.getX(), bds.getY());
            clip.add(bds.getX() + bds.getWidth(),
                    bds.getY() + bds.getHeight());
            g.setClip(clip);

            // And finally draw the circuit onto the page
            ComponentDrawContext context = new ComponentDrawContext(
                    proj.getFrame().getCanvas(), circ, circState,
                    base, g, printerView);
            Collection<Component> noComps = Collections.emptySet();
            circ.draw(context, noComps);
            g.dispose();
            return Printable.PAGE_EXISTS;
        }
View Full Code Here

TOP

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

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.