Package com.cburch.logisim.std.gates

Source Code of com.cburch.logisim.std.gates.NandGate

/* Copyright (c) 2010, Carl Burch. License information is located in the
* com.cburch.logisim.Main source code and at www.cburch.com/logisim/. */

package com.cburch.logisim.std.gates;

import java.awt.Graphics;

import com.cburch.logisim.analyze.model.Expression;
import com.cburch.logisim.analyze.model.Expressions;
import com.cburch.logisim.data.Value;
import com.cburch.logisim.instance.InstancePainter;
import com.cburch.logisim.instance.InstanceState;
import com.cburch.logisim.util.GraphicsUtil;
import static com.cburch.logisim.util.LocaleString.*;

class NandGate extends AbstractGate {
    public static NandGate FACTORY = new NandGate();

    private NandGate() {
        super("NAND Gate", getFromLocale("nandGateComponent"));
        setNegateOutput(true);
        setRectangularLabel(AndGate.FACTORY.getRectangularLabel(null));
        setIconNames("nandGate.svg", "nandGateRect.svg", "dinNandGate.svg");
    }

    @Override
    public void paintIconShaped(InstancePainter painter) {
        Graphics g = painter.getGraphics();
        int[] xp = new int[] { 8, 0, 0, 8 };
        int[] yp = new int[] { 2, 2, 18, 18 };
        g.drawPolyline(xp, yp, 4);
        GraphicsUtil.drawCenteredArc(g, 8, 10, 8, -90, 180);
        g.drawOval(16, 8, 4, 4);
    }

    @Override
    protected void paintShape(InstancePainter painter, int width, int height) {
        PainterShaped.paintAnd(painter, width, height);
    }

    @Override
    protected void paintDinShape(InstancePainter painter, int width, int height,
            int inputs) {
        PainterDin.paintAnd(painter, width, height, true);
    }

    @Override
    protected Value computeOutput(Value[] inputs, int numInputs,
            InstanceState state) {
        return GateFunctions.computeAnd(inputs, numInputs).not();
    }

    @Override
    protected Expression computeExpression(Expression[] inputs, int numInputs) {
        Expression ret = inputs[0];
        for (int i = 1; i < numInputs; i++) {
            ret = Expressions.and(ret, inputs[i]);
        }
        return Expressions.not(ret);
    }

    @Override
    protected Value getIdentity() { return Value.TRUE; }
}
TOP

Related Classes of com.cburch.logisim.std.gates.NandGate

TOP
Copyright © 2018 www.massapi.com. 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.