Package com.cburch.logisim.comp

Examples of com.cburch.logisim.comp.ComponentFactory


    HashMap<ComponentFactory, ComponentFactory> factoryReplacements;
    factoryReplacements = new HashMap<ComponentFactory, ComponentFactory>();
    for (Component comp : comps) {
      if (comp instanceof Wire) continue;
     
      ComponentFactory compFactory = comp.getFactory();
      ComponentFactory copyFactory = findComponentFactory(compFactory, libs, false);
      if (factoryReplacements.containsKey(compFactory)) {
        copyFactory = factoryReplacements.get(compFactory);
      } else if (copyFactory == null) {
        ComponentFactory candidate = findComponentFactory(compFactory, libs, true);
        if (candidate == null) {
          if (dropped == null) {
            dropped = new ArrayList<String>();
          }
          dropped.add(compFactory.getDisplayName());
View Full Code Here


    for (Library lib : libs) {
      for (Tool tool : lib.getTools()) {
        if (tool instanceof AddTool) {
          AddTool addTool = (AddTool) tool;
          if (name.equals(addTool.getName())) {
            ComponentFactory fact = addTool.getFactory(true);
            if (acceptNameMatch) {
              return fact;
            } else if (fact == factory) {
              return fact;
            } else if (fact.getClass() == factory.getClass()
                && !(fact instanceof SubcircuitFactory)) {
              return fact;
            }
          }
        }
View Full Code Here

    if (det instanceof CircuitDetermination.Input) {
      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);
    if (sub.length == 1) betweenWidth = 20;
    if (subWidth == 0) betweenWidth = 0;
    int width = subWidth + betweenWidth + bds.getWidth();
   
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

        singleInput.ys.add(spineLoc);
      }
      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
        /* This should no longer matter - the wires will be repaired
View Full Code Here

    HashMap<Component, KeyConfigurator> handlers = keyHandlers;
    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

    Circuit circ = null;

    ToolIcon(Tool tool) {
      this.tool = tool;
      if (tool instanceof AddTool) {
        ComponentFactory fact = ((AddTool) tool).getFactory(false);
        if (fact instanceof SubcircuitFactory) {
          circ = ((SubcircuitFactory) fact).getSubcircuit();
        }
      }
    }
View Full Code Here

    }
    return ret;
  }

  Element fromComponent(Component comp) {
    ComponentFactory source = comp.getFactory();
    Library lib = findLibrary(source);
    String lib_name;
    if (lib == null) {
      loader.showError(source.getName() + " component not found");
      return null;
    } else if (lib == file) {
      lib_name = null;
    } else {
      lib_name = libs.get(lib);
      if (lib_name == null) {
        loader.showError("unknown library within file");
        return null;
      }
    }

    Element ret = doc.createElement("comp");
    if (lib_name != null) ret.setAttribute("lib", lib_name);
    ret.setAttribute("name", source.getName());
    ret.setAttribute("loc", comp.getLocation().toString());
    addAttributeSetContent(ret, comp.getAttributeSet(), comp.getFactory());
    return ret;
  }
View Full Code Here

        toolMap = new HashMap<Tool,Tool>();
        for (Tool oldTool : old.getTools()) {
            Tool newTool = base.getTool(oldTool.getName());
            toolMap.put(oldTool, newTool);
            if (oldTool instanceof AddTool) {
                ComponentFactory oldFactory = ((AddTool) oldTool).getFactory();
                if (newTool != null && newTool instanceof AddTool) {
                    ComponentFactory newFactory = ((AddTool) newTool).getFactory();
                    componentMap.put(oldFactory, newFactory);
                } else {
                    componentMap.put(oldFactory, null);
                }
            }
View Full Code Here

        }
        if (toReplace != null) {
            CircuitMutation xn = new CircuitMutation(circuit);
            for (Component comp : toReplace) {
                xn.remove(comp);
                ComponentFactory factory = compMap.get(comp.getFactory());
                if (factory != null) {
                    AttributeSet newAttrs = createAttributes(factory, comp.getAttributeSet());
                    xn.add(factory.createComponent(comp.getLocation(), newAttrs));
                }
            }
            xn.execute();
        }
    }
View Full Code Here

TOP

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

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.