Search in sources :

Example 6 with Attribute

use of com.cburch.logisim.data.Attribute in project logisim-evolution by reds-heig.

the class ToolAttributeAction method doIt.

@Override
public void doIt(Project proj) {
    AttributeSet attrs = config.getEvent().getAttributeSet();
    Map<Attribute<?>, Object> newValues = config.getAttributeValues();
    Map<Attribute<?>, Object> oldValues = new HashMap<Attribute<?>, Object>(newValues.size());
    for (Map.Entry<Attribute<?>, Object> entry : newValues.entrySet()) {
        @SuppressWarnings("unchecked") Attribute<Object> attr = (Attribute<Object>) entry.getKey();
        oldValues.put(attr, attrs.getValue(attr));
        attrs.setValue(attr, entry.getValue());
    }
    this.oldValues = oldValues;
}
Also used : AttributeSet(com.cburch.logisim.data.AttributeSet) Attribute(com.cburch.logisim.data.Attribute) HashMap(java.util.HashMap) Map(java.util.Map) HashMap(java.util.HashMap)

Example 7 with Attribute

use of com.cburch.logisim.data.Attribute in project logisim-evolution by reds-heig.

the class ToolAttributeAction method undo.

@Override
public void undo(Project proj) {
    AttributeSet attrs = config.getEvent().getAttributeSet();
    Map<Attribute<?>, Object> oldValues = this.oldValues;
    for (Map.Entry<Attribute<?>, Object> entry : oldValues.entrySet()) {
        @SuppressWarnings("unchecked") Attribute<Object> attr = (Attribute<Object>) entry.getKey();
        attrs.setValue(attr, entry.getValue());
    }
}
Also used : AttributeSet(com.cburch.logisim.data.AttributeSet) Attribute(com.cburch.logisim.data.Attribute) Map(java.util.Map) HashMap(java.util.HashMap)

Example 8 with Attribute

use of com.cburch.logisim.data.Attribute in project logisim-evolution by reds-heig.

the class InstanceComponent method computeEnds.

private void computeEnds() {
    List<Port> ports = portList;
    EndData[] esOld = endArray;
    int esOldLength = esOld == null ? 0 : esOld.length;
    EndData[] es = esOld;
    if (es == null || es.length != ports.size()) {
        es = new EndData[ports.size()];
        if (esOldLength > 0) {
            int toCopy = Math.min(esOldLength, es.length);
            System.arraycopy(esOld, 0, es, 0, toCopy);
        }
    }
    HashSet<Attribute<BitWidth>> wattrs = null;
    boolean toolTipFound = false;
    ArrayList<EndData> endsChangedOld = null;
    ArrayList<EndData> endsChangedNew = null;
    Iterator<Port> pit = ports.iterator();
    for (int i = 0; pit.hasNext() || i < esOldLength; i++) {
        Port p = pit.hasNext() ? pit.next() : null;
        EndData oldEnd = i < esOldLength ? esOld[i] : null;
        EndData newEnd = p == null ? null : p.toEnd(loc, attrs);
        if (oldEnd == null || !oldEnd.equals(newEnd)) {
            if (newEnd != null)
                es[i] = newEnd;
            if (endsChangedOld == null) {
                endsChangedOld = new ArrayList<EndData>();
                endsChangedNew = new ArrayList<EndData>();
            }
            endsChangedOld.add(oldEnd);
            endsChangedNew.add(newEnd);
        }
        if (p != null) {
            Attribute<BitWidth> attr = p.getWidthAttribute();
            if (attr != null) {
                if (wattrs == null) {
                    wattrs = new HashSet<Attribute<BitWidth>>();
                }
                wattrs.add(attr);
            }
            if (p.getToolTip() != null)
                toolTipFound = true;
        }
    }
    if (!attrListenRequested) {
        HashSet<Attribute<BitWidth>> oldWattrs = widthAttrs;
        if (wattrs == null && oldWattrs != null) {
            getAttributeSet().removeAttributeListener(this);
        } else if (wattrs != null && oldWattrs == null) {
            getAttributeSet().addAttributeListener(this);
        }
    }
    if (es != esOld) {
        endArray = es;
        endList = new UnmodifiableList<EndData>(es);
    }
    widthAttrs = wattrs;
    hasToolTips = toolTipFound;
    if (endsChangedOld != null) {
        fireEndsChanged(endsChangedOld, endsChangedNew);
    }
}
Also used : EndData(com.cburch.logisim.comp.EndData) Attribute(com.cburch.logisim.data.Attribute) BitWidth(com.cburch.logisim.data.BitWidth)

Example 9 with Attribute

use of com.cburch.logisim.data.Attribute in project logisim-evolution by reds-heig.

the class InstanceFactory method getDefaultAttributeValue.

@Override
public Object getDefaultAttributeValue(Attribute<?> attr, LogisimVersion ver) {
    Attribute<?>[] as = attrs;
    if (as != null) {
        for (int i = 0; i < as.length; i++) {
            if (as[i] == attr) {
                return defaults[i];
            }
        }
        return null;
    } else {
        AttributeSet dfltSet = defaultSet;
        if (dfltSet == null) {
            dfltSet = createAttributeSet();
            defaultSet = dfltSet;
        }
        return ((AttributeSet) dfltSet.clone()).getValue(attr);
    }
}
Also used : Attribute(com.cburch.logisim.data.Attribute) AttributeSet(com.cburch.logisim.data.AttributeSet)

Example 10 with Attribute

use of com.cburch.logisim.data.Attribute in project logisim-evolution by reds-heig.

the class DrawingAttributeSet method setValue.

public <V> void setValue(Attribute<V> attr, V value) {
    Iterator<Attribute<?>> ait = attrs.iterator();
    ListIterator<Object> vit = values.listIterator();
    while (ait.hasNext()) {
        Object a = ait.next();
        vit.next();
        if (a.equals(attr)) {
            vit.set(value);
            AttributeEvent e = new AttributeEvent(this, attr, value, null);
            for (AttributeListener listener : listeners) {
                listener.attributeValueChanged(e);
            }
            if (attr == DrawAttr.PAINT_TYPE) {
                e = new AttributeEvent(this);
                for (AttributeListener listener : listeners) {
                    listener.attributeListChanged(e);
                }
            }
            return;
        }
    }
    throw new IllegalArgumentException(attr.toString());
}
Also used : Attribute(com.cburch.logisim.data.Attribute) AbstractCanvasObject(com.cburch.draw.model.AbstractCanvasObject) CanvasObject(com.cburch.draw.model.CanvasObject) AttributeListener(com.cburch.logisim.data.AttributeListener) AttributeEvent(com.cburch.logisim.data.AttributeEvent)

Aggregations

Attribute (com.cburch.logisim.data.Attribute)21 AttributeSet (com.cburch.logisim.data.AttributeSet)12 AbstractCanvasObject (com.cburch.draw.model.AbstractCanvasObject)5 CanvasObject (com.cburch.draw.model.CanvasObject)4 Map (java.util.Map)4 Component (com.cburch.logisim.comp.Component)3 ComponentFactory (com.cburch.logisim.comp.ComponentFactory)3 Direction (com.cburch.logisim.data.Direction)3 HashMap (java.util.HashMap)3 AbstractAttributeSet (com.cburch.logisim.data.AbstractAttributeSet)2 Color (java.awt.Color)2 LogisimVersion (com.cburch.logisim.LogisimVersion)1 ReplacementMap (com.cburch.logisim.circuit.ReplacementMap)1 EndData (com.cburch.logisim.comp.EndData)1 AttributeEvent (com.cburch.logisim.data.AttributeEvent)1 AttributeListener (com.cburch.logisim.data.AttributeListener)1 BitWidth (com.cburch.logisim.data.BitWidth)1 Selection (com.cburch.logisim.gui.main.Selection)1 ToolAttributeAction (com.cburch.logisim.gui.main.ToolAttributeAction)1 Action (com.cburch.logisim.proj.Action)1