Package com.cburch.logisim.data

Examples of com.cburch.logisim.data.BitWidth


  public void paintInstance(InstancePainter painter) {
    Graphics g = painter.getGraphics();
    Bounds bds = painter.getBounds();
    Direction facing = painter.getAttributeValue(StdAttr.FACING);
    Object selectLoc = painter.getAttributeValue(Plexers.ATTR_SELECT_LOC);
    BitWidth select = painter.getAttributeValue(Plexers.ATTR_SELECT);
    boolean enable = painter.getAttributeValue(Plexers.ATTR_ENABLE).booleanValue();
    int selMult = selectLoc == Plexers.SELECT_TOP_RIGHT ? -1 : 1;
    int outputs = 1 << select.getWidth();

    // draw stubs for select and enable ports
    GraphicsUtil.switchToWidth(g, 3);
    boolean vertical = facing == Direction.NORTH || facing == Direction.SOUTH;
    int dx = vertical ? selMult : 0;
View Full Code Here


    Object oldValue = base.getValue(attr);
    if (oldValue == null ? value == null : oldValue.equals(value)) return;

    Integer newMax = null;
    if (attr == StdAttr.WIDTH) {
      BitWidth oldWidth = base.getValue(StdAttr.WIDTH);
      BitWidth newWidth = (BitWidth) value;
      int oldW = oldWidth.getWidth();
      int newW = newWidth.getWidth();
      Integer oldValObj = base.getValue(Counter.ATTR_MAX);
      int oldVal = oldValObj.intValue();
      base.setValue(StdAttr.WIDTH, newWidth);
      if (newW > oldW) {
        newMax = Integer.valueOf(newWidth.getMask());
      } else {
        int v = oldVal & newWidth.getMask();
        if (v != oldVal) {
          Integer newValObj = Integer.valueOf(v);
          base.setValue(Counter.ATTR_MAX, newValObj);
          fireAttributeValueChanged(Counter.ATTR_MAX, newValObj);
        }
      }
      fireAttributeValueChanged(StdAttr.WIDTH, newWidth);
    } else if (attr == Counter.ATTR_MAX) {
      int oldVal = ((Integer) value).intValue();
      BitWidth width = base.getValue(StdAttr.WIDTH);
      int newVal = oldVal & width.getMask();
      if (newVal != oldVal) {
        @SuppressWarnings("unchecked")
        V val = (V) Integer.valueOf(newVal);
        value = val;
      }
View Full Code Here

  }

  @Override
  public void paint(InstancePainter painter) {
    Bounds bds = painter.getBounds();
    BitWidth dataWidth = painter.getAttributeValue(StdAttr.WIDTH);
    int width = dataWidth == null ? 8 : dataWidth.getWidth();
    int len = (width + 3) / 4;

    Graphics g = painter.getGraphics();
    g.setColor(Color.RED);
    if (len > 4) {
View Full Code Here

  @Override
  public void keyTyped(InstanceState state, KeyEvent e) {
    int val = Character.digit(e.getKeyChar(), 16);
    if (val < 0) return;

    BitWidth dataWidth = state.getAttributeValue(StdAttr.WIDTH);
    if (dataWidth == null) dataWidth = BitWidth.create(8);
    curValue = (curValue * 16 + val) & dataWidth.getMask();
    RegisterData data = (RegisterData) state.getData();
    data.value = curValue;

    state.fireInvalidated();
  }
View Full Code Here

    if (data == null) {
      data = new StateData(state.getAttributeValue(ATTR_SEED));
      state.setData(data);
    }

    BitWidth dataWidth = state.getAttributeValue(StdAttr.WIDTH);
    Object triggerType = state.getAttributeValue(StdAttr.EDGE_TRIGGER);
    boolean triggered = data.updateClock(state.getPort(CK), triggerType);

    if (state.getPort(RST) == Value.TRUE) {
      data.reset(state.getAttributeValue(ATTR_SEED));
View Full Code Here

  @Override
  public void paintInstance(InstancePainter painter) {
    Graphics g = painter.getGraphics();
    Bounds bds = painter.getBounds();
    StateData state = (StateData) painter.getData();
    BitWidth widthVal = painter.getAttributeValue(StdAttr.WIDTH);
    int width = widthVal == null ? 8 : widthVal.getWidth();

    // draw boundary, label
    painter.drawBounds();
    painter.drawLabel();
View Full Code Here

    for (Map.Entry<Location, Instance> portLoc : portLocs.entrySet()) {
      i++;
      Location loc = portLoc.getKey();
      Instance pin = portLoc.getValue();
      String type = Pin.FACTORY.isInputPin(pin) ? Port.INPUT : Port.OUTPUT;
      BitWidth width = pin.getAttributeValue(StdAttr.WIDTH);
      ports[i] = new Port(loc.getX(), loc.getY(), type, width);
      pins[i] = pin;
     
      String label = pin.getAttributeValue(StdAttr.LABEL);
      if (label != null && label.length() > 0) {
View Full Code Here

      configurePorts(instance);
    }
  }
 
  private void configurePorts(Instance instance) {
    BitWidth widthObj = instance.getAttributeValue(StdAttr.WIDTH);
    int width = widthObj.getWidth();
    Boolean parallelObj = instance.getAttributeValue(ATTR_LOAD);
    Bounds bds = instance.getBounds();
    Port[] ps;
    if (parallelObj == null || parallelObj.booleanValue()) {
      Integer lenObj = instance.getAttributeValue(ATTR_LENGTH);
View Full Code Here

        bds.getY() + bds.getHeight() / 4,
        GraphicsUtil.H_CENTER, GraphicsUtil.V_CENTER);
  }
 
  private ShiftRegisterData getData(InstanceState state) {
    BitWidth width = state.getAttributeValue(StdAttr.WIDTH);
    Integer lenObj = state.getAttributeValue(ATTR_LENGTH);
    int length = lenObj == null ? 8 : lenObj.intValue();
    ShiftRegisterData data = (ShiftRegisterData) state.getData();
    if (data == null) {
      data = new ShiftRegisterData(width, length);
View Full Code Here

    painter.drawLabel();
   
    // draw state
    boolean parallel = painter.getAttributeValue(ATTR_LOAD).booleanValue();
    if (parallel) {
      BitWidth widObj = painter.getAttributeValue(StdAttr.WIDTH);
      int wid = widObj.getWidth();
      Integer lenObj = painter.getAttributeValue(ATTR_LENGTH);
      int len = lenObj == null ? 8 : lenObj.intValue();
      if (painter.getShowState()) {
        if (wid <= 4) {
          ShiftRegisterData data = getData(painter);
View Full Code Here

TOP

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

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.