Package com.cburch.logisim.data

Examples of com.cburch.logisim.data.AttributeSet


      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()];
    int subWidth = 0; // maximum width of sublayouts
    int subHeight = 0; // total height of sublayouts
    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);
View Full Code Here


      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));
      }
    }

    for (int i = 0; i < layout.subLayouts.length; i++) {
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

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

    public ConstantExpression(Instance instance) {
      this.instance = instance;
    }
   
    public void computeExpression(Map<Location,Expression> expressionMap) {
      AttributeSet attrs = instance.getAttributeSet();
      int intValue = attrs.getValue(ATTR_VALUE).intValue();

      expressionMap.put(instance.getLocation(),
          Expressions.constant(intValue));
    }
View Full Code Here

  }
 
  @Override
  public AttributeSet createAttributeSet() {
    Attribute<?>[] as = attrs;
    AttributeSet ret = as == null ? AttributeSets.EMPTY : AttributeSets.fixedSet(as, defaults);
    return ret;
  }
View Full Code Here

          return defaults[i];
        }
      }
      return null;
    } else {
      AttributeSet dfltSet = defaultSet;
      if (dfltSet == null) {
        dfltSet = createAttributeSet();
        defaultSet = dfltSet;
      }
      return dfltSet.getValue(attr);
    }
  }
View Full Code Here

    if (handlers == null) {
      handlers = new HashMap<Component, KeyConfigurator>();
      Selection sel = canvas.getSelection();
      for (Component comp : sel.getComponents()) {
        ComponentFactory factory = comp.getFactory();
        AttributeSet attrs = comp.getAttributeSet();
        Object handler = factory.getFeature(KeyConfigurator.class, attrs);
        if (handler != null) {
          KeyConfigurator base = (KeyConfigurator) handler;
          handlers.put(comp, base.clone());
        }
View Full Code Here

    this.fieldX = x;
    this.fieldY = y;
    this.halign = halign;
    this.valign = valign;
    boolean shouldReg = shouldRegister();
    AttributeSet attrs = comp.getAttributeSet();
    if (!wasReg && shouldReg) attrs.addAttributeListener(this);
    if (wasReg && !shouldReg) attrs.removeAttributeListener(this);
   
    updateField(attrs);
  }
View Full Code Here

    }
    libs.put(lib, name);
    ret.setAttribute("name", name);
    ret.setAttribute("desc", desc);
    for (Tool t : lib.getTools()) {
      AttributeSet attrs = t.getAttributeSet();
      if (attrs != null) {
        Element toAdd = doc.createElement("tool");
        toAdd.setAttribute("name", t.getName());
        addAttributeSetContent(toAdd, attrs, t);
        if (toAdd.getChildNodes().getLength() > 0) {
View Full Code Here

TOP

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

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.