Search in sources :

Example 16 with Attribute

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

the class XmlWriter method addAttributeSetContent.

void addAttributeSetContent(Element elt, AttributeSet attrs, AttributeDefaultProvider source) {
    if (attrs == null)
        return;
    LogisimVersion ver = Main.VERSION;
    if (source != null && source.isAllDefaultValues(attrs, ver))
        return;
    for (Attribute<?> attrBase : attrs.getAttributes()) {
        @SuppressWarnings("unchecked") Attribute<Object> attr = (Attribute<Object>) attrBase;
        Object val = attrs.getValue(attr);
        if (attrs.isToSave(attr) && val != null) {
            Object dflt = source == null ? null : source.getDefaultAttributeValue(attr, ver);
            if (dflt == null || !dflt.equals(val)) {
                Element a = doc.createElement("a");
                a.setAttribute("name", attr.getName());
                String value = attr.toStandardString(val);
                if (attr.getName().equals("filePath") && outFilepath != null) {
                    Path outFP = Paths.get(outFilepath);
                    Path attrValP = Paths.get(value);
                    value = (outFP.relativize(attrValP)).toString();
                    a.setAttribute("val", value);
                } else {
                    if (value.indexOf("\n") >= 0) {
                        a.appendChild(doc.createTextNode(value));
                    } else {
                        a.setAttribute("val", attr.toStandardString(val));
                    }
                }
                elt.appendChild(a);
            }
        }
    }
}
Also used : Path(java.nio.file.Path) Attribute(com.cburch.logisim.data.Attribute) Element(org.w3c.dom.Element) AbstractCanvasObject(com.cburch.draw.model.AbstractCanvasObject) LogisimVersion(com.cburch.logisim.LogisimVersion)

Example 17 with Attribute

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

the class SelectTool method processKeyEvent.

private void processKeyEvent(Canvas canvas, KeyEvent e, int type) {
    HashMap<Component, KeyConfigurator> handlers = keyHandlers;
    if (handlers == null) {
        handlers = new HashMap<Component, KeyConfigurator>();
        Selection sel = canvas.getSelection();
        for (Component comp : sel.getComponents()) {
            ComponentFactory factory = comp.getFactory();
            AttributeSet attrs = comp.getAttributeSet();
            Object handler = factory.getFeature(KeyConfigurator.class, attrs);
            if (handler != null) {
                KeyConfigurator base = (KeyConfigurator) handler;
                handlers.put(comp, base.clone());
            }
        }
        keyHandlers = handlers;
    }
    if (!handlers.isEmpty()) {
        boolean consume = false;
        ArrayList<KeyConfigurationResult> results;
        results = new ArrayList<KeyConfigurationResult>();
        for (Map.Entry<Component, KeyConfigurator> entry : handlers.entrySet()) {
            Component comp = entry.getKey();
            KeyConfigurator handler = entry.getValue();
            KeyConfigurationEvent event = new KeyConfigurationEvent(type, comp.getAttributeSet(), e, comp);
            KeyConfigurationResult result = handler.keyEventReceived(event);
            consume |= event.isConsumed();
            if (result != null) {
                results.add(result);
            }
        }
        if (consume) {
            e.consume();
        }
        if (!results.isEmpty()) {
            SetAttributeAction act = new SetAttributeAction(canvas.getCircuit(), Strings.getter("changeComponentAttributesAction"));
            for (KeyConfigurationResult result : results) {
                Component comp = (Component) result.getEvent().getData();
                Map<Attribute<?>, Object> newValues = result.getAttributeValues();
                for (Map.Entry<Attribute<?>, Object> entry : newValues.entrySet()) {
                    act.set(comp, entry.getKey(), entry.getValue());
                }
            }
            if (!act.isEmpty()) {
                canvas.getProject().doAction(act);
            }
        }
    }
}
Also used : KeyConfigurationResult(com.cburch.logisim.tools.key.KeyConfigurationResult) Attribute(com.cburch.logisim.data.Attribute) Selection(com.cburch.logisim.gui.main.Selection) ComponentFactory(com.cburch.logisim.comp.ComponentFactory) AttributeSet(com.cburch.logisim.data.AttributeSet) KeyConfigurationEvent(com.cburch.logisim.tools.key.KeyConfigurationEvent) Component(com.cburch.logisim.comp.Component) KeyConfigurator(com.cburch.logisim.tools.key.KeyConfigurator) HashMap(java.util.HashMap) Map(java.util.Map) ReplacementMap(com.cburch.logisim.circuit.ReplacementMap)

Example 18 with Attribute

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

the class AddTool method getFacing.

private Direction getFacing() {
    ComponentFactory source = getFactory();
    if (source == null)
        return Direction.NORTH;
    AttributeSet base = getBaseAttributes();
    Object feature = source.getFeature(ComponentFactory.FACING_ATTRIBUTE_KEY, base);
    @SuppressWarnings("unchecked") Attribute<Direction> attr = (Attribute<Direction>) feature;
    if (attr != null)
        return base.getValue(attr);
    else
        return Direction.NORTH;
}
Also used : 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 19 with Attribute

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

the class EditTool method getFacingAttribute.

private Attribute<Direction> getFacingAttribute(Component comp) {
    AttributeSet attrs = comp.getAttributeSet();
    Object key = ComponentFactory.FACING_ATTRIBUTE_KEY;
    Attribute<?> a = (Attribute<?>) comp.getFactory().getFeature(key, attrs);
    @SuppressWarnings("unchecked") Attribute<Direction> ret = (Attribute<Direction>) a;
    return ret;
}
Also used : AttributeSet(com.cburch.logisim.data.AttributeSet) Attribute(com.cburch.logisim.data.Attribute) Direction(com.cburch.logisim.data.Direction)

Example 20 with Attribute

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

the class AbstractCanvasObject method setForFill.

protected boolean setForFill(Graphics g) {
    List<Attribute<?>> attrs = getAttributes();
    if (attrs.contains(DrawAttr.PAINT_TYPE)) {
        Object value = getValue(DrawAttr.PAINT_TYPE);
        if (value == DrawAttr.PAINT_STROKE)
            return false;
    }
    Color color = getValue(DrawAttr.FILL_COLOR);
    if (color != null && color.getAlpha() == 0) {
        return false;
    } else {
        if (color != null)
            g.setColor(color);
        return true;
    }
}
Also used : Attribute(com.cburch.logisim.data.Attribute) Color(java.awt.Color)

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