本文整理汇总了Java中com.cburch.logisim.instance.StdAttr类的典型用法代码示例。如果您正苦于以下问题:Java StdAttr类的具体用法?Java StdAttr怎么用?Java StdAttr使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
StdAttr类属于com.cburch.logisim.instance包,在下文中一共展示了StdAttr类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: keyTyped
import com.cburch.logisim.instance.StdAttr; //导入依赖的package包/类
/** Processes a key by just adding it onto the end of the current value. */
@Override
public void keyTyped(InstanceState state, KeyEvent e) {
// convert it to a hex digit; if it isn't a hex digit, abort.
int val = Character.digit(e.getKeyChar(), 16);
BitWidth width = state.getAttributeValue(StdAttr.WIDTH);
if (val < 0 || (val & width.getMask()) != val)
return;
// compute the next value
CounterData cur = CounterData.get(state, width);
int newVal = (cur.getValue().toIntValue() * 16 + val) & width.getMask();
Value newValue = Value.createKnown(width, newVal);
cur.setValue(newValue);
state.fireInvalidated();
// You might be tempted to propagate the value immediately here, using
// state.setPort. However, the circuit may currently be propagating in
// another thread, and invoking setPort directly could interfere with
// that. Using fireInvalidated notifies the propagation thread to
// invoke propagate on the counter at its next opportunity.
}
示例2: propagate
import com.cburch.logisim.instance.StdAttr; //导入依赖的package包/类
@Override
public void propagate(InstanceState state) {
Object triggerType = state.getAttributeValue(StdAttr.EDGE_TRIGGER);
boolean parallel = state.getAttributeValue(ATTR_LOAD).booleanValue();
ShiftRegisterData data = getData(state);
int len = data.getLength();
boolean triggered = data.updateClock(state.getPort(CK), triggerType);
if (state.getPort(CLR) == Value.TRUE) {
data.clear();
} else if (triggered) {
if (parallel && state.getPort(LD) == Value.TRUE) {
data.clear();
for (int i = len - 1; i >= 0; i--)
data.push(state.getPort(6 + 2 * i));
} else if (state.getPort(SH) != Value.FALSE) {
data.push(state.getPort(IN));
}
}
state.setPort(OUT, data.get(0), 4);
if (parallel) {
for (int i = 0; i < len; i++)
state.setPort(6 + 2 * i + 1, data.get(len - 1 - i), 4);
}
}
示例3: Random
import com.cburch.logisim.instance.StdAttr; //导入依赖的package包/类
public Random() {
super("Random", Strings.getter("randomComponent"));
setAttributes(
new Attribute[] { StdAttr.WIDTH, ATTR_SEED, StdAttr.EDGE_TRIGGER, StdAttr.LABEL, StdAttr.LABEL_FONT,
StdAttr.ATTR_LABEL_COLOR },
new Object[] { BitWidth.create(8), Integer.valueOf(0), StdAttr.TRIG_RISING, "",
StdAttr.DEFAULT_LABEL_FONT, Color.BLACK });
setKeyConfigurator(new BitWidthConfigurator(StdAttr.WIDTH));
setOffsetBounds(Bounds.create(-30, -20, 30, 40));
setIconName("random.gif");
setInstanceLogger(Logger.class);
Port[] ps = new Port[4];
ps[OUT] = new Port(0, 0, Port.OUTPUT, StdAttr.WIDTH);
ps[CK] = new Port(-30, -10, Port.INPUT, 1);
ps[NXT] = new Port(-30, 10, Port.INPUT, 1);
ps[RST] = new Port(-20, 20, Port.INPUT, 1);
ps[OUT].setToolTip(Strings.getter("randomQTip"));
ps[CK].setToolTip(Strings.getter("randomClockTip"));
ps[NXT].setToolTip(Strings.getter("randomNextTip"));
ps[RST].setToolTip(Strings.getter("randomResetTip"));
setPorts(ps);
}
示例4: configurePorts
import com.cburch.logisim.instance.StdAttr; //导入依赖的package包/类
void configurePorts(Instance instance) {
Port[] ps = new Port[7];
ps[OUT] = new Port(0, 0, Port.OUTPUT, StdAttr.WIDTH);
ps[IN] = new Port(-30, 0, Port.INPUT, StdAttr.WIDTH);
ps[CK] = new Port(-20, 20, Port.INPUT, 1);
ps[CLR] = new Port(-10, 20, Port.INPUT, 1);
ps[PRE] = new Port(-10, -20, Port.INPUT, 1);
ps[EN] = new Port(-30, 10, Port.INPUT, 1);
ps[CS] = new Port(-30, -10, Port.INPUT, 1);
ps[OUT].setToolTip(Strings.getter("registerQTip"));
ps[IN].setToolTip(Strings.getter("registerDTip"));
ps[CK].setToolTip(Strings.getter("registerClkTip"));
ps[CLR].setToolTip(Strings.getter("registerClrTip"));
ps[PRE].setToolTip(Strings.getter("registerPreTip"));
ps[EN].setToolTip(Strings.getter("registerEnableTip"));
if (instance.getAttributeValue(Mem.ATTR_SELECTION) == Mem.SEL_HIGH)
ps[CS].setToolTip(Strings.getter("memCSTip", "0"));
else
ps[CS].setToolTip(Strings.getter("memCSTip", "1"));
instance.setPorts(ps);
}
示例5: paintInternalBase
import com.cburch.logisim.instance.StdAttr; //导入依赖的package包/类
private void paintInternalBase(InstancePainter painter) {
Direction dir = painter.getAttributeValue(StdAttr.FACING);
Bounds bds = painter.getBounds();
int x = bds.getX();
int y = bds.getY();
int width = bds.getWidth();
int height = bds.getHeight();
if (dir == Direction.SOUTH || dir == Direction.NORTH) {
x += (width - height) / 2;
y += (height - width) / 2;
width = bds.getHeight();
height = bds.getWidth();
}
if (this.ngatestodraw == 0)
paintInternal(painter, x, y, height, false);
else {
paintBase(painter, false, false);
for (int i = 0; i < this.ngatestodraw; i++) {
paintInternal(painter,
x + (i < this.ngatestodraw / 2 ? i : i - this.ngatestodraw / 2)
* ((width - 20) / (this.ngatestodraw / 2)) + (i < this.ngatestodraw / 2 ? 0 : 20),
y, height, !(i < this.ngatestodraw / 2));
}
}
}
示例6: Multiplier
import com.cburch.logisim.instance.StdAttr; //导入依赖的package包/类
public Multiplier() {
super("Multiplier", Strings.getter("multiplierComponent"));
setAttributes(new Attribute[] { StdAttr.WIDTH }, new Object[] { BitWidth.create(8) });
setKeyConfigurator(new BitWidthConfigurator(StdAttr.WIDTH));
setOffsetBounds(Bounds.create(-40, -20, 40, 40));
setIconName("multiplier.gif");
Port[] ps = new Port[5];
ps[IN0] = new Port(-40, -10, Port.INPUT, StdAttr.WIDTH);
ps[IN1] = new Port(-40, 10, Port.INPUT, StdAttr.WIDTH);
ps[OUT] = new Port(0, 0, Port.OUTPUT, StdAttr.WIDTH);
ps[C_IN] = new Port(-20, -20, Port.INPUT, StdAttr.WIDTH);
ps[C_OUT] = new Port(-20, 20, Port.OUTPUT, StdAttr.WIDTH);
ps[IN0].setToolTip(Strings.getter("multiplierInputTip"));
ps[IN1].setToolTip(Strings.getter("multiplierInputTip"));
ps[OUT].setToolTip(Strings.getter("multiplierOutputTip"));
ps[C_IN].setToolTip(Strings.getter("multiplierCarryInTip"));
ps[C_OUT].setToolTip(Strings.getter("multiplierCarryOutTip"));
setPorts(ps);
}
示例7: propagate
import com.cburch.logisim.instance.StdAttr; //导入依赖的package包/类
@Override
public void propagate(InstanceState state) {
// get attributes
BitWidth data = state.getAttributeValue(StdAttr.WIDTH);
// compute outputs
Value a = state.getPort(IN0);
Value b = state.getPort(IN1);
Value b_in = state.getPort(B_IN);
if (b_in == Value.UNKNOWN || b_in == Value.NIL)
b_in = Value.FALSE;
Value[] outs = Adder.computeSum(data, a, b.not(), b_in.not());
// propagate them
int delay = (data.getWidth() + 4) * Adder.PER_DELAY;
state.setPort(OUT, outs[0], delay);
state.setPort(B_OUT, outs[1].not(), delay);
}
示例8: getValue
import com.cburch.logisim.instance.StdAttr; //导入依赖的package包/类
@Override
public <V> V getValue(Attribute<V> attr) {
if (attr == StdAttr.FACING) {
return (V) facing;
} else if (attr == ATTR_FANOUT) {
return (V) Integer.valueOf(fanout);
} else if (attr == ATTR_WIDTH) {
return (V) BitWidth.create(bit_end.length);
} else if (attr == ATTR_APPEARANCE) {
return (V) appear;
} else if (attr instanceof BitOutAttribute) {
BitOutAttribute bitOut = (BitOutAttribute) attr;
return (V) Integer.valueOf(bit_end[bitOut.which]);
} else {
return null;
}
}
示例9: ControlledBuffer
import com.cburch.logisim.instance.StdAttr; //导入依赖的package包/类
private ControlledBuffer(boolean isInverter) {
super(isInverter ? "Controlled Inverter" : "Controlled Buffer",
isInverter ? Strings.getter("controlledInverterComponent")
: Strings.getter("controlledBufferComponent"));
this.isInverter = isInverter;
if (isInverter) {
setAttributes(
new Attribute[] { StdAttr.FACING, StdAttr.WIDTH, NotGate.ATTR_SIZE, ATTR_CONTROL, NEGATE_CONTROL,
StdAttr.LABEL, StdAttr.LABEL_FONT, StdAttr.ATTR_LABEL_COLOR },
new Object[] { Direction.EAST, BitWidth.ONE, NotGate.SIZE_NARROW, RIGHT_HANDED, Boolean.FALSE, "",
StdAttr.DEFAULT_LABEL_FONT, Color.BLACK });
} else {
setAttributes(
new Attribute[] { StdAttr.FACING, StdAttr.WIDTH, ATTR_CONTROL, NEGATE_CONTROL, StdAttr.LABEL,
StdAttr.LABEL_FONT, StdAttr.ATTR_LABEL_COLOR },
new Object[] { Direction.EAST, BitWidth.ONE, RIGHT_HANDED, Boolean.FALSE, "",
StdAttr.DEFAULT_LABEL_FONT, Color.BLACK });
}
setFacingAttribute(StdAttr.FACING);
setKeyConfigurator(new BitWidthConfigurator(StdAttr.WIDTH));
}
示例10: propagate
import com.cburch.logisim.instance.StdAttr; //导入依赖的package包/类
@Override
public void propagate(InstanceState state) {
// get attributes
BitWidth dataWidth = state.getAttributeValue(StdAttr.WIDTH);
// compute outputs
Value a = state.getPort(IN0);
Value b = state.getPort(IN1);
Value c_in = state.getPort(C_IN);
Value[] outs = Adder.computeSum(dataWidth, a, b, c_in);
// propagate them
int delay = (dataWidth.getWidth() + 2) * PER_DELAY;
state.setPort(OUT, outs[0], delay);
state.setPort(C_OUT, outs[1], delay);
}
示例11: configureLabel
import com.cburch.logisim.instance.StdAttr; //导入依赖的package包/类
static void configureLabel(Instance instance, boolean isRectangular, Location control) {
Object facing = instance.getAttributeValue(StdAttr.FACING);
Bounds bds = instance.getBounds();
int x;
int y;
int halign;
if (facing == Direction.NORTH || facing == Direction.SOUTH) {
x = bds.getX() + bds.getWidth() / 2 + 2;
y = bds.getY() - 2;
halign = TextField.H_LEFT;
} else { // west or east
y = isRectangular ? bds.getY() - 2 : bds.getY();
if (control != null && control.getY() == bds.getY()) {
// the control line will get in the way
x = control.getX() + 2;
halign = TextField.H_LEFT;
} else {
x = bds.getX() + bds.getWidth() / 2;
halign = TextField.H_CENTER;
}
}
instance.setTextField(StdAttr.LABEL, StdAttr.LABEL_FONT, StdAttr.ATTR_LABEL_COLOR, x, y, halign,
TextField.V_BASELINE);
}
示例12: Comparator
import com.cburch.logisim.instance.StdAttr; //导入依赖的package包/类
public Comparator() {
super("Comparator", Strings.getter("comparatorComponent"));
setAttributes(new Attribute[] { StdAttr.WIDTH, MODE_ATTRIBUTE },
new Object[] { BitWidth.create(8), SIGNED_OPTION });
setKeyConfigurator(new BitWidthConfigurator(StdAttr.WIDTH));
setOffsetBounds(Bounds.create(-40, -20, 40, 40));
setIconName("comparator.gif");
Port[] ps = new Port[5];
ps[IN0] = new Port(-40, -10, Port.INPUT, StdAttr.WIDTH);
ps[IN1] = new Port(-40, 10, Port.INPUT, StdAttr.WIDTH);
ps[GT] = new Port(0, -10, Port.OUTPUT, 1);
ps[EQ] = new Port(0, 0, Port.OUTPUT, 1);
ps[LT] = new Port(0, 10, Port.OUTPUT, 1);
ps[IN0].setToolTip(Strings.getter("comparatorInputATip"));
ps[IN1].setToolTip(Strings.getter("comparatorInputBTip"));
ps[GT].setToolTip(Strings.getter("comparatorGreaterTip"));
ps[EQ].setToolTip(Strings.getter("comparatorEqualTip"));
ps[LT].setToolTip(Strings.getter("comparatorLessTip"));
setPorts(ps);
}
示例13: Subtractor
import com.cburch.logisim.instance.StdAttr; //导入依赖的package包/类
public Subtractor() {
super("Subtractor", Strings.getter("subtractorComponent"));
setAttributes(new Attribute[] { StdAttr.WIDTH }, new Object[] { BitWidth.create(8) });
setKeyConfigurator(new BitWidthConfigurator(StdAttr.WIDTH));
setOffsetBounds(Bounds.create(-40, -20, 40, 40));
setIconName("subtractor.gif");
Port[] ps = new Port[5];
ps[IN0] = new Port(-40, -10, Port.INPUT, StdAttr.WIDTH);
ps[IN1] = new Port(-40, 10, Port.INPUT, StdAttr.WIDTH);
ps[OUT] = new Port(0, 0, Port.OUTPUT, StdAttr.WIDTH);
ps[B_IN] = new Port(-20, -20, Port.INPUT, 1);
ps[B_OUT] = new Port(-20, 20, Port.OUTPUT, 1);
ps[IN0].setToolTip(Strings.getter("subtractorMinuendTip"));
ps[IN1].setToolTip(Strings.getter("subtractorSubtrahendTip"));
ps[OUT].setToolTip(Strings.getter("subtractorOutputTip"));
ps[B_IN].setToolTip(Strings.getter("subtractorBorrowInTip"));
ps[B_OUT].setToolTip(Strings.getter("subtractorBorrowOutTip"));
setPorts(ps);
}
示例14: setValue
import com.cburch.logisim.instance.StdAttr; //导入依赖的package包/类
@Override
public <V> void setValue(Attribute<V> attr, V value) {
if (attr == StdAttr.FACING) {
facing = (Direction) value;
} else if (attr == StdAttr.LABEL) {
label = (String) value;
} else if (attr == Pin.ATTR_LABEL_LOC) {
labelloc = (Direction) value;
} else if (attr == StdAttr.LABEL_FONT) {
labelfont = (Font) value;
} else if (attr == RadixOption.ATTRIBUTE) {
radix = (RadixOption) value;
} else if (attr == StdAttr.ATTR_LABEL_COLOR) {
labelColor = (Color) value;
} else {
throw new IllegalArgumentException("unknown attribute");
}
fireAttributeValueChanged(attr, value);
}
示例15: paintGhost
import com.cburch.logisim.instance.StdAttr; //导入依赖的package包/类
@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(), y + bds.getY(), bds.getWidth(), bds.getHeight());
} else {
g.drawRoundRect(x + bds.getX(), y + bds.getY(), bds.getWidth(), bds.getHeight(), 10, 10);
}
} else {
g.drawRect(x + bds.getX(), y + bds.getY(), bds.getWidth(), bds.getHeight());
}
}