Search in sources :

Example 1 with Attribute

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

the class SelectionAttributes method updateList.

private void updateList(boolean ignoreIfSelectionSame) {
    Selection sel = selection;
    Set<Component> oldSel = selected;
    Set<Component> newSel;
    if (sel == null) {
        newSel = Collections.emptySet();
    } else {
        newSel = createSet(sel.getComponents());
    }
    if (haveSameElements(newSel, oldSel)) {
        if (ignoreIfSelectionSame) {
            return;
        }
        newSel = oldSel;
    } else {
        for (Component o : oldSel) {
            if (!newSel.contains(o)) {
                o.getAttributeSet().removeAttributeListener(listener);
            }
        }
        for (Component o : newSel) {
            if (!oldSel.contains(o)) {
                o.getAttributeSet().addAttributeListener(listener);
            }
        }
    }
    LinkedHashMap<Attribute<Object>, Object> attrMap = computeAttributes(newSel);
    boolean same = isSame(attrMap, this.attrs, this.values);
    if (same) {
        if (newSel != oldSel) {
            this.selected = newSel;
        }
    } else {
        Attribute<?>[] oldAttrs = this.attrs;
        Object[] oldValues = this.values;
        Attribute<?>[] newAttrs = new Attribute[attrMap.size()];
        Object[] newValues = new Object[newAttrs.length];
        boolean[] newReadOnly = new boolean[newAttrs.length];
        int i = -1;
        for (Map.Entry<Attribute<Object>, Object> entry : attrMap.entrySet()) {
            i++;
            newAttrs[i] = entry.getKey();
            newValues[i] = entry.getValue();
            newReadOnly[i] = computeReadOnly(newSel, newAttrs[i]);
        }
        if (newSel != oldSel) {
            this.selected = newSel;
        }
        this.attrs = newAttrs;
        this.attrsView = new UnmodifiableList<Attribute<?>>(newAttrs);
        this.values = newValues;
        this.readOnly = newReadOnly;
        boolean listSame = oldAttrs != null && oldAttrs.length == newAttrs.length;
        if (listSame) {
            for (i = 0; i < oldAttrs.length; i++) {
                if (!oldAttrs[i].equals(newAttrs[i])) {
                    listSame = false;
                    break;
                }
            }
        }
        if (listSame) {
            for (i = 0; i < oldValues.length; i++) {
                Object oldVal = oldValues[i];
                Object newVal = newValues[i];
                boolean sameVals = oldVal == null ? newVal == null : oldVal.equals(newVal);
                if (!sameVals) {
                    @SuppressWarnings("unchecked") Attribute<Object> attr = (Attribute<Object>) oldAttrs[i];
                    fireAttributeValueChanged(attr, newVal, oldVal);
                }
            }
        } else {
            fireAttributeListChanged();
        }
    }
}
Also used : Attribute(com.cburch.logisim.data.Attribute) Component(com.cburch.logisim.comp.Component) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 2 with Attribute

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

the class AddTool method setFacing.

private void setFacing(Canvas canvas, Direction facing) {
    ComponentFactory source = getFactory();
    if (source == null)
        return;
    AttributeSet base = getBaseAttributes();
    Object feature = source.getFeature(ComponentFactory.FACING_ATTRIBUTE_KEY, base);
    @SuppressWarnings("unchecked") Attribute<Direction> attr = (Attribute<Direction>) feature;
    if (attr != null) {
        Action act = ToolAttributeAction.create(this, attr, facing);
        canvas.getProject().doAction(act);
    }
}
Also used : Action(com.cburch.logisim.proj.Action) ToolAttributeAction(com.cburch.logisim.gui.main.ToolAttributeAction) AttributeSet(com.cburch.logisim.data.AttributeSet) Attribute(com.cburch.logisim.data.Attribute) ComponentFactory(com.cburch.logisim.comp.ComponentFactory) Direction(com.cburch.logisim.data.Direction)

Example 3 with Attribute

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

the class DrawingAttributeSet method getValue.

@SuppressWarnings("unchecked")
public <V> V getValue(Attribute<V> attr) {
    Iterator<Attribute<?>> ait = attrs.iterator();
    Iterator<Object> vit = values.iterator();
    while (ait.hasNext()) {
        Object a = ait.next();
        Object v = vit.next();
        if (a.equals(attr)) {
            return (V) v;
        }
    }
    return null;
}
Also used : Attribute(com.cburch.logisim.data.Attribute) AbstractCanvasObject(com.cburch.draw.model.AbstractCanvasObject) CanvasObject(com.cburch.draw.model.CanvasObject)

Example 4 with Attribute

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

the class DrawingAttributeSet method applyTo.

public <E extends CanvasObject> E applyTo(E drawable) {
    AbstractCanvasObject d = (AbstractCanvasObject) drawable;
    // use a for(i...) loop since the attribute list may change as we go on
    for (int i = 0; i < d.getAttributes().size(); i++) {
        Attribute<?> attr = d.getAttributes().get(i);
        @SuppressWarnings("unchecked") Attribute<Object> a = (Attribute<Object>) attr;
        if (attr == DrawAttr.FILL_COLOR && this.containsAttribute(DrawAttr.TEXT_DEFAULT_FILL)) {
            d.setValue(a, this.getValue(DrawAttr.TEXT_DEFAULT_FILL));
        } else if (this.containsAttribute(a)) {
            Object value = this.getValue(a);
            d.setValue(a, value);
        }
    }
    return drawable;
}
Also used : Attribute(com.cburch.logisim.data.Attribute) AbstractCanvasObject(com.cburch.draw.model.AbstractCanvasObject) AbstractCanvasObject(com.cburch.draw.model.AbstractCanvasObject) CanvasObject(com.cburch.draw.model.CanvasObject)

Example 5 with Attribute

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

the class SelectionAttributes method setValue.

@Override
public <V> void setValue(Attribute<V> attr, V value) {
    Attribute<?>[] attrs = this.selAttrs;
    Object[] values = this.selValues;
    for (int i = 0; i < attrs.length; i++) {
        if (attrs[i] == attr) {
            boolean same = value == null ? values[i] == null : value.equals(values[i]);
            if (!same) {
                values[i] = value;
                for (AttributeSet objAttrs : selected.keySet()) {
                    objAttrs.setValue(attr, value);
                }
            }
            break;
        }
    }
}
Also used : Attribute(com.cburch.logisim.data.Attribute) AbstractAttributeSet(com.cburch.logisim.data.AbstractAttributeSet) AttributeSet(com.cburch.logisim.data.AttributeSet) CanvasObject(com.cburch.draw.model.CanvasObject)

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