Package com.cburch.logisim.data

Examples of com.cburch.logisim.data.Value


    } else {
      try {
        int val = Integer.parseInt("" + e.getKeyChar(), 16);
        BitWidth widObj = state.getAttributeValue(StdAttr.WIDTH);
        if ((val & ~widObj.getMask()) != 0) return;
        Value valObj = Value.createKnown(widObj, val);
        ShiftRegisterData data = (ShiftRegisterData) state.getData();
        int i = data.getLength() - 1 - loc;
        if (!data.get(i).equals(valObj)) {
          data.set(i, valObj);
          state.fireInvalidated();
View Full Code Here


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

    GraphicsUtil.switchToWidth(g, 2);
    int x0 = xMid - diam / 2;
    Color oldColor = g.getColor();
    if (painter.getShowState()) {
      Value val = painter.getPort(0);
      g.setColor(val.getColor());
    }
    g.drawLine(x0 + diam, 0, 0, 0);
    g.setColor(oldColor);
    if (height <= diam) {
      g.drawArc(x0, y0, diam, diam, -90, 180);
View Full Code Here

    boolean changed = false;
    for (int i = selection.size() - 1; i >= 0; i--) {
      SelectionItem item = selection.get(i);
      vals[i] = item.fetchValue(circuitState);
      if (!changed) {
        Value v = getValueLog(item).getLast();
        changed = v == null ? vals[i] != null : !v.equals(vals[i]);
      }
    }
    if (changed) {
      for (int i = selection.size() - 1; i >= 0; i--) {
        SelectionItem item = selection.get(i);
View Full Code Here

    state.setPort(OUTPUT, computeOutput(state), 1);
  }
 
  private Value computeOutput(InstanceState state) {
    BitWidth width = state.getAttributeValue(StdAttr.WIDTH);
    Value gate = state.getPort(GATE);
    Value input = state.getPort(INPUT);
    Value desired = state.getAttributeValue(ATTR_TYPE) == TYPE_P
      ? Value.FALSE : Value.TRUE;

    if (!gate.isFullyDefined()) {
      if (input.isFullyDefined()) {
        return Value.createError(width);
View Full Code Here

    Color platform;
    if (!isGhost && painter.getShowState()) {
      gate = painter.getPort(GATE).getColor();
      input = painter.getPort(INPUT).getColor();
      output = painter.getPort(OUTPUT).getColor();
      Value out = computeOutput(painter);
      platform = out.isUnknown() ? Value.UNKNOWN.getColor() : out.getColor();
    } else {
      Color base = g.getColor();
      gate = base;
      input = base;
      output = base;
View Full Code Here

    else if (dir == Direction.SOUTH) { pinx = 9; piny = 16; }

    Graphics g = painter.getGraphics();
    if (w == 1) {
      int v = painter.getAttributeValue(ATTR_VALUE).intValue();
      Value val = v == 1 ? Value.TRUE : Value.FALSE;
      g.setColor(val.getColor());
      GraphicsUtil.drawCenteredText(g, "" + v, 10, 9);
    } else {
      g.setFont(g.getFont().deriveFont(9.0f));
      GraphicsUtil.drawCenteredText(g, "x" + w, 10, 9);
    }
View Full Code Here

  @Override
  public void paintInstance(InstancePainter painter) {
    Bounds bds = painter.getOffsetBounds();
    BitWidth width = painter.getAttributeValue(StdAttr.WIDTH);
    int intValue = painter.getAttributeValue(ATTR_VALUE).intValue();
    Value v = Value.createKnown(width, intValue);
    Location loc = painter.getLocation();
    int x = loc.getX();
    int y = loc.getY();

    Graphics g = painter.getGraphics();
    if (painter.shouldDrawColor()) {
      g.setColor(BACKGROUND_COLOR);
      g.fillRect(x + bds.getX(), y + bds.getY(), bds.getWidth(), bds.getHeight());
    }
    if (v.getWidth() == 1) {
      if (painter.shouldDrawColor()) g.setColor(v.getColor());
      GraphicsUtil.drawCenteredText(g, v.toString(),
        x + bds.getX() + bds.getWidth() / 2,
        y + bds.getY() + bds.getHeight() / 2 - 2);
    } else {
      g.setColor(Color.BLACK);
      GraphicsUtil.drawCenteredText(g, v.toHexString(),
        x + bds.getX() + bds.getWidth() / 2,
        y + bds.getY() + bds.getHeight() / 2 - 2);
    }
    painter.drawPorts();
  }
View Full Code Here

      bds.getWidth() - 1, bds.getHeight() - 1);
  }

  @Override
  public void paintInstance(InstancePainter painter) {
    Value value = getValue(painter);
   
    Graphics g = painter.getGraphics();
    Bounds bds = painter.getBounds(); // intentionally with no graphics object - we don't want label included
    int x = bds.getX();
    int y = bds.getY();
    g.setColor(Color.WHITE);
    g.fillRect(x + 5, y + 5, bds.getWidth() - 10, bds.getHeight() - 10);
    g.setColor(Color.GRAY);
    if (value.getWidth() <= 1) {
      g.drawOval(x + 1, y + 1,
        bds.getWidth() - 2, bds.getHeight() - 2);
    } else {
      g.drawRoundRect(x + 1, y + 1,
        bds.getWidth() - 2, bds.getHeight() - 2, 6, 6);
    }

    g.setColor(Color.BLACK);
    painter.drawLabel();

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

  }

  @Override
  public void propagate(InstanceState state) {
    StateData oldData = (StateData) state.getData();
    Value oldValue = oldData == null ? Value.NIL : oldData.curValue;
    Value newValue = state.getPort(0);
    boolean same = oldValue == null ? newValue == null : oldValue.equals(newValue);
    if (!same) {
      if (oldData == null) {
        oldData = new StateData();
        oldData.curValue = newValue;
        state.setData(oldData);
      } else {
        oldData.curValue = newValue;
      }
      int oldWidth = oldValue == null ? 1 : oldValue.getBitWidth().getWidth();
      int newWidth = newValue.getBitWidth().getWidth();
      if (oldWidth != newWidth) {
        ProbeAttributes attrs = (ProbeAttributes) state.getAttributeSet();
        attrs.width = newValue.getBitWidth();
        state.getInstance().recomputeBounds();
        configureLabel(state.getInstance());
      }
      state.fireInvalidated();
    }
View Full Code Here

TOP

Related Classes of com.cburch.logisim.data.Value

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.