Search in sources :

Example 66 with Value

use of com.cburch.logisim.data.Value in project logisim-evolution by reds-heig.

the class TablePanel method paintComponent.

@Override
public void paintComponent(Graphics g) {
    super.paintComponent(g);
    Dimension sz = getSize();
    int top = Math.max(0, (sz.height - tableHeight) / 2);
    int left = Math.max(0, (sz.width - tableWidth) / 2);
    Model model = getModel();
    if (model == null)
        return;
    Selection sel = model.getSelection();
    int columns = sel.size();
    if (columns == 0) {
        g.setFont(BODY_FONT);
        GraphicsUtil.drawCenteredText(g, Strings.get("tableEmptyMessage"), sz.width / 2, sz.height / 2);
        return;
    }
    g.setColor(Color.GRAY);
    int lineY = top + cellHeight + HEADER_SEP / 2;
    g.drawLine(left, lineY, left + tableWidth, lineY);
    g.setColor(Color.BLACK);
    g.setFont(HEAD_FONT);
    FontMetrics headerMetric = g.getFontMetrics();
    int x = left;
    int y = top + headerMetric.getAscent() + 1;
    for (int i = 0; i < columns; i++) {
        x = paintHeader(sel.get(i).toShortString(), x, y, g, headerMetric);
    }
    g.setFont(BODY_FONT);
    FontMetrics bodyMetric = g.getFontMetrics();
    Rectangle clip = g.getClipBounds();
    int firstRow = Math.max(0, (clip.y - y) / cellHeight - 1);
    int lastRow = Math.min(rowCount, 2 + (clip.y + clip.height - y) / cellHeight);
    int y0 = top + cellHeight + HEADER_SEP;
    x = left;
    for (int col = 0; col < columns; col++) {
        SelectionItem item = sel.get(col);
        ValueLog log = model.getValueLog(item);
        int radix = item.getRadix();
        int offs = rowCount - log.size();
        y = y0 + Math.max(offs, firstRow) * cellHeight;
        for (int row = Math.max(offs, firstRow); row < lastRow; row++) {
            Value val = log.get(row - offs);
            String label = val.toDisplayString(radix);
            int width = bodyMetric.stringWidth(label);
            g.drawString(label, x + (cellWidth - width) / 2, y + bodyMetric.getAscent());
            y += cellHeight;
        }
        x += cellWidth + COLUMN_SEP;
    }
}
Also used : FontMetrics(java.awt.FontMetrics) Rectangle(java.awt.Rectangle) Value(com.cburch.logisim.data.Value) Dimension(java.awt.Dimension)

Example 67 with Value

use of com.cburch.logisim.data.Value in project logisim-evolution by reds-heig.

the class Pin method propagate.

@Override
public void propagate(InstanceState state) {
    PinAttributes attrs = (PinAttributes) state.getAttributeSet();
    PinState q = getState(state);
    if (attrs.type == EndData.OUTPUT_ONLY) {
        Value found = state.getPortValue(0);
        q.intendedValue = found;
        q.foundValue = found;
        state.setPort(0, Value.createUnknown(attrs.width), 1);
    } else {
        Value found = state.getPortValue(0);
        Value toSend = q.intendedValue;
        Object pull = attrs.pull;
        Value pullTo = null;
        if (pull == PULL_DOWN) {
            pullTo = Value.FALSE;
        } else if (pull == PULL_UP) {
            pullTo = Value.TRUE;
        } else if (!attrs.threeState && !state.isCircuitRoot()) {
            pullTo = Value.FALSE;
        }
        if (pullTo != null) {
            toSend = pull2(toSend, attrs.width, pullTo);
            if (state.isCircuitRoot()) {
                q.intendedValue = toSend;
            }
        }
        q.foundValue = found;
        if (!toSend.equals(found)) {
            // ignore if no change
            state.setPort(0, toSend, 1);
        }
    }
}
Also used : Value(com.cburch.logisim.data.Value)

Example 68 with Value

use of com.cburch.logisim.data.Value in project logisim-evolution by reds-heig.

the class Pin method getState.

private static PinState getState(InstanceState state) {
    PinAttributes attrs = (PinAttributes) state.getAttributeSet();
    BitWidth width = attrs.width;
    PinState ret = (PinState) state.getData();
    if (ret == null) {
        Value val = attrs.threeState ? Value.UNKNOWN : Value.FALSE;
        if (width.getWidth() > 1) {
            Value[] arr = new Value[width.getWidth()];
            java.util.Arrays.fill(arr, val);
            val = Value.create(arr);
        }
        ret = new PinState(val, val);
        state.setData(ret);
    }
    if (ret.intendedValue.getWidth() != width.getWidth()) {
        ret.intendedValue = ret.intendedValue.extendWidth(width.getWidth(), attrs.threeState ? Value.UNKNOWN : Value.FALSE);
    }
    if (ret.foundValue.getWidth() != width.getWidth()) {
        ret.foundValue = ret.foundValue.extendWidth(width.getWidth(), Value.UNKNOWN);
    }
    return ret;
}
Also used : BitWidth(com.cburch.logisim.data.BitWidth) Value(com.cburch.logisim.data.Value)

Example 69 with Value

use of com.cburch.logisim.data.Value in project logisim-evolution by reds-heig.

the class Probe method paintInstance.

@Override
public void paintInstance(InstancePainter painter) {
    Value value = getValue(painter);
    Graphics g = painter.getGraphics();
    // intentionally with no graphics
    Bounds bds = painter.getBounds();
    // object - we don't want label
    // included
    int x = bds.getX();
    int y = bds.getY();
    Color back = new Color(0xff, 0xf0, 0x99);
    if (value.getWidth() <= 1) {
        g.setColor(back);
        g.fillOval(x + 1, y + 1, bds.getWidth() - 2, bds.getHeight() - 2);
        g.setColor(Color.lightGray);
        g.drawOval(x + 1, y + 1, bds.getWidth() - 2, bds.getHeight() - 2);
    } else {
        g.setColor(back);
        g.fillRoundRect(x + 1, y + 1, bds.getWidth() - 2, bds.getHeight() - 2, 20, 20);
        g.setColor(Color.lightGray);
        g.drawRoundRect(x + 1, y + 1, bds.getWidth() - 2, bds.getHeight() - 2, 20, 20);
    }
    g.setColor(Color.GRAY);
    painter.drawLabel();
    g.setColor(Color.DARK_GRAY);
    if (!painter.getShowState()) {
        if (value.getWidth() > 0) {
            GraphicsUtil.drawCenteredText(g, "x" + value.getWidth(), bds.getX() + bds.getWidth() / 2, bds.getY() + bds.getHeight() / 2);
        }
    } else {
        paintValue(painter, value);
    }
    painter.drawPorts();
}
Also used : Graphics(java.awt.Graphics) Bounds(com.cburch.logisim.data.Bounds) Color(java.awt.Color) Value(com.cburch.logisim.data.Value)

Example 70 with Value

use of com.cburch.logisim.data.Value in project logisim-evolution by reds-heig.

the class PullResistor method paintGhost.

@Override
public void paintGhost(InstancePainter painter) {
    Value pull = getPullValue(painter.getAttributeSet());
    paintBase(painter, pull, null, null);
}
Also used : Value(com.cburch.logisim.data.Value)

Aggregations

Value (com.cburch.logisim.data.Value)89 BitWidth (com.cburch.logisim.data.BitWidth)30 Graphics (java.awt.Graphics)15 Location (com.cburch.logisim.data.Location)9 Color (java.awt.Color)8 Bounds (com.cburch.logisim.data.Bounds)7 InstanceDataSingleton (com.cburch.logisim.instance.InstanceDataSingleton)7 AttributeSet (com.cburch.logisim.data.AttributeSet)6 InstanceState (com.cburch.logisim.instance.InstanceState)6 Direction (com.cburch.logisim.data.Direction)3 Instance (com.cburch.logisim.instance.Instance)3 Port (com.cburch.logisim.instance.Port)3 CircuitState (com.cburch.logisim.circuit.CircuitState)2 Component (com.cburch.logisim.comp.Component)2 FailException (com.cburch.logisim.data.FailException)2 TestException (com.cburch.logisim.data.TestException)2 Dimension (java.awt.Dimension)2 FontMetrics (java.awt.FontMetrics)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2