Package com.cburch.logisim.circuit

Examples of com.cburch.logisim.circuit.Circuit


    considerRepairs(doc, elt);
    LogisimFile file = new LogisimFile((Loader) loader);
    ReadContext context = new ReadContext(file);
    context.toLogisimFile(elt);
    if (file.getCircuitCount() == 0) {
      file.addCircuit(new Circuit("main"));
    }
    if (context.messages.size() > 0) {
      StringBuilder all = new StringBuilder();
      for (String msg : context.messages) {
        all.append(msg);
View Full Code Here


      for (Element circElt : XmlIterator.forChildElements(elt, "circuit")) {
        String name = circElt.getAttribute("name");
        if (name == null || name.equals("")) {
          addError(Strings.get("circNameMissingError"), "C??");
        }
        CircuitData circData = new CircuitData(circElt, new Circuit(name));
        file.addCircuit(circData.circuit);
        circData.knownComponents = loadKnownComponents(circElt);
        for (Element appearElt : XmlIterator.forChildElements(circElt, "appear")) {
          loadAppearance(appearElt, circData, name + ".appear");
        }
        circuitsData.add(circData);
      }

      // third, process the other child elements
      for (Element sub_elt : XmlIterator.forChildElements(elt)) {
        String name = sub_elt.getTagName();
        if (name.equals("circuit") || name.equals("lib")) {
          ; // Nothing to do: Done earlier.
        } else if (name.equals("options")) {
          try {
            initAttributeSet(sub_elt, file.getOptions().getAttributeSet(), null);
          } catch (XmlReaderException e) {
            addErrors(e, "options");
          }
        } else if (name.equals("mappings")) {
          initMouseMappings(sub_elt);
        } else if (name.equals("toolbar")) {
          initToolbarData(sub_elt);
        } else if (name.equals("main")) {
          String main = sub_elt.getAttribute("name");
          Circuit circ = file.getCircuit(main);
          if (circ != null) {
            file.setMainCircuit(circ);
          }
        } else if (name.equals("message")) {
          file.addMessage(sub_elt.getAttribute("value"));
View Full Code Here

        }
      } else if (type == ProjectEvent.ACTION_MERGE) {
        SelectionSave save = savedSelections.get(event.getOldData());
        savedSelections.put((Action) event.getData(), save);
      } else if (type == ProjectEvent.UNDO_COMPLETE) {
        Circuit circ = event.getProject().getCurrentCircuit();
        Action act = (Action) event.getData();
        SelectionSave save = savedSelections.get(act);
        if (save != null) {
          lifted.clear();
          selected.clear();
          for (int i = 0; i < 2; i++) {
            Component[] cs;
            if (i == 0) cs = save.getFloatingComponents();
            else cs = save.getAnchoredComponents();

            if (cs != null) {
              for (Component c : cs) {
                if (circ.contains(c)) {
                  selected.add(c);
                } else {
                  lifted.add(c);
                }
              }
View Full Code Here

      }
    }
   
    public void circuitChanged(CircuitEvent event) {
      if (event.getAction() == CircuitEvent.TRANSACTION_DONE) {
        Circuit circuit = event.getCircuit();
        ReplacementMap repl = event.getResult().getReplacementMap(circuit);
        boolean change = false;
       
        ArrayList<Component> oldAnchored;
        oldAnchored = new ArrayList<Component>(getComponents());
        for (Component comp : oldAnchored) {
          Collection<Component> replacedBy = repl.get(comp);
          if (replacedBy != null) {
            change = true;
            selected.remove(comp);
            lifted.remove(comp);
            for (Component add : replacedBy) {
              if (circuit.contains(add)) {
                selected.add(add);
              } else {
                lifted.add(add);
              }
            }
View Full Code Here

  }
 
  public void setCircuit(Project proj, CircuitState circuitState) {
    this.proj = proj;
    this.circuitState = circuitState;
    Circuit circuit = circuitState.getCircuit();
    setModel(circuit.getAppearance(), this);
  }
View Full Code Here

  private ProjectCircuitActions() { }
 
  public static void doAddCircuit(Project proj) {
    String name = promptForCircuitName(proj.getFrame(), proj.getLogisimFile(), "");
    if (name != null) {
      Circuit circuit = new Circuit(name);
      proj.doAction(LogisimFileActions.addCircuit(circuit));
      proj.setCurrentCircuit(circuit);
    }
  }
View Full Code Here

    return grid;
  }
 
  @Override
  public void doAction(Action canvasAction) {
    Circuit circuit = circuitState.getCircuit();
    if (!proj.getLogisimFile().contains(circuit)) {
      return;
    }
   
    if (canvasAction instanceof ModelReorderAction) {
View Full Code Here

  }

  @Override
  public void mousePressed(Canvas canvas, Graphics g, MouseEvent e) {
    // verify the addition would be valid
    Circuit circ = canvas.getCircuit();
    if (!canvas.getProject().getLogisimFile().contains(circ)) {
      canvas.setErrorMessage(Strings.getter("cannotModifyError"));
      return;
    }
    if (factory instanceof SubcircuitFactory) {
View Full Code Here

  @Override
  public void mouseReleased(Canvas canvas, Graphics g,
      MouseEvent e) {
    Component added = null;
    if (state == SHOW_ADD) {
      Circuit circ = canvas.getCircuit();
      if (!canvas.getProject().getLogisimFile().contains(circ)) return;
      if (shouldSnap) Canvas.snapToGrid(e);
      moveTo(canvas, g, e.getX(), e.getY());

      Location loc = Location.create(e.getX(), e.getY());
      AttributeSet attrsCopy = (AttributeSet) attrs.clone();
      ComponentFactory source = getFactory();
      if (source == null) return;
      Component c = source.createComponent(loc, attrsCopy);
     
      if (circ.hasConflict(c)) {
        canvas.setErrorMessage(Strings.getter("exclusiveError"));
        return;
      }
     
      Bounds bds = c.getBounds(g);
View Full Code Here

 
  private static void replaceAll(Map<ComponentFactory,ComponentFactory> compMap,
      Map<Tool,Tool> toolMap) {
    for (Project proj : Projects.getOpenProjects()) {
      Tool oldTool = proj.getTool();
      Circuit oldCircuit = proj.getCurrentCircuit();
      if (toolMap.containsKey(oldTool)) {
        proj.setTool(toolMap.get(oldTool));
      }
      SubcircuitFactory oldFactory = oldCircuit.getSubcircuitFactory();
      if (compMap.containsKey(oldFactory)) {
        SubcircuitFactory newFactory;
        newFactory = (SubcircuitFactory) compMap.get(oldFactory);
        proj.setCurrentCircuit(newFactory.getSubcircuit());
      }
View Full Code Here

TOP

Related Classes of com.cburch.logisim.circuit.Circuit

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.