Package com.cburch.logisim.comp

Examples of com.cburch.logisim.comp.ComponentFactory


    }

    private Bounds getBounds() {
        Bounds ret = bounds;
        if (ret == null) {
            ComponentFactory source = getFactory();
            if (source == null) {
                ret = Bounds.EMPTY_BOUNDS;
            } else {
                AttributeSet base = getBaseAttributes();
                ret = source.getOffsetBounds(base).expand(5);
            }
            bounds = ret;
        }
        return ret;
    }
View Full Code Here


            if (inputs.size() <= 2) {
                for (CircuitDetermination a : inputs) {
                    a.convertToTwoInputs();
                }
            } else {
                ComponentFactory subFactory;
                if (factory == NorGate.FACTORY) {
                    subFactory = OrGate.FACTORY;
                }

                else if (factory == NandGate.FACTORY) {
View Full Code Here

            if (num > GateAttributes.MAX_INPUTS) {
                int newNum = (num + GateAttributes.MAX_INPUTS - 1) / GateAttributes.MAX_INPUTS;
                ArrayList<CircuitDetermination> oldInputs = inputs;
                inputs = new ArrayList<CircuitDetermination>();

                ComponentFactory subFactory = factory;
                if (subFactory == NandGate.FACTORY) {
                    subFactory = AndGate.FACTORY;
                }

                if (subFactory == NorGate.FACTORY) {
View Full Code Here

        if (det instanceof CircuitDetermination.Input) {
            CircuitDetermination.Input input = (CircuitDetermination.Input) det;
            return new Layout(input.getName());
        } else if (det instanceof CircuitDetermination.Value) {
            CircuitDetermination.Value value = (CircuitDetermination.Value) det;
            ComponentFactory factory = Constant.FACTORY;
            AttributeSet attrs = factory.createAttributeSet();
            attrs.setValue(Constant.ATTR_VALUE,
                    Integer.valueOf(value.getValue()));
            Bounds bds = factory.getOffsetBounds(attrs);
            return new Layout(bds.getWidth(), bds.getHeight(),
                    -bds.getY(), factory, attrs,
                    new Layout[0], 0);
        }

        // We know det is a Gate. Determine sublayouts.
        CircuitDetermination.Gate gate = (CircuitDetermination.Gate) det;
        ComponentFactory factory = gate.getFactory();
        ArrayList<CircuitDetermination> inputs = gate.getInputs();

        // Handle a NOT implemented with a NAND as a special case
        if (gate.isNandNot()) {
            CircuitDetermination subDet = inputs.get(0);
            if (!(subDet instanceof CircuitDetermination.Input)) {
                Layout[] sub = new Layout[1];
                sub[0] = layoutGatesSub(subDet);
                sub[0].y = 0;

                AttributeSet attrs = factory.createAttributeSet();
                attrs.setValue(GateAttributes.ATTR_SIZE, GateAttributes.SIZE_NARROW);
                attrs.setValue(GateAttributes.ATTR_INPUTS, Integer.valueOf(2));

                // determine layout's width
                Bounds bds = factory.getOffsetBounds(attrs);
                int betweenWidth = 40;
                if (sub[0].width == 0) {
                    betweenWidth = 0;
                }

                int width = sub[0].width + betweenWidth + bds.getWidth();

                // determine outputY and layout's height.
                int outputY = sub[0].y + sub[0].outputY;
                int height = sub[0].height;
                int minOutputY = roundUp(-bds.getY());
                if (minOutputY > outputY) {
                    // we have to shift everything down because otherwise
                    // the component will peek over the rectangle's top.
                    int dy = minOutputY - outputY;
                    sub[0].y += dy;
                    height += dy;
                    outputY += dy;
                }
                int minHeight = outputY + bds.getY() + bds.getHeight();
                if (minHeight > height) {
                    height = minHeight;
                }


                // ok; create and return the layout.
                return new Layout(width, height, outputY, factory, attrs,
                        sub, sub[0].width);
            }
        }

        Layout[] sub = new Layout[inputs.size()];
        // maximum width of sublayouts
        int subWidth = 0;
        // total height of sublayouts
        int subHeight = 0;
        for (int i = 0; i < sub.length; i++) {
            sub[i] = layoutGatesSub(inputs.get(i));
            if (sub.length % 2 == 0 && i == (sub.length + 1) / 2
                    && sub[i - 1].height + sub[i].height == 0) {
                // if there are an even number of inputs, then there is a
                // 20-tall gap between the middle two inputs. Ensure the two
                // middle inputs are at least 20 pixels apart.
                subHeight += 10;
            }
            sub[i].y = subHeight;
            subWidth = Math.max(subWidth, sub[i].width);
            subHeight += sub[i].height + 10;
        }
        subHeight -= 10;

        AttributeSet attrs = factory.createAttributeSet();
        if (factory == NotGate.FACTORY) {
            attrs.setValue(NotGate.ATTR_SIZE, NotGate.SIZE_NARROW);
        } else {
            attrs.setValue(GateAttributes.ATTR_SIZE, GateAttributes.SIZE_NARROW);

            int ins = sub.length;
            attrs.setValue(GateAttributes.ATTR_INPUTS, Integer.valueOf(ins));
        }

        // determine layout's width
        Bounds bds = factory.getOffsetBounds(attrs);
        int betweenWidth = 40 + 10 * (sub.length / 2 - 1);
        if (sub.length == 1) {
            betweenWidth = 20;
        }

View Full Code Here

    //
    // placeOutput
    //
    private static void placeOutput(CircuitMutation result, Location loc, String name) {
        ComponentFactory factory = Pin.FACTORY;
        AttributeSet attrs = factory.createAttributeSet();
        attrs.setValue(StdAttr.FACING, Direction.WEST);
        attrs.setValue(Pin.ATTR_TYPE, Boolean.TRUE);
        attrs.setValue(StdAttr.LABEL, name);
        attrs.setValue(Pin.ATTR_LABEL_LOC, Direction.NORTH);
        result.add(factory.createComponent(loc, attrs));
    }
View Full Code Here

                singleInput.ys.add(spineLoc);
            }
            Location loc = Location.create(curX, curY);

            // now create the pin
            ComponentFactory factory = Pin.FACTORY;
            AttributeSet attrs = factory.createAttributeSet();
            attrs.setValue(StdAttr.FACING, Direction.EAST);
            attrs.setValue(Pin.ATTR_TYPE, Boolean.FALSE);
            attrs.setValue(Pin.ATTR_TRISTATE, Boolean.FALSE);
            attrs.setValue(StdAttr.LABEL, name);
            attrs.setValue(Pin.ATTR_LABEL_LOC, Direction.NORTH);
            result.add(factory.createComponent(loc, attrs));

            ArrayList<Location> spine = singleInput.ys;
            if (spine.size() > 0) {
                // create wire connecting pin to spine
                /* This should no longer matter - the wires will be repaired
View Full Code Here

            return ret;
        }
    }

    public ComponentFactory getFactory(Class<? extends Library> libraryClass) {
        ComponentFactory ret = factory;
        if (factory != null || factoryLoadAttempted) {
            return ret;
        } else {
            String msg = "";
            try {
View Full Code Here

        Object selected = event.getTarget();
        if (selected instanceof ProjectExplorerToolNode) {
            Tool tool = ((ProjectExplorerToolNode) selected).getValue();
            if (tool instanceof AddTool) {
                AddTool addTool = (AddTool) tool;
                ComponentFactory source = addTool.getFactory();
                if (source instanceof SubcircuitFactory) {
                    SubcircuitFactory circFact = (SubcircuitFactory) source;
                    Circuit circ = circFact.getSubcircuit();
                    if (proj.getCurrentCircuit() == circ) {
                        AttrTableModel m = new AttrTableCircuitModel(proj, circ);
View Full Code Here

        Object clicked = event.getTarget();
        if (clicked instanceof ProjectExplorerToolNode) {
            Tool baseTool = ((ProjectExplorerToolNode) clicked).getValue();
            if (baseTool instanceof AddTool) {
                AddTool tool = (AddTool) baseTool;
                ComponentFactory source = tool.getFactory();
                if (source instanceof SubcircuitFactory) {
                    SubcircuitFactory circFact = (SubcircuitFactory) source;
                    proj.setCurrentCircuit(circFact.getSubcircuit());
                    proj.getFrame().setEditorView(Frame.EDIT_LAYOUT);
                    if (lastSelected != null) {
View Full Code Here

            Library lib = ((ProjectExplorerLibraryNode) request).getValue();
            ProjectLibraryActions.doUnloadLibrary(proj, lib);
        } else if (request instanceof ProjectExplorerToolNode) {
            Tool tool = ((ProjectExplorerToolNode) request).getValue();
            if (tool instanceof AddTool) {
                ComponentFactory factory = ((AddTool) tool).getFactory();
                if (factory instanceof SubcircuitFactory) {
                    SubcircuitFactory circFact = (SubcircuitFactory) factory;
                    ProjectCircuitActions.doRemoveCircuit(proj, circFact.getSubcircuit());
                }
            }
View Full Code Here

TOP

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

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.