本文整理汇总了Java中com.cburch.logisim.data.Direction.NORTH属性的典型用法代码示例。如果您正苦于以下问题:Java Direction.NORTH属性的具体用法?Java Direction.NORTH怎么用?Java Direction.NORTH使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类com.cburch.logisim.data.Direction
的用法示例。
在下文中一共展示了Direction.NORTH属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: drawPin
public void drawPin(Component comp, int i, String label, Direction dir) {
Color curColor = g.getColor();
if (i < 0 || i >= comp.getEnds().size())
return;
EndData e = comp.getEnd(i);
Location pt = e.getLocation();
int x = pt.getX();
int y = pt.getY();
if (getShowState()) {
CircuitState state = getCircuitState();
g.setColor(state.getValue(pt).getColor());
} else {
g.setColor(Color.BLACK);
}
g.fillOval(x - PIN_OFFS, y - PIN_OFFS, PIN_RAD, PIN_RAD);
g.setColor(curColor);
if (dir == Direction.EAST) {
GraphicsUtil.drawText(g, label, x + 3, y, GraphicsUtil.H_LEFT, GraphicsUtil.V_CENTER);
} else if (dir == Direction.WEST) {
GraphicsUtil.drawText(g, label, x - 3, y, GraphicsUtil.H_RIGHT, GraphicsUtil.V_CENTER);
} else if (dir == Direction.SOUTH) {
GraphicsUtil.drawText(g, label, x, y - 3, GraphicsUtil.H_CENTER, GraphicsUtil.V_BASELINE);
} else if (dir == Direction.NORTH) {
GraphicsUtil.drawText(g, label, x, y + 3, GraphicsUtil.H_CENTER, GraphicsUtil.V_TOP);
}
}
示例2: getOffsetBounds
@Override
public Bounds getOffsetBounds(AttributeSet attrsBase) {
GateAttributes attrs = (GateAttributes) attrsBase;
Direction facing = attrs.facing;
int size = ((Integer) attrs.size.getValue()).intValue();
int inputs = attrs.inputs;
if (inputs % 2 == 0) {
inputs++;
}
int negated = attrs.negated;
int width = size + bonusWidth + (negateOutput ? 10 : 0);
if (negated != 0) {
width += 10;
}
int height = Math.max(10 * inputs, size);
if (facing == Direction.SOUTH) {
return Bounds.create(-height / 2, -width, height, width);
} else if (facing == Direction.NORTH) {
return Bounds.create(-height / 2, 0, height, width);
} else if (facing == Direction.WEST) {
return Bounds.create(0, -height / 2, width, height);
} else {
return Bounds.create(-width, -height / 2, width, height);
}
}
示例3: updateports
private void updateports(Instance instance) {
Direction facing = instance.getAttributeValue(StdAttr.FACING);
BitWidth bits = (instance.getAttributeValue(Io.MULTI_BIT)) ? BitWidth.create(8) : BitWidth.ONE;
Port[] port = new Port[3];
if (facing == Direction.NORTH || facing == Direction.SOUTH) {
port[0] = new Port(-10, 0, Port.INPUT, bits);
port[1] = new Port(0, 0, Port.INPUT, bits);
port[2] = new Port(10, 0, Port.INPUT, bits);
} else {
port[0] = new Port(0, -10, Port.INPUT, bits);
port[1] = new Port(0, 0, Port.INPUT, bits);
port[2] = new Port(0, 10, Port.INPUT, bits);
}
port[0].setToolTip(Strings.getter("Red"));
port[1].setToolTip(Strings.getter("Green"));
port[2].setToolTip(Strings.getter("Blue"));
instance.setPorts(port);
}
示例4: configureLabel
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);
}
示例5: computeTextField
private void computeTextField(Instance instance) {
Direction facing = instance.getAttributeValue(StdAttr.FACING);
Object labelLoc = instance.getAttributeValue(Io.ATTR_LABEL_LOC);
Bounds bds = instance.getBounds();
int x = bds.getX() + bds.getWidth() / 2;
int y = bds.getY() + bds.getHeight() / 2;
int halign = GraphicsUtil.H_CENTER;
int valign = GraphicsUtil.V_CENTER;
if (labelLoc == Io.LABEL_CENTER) {
x = bds.getX() + (bds.getWidth() - DEPTH) / 2;
y = bds.getY() + (bds.getHeight() - DEPTH) / 2;
} else if (labelLoc == Direction.NORTH) {
y = bds.getY() - 2;
valign = GraphicsUtil.V_BOTTOM;
} else if (labelLoc == Direction.SOUTH) {
y = bds.getY() + bds.getHeight() + 2;
valign = GraphicsUtil.V_TOP;
} else if (labelLoc == Direction.EAST) {
x = bds.getX() + bds.getWidth() + 2;
halign = GraphicsUtil.H_LEFT;
} else if (labelLoc == Direction.WEST) {
x = bds.getX() - 2;
halign = GraphicsUtil.H_RIGHT;
}
if (labelLoc == facing) {
if (labelLoc == Direction.NORTH || labelLoc == Direction.SOUTH) {
x += 2;
halign = GraphicsUtil.H_LEFT;
} else {
y -= 2;
valign = GraphicsUtil.V_BOTTOM;
}
}
instance.setTextField(StdAttr.LABEL, StdAttr.LABEL_FONT, StdAttr.ATTR_LABEL_COLOR, x, y, halign, valign);
}
示例6: keyEventReceived
@Override
public KeyConfigurationResult keyEventReceived(KeyConfigurationEvent event) {
if (event.getType() == KeyConfigurationEvent.KEY_PRESSED) {
KeyEvent e = event.getKeyEvent();
if (e.getModifiersEx() == modsEx) {
Direction value = null;
switch (e.getKeyCode()) {
case KeyEvent.VK_UP:
value = Direction.NORTH;
break;
case KeyEvent.VK_DOWN:
value = Direction.SOUTH;
break;
case KeyEvent.VK_LEFT:
value = Direction.WEST;
break;
case KeyEvent.VK_RIGHT:
value = Direction.EAST;
break;
}
if (value != null) {
event.consume();
return new KeyConfigurationResult(event, attr, value);
}
}
}
return null;
}
示例7: computeLabel
private void computeLabel(Instance instance) {
GateAttributes attrs = (GateAttributes) instance.getAttributeSet();
Direction facing = attrs.facing;
int baseWidth = ((Integer) attrs.size.getValue()).intValue();
int axis = baseWidth / 2 + (negateOutput ? 10 : 0);
int perp = 0;
if (AppPreferences.GATE_SHAPE.get().equals(AppPreferences.SHAPE_RECTANGULAR)) {
perp += 6;
}
Location loc = instance.getLocation();
int cx;
int cy;
if (facing == Direction.NORTH) {
cx = loc.getX() + perp;
cy = loc.getY() + axis;
} else if (facing == Direction.SOUTH) {
cx = loc.getX() - perp;
cy = loc.getY() - axis;
} else if (facing == Direction.WEST) {
cx = loc.getX() + axis;
cy = loc.getY() - perp;
} else {
cx = loc.getX() - axis;
cy = loc.getY() + perp;
}
instance.setTextField(StdAttr.LABEL, StdAttr.LABEL_FONT, StdAttr.ATTR_LABEL_COLOR, cx, cy, TextField.H_CENTER,
TextField.V_CENTER);
}
示例8: CircuitAttributes
public CircuitAttributes(Circuit source) {
this.source = source;
subcircInstance = null;
facing = source.getAppearance().getFacing();
label = "";
labelLocation = Direction.NORTH;
labelFont = StdAttr.DEFAULT_LABEL_FONT;
labelcolor = StdAttr.DEFAULT_LABEL_COLOR;
pinInstances = new Instance[0];
}
示例9: updatePorts
private void updatePorts(Instance instance) {
Direction facing = instance.getAttributeValue(StdAttr.FACING);
int dx = 0;
int dy = 0;
if (facing == Direction.NORTH) {
dy = 1;
} else if (facing == Direction.EAST) {
dx = -1;
} else if (facing == Direction.SOUTH) {
dy = -1;
} else if (facing == Direction.WEST) {
dx = 1;
}
Object powerLoc = instance.getAttributeValue(Wiring.ATTR_GATE);
boolean flip = (facing == Direction.SOUTH || facing == Direction.WEST) == (powerLoc == Wiring.GATE_TOP_LEFT);
Port[] ports = new Port[3];
ports[OUTPUT] = new Port(0, 0, Port.OUTPUT, StdAttr.WIDTH);
ports[INPUT] = new Port(40 * dx, 40 * dy, Port.INPUT, StdAttr.WIDTH);
if (flip) {
ports[GATE] = new Port(20 * (dx + dy), 20 * (-dx + dy), Port.INPUT, 1);
} else {
ports[GATE] = new Port(20 * (dx - dy), 20 * (dx + dy), Port.INPUT, 1);
}
instance.setPorts(ports);
}
示例10: computeTextField
private void computeTextField(Instance instance) {
Direction facing = instance.getAttributeValue(StdAttr.FACING);
Object labelLoc = instance.getAttributeValue(Io.ATTR_LABEL_LOC);
Bounds bds = instance.getBounds();
int x = bds.getX() + bds.getWidth() / 2;
int y = bds.getY() + bds.getHeight() / 2;
int halign = GraphicsUtil.H_CENTER;
int valign = GraphicsUtil.V_CENTER;
if (labelLoc == Direction.NORTH) {
y = bds.getY() - 2;
valign = GraphicsUtil.V_BOTTOM;
} else if (labelLoc == Direction.SOUTH) {
y = bds.getY() + bds.getHeight() + 2;
valign = GraphicsUtil.V_TOP;
} else if (labelLoc == Direction.EAST) {
x = bds.getX() + bds.getWidth() + 2;
halign = GraphicsUtil.H_LEFT;
} else if (labelLoc == Direction.WEST) {
x = bds.getX() - 2;
halign = GraphicsUtil.H_RIGHT;
}
if (labelLoc == facing) {
if (labelLoc == Direction.NORTH || labelLoc == Direction.SOUTH) {
x += 12;
halign = GraphicsUtil.H_LEFT;
} else {
y -= 12;
valign = GraphicsUtil.V_BOTTOM;
}
}
instance.setTextField(StdAttr.LABEL, StdAttr.LABEL_FONT, StdAttr.ATTR_LABEL_COLOR, x, y, halign, valign);
}
示例11: updateports
private void updateports(Instance instance) {
Port[] ps = new Port[2];
BitWidth b = instance.getAttributeValue(StdAttr.WIDTH);
Direction dir = instance.getAttributeValue(StdAttr.FACING);
ps[0] = dir == Direction.EAST ? new Port(-20, 0, Port.INPUT, b)
: dir == Direction.WEST ? new Port(20, 0, Port.INPUT, b)
: dir == Direction.NORTH ? new Port(0, 20, Port.INPUT, b) : new Port(0, -20, Port.INPUT, b);
ps[0].setToolTip(Strings.getter("pinInputName"));
ps[1] = new Port(0, 0, Port.OUTPUT, b);
ps[1].setToolTip(Strings.getter("pinOutputName"));
instance.setPorts(ps);
}
示例12: paintInstance
@Override
public void paintInstance(InstancePainter painter) {
Graphics g = painter.getGraphics();
Direction facing = painter.getAttributeValue(StdAttr.FACING);
painter.drawRoundBounds(Color.WHITE);
Bounds bds = painter.getBounds();
g.setColor(Color.GRAY);
int x0;
int y0;
int halign;
if (facing == Direction.WEST) {
x0 = bds.getX() + bds.getWidth() - 3;
y0 = bds.getY() + 15;
halign = GraphicsUtil.H_RIGHT;
} else if (facing == Direction.NORTH) {
x0 = bds.getX() + 10;
y0 = bds.getY() + bds.getHeight() - 2;
halign = GraphicsUtil.H_CENTER;
} else if (facing == Direction.SOUTH) {
x0 = bds.getX() + 10;
y0 = bds.getY() + 12;
halign = GraphicsUtil.H_CENTER;
} else {
x0 = bds.getX() + 3;
y0 = bds.getY() + 15;
halign = GraphicsUtil.H_LEFT;
}
GraphicsUtil.drawText(g, "0", x0, y0, halign, GraphicsUtil.V_BASELINE);
g.setColor(Color.BLACK);
GraphicsUtil.drawCenteredText(g, "Pri", bds.getX() + bds.getWidth() / 2, bds.getY() + bds.getHeight() / 2);
painter.drawPorts();
}
示例13: contains
static boolean contains(Location loc, Bounds bds, Direction facing) {
if (bds.contains(loc, 1)) {
int x = loc.getX();
int y = loc.getY();
int x0 = bds.getX();
int x1 = x0 + bds.getWidth();
int y0 = bds.getY();
int y1 = y0 + bds.getHeight();
if (facing == Direction.NORTH || facing == Direction.SOUTH) {
if (x < x0 + 5 || x > x1 - 5) {
if (facing == Direction.SOUTH) {
return y < y0 + 5;
} else {
return y > y1 - 5;
}
} else {
return true;
}
} else {
if (y < y0 + 5 || y > y1 - 5) {
if (facing == Direction.EAST) {
return x < x0 + 5;
} else {
return x > x1 - 5;
}
} else {
return true;
}
}
} else {
return false;
}
}
示例14: updatePorts
private void updatePorts(Instance instance) {
Direction facing = instance.getAttributeValue(StdAttr.FACING);
Object selectLoc = instance.getAttributeValue(Plexers.ATTR_SELECT_LOC);
BitWidth data = instance.getAttributeValue(StdAttr.WIDTH);
BitWidth select = instance.getAttributeValue(Plexers.ATTR_SELECT);
boolean enable = instance.getAttributeValue(Plexers.ATTR_ENABLE).booleanValue();
int outputs = 1 << select.getWidth();
Port[] ps = new Port[outputs + (enable ? 3 : 2)];
Location sel;
int selMult = selectLoc == Plexers.SELECT_BOTTOM_LEFT ? 1 : -1;
if (outputs == 2) {
Location end0;
Location end1;
if (facing == Direction.WEST) {
end0 = Location.create(-30, -10);
end1 = Location.create(-30, 10);
sel = Location.create(-20, selMult * 20);
} else if (facing == Direction.NORTH) {
end0 = Location.create(-10, -30);
end1 = Location.create(10, -30);
sel = Location.create(selMult * -20, -20);
} else if (facing == Direction.SOUTH) {
end0 = Location.create(-10, 30);
end1 = Location.create(10, 30);
sel = Location.create(selMult * -20, 20);
} else {
end0 = Location.create(30, -10);
end1 = Location.create(30, 10);
sel = Location.create(20, selMult * 20);
}
ps[0] = new Port(end0.getX(), end0.getY(), Port.OUTPUT, data.getWidth());
ps[1] = new Port(end1.getX(), end1.getY(), Port.OUTPUT, data.getWidth());
} else {
int dx = -(outputs / 2) * 10;
int ddx = 10;
int dy = dx;
int ddy = 10;
if (facing == Direction.WEST) {
dx = -40;
ddx = 0;
sel = Location.create(-20, selMult * (dy + 10 * outputs));
} else if (facing == Direction.NORTH) {
dy = -40;
ddy = 0;
sel = Location.create(selMult * dx, -20);
} else if (facing == Direction.SOUTH) {
dy = 40;
ddy = 0;
sel = Location.create(selMult * dx, 20);
} else {
dx = 40;
ddx = 0;
sel = Location.create(20, selMult * (dy + 10 * outputs));
}
for (int i = 0; i < outputs; i++) {
ps[i] = new Port(dx, dy, Port.OUTPUT, data.getWidth());
dx += ddx;
dy += ddy;
}
}
Location en = sel.translate(facing, -10);
ps[outputs] = new Port(sel.getX(), sel.getY(), Port.INPUT, select.getWidth());
if (enable) {
ps[outputs + 1] = new Port(en.getX(), en.getY(), Port.INPUT, BitWidth.ONE);
}
ps[ps.length - 1] = new Port(0, 0, Port.INPUT, data.getWidth());
for (int i = 0; i < outputs; i++) {
ps[i].setToolTip(Strings.getter("demultiplexerOutTip", "" + i));
}
ps[outputs].setToolTip(Strings.getter("demultiplexerSelectTip"));
if (enable) {
ps[outputs + 1].setToolTip(Strings.getter("demultiplexerEnableTip"));
}
ps[ps.length - 1].setToolTip(Strings.getter("demultiplexerInTip"));
instance.setPorts(ps);
}
示例15: getHeuristic
private int getHeuristic() {
Location cur = loc;
Location dst = dest;
Direction curDir = dir;
int dx = dst.getX() - cur.getX();
int dy = dst.getY() - cur.getY();
int ret = -1;
if (extendsWire) {
ret = -1;
if (curDir == Direction.EAST) {
if (dx > 0)
ret = dx / 10 * 9 + Math.abs(dy);
} else if (curDir == Direction.WEST) {
if (dx < 0)
ret = -dx / 10 * 9 + Math.abs(dy);
} else if (curDir == Direction.SOUTH) {
if (dy > 0)
ret = Math.abs(dx) + dy / 10 * 9;
} else if (curDir == Direction.NORTH) {
if (dy < 0)
ret = Math.abs(dx) - dy / 10 * 9;
}
}
if (ret < 0) {
ret = Math.abs(dx) + Math.abs(dy);
}
boolean penalizeDoubleTurn = false;
if (curDir == Direction.EAST) {
penalizeDoubleTurn = dx < 0;
} else if (curDir == Direction.WEST) {
penalizeDoubleTurn = dx > 0;
} else if (curDir == Direction.NORTH) {
penalizeDoubleTurn = dy > 0;
} else if (curDir == Direction.SOUTH) {
penalizeDoubleTurn = dy < 0;
} else if (curDir == null) {
if (dx != 0 || dy != 0)
ret += TURN_PENALTY;
}
if (penalizeDoubleTurn) {
ret += 2 * TURN_PENALTY;
} else if (dx != 0 && dy != 0) {
ret += TURN_PENALTY;
}
return ret;
}