Search in sources :

Example 11 with Attribute

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

the class SvgReader method createShape.

public static AbstractCanvasObject createShape(Element elt) {
    String name = elt.getTagName();
    AbstractCanvasObject ret;
    if (name.equals("ellipse")) {
        ret = createOval(elt);
    } else if (name.equals("line")) {
        ret = createLine(elt);
    } else if (name.equals("path")) {
        ret = createPath(elt);
    } else if (name.equals("polyline")) {
        ret = createPolyline(elt);
    } else if (name.equals("polygon")) {
        ret = createPolygon(elt);
    } else if (name.equals("rect")) {
        ret = createRectangle(elt);
    } else if (name.equals("text")) {
        ret = createText(elt);
    } else {
        return null;
    }
    List<Attribute<?>> attrs = ret.getAttributes();
    if (attrs.contains(DrawAttr.PAINT_TYPE)) {
        String stroke = elt.getAttribute("stroke");
        String fill = elt.getAttribute("fill");
        if (stroke.equals("") || stroke.equals("none")) {
            ret.setValue(DrawAttr.PAINT_TYPE, DrawAttr.PAINT_FILL);
        } else if (fill.equals("none")) {
            ret.setValue(DrawAttr.PAINT_TYPE, DrawAttr.PAINT_STROKE);
        } else {
            ret.setValue(DrawAttr.PAINT_TYPE, DrawAttr.PAINT_STROKE_FILL);
        }
    }
    // since changing paintType could change it
    attrs = ret.getAttributes();
    if (attrs.contains(DrawAttr.STROKE_WIDTH) && elt.hasAttribute("stroke-width")) {
        Integer width = Integer.valueOf(elt.getAttribute("stroke-width"));
        ret.setValue(DrawAttr.STROKE_WIDTH, width);
    }
    if (attrs.contains(DrawAttr.STROKE_COLOR)) {
        String color = elt.getAttribute("stroke");
        String opacity = elt.getAttribute("stroke-opacity");
        if (!color.equals("none")) {
            ret.setValue(DrawAttr.STROKE_COLOR, getColor(color, opacity));
        }
    }
    if (attrs.contains(DrawAttr.FILL_COLOR)) {
        String color = elt.getAttribute("fill");
        if (color.equals(""))
            color = "#000000";
        String opacity = elt.getAttribute("fill-opacity");
        if (!color.equals("none")) {
            ret.setValue(DrawAttr.FILL_COLOR, getColor(color, opacity));
        }
    }
    return ret;
}
Also used : Attribute(com.cburch.logisim.data.Attribute) AbstractCanvasObject(com.cburch.draw.model.AbstractCanvasObject)

Example 12 with Attribute

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

the class SelectionAttributes method computeAttributes.

private static LinkedHashMap<Attribute<Object>, Object> computeAttributes(Collection<Component> newSel) {
    LinkedHashMap<Attribute<Object>, Object> attrMap;
    attrMap = new LinkedHashMap<Attribute<Object>, Object>();
    Iterator<Component> sit = newSel.iterator();
    if (sit.hasNext()) {
        AttributeSet first = sit.next().getAttributeSet();
        for (Attribute<?> attr : first.getAttributes()) {
            @SuppressWarnings("unchecked") Attribute<Object> attrObj = (Attribute<Object>) attr;
            attrMap.put(attrObj, first.getValue(attr));
        }
        while (sit.hasNext()) {
            AttributeSet next = sit.next().getAttributeSet();
            Iterator<Attribute<Object>> ait = attrMap.keySet().iterator();
            while (ait.hasNext()) {
                Attribute<Object> attr = ait.next();
                if (next.containsAttribute(attr)) {
                    Object v = attrMap.get(attr);
                    if (v != null && !v.equals(next.getValue(attr))) {
                        attrMap.put(attr, null);
                    }
                } else {
                    ait.remove();
                }
            }
        }
    }
    return attrMap;
}
Also used : Attribute(com.cburch.logisim.data.Attribute) AbstractAttributeSet(com.cburch.logisim.data.AbstractAttributeSet) AttributeSet(com.cburch.logisim.data.AttributeSet) Component(com.cburch.logisim.comp.Component)

Example 13 with Attribute

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

the class InstanceFactory method createAttributeSet.

@Override
public AttributeSet createAttributeSet() {
    Attribute<?>[] as = attrs;
    AttributeSet ret = as == null ? AttributeSets.EMPTY : AttributeSets.fixedSet(as, defaults);
    return ret;
}
Also used : Attribute(com.cburch.logisim.data.Attribute) AttributeSet(com.cburch.logisim.data.AttributeSet)

Example 14 with Attribute

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

the class CircuitMutatorImpl method set.

public void set(Circuit circuit, Component comp, Attribute<?> attr, Object newValue) {
    if (circuit.contains(comp)) {
        modified.add(circuit);
        @SuppressWarnings("unchecked") Attribute<Object> a = (Attribute<Object>) attr;
        AttributeSet attrs = comp.getAttributeSet();
        Object oldValue = attrs.getValue(a);
        log.add(CircuitChange.set(circuit, comp, attr, oldValue, newValue));
        attrs.setValue(a, newValue);
    }
}
Also used : Attribute(com.cburch.logisim.data.Attribute) AttributeSet(com.cburch.logisim.data.AttributeSet)

Example 15 with Attribute

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

the class CircuitMutatorImpl method setForCircuit.

public void setForCircuit(Circuit circuit, Attribute<?> attr, Object newValue) {
    @SuppressWarnings("unchecked") Attribute<Object> a = (Attribute<Object>) attr;
    AttributeSet attrs = circuit.getStaticAttributes();
    Object oldValue = attrs.getValue(a);
    log.add(CircuitChange.setForCircuit(circuit, attr, oldValue, newValue));
    attrs.setValue(a, newValue);
    if (attr == CircuitAttributes.NAME_ATTR || attr == CircuitAttributes.NAMED_CIRCUIT_BOX) {
        circuit.getAppearance().recomputeDefaultAppearance();
    }
}
Also used : Attribute(com.cburch.logisim.data.Attribute) AttributeSet(com.cburch.logisim.data.AttributeSet)

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