Package com.cburch.logisim.comp

Examples of com.cburch.logisim.comp.Component


  public Bounds getBounds() {
    Bounds wireBounds = wires.getWireBounds();
    Iterator<Component> it = comps.iterator();
    if (!it.hasNext()) return wireBounds;
    Component first = it.next();
    Bounds firstBounds = first.getBounds();
    int xMin = firstBounds.getX();
    int yMin = firstBounds.getY();
    int xMax = xMin + firstBounds.getWidth();
    int yMax = yMin + firstBounds.getHeight();
    while (it.hasNext()) {
      Component c = it.next();
      Bounds bds = c.getBounds();
      int x0 = bds.getX(); int x1 = x0 + bds.getWidth();
      int y0 = bds.getY(); int y1 = y0 + bds.getHeight();
      if (x0 < xMin) xMin = x0;
      if (x1 > xMax) xMax = x1;
      if (y0 < yMin) yMin = y0;
View Full Code Here


  }

  private class MyComponentListener implements ComponentListener {
    public void endChanged(ComponentEvent e) {
      locker.checkForWritePermission("ends changed");
      Component comp = e.getSource();
      HashMap<Location,EndData> toRemove = toMap(e.getOldData());
      HashMap<Location,EndData> toAdd = toMap(e.getData());
      EndChangedTransaction xn = new EndChangedTransaction(comp, toRemove, toAdd);
      locker.execute(xn);
      fireEvent(CircuitEvent.ACTION_INVALIDATE, comp);
View Full Code Here

    oldAttrs = null;
    newAttrs = null;
    for (Component base : sel.getComponents()) {
      AttributeSet baseAttrs = base.getAttributeSet();
      AttributeSet copyAttrs = (AttributeSet) baseAttrs.clone();
      Component copy = base.getFactory().createComponent(base.getLocation(),
          copyAttrs);
      components.add(copy);
      if (baseAttrs == viewAttrs) {
        oldAttrs = baseAttrs;
        newAttrs = copyAttrs;
View Full Code Here

        break;
      }
    }

    public void circuitChanged(CircuitEvent e) {
      Component comp;
      switch (e.getAction()) {
      case CircuitEvent.ACTION_ADD:
        comp = (Component) e.getData();
        if (comp.getFactory() instanceof SubcircuitFactory) {
          SubcircuitFactory factory = (SubcircuitFactory) comp.getFactory();
          depends.addEdge(e.getCircuit(), factory.getSubcircuit());
        }
        break;
      case CircuitEvent.ACTION_REMOVE:
        comp = (Component) e.getData();
        if (comp.getFactory() instanceof SubcircuitFactory) {
          SubcircuitFactory factory = (SubcircuitFactory) comp.getFactory();
          boolean found = false;
          for (Component o : e.getCircuit().getNonWires()) {
            if (o.getFactory() == factory) {
              found = true;
              break;
View Full Code Here

    return true;
  }
 
  @Override
  public Set<Component> getHiddenComponents(Canvas canvas) {
    Component shorten = willShorten(start, cur);
    if (shorten != null) {
      return Collections.singleton(shorten);
    } else {
      return null;
    }
View Full Code Here

    haloedComponent = comp;
    exposeHaloedComponent(g);
  }

  private void exposeHaloedComponent(Graphics g) {
    Component c = haloedComponent;
    if (c == null) return;
    Bounds bds = c.getBounds(g).expand(7);
    int w = bds.getWidth();
    int h = bds.getHeight();
    double a = Canvas.SQRT_2 * w;
    double b = Canvas.SQRT_2 * h;
    canvas.repaint((int) Math.round(bds.getX() + w/2.0 - a/2.0),
View Full Code Here

      if (e != null && bundle != null && bundle.points != null) {
        for (Location p2 : bundle.points) {
          if (p2.equals(p)) continue;
          Expression old = expressionMap.get(p2);
          if (old != null) {
            Component eCause = expressionMap.currentCause;
            Component oldCause = expressionMap.causes.get(p2);
            if (eCause != oldCause && !old.equals(e)) {
              throw new AnalyzeException.Conflict();
            }
          }
          expressionMap.put(p2, e);
View Full Code Here

      if (copyFactory == null) {
        replMap.put(comp, null);
      } else if (copyFactory != compFactory) {
        Location copyLoc = comp.getLocation();
        AttributeSet copyAttrs = (AttributeSet) comp.getAttributeSet().clone();
        Component copy = copyFactory.createComponent(copyLoc, copyAttrs);
        replMap.put(comp, copy);
      }
    }
   
    if (dropped != null) {
View Full Code Here

   
    private Collection<Component> computeAdditions(Collection<Component> comps) {
      HashMap<Component, Component> replMap = componentReplacements;
      ArrayList<Component> toAdd = new ArrayList<Component>(comps.size());
      for (Iterator<Component> it = comps.iterator(); it.hasNext(); ) {
        Component comp = it.next();
        if (replMap.containsKey(comp)) {
          Component repl = replMap.get(comp);
          if (repl != null) {
            toAdd.add(repl);
          }
        } else {
          toAdd.add(comp);
View Full Code Here

      result.add(Wire.create(input, output));
      return;
    }

    Location compOutput = Location.create(x + layout.width, output.getY());
    Component parent = layout.factory.createComponent(compOutput,
        layout.attrs);
    result.add(parent);
    if (!compOutput.equals(output)) {
      result.add(Wire.create(compOutput, output));
    }
   
    // handle a NOT gate pattern implemented with NAND as a special case
    if (layout.factory == NandGate.FACTORY && layout.subLayouts.length == 1
        && layout.subLayouts[0].inputName == null) {
      Layout sub = layout.subLayouts[0];
     
      Location input0 = parent.getEnd(1).getLocation();
      Location input1 = parent.getEnd(2).getLocation();
     
      int midX = input0.getX() - 20;
      Location subOutput = Location.create(midX, output.getY());
      Location midInput0 = Location.create(midX, input0.getY());
      Location midInput1 = Location.create(midX, input1.getY());
      result.add(Wire.create(subOutput, midInput0));
      result.add(Wire.create(midInput0, input0));
      result.add(Wire.create(subOutput, midInput1));
      result.add(Wire.create(midInput1, input1));
     
      int subX = x + layout.subX - sub.width; 
      placeComponents(result, sub, subX, y + sub.y, inputData, subOutput);
      return;
    }
   
    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));
      }
    }

    for (int i = 0; i < layout.subLayouts.length; i++) {
      Layout sub = layout.subLayouts[i];
     
      int inputIndex = i + 1;
      Location subDest = parent.getEnd(inputIndex).getLocation();
     
      int subOutputY = y + sub.y + sub.outputY;
      if (sub.inputName != null) {
        int destY = subDest.getY();
        if (i == 0 && destY < subOutputY
View Full Code Here

TOP

Related Classes of com.cburch.logisim.comp.Component

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.