Package com.cburch.logisim.comp

Examples of com.cburch.logisim.comp.Component


          in.getAttributeSet().removeAttributeListener(myComponentListener);
          Collection<Component> rs = repl.getComponentsReplacing(comp);
          if (rs.isEmpty()) {
            removes.add(in);
          } else {
            Component r = rs.iterator().next();
            Instance rin = Instance.getInstanceFor(r);
            adds.remove(rin);
            replaces.put(in, rin);
          }
        }
View Full Code Here


    }

    public void circuitChanged(CircuitEvent event) {
      int act = event.getAction();
      if (act == CircuitEvent.ACTION_REMOVE) {
        Component c = (Component) event.getData();
        if (c == painter.getHaloedComponent()) {
          proj.getFrame().viewComponentAttributes(null, null);
        }
      } else if (act == CircuitEvent.ACTION_CLEAR) {
        if (painter.getHaloedComponent() != null) {
View Full Code Here

    }
  }
 
  void append(ReplacementMap next) {
    for (Map.Entry<Component,HashSet<Component>> e : next.map.entrySet()) {
      Component b = e.getKey();
      HashSet<Component> cs = e.getValue(); // what b is replaced by
      HashSet<Component> as = this.inverse.remove(b); // what was replaced to get b
      if (as == null) {                   // b pre-existed replacements so
        as = new HashSet<Component>(3); // we say it replaces itself.
        as.add(b);
      }
     
      for (Component a : as) {
        HashSet<Component> aDst = this.map.get(a);
        if (aDst == null) { // should happen when b pre-existed only
          aDst = new HashSet<Component>(cs.size());
          this.map.put(a, aDst);
        }
        aDst.remove(b);
        aDst.addAll(cs);
      }

      for (Component c : cs) {
        HashSet<Component> cSrc = this.inverse.get(c); // should always be null
        if (cSrc == null) {
          cSrc = new HashSet<Component>(as.size());
          this.inverse.put(c, cSrc);
        }
        cSrc.addAll(as);
      }
    }
   
    for (Map.Entry<Component,HashSet<Component>> e : next.inverse.entrySet()) {
      Component c = e.getKey();
      if (!inverse.containsKey(c)) {
        HashSet<Component> bs = e.getValue();
        if (!bs.isEmpty()) {
          System.err.println("internal error: component replaced but not represented"); //OK
        }
View Full Code Here

   
    private Map<Element, Component> loadKnownComponents(Element elt) {
      Map<Element, Component> known = new HashMap<Element, Component>();
      for (Element sub : XmlIterator.forChildElements(elt, "comp")) {
        try {
          Component comp = XmlCircuitReader.getComponent(sub, this);
          known.put(sub, comp);
        } catch (XmlReaderException e) { }
      }
      return known;
    }
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);
      if (bds.getX() < 0 || bds.getY() < 0) {
        canvas.setErrorMessage(Strings.getter("negativeCoordError"));
        return;
      }
View Full Code Here

    JPopupMenu menu;
    Project proj = canvas.getProject();
    Selection sel = proj.getSelection();
    Collection<Component> in_sel = sel.getComponentsContaining(pt, g);
    if (!in_sel.isEmpty()) {
      Component comp = in_sel.iterator().next();
      if (sel.getComponents().size() > 1) {
        menu = new MenuSelection(proj);
      } else {
        menu = new MenuComponent(proj,
          canvas.getCircuit(), comp);
        MenuExtender extender = (MenuExtender) comp.getFeature(MenuExtender.class);
        if (extender != null) extender.configureMenu(menu, proj);
      }
    } else {
      Collection<Component> cl = canvas.getCircuit().getAllContaining(pt, g);
      if (!cl.isEmpty()) {
        Component comp = cl.iterator().next();
        menu = new MenuComponent(proj,
          canvas.getCircuit(), comp);
        MenuExtender extender = (MenuExtender) comp.getFeature(MenuExtender.class);
        if (extender != null) extender.configureMenu(menu, proj);
      } else {
        menu = null;
      }
    }
View Full Code Here

  public void doIt(Project proj) {
    CircuitMutation xn = new CircuitMutation(circuit);
    int len = values.size();
    oldValues.clear();
    for (int i = 0; i < len; i++) {
      Component comp = comps.get(i);
      Attribute<Object> attr = attrs.get(i);
      Object value = values.get(i);
      if (circuit.contains(comp)) {
        oldValues.add(null);
        xn.set(comp, attr, value);
      } else {
        AttributeSet compAttrs = comp.getAttributeSet();
        oldValues.add(compAttrs.getValue(attr));
        compAttrs.setValue(attr, value);   
      }
    }
   
View Full Code Here

  @Override
  public void undo(Project proj) {
    if (xnReverse != null) xnReverse.execute();
    for (int i = oldValues.size() - 1; i >= 0; i--) {
      Component comp = comps.get(i);
      Attribute<Object> attr = attrs.get(i);
      Object value = oldValues.get(i);
      if (value != null) {
        comp.getAttributeSet().setValue(attr, value);
      }
    }
  }
View Full Code Here

    for (Element sub_elt : XmlIterator.forChildElements(elt)) {
      String sub_elt_name = sub_elt.getTagName();
      if (sub_elt_name.equals("comp")) {
        try {
          Component comp = knownComponents.get(sub_elt);
          if (comp == null) {
            comp = getComponent(sub_elt, reader);
          }
          mutator.add(dest, comp);
        } catch (XmlReaderException e) {
View Full Code Here

      java.awt.Component ret = super.getListCellRendererComponent(list,
        value, index, isSelected, hasFocus);
      if (ret instanceof JLabel && value instanceof SelectionItem) {
        JLabel label = (JLabel) ret;
        SelectionItem item = (SelectionItem) value;
        Component comp = item.getComponent();
        label.setIcon(new ComponentIcon(comp));
        label.setText(item.toString() + " - " + item.getRadix());
      }
      return ret;
    }
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.