Package com.cburch.logisim.comp

Examples of com.cburch.logisim.comp.Component


        oldAttrs = null;
        newAttrs = null;
        for (Component base : sel.getComponents()) {
            AttributeSet baseAttrs = base.getAttributeSet();
            AttributeSet copyAttrs = (AttributeSet) baseAttrs.clone();
            Component copy = base.getFactory().createComponent(base.getLocation(),
                    copyAttrs);
            components.add(copy);
            if (baseAttrs == viewAttrs) {
                oldAttrs = baseAttrs;
                newAttrs = copyAttrs;
View Full Code Here


        }
    }

    void append(ReplacementMap next) {
        for (Map.Entry<Component,HashSet<Component>> e : next.map.entrySet()) {
            Component b = e.getKey();
            // what b is replaced by
            HashSet<Component> cs = e.getValue();
            // what was replaced to get b
            HashSet<Component> as = this.inverse.remove(b);
            // b pre-existed replacements so
            if (as == null) {
                // we say it replaces itself.
                as = new HashSet<Component>(3);
                as.add(b);
            }

            for (Component a : as) {
                HashSet<Component> aDst = this.map.get(a);
                // should happen when b pre-existed only
                if (aDst == null) {
                    aDst = new HashSet<Component>(cs.size());
                    this.map.put(a, aDst);
                }
                aDst.remove(b);
                aDst.addAll(cs);
            }

            for (Component c : cs) {
                // should always be null
                HashSet<Component> cSrc = this.inverse.get(c);
                if (cSrc == null) {
                    cSrc = new HashSet<Component>(as.size());
                    this.inverse.put(c, cSrc);
                }
                cSrc.addAll(as);
            }
        }

        for (Map.Entry<Component,HashSet<Component>> e : next.inverse.entrySet()) {
            Component c = e.getKey();
            if (!inverse.containsKey(c)) {
                HashSet<Component> bs = e.getValue();
                if (!bs.isEmpty()) {
                    //OK
                    System.err.println("internal error: component replaced but not represented");
View Full Code Here

        private Collection<Component> computeAdditions(Collection<Component> comps) {
            HashMap<Component, Component> replMap = componentReplacements;
            ArrayList<Component> toAdd = new ArrayList<Component>(comps.size());
            for (Iterator<Component> it = comps.iterator(); it.hasNext(); ) {
                Component comp = it.next();
                if (replMap.containsKey(comp)) {
                    Component repl = replMap.get(comp);
                    if (repl != null) {
                        toAdd.add(repl);
                    }
                } else {
                    toAdd.add(comp);
View Full Code Here

        haloedComponent = comp;
        exposeHaloedComponent(g);
    }

    private void exposeHaloedComponent(Graphics g) {
        Component c = haloedComponent;
        if (c == null) {
            return;
        }

        Bounds bds = c.getBounds(g).expand(7);
        int w = bds.getWidth();
        int h = bds.getHeight();
        double a = Canvas.SQRT_2 * w;
        double b = Canvas.SQRT_2 * h;
        canvas.repaint((int) Math.round(bds.getX() + w/2.0 - a/2.0),
View Full Code Here

        return true;
    }

    @Override
    public Set<Component> getHiddenComponents(Canvas canvas) {
        Component shorten = willShorten(start, cur);
        if (shorten != null) {
            return Collections.singleton(shorten);
        } else {
            return null;
        }
View Full Code Here

        private Map<Element, Component> loadKnownComponents(Element elt) {
            Map<Element, Component> known = new HashMap<Element, Component>();
            for (Element sub : XmlIterator.forChildElements(elt, "comp")) {
                try {
                    Component comp = XmlCircuitReader.getComponent(sub, this);
                    known.put(sub, comp);
                } catch (XmlReaderException e) { }
            }
            return known;
        }
View Full Code Here

    }

    @Override
    public void mouseReleased(Canvas canvas, Graphics g,
            MouseEvent e) {
        Component added = null;
        if (state == SHOW_ADD) {
            Circuit circ = canvas.getCircuit();
            if (!canvas.getProject().getLogisimFile().contains(circ)) {
                return;
            }

            if (shouldSnap) {
                Canvas.snapToGrid(e);
            }

            moveTo(canvas, g, e.getX(), e.getY());

            Location loc = Location.create(e.getX(), e.getY());
            AttributeSet attrsCopy = (AttributeSet) attrs.clone();
            ComponentFactory source = getFactory();
            if (source == null) {
                return;
            }

            Component c = source.createComponent(loc, attrsCopy);

            if (circ.hasConflict(c)) {
                canvas.setErrorMessage(getFromLocale("exclusiveError"), 0, 0);
                return;
            }

            Bounds bds = c.getBounds(g);
            if (bds.getX() < 0 || bds.getY() < 0) {
                canvas.setErrorMessage(getFromLocale("negativeCoordError"), 0, 0);
                return;
            }
View Full Code Here

        JPopupMenu menu;
        Project proj = canvas.getProject();
        Selection sel = proj.getSelection();
        Collection<Component> in_sel = sel.getComponentsContaining(pt, g);
        if (!in_sel.isEmpty()) {
            Component comp = in_sel.iterator().next();
            if (sel.getComponents().size() > 1) {
                menu = new MenuSelection(proj);
            } else {
                menu = new MenuComponent(proj,
                    canvas.getCircuit(), comp);
                MenuExtender extender = (MenuExtender) comp.getFeature(MenuExtender.class);
                if (extender != null) {
                    extender.configureMenu(menu, proj);
                }

            }
        } else {
            Collection<Component> cl = canvas.getCircuit().getAllContaining(pt, g);
            if (!cl.isEmpty()) {
                Component comp = cl.iterator().next();
                menu = new MenuComponent(proj,
                    canvas.getCircuit(), comp);
                MenuExtender extender = (MenuExtender) comp.getFeature(MenuExtender.class);
                if (extender != null) {
                    extender.configureMenu(menu, proj);
                }

            } else {
View Full Code Here

            result.add(Wire.create(input, output));
            return;
        }

        Location compOutput = Location.create(x + layout.width, output.getY());
        Component parent = layout.factory.createComponent(compOutput,
                layout.attrs);
        result.add(parent);
        if (!compOutput.equals(output)) {
            result.add(Wire.create(compOutput, output));
        }

        // handle a NOT gate pattern implemented with NAND as a special case
        if (layout.factory == NandGate.FACTORY && layout.subLayouts.length == 1
                && layout.subLayouts[0].inputName == null) {
            Layout sub = layout.subLayouts[0];

            Location input0 = parent.getEnd(1).getLocation();
            Location input1 = parent.getEnd(2).getLocation();

            int midX = input0.getX() - 20;
            Location subOutput = Location.create(midX, output.getY());
            Location midInput0 = Location.create(midX, input0.getY());
            Location midInput1 = Location.create(midX, input1.getY());
            result.add(Wire.create(subOutput, midInput0));
            result.add(Wire.create(midInput0, input0));
            result.add(Wire.create(subOutput, midInput1));
            result.add(Wire.create(midInput1, input1));

            int subX = x + layout.subX - sub.width;
            placeComponents(result, sub, subX, y + sub.y, inputData, subOutput);
            return;
        }

        if (layout.subLayouts.length == parent.getEnds().size() - 2) {
            int index = layout.subLayouts.length / 2 + 1;
            Object factory = parent.getFactory();
            if (factory instanceof AbstractGate) {
                Value val = ((AbstractGate) factory).getIdentity();
                Integer valInt = Integer.valueOf(val.toIntValue());
                Location loc = parent.getEnd(index).getLocation();
                AttributeSet attrs = Constant.FACTORY.createAttributeSet();
                attrs.setValue(Constant.ATTR_VALUE, valInt);
                result.add(Constant.FACTORY.createComponent(loc, attrs));
            }
        }

        for (int i = 0; i < layout.subLayouts.length; i++) {
            Layout sub = layout.subLayouts[i];

            int inputIndex = i + 1;
            Location subDest = parent.getEnd(inputIndex).getLocation();

            int subOutputY = y + sub.y + sub.outputY;
            if (sub.inputName != null) {
                int destY = subDest.getY();
                if (i == 0 && destY < subOutputY
View Full Code Here

    public void doIt(Project proj) {
        CircuitMutation xn = new CircuitMutation(circuit);
        int len = values.size();
        oldValues.clear();
        for (int i = 0; i < len; i++) {
            Component comp = comps.get(i);
            Attribute<Object> attr = attrs.get(i);
            Object value = values.get(i);
            if (circuit.contains(comp)) {
                oldValues.add(null);
                xn.set(comp, attr, value);
            } else {
                AttributeSet compAttrs = comp.getAttributeSet();
                oldValues.add(compAttrs.getValue(attr));
                compAttrs.setValue(attr, value);
            }
        }
View Full Code Here

TOP

Related Classes of com.cburch.logisim.comp.Component

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.