Search in sources :

Example 21 with BitWidth

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

the class RegisterLogger method getLogValue.

@Override
public Value getLogValue(InstanceState state, Object option) {
    BitWidth dataWidth = state.getAttributeValue(StdAttr.WIDTH);
    if (dataWidth == null)
        dataWidth = BitWidth.create(0);
    RegisterData data = (RegisterData) state.getData();
    if (data == null)
        return Value.createKnown(dataWidth, 0);
    return data.value;
}
Also used : BitWidth(com.cburch.logisim.data.BitWidth)

Example 22 with BitWidth

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

the class RegisterPoker method keyTyped.

@Override
public void keyTyped(InstanceState state, KeyEvent e) {
    int val = Character.digit(e.getKeyChar(), 16);
    if (val < 0)
        return;
    BitWidth dataWidth = state.getAttributeValue(StdAttr.WIDTH);
    if (dataWidth == null)
        dataWidth = BitWidth.create(8);
    curValue = (curValue * 16 + val) & dataWidth.getMask();
    RegisterData data = (RegisterData) state.getData();
    data.value = Value.createKnown(dataWidth, curValue);
    state.fireInvalidated();
}
Also used : BitWidth(com.cburch.logisim.data.BitWidth)

Example 23 with BitWidth

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

the class RomAttributes method setValue.

@Override
public <V> void setValue(Attribute<V> attr, V value) {
    if (attr == Mem.ADDR_ATTR) {
        BitWidth newAddr = (BitWidth) value;
        if (newAddr == addrBits)
            return;
        addrBits = newAddr;
        contents.setDimensions(addrBits.getWidth(), dataBits.getWidth(), true);
        fireAttributeValueChanged(attr, value, null);
    } else if (attr == Mem.DATA_ATTR) {
        BitWidth newData = (BitWidth) value;
        if (newData == dataBits)
            return;
        dataBits = newData;
        contents.setDimensions(addrBits.getWidth(), dataBits.getWidth(), true);
        fireAttributeValueChanged(attr, value, null);
    } else if (attr == Rom.CONTENTS_ATTR) {
        MemContents newContents = (MemContents) value;
        if (contents.equals(newContents))
            return;
        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.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);
    }
}
Also used : BitWidth(com.cburch.logisim.data.BitWidth) Font(java.awt.Font)

Example 24 with BitWidth

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

the class Random method paintInstance.

@Override
public void paintInstance(InstancePainter painter) {
    Bounds bds = painter.getBounds();
    int x = bds.getX();
    int y = bds.getY();
    StateData state = (StateData) painter.getData();
    int val = state == null ? 0 : state.value;
    BitWidth widthVal = painter.getAttributeValue(StdAttr.WIDTH);
    int width = widthVal == null ? 8 : widthVal.getWidth();
    painter.drawLabel();
    DrawControl(painter, x, y, width);
    DrawData(painter, x, y + 70, width, val);
}
Also used : BitWidth(com.cburch.logisim.data.BitWidth) Bounds(com.cburch.logisim.data.Bounds)

Example 25 with BitWidth

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

the class Pin method paintGhost.

@Override
public void paintGhost(InstancePainter painter) {
    PinAttributes attrs = (PinAttributes) painter.getAttributeSet();
    Location loc = painter.getLocation();
    Bounds bds = painter.getOffsetBounds();
    int x = loc.getX();
    int y = loc.getY();
    Graphics g = painter.getGraphics();
    GraphicsUtil.switchToWidth(g, 2);
    boolean output = attrs.isOutput();
    if (output) {
        BitWidth width = attrs.getValue(StdAttr.WIDTH);
        if (width == BitWidth.ONE) {
            g.drawOval(x + bds.getX() + 1, y + bds.getY() + 1, bds.getWidth() - 1, bds.getHeight() - 1);
        } else {
            g.drawRoundRect(x + bds.getX() + 1, y + bds.getY() + 1, bds.getWidth() - 1, bds.getHeight() - 1, 6, 6);
        }
    } else {
        g.drawRect(x + bds.getX() + 1, y + bds.getY() + 1, bds.getWidth() - 1, bds.getHeight() - 1);
    }
}
Also used : Graphics(java.awt.Graphics) BitWidth(com.cburch.logisim.data.BitWidth) Bounds(com.cburch.logisim.data.Bounds) Location(com.cburch.logisim.data.Location)

Aggregations

BitWidth (com.cburch.logisim.data.BitWidth)106 Value (com.cburch.logisim.data.Value)30 Bounds (com.cburch.logisim.data.Bounds)21 Direction (com.cburch.logisim.data.Direction)20 Location (com.cburch.logisim.data.Location)16 Graphics (java.awt.Graphics)15 Port (com.cburch.logisim.instance.Port)12 EndData (com.cburch.logisim.comp.EndData)3 AttributeSet (com.cburch.logisim.data.AttributeSet)3 Font (java.awt.Font)3 FontMetrics (java.awt.FontMetrics)3 AttributeOption (com.cburch.logisim.data.AttributeOption)2 Graphics2D (java.awt.Graphics2D)2 ArrayList (java.util.ArrayList)2 TreeMap (java.util.TreeMap)2 WidthIncompatibilityData (com.cburch.logisim.circuit.WidthIncompatibilityData)1 Attribute (com.cburch.logisim.data.Attribute)1 Instance (com.cburch.logisim.instance.Instance)1 InstanceState (com.cburch.logisim.instance.InstanceState)1 Dimension (java.awt.Dimension)1