Search in sources :

Example 1 with AttributeOption

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

the class SplitterAttributes method setValue.

@Override
public <V> void setValue(Attribute<V> attr, V value) {
    if (attr == StdAttr.FACING) {
        Direction NewFacing = (Direction) value;
        if (facing.equals(NewFacing))
            return;
        facing = (Direction) value;
        configureOptions();
        parameters = null;
    } else if (attr == ATTR_FANOUT) {
        int newValue = ((Integer) value).intValue();
        byte[] bits = bit_end;
        for (int i = 0; i < bits.length; i++) {
            if (bits[i] >= newValue)
                bits[i] = (byte) (newValue - 1);
        }
        if (fanout == (byte) newValue)
            return;
        fanout = (byte) newValue;
        configureOptions();
        configureDefaults();
        parameters = null;
    } else if (attr == ATTR_WIDTH) {
        BitWidth width = (BitWidth) value;
        if (bit_end.length == width.getWidth())
            return;
        bit_end = new byte[width.getWidth()];
        configureOptions();
        configureDefaults();
    } else if (attr == ATTR_APPEARANCE) {
        AttributeOption appearance = (AttributeOption) value;
        if (appear.equals(appearance))
            return;
        appear = appearance;
        parameters = null;
    } else if (attr instanceof BitOutAttribute) {
        BitOutAttribute bitOutAttr = (BitOutAttribute) attr;
        int val;
        if (value instanceof Integer) {
            val = ((Integer) value).intValue();
        } else {
            val = ((BitOutOption) value).value + 1;
        }
        if (val >= 0 && val <= fanout) {
            if (bit_end[bitOutAttr.which] == (byte) val)
                return;
            bit_end[bitOutAttr.which] = (byte) val;
        } else
            return;
    } else {
        throw new IllegalArgumentException("unknown attribute " + attr);
    }
    fireAttributeValueChanged(attr, value, null);
}
Also used : BitWidth(com.cburch.logisim.data.BitWidth) Direction(com.cburch.logisim.data.Direction) AttributeOption(com.cburch.logisim.data.AttributeOption)

Example 2 with AttributeOption

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

the class Text method getValue.

@Override
@SuppressWarnings("unchecked")
public <V> V getValue(Attribute<V> attr) {
    if (attr == DrawAttr.FONT) {
        return (V) label.getFont();
    } else if (attr == DrawAttr.FILL_COLOR) {
        return (V) label.getColor();
    } else if (attr == DrawAttr.ALIGNMENT) {
        int halign = label.getHorizontalAlignment();
        AttributeOption h;
        if (halign == EditableLabel.LEFT) {
            h = DrawAttr.ALIGN_LEFT;
        } else if (halign == EditableLabel.RIGHT) {
            h = DrawAttr.ALIGN_RIGHT;
        } else {
            h = DrawAttr.ALIGN_CENTER;
        }
        return (V) h;
    } else {
        return null;
    }
}
Also used : AttributeOption(com.cburch.logisim.data.AttributeOption)

Example 3 with AttributeOption

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

the class SvgReader method createText.

private static AbstractCanvasObject createText(Element elt) {
    int x = Integer.parseInt(elt.getAttribute("x"));
    int y = Integer.parseInt(elt.getAttribute("y"));
    String text = elt.getTextContent();
    Text ret = new Text(x, y, text);
    String fontFamily = elt.getAttribute("font-family");
    String fontStyle = elt.getAttribute("font-style");
    String fontWeight = elt.getAttribute("font-weight");
    String fontSize = elt.getAttribute("font-size");
    int styleFlags = 0;
    if (fontStyle.equals("italic"))
        styleFlags |= Font.ITALIC;
    if (fontWeight.equals("bold"))
        styleFlags |= Font.BOLD;
    int size = Integer.parseInt(fontSize);
    ret.setValue(DrawAttr.FONT, new Font(fontFamily, styleFlags, size));
    String alignStr = elt.getAttribute("text-anchor");
    AttributeOption halign;
    if (alignStr.equals("start")) {
        halign = DrawAttr.ALIGN_LEFT;
    } else if (alignStr.equals("end")) {
        halign = DrawAttr.ALIGN_RIGHT;
    } else {
        halign = DrawAttr.ALIGN_CENTER;
    }
    ret.setValue(DrawAttr.ALIGNMENT, halign);
    // fill color is handled after we return
    return ret;
}
Also used : Font(java.awt.Font) AttributeOption(com.cburch.logisim.data.AttributeOption)

Example 4 with AttributeOption

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

the class RamAttributes method setValue.

@Override
public <V> void setValue(Attribute<V> attr, V value) {
    if (attr == Mem.ADDR_ATTR) {
        BitWidth newAddr = (BitWidth) value;
        if (addrBits == newAddr) {
            return;
        }
        addrBits = newAddr;
        contents.setDimensions(addrBits.getWidth(), dataBits.getWidth(), false);
        fireAttributeValueChanged(attr, value, null);
    } else if (attr == Mem.DATA_ATTR) {
        BitWidth newData = (BitWidth) value;
        if (dataBits == newData) {
            return;
        }
        dataBits = newData;
        contents.setDimensions(addrBits.getWidth(), dataBits.getWidth(), false);
        fireAttributeValueChanged(attr, value, null);
    } else if (attr == Ram.CONTENTS_ATTR) {
        MemContents newContents = (MemContents) value;
        if (contents.equals(newContents)) {
            return;
        }
        if ((newContents.getLogLength() != addrBits.getWidth()) || (newContents.getValueWidth() != dataBits.getWidth())) {
            newContents.setDimensions(addrBits.getWidth(), dataBits.getWidth(), false);
        }
        contents = newContents;
        fireAttributeValueChanged(attr, value, null);
    } else if (attr == StdAttr.LABEL) {
        String NewLabel = (String) value;
        if (Label.equals(NewLabel)) {
            return;
        }
        @SuppressWarnings("unchecked") V Oldlabel = (V) Label;
        Label = NewLabel;
        fireAttributeValueChanged(attr, value, Oldlabel);
    } else if (attr == StdAttr.TRIGGER) {
        AttributeOption newTrigger = (AttributeOption) value;
        if (Trigger.equals(newTrigger)) {
            return;
        }
        Trigger = newTrigger;
        fireAttributeValueChanged(attr, value, null);
    } else if (attr == ATTR_DBUS) {
        AttributeOption NewStyle = (AttributeOption) value;
        if (BusStyle.equals(NewStyle)) {
            return;
        }
        BusStyle = NewStyle;
        fireAttributeValueChanged(attr, value, null);
    } else if (attr == StdAttr.LABEL_FONT) {
        Font NewFont = (Font) value;
        if (LabelFont.equals(NewFont)) {
            return;
        }
        LabelFont = NewFont;
        fireAttributeValueChanged(attr, value, null);
    } else if (attr == StdAttr.LABEL_VISIBILITY) {
        Boolean newVis = (Boolean) value;
        if (LabelVisable.equals(newVis))
            return;
        LabelVisable = newVis;
        fireAttributeValueChanged(attr, value, null);
    } else if (attr == ATTR_ByteEnables) {
        AttributeOption NewBE = (AttributeOption) value;
        if (ByteEnables.equals(NewBE)) {
            return;
        }
        if (dataBits.getWidth() < 9) {
            NewBE = BUS_WITHOUT_BYTEENABLES;
        }
        ByteEnables = NewBE;
        fireAttributeValueChanged(attr, value, null);
    }
}
Also used : BitWidth(com.cburch.logisim.data.BitWidth) Font(java.awt.Font) AttributeOption(com.cburch.logisim.data.AttributeOption)

Aggregations

AttributeOption (com.cburch.logisim.data.AttributeOption)4 BitWidth (com.cburch.logisim.data.BitWidth)2 Font (java.awt.Font)2 Direction (com.cburch.logisim.data.Direction)1