本文整理汇总了Java中com.cburch.logisim.util.GraphicsUtil.drawText方法的典型用法代码示例。如果您正苦于以下问题:Java GraphicsUtil.drawText方法的具体用法?Java GraphicsUtil.drawText怎么用?Java GraphicsUtil.drawText使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.cburch.logisim.util.GraphicsUtil
的用法示例。
在下文中一共展示了GraphicsUtil.drawText方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: drawPin
import com.cburch.logisim.util.GraphicsUtil; //导入方法依赖的package包/类
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: paintGhost
import com.cburch.logisim.util.GraphicsUtil; //导入方法依赖的package包/类
@Override
public void paintGhost(InstancePainter painter) {
TextAttributes attrs = (TextAttributes) painter.getAttributeSet();
String text = attrs.getText();
if (text == null || text.equals(""))
return;
int halign = attrs.getHorizontalAlign();
int valign = attrs.getVerticalAlign();
Graphics g = painter.getGraphics();
Font oldFont = g.getFont();
Color oldColor = g.getColor();
g.setFont(attrs.getFont());
g.setColor(painter.getAttributeValue(ATTR_COLOR));
GraphicsUtil.drawText(g, text, 0, 0, halign, valign);
String textTrim = text.endsWith(" ") ? text.substring(0, text.length() - 1) : text;
Bounds newBds;
if (textTrim.equals("")) {
newBds = Bounds.EMPTY_BOUNDS;
} else {
Rectangle bdsOut = GraphicsUtil.getTextBounds(g, textTrim, 0, 0, halign, valign);
newBds = Bounds.create(bdsOut).expand(4);
}
if (attrs.setOffsetBounds(newBds)) {
Instance instance = painter.getInstance();
if (instance != null)
instance.recomputeBounds();
}
g.setFont(oldFont);
g.setColor(oldColor);
}
示例3: paint
import com.cburch.logisim.util.GraphicsUtil; //导入方法依赖的package包/类
public void paint(Graphics g, int leftX, int topY) {
int addrBits = getAddrBits();
int dataBits = contents.getWidth();
int boxX = leftX + (addrBits <= 12 ? ENTRY_XOFFS12 : ENTRY_XOFFS32);
int boxY = topY + ENTRY_YOFFS;
int boxW = addrBits <= 12 ? TABLE_WIDTH12 : TABLE_WIDTH32;
int boxH = ROWS * ENTRY_HEIGHT;
GraphicsUtil.switchToWidth(g, 1);
g.drawRect(boxX, boxY, boxW, boxH);
int entryWidth = boxW / columns;
for (int row = 0; row < ROWS; row++) {
long addr = (curScroll / columns * columns) + columns * row;
int x = boxX;
int y = boxY + ENTRY_HEIGHT * row;
int yoffs = ENTRY_HEIGHT - 3;
if (isValidAddr(addr)) {
g.setColor(Color.GRAY);
GraphicsUtil.drawText(g, StringUtil.toHexString(getAddrBits(), (int) addr), x - 2, y + yoffs,
GraphicsUtil.H_RIGHT, GraphicsUtil.V_BASELINE);
}
g.setColor(Color.BLACK);
for (int col = 0; col < columns && isValidAddr(addr); col++) {
int val = contents.get(addr);
if (addr == curAddr) {
g.fillRect(x, y, entryWidth, ENTRY_HEIGHT);
g.setColor(Color.WHITE);
GraphicsUtil.drawText(g, StringUtil.toHexString(dataBits, val), x + entryWidth / 2, y + yoffs,
GraphicsUtil.H_CENTER, GraphicsUtil.V_BASELINE);
g.setColor(Color.BLACK);
} else {
GraphicsUtil.drawText(g, StringUtil.toHexString(dataBits, val), x + entryWidth / 2, y + yoffs,
GraphicsUtil.H_CENTER, GraphicsUtil.V_BASELINE);
}
addr++;
x += entryWidth;
}
}
}
示例4: paintInstance
import com.cburch.logisim.util.GraphicsUtil; //导入方法依赖的package包/类
@Override
public void paintInstance(InstancePainter painter) {
Graphics g = painter.getGraphics();
Bounds bds = painter.getBounds();
StateData state = (StateData) painter.getData();
BitWidth widthVal = painter.getAttributeValue(StdAttr.WIDTH);
int width = widthVal == null ? 8 : widthVal.getWidth();
// draw boundary, label
painter.drawRoundBounds(Color.WHITE);
painter.drawLabel();
// draw input and output ports
painter.drawPort(OUT, "Q", Direction.WEST);
painter.drawPort(RST);
painter.drawPort(NXT);
painter.drawClock(CK, Direction.EAST);
// draw contents
if (painter.getShowState()) {
int val = state == null ? 0 : state.value;
String str = StringUtil.toHexString(width, val);
if (str.length() <= 4) {
GraphicsUtil.drawText(g, str, bds.getX() + 15, bds.getY() + 4, GraphicsUtil.H_CENTER,
GraphicsUtil.V_TOP);
} else {
int split = str.length() - 4;
GraphicsUtil.drawText(g, str.substring(0, split), bds.getX() + 15, bds.getY() + 3,
GraphicsUtil.H_CENTER, GraphicsUtil.V_TOP);
GraphicsUtil.drawText(g, str.substring(split), bds.getX() + 15, bds.getY() + 15, GraphicsUtil.H_CENTER,
GraphicsUtil.V_TOP);
}
}
}
示例5: paintInstance
import com.cburch.logisim.util.GraphicsUtil; //导入方法依赖的package包/类
@Override
public void paintInstance(InstancePainter painter) {
Graphics g = painter.getGraphics();
FontMetrics fm = g.getFontMetrics();
int asc = fm.getAscent();
painter.drawRoundBounds(Color.WHITE);
String s0;
String type = getType(painter.getAttributeSet());
if (type.equals("zero"))
s0 = Strings.get("extenderZeroLabel");
else if (type.equals("one"))
s0 = Strings.get("extenderOneLabel");
else if (type.equals("sign"))
s0 = Strings.get("extenderSignLabel");
else if (type.equals("input"))
s0 = Strings.get("extenderInputLabel");
else
s0 = "???"; // should never happen
String s1 = Strings.get("extenderMainLabel");
Bounds bds = painter.getBounds();
int x = bds.getX() + bds.getWidth() / 2;
int y0 = bds.getY() + (bds.getHeight() / 2 + asc) / 2;
int y1 = bds.getY() + (3 * bds.getHeight() / 2 + asc) / 2;
GraphicsUtil.drawText(g, s0, x, y0, GraphicsUtil.H_CENTER, GraphicsUtil.V_BASELINE);
GraphicsUtil.drawText(g, s1, x, y1, GraphicsUtil.H_CENTER, GraphicsUtil.V_BASELINE);
BitWidth w0 = painter.getAttributeValue(ATTR_OUT_WIDTH);
BitWidth w1 = painter.getAttributeValue(ATTR_IN_WIDTH);
painter.drawPort(0, "" + w0.getWidth(), Direction.WEST);
painter.drawPort(1, "" + w1.getWidth(), Direction.EAST);
if (type.equals("input"))
painter.drawPort(2);
}
示例6: computeBounds
import com.cburch.logisim.util.GraphicsUtil; //导入方法依赖的package包/类
private Bounds computeBounds(TunnelAttributes attrs, int textWidth, int textHeight, Graphics g, String label) {
int x = attrs.getLabelX();
int y = attrs.getLabelY();
int halign = attrs.getLabelHAlign();
int valign = attrs.getLabelVAlign();
int minDim = ARROW_MIN_WIDTH - 2 * MARGIN;
int bw = Math.max(minDim, textWidth);
int bh = Math.max(minDim, textHeight);
int bx;
int by;
switch (halign) {
case TextField.H_LEFT:
bx = x;
break;
case TextField.H_RIGHT:
bx = x - bw;
break;
default:
bx = x - (bw / 2);
}
switch (valign) {
case TextField.V_TOP:
by = y;
break;
case TextField.V_BOTTOM:
by = y - bh;
break;
default:
by = y - (bh / 2);
}
if (g != null) {
GraphicsUtil.drawText(g, label, bx + bw / 2, by + bh / 2, GraphicsUtil.H_CENTER,
GraphicsUtil.V_CENTER_OVERALL);
}
return Bounds.create(bx, by, bw, bh).expand(MARGIN).add(0, 0);
}
示例7: paintInstance
import com.cburch.logisim.util.GraphicsUtil; //导入方法依赖的package包/类
@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();
}
示例8: paintInstance
import com.cburch.logisim.util.GraphicsUtil; //导入方法依赖的package包/类
@Override
public void paintInstance(InstancePainter painter) {
Graphics g = painter.getGraphics();
Bounds bds = painter.getBounds();
RegisterData state = (RegisterData) painter.getData();
BitWidth widthVal = painter.getAttributeValue(StdAttr.WIDTH);
int width = widthVal == null ? 8 : widthVal.getWidth();
// determine text to draw in label
String a;
String b = null;
if (painter.getShowState()) {
int val = state == null ? 0 : state.value;
String str = StringUtil.toHexString(width, val);
if (str.length() <= 4) {
a = str;
} else {
int split = str.length() - 4;
a = str.substring(0, split);
b = str.substring(split);
}
} else {
a = Strings.get("counterLabel");
b = Strings.get("registerWidthLabel", "" + widthVal.getWidth());
}
// draw boundary, label
painter.drawRoundBounds(Color.WHITE);
painter.drawLabel();
// draw input and output ports
if (b == null) {
painter.drawPort(IN, "D", Direction.EAST);
painter.drawPort(OUT, "Q", Direction.WEST);
} else {
painter.drawPort(IN);
painter.drawPort(OUT);
}
g.setColor(Color.GRAY);
painter.drawPort(LD);
painter.drawPort(CARRY);
painter.drawPort(PRE);
painter.drawPort(CLR, "0", Direction.SOUTH);
painter.drawPort(CT, Strings.get("counterEnableLabel"), Direction.EAST);
g.setColor(Color.BLACK);
painter.drawClock(CK, Direction.NORTH);
// draw contents
if (b == null) {
GraphicsUtil.drawText(g, a, bds.getX() + 15, bds.getY() + 4, GraphicsUtil.H_CENTER, GraphicsUtil.V_TOP);
} else {
GraphicsUtil.drawText(g, a, bds.getX() + 15, bds.getY() + 3, GraphicsUtil.H_CENTER, GraphicsUtil.V_TOP);
GraphicsUtil.drawText(g, b, bds.getX() + 15, bds.getY() + 15, GraphicsUtil.H_CENTER, GraphicsUtil.V_TOP);
}
}
示例9: paintInstance
import com.cburch.logisim.util.GraphicsUtil; //导入方法依赖的package包/类
@Override
public void paintInstance(InstancePainter painter) {
Graphics g = painter.getGraphics();
Bounds bds = painter.getBounds();
RegisterData state = (RegisterData) painter.getData();
BitWidth widthVal = painter.getAttributeValue(StdAttr.WIDTH);
int width = widthVal == null ? 8 : widthVal.getWidth();
// determine text to draw in label
String a;
String b = null;
if (painter.getShowState()) {
int val = state == null ? 0 : state.value;
String str = StringUtil.toHexString(width, val);
if (str.length() <= 4) {
a = str;
} else {
int split = str.length() - 4;
a = str.substring(0, split);
b = str.substring(split);
}
} else {
a = Strings.get("registerLabel");
b = Strings.get("registerWidthLabel", "" + widthVal.getWidth());
}
// draw boundary, label
painter.drawRoundBounds(Color.WHITE);
// draw input and output ports
if (b == null) {
painter.drawPort(IN, "D", Direction.EAST);
painter.drawPort(OUT, "Q", Direction.WEST);
} else {
painter.drawPort(IN);
painter.drawPort(OUT);
}
g.setColor(Color.GRAY);
painter.drawPort(CLR, "0", Direction.SOUTH);
painter.drawPort(PRE);
painter.drawPort(EN, Strings.get("memEnableLabel"), Direction.EAST);
painter.drawPort(CS);
g.setColor(Color.BLACK);
painter.drawClock(CK, Direction.NORTH);
// draw contents
if (b == null) {
GraphicsUtil.drawText(g, a, bds.getX() + 15, bds.getY() + 4, GraphicsUtil.H_CENTER, GraphicsUtil.V_TOP);
} else {
GraphicsUtil.drawText(g, a, bds.getX() + 15, bds.getY() + 3, GraphicsUtil.H_CENTER, GraphicsUtil.V_TOP);
GraphicsUtil.drawText(g, b, bds.getX() + 15, bds.getY() + 15, GraphicsUtil.H_CENTER, GraphicsUtil.V_TOP);
}
painter.drawLabel();
}
示例10: paintBase
import com.cburch.logisim.util.GraphicsUtil; //导入方法依赖的package包/类
private void paintBase(InstancePainter painter, Value pullValue, Color inColor, Color outColor) {
boolean color = painter.shouldDrawColor();
Direction facing = painter.getAttributeValue(StdAttr.FACING);
Graphics g = painter.getGraphics();
Color baseColor = g.getColor();
GraphicsUtil.switchToWidth(g, 3);
if (color && inColor != null)
g.setColor(inColor);
if (facing == Direction.EAST) {
GraphicsUtil.drawText(g, pullValue.toDisplayString(), -32, 0, GraphicsUtil.H_RIGHT, GraphicsUtil.V_CENTER);
} else if (facing == Direction.WEST) {
GraphicsUtil.drawText(g, pullValue.toDisplayString(), 32, 0, GraphicsUtil.H_LEFT, GraphicsUtil.V_CENTER);
} else if (facing == Direction.NORTH) {
GraphicsUtil.drawText(g, pullValue.toDisplayString(), 0, 32, GraphicsUtil.H_CENTER, GraphicsUtil.V_TOP);
} else {
GraphicsUtil.drawText(g, pullValue.toDisplayString(), 0, -32, GraphicsUtil.H_CENTER,
GraphicsUtil.V_BASELINE);
}
double rotate = 0.0;
if (g instanceof Graphics2D) {
rotate = Direction.SOUTH.toRadians() - facing.toRadians();
if (rotate != 0.0)
((Graphics2D) g).rotate(rotate);
}
g.drawLine(0, -30, 0, -26);
g.drawLine(-6, -30, 6, -30);
if (color && outColor != null)
g.setColor(outColor);
g.drawLine(0, -4, 0, 0);
g.setColor(baseColor);
GraphicsUtil.switchToWidth(g, 2);
if (painter.getGateShape() == AppPreferences.SHAPE_SHAPED) {
int[] xp = { 0, -5, 5, -5, 5, -5, 0 };
int[] yp = { -25, -23, -19, -15, -11, -7, -5 };
g.drawPolyline(xp, yp, xp.length);
} else {
g.drawRect(-5, -25, 10, 20);
}
if (rotate != 0.0) {
((Graphics2D) g).rotate(-rotate);
}
}
示例11: paintInstance
import com.cburch.logisim.util.GraphicsUtil; //导入方法依赖的package包/类
@Override
public void paintInstance(InstancePainter painter) {
Graphics g = painter.getGraphics();
Bounds bds = painter.getBounds();
Direction facing = painter.getAttributeValue(StdAttr.FACING);
BitWidth select = painter.getAttributeValue(Plexers.ATTR_SELECT);
boolean enable = painter.getAttributeValue(Plexers.ATTR_ENABLE).booleanValue();
int inputs = 1 << select.getWidth();
// draw stubs for select/enable inputs that aren't on instance boundary
GraphicsUtil.switchToWidth(g, 3);
boolean vertical = facing != Direction.NORTH && facing != Direction.SOUTH;
Object selectLoc = painter.getAttributeValue(Plexers.ATTR_SELECT_LOC);
int selMult = selectLoc == Plexers.SELECT_BOTTOM_LEFT ? 1 : -1;
int dx = vertical ? 0 : -selMult;
int dy = vertical ? selMult : 0;
if (inputs == 2) { // draw select wire
Location pt = painter.getInstance().getPortLocation(inputs);
if (painter.getShowState()) {
g.setColor(painter.getPort(inputs).getColor());
}
g.drawLine(pt.getX() - 2 * dx, pt.getY() - 2 * dy, pt.getX(), pt.getY());
}
if (enable) {
Location en = painter.getInstance().getPortLocation(inputs + 1);
if (painter.getShowState()) {
g.setColor(painter.getPort(inputs + 1).getColor());
}
int len = inputs == 2 ? 6 : 4;
g.drawLine(en.getX() - len * dx, en.getY() - len * dy, en.getX(), en.getY());
}
GraphicsUtil.switchToWidth(g, 1);
// draw a circle indicating where the select input is located
Multiplexer.drawSelectCircle(g, bds, painter.getInstance().getPortLocation(inputs));
// draw a 0 indicating where the numbering starts for inputs
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;
}
g.setColor(Color.GRAY);
GraphicsUtil.drawText(g, "0", x0, y0, halign, GraphicsUtil.V_BASELINE);
// draw the trapezoid, "MUX" string, the individual ports
g.setColor(Color.BLACK);
Plexers.drawTrapezoid(g, bds, facing, select.getWidth() == 1 ? 10 : 20);
GraphicsUtil.drawCenteredText(g, "MUX", bds.getX() + bds.getWidth() / 2, bds.getY() + bds.getHeight() / 2);
painter.drawPorts();
}
示例12: paintInstance
import com.cburch.logisim.util.GraphicsUtil; //导入方法依赖的package包/类
@Override
public void paintInstance(InstancePainter painter) {
Graphics g = painter.getGraphics();
Bounds bds = painter.getBounds();
Direction facing = painter.getAttributeValue(StdAttr.FACING);
Object selectLoc = painter.getAttributeValue(Plexers.ATTR_SELECT_LOC);
BitWidth select = painter.getAttributeValue(Plexers.ATTR_SELECT);
boolean enable = painter.getAttributeValue(Plexers.ATTR_ENABLE).booleanValue();
int selMult = selectLoc == Plexers.SELECT_TOP_RIGHT ? -1 : 1;
int outputs = 1 << select.getWidth();
// draw stubs for select and enable ports
GraphicsUtil.switchToWidth(g, 3);
boolean vertical = facing == Direction.NORTH || facing == Direction.SOUTH;
int dx = vertical ? selMult : 0;
int dy = vertical ? 0 : -selMult;
if (outputs == 2) { // draw select wire
if (painter.getShowState()) {
g.setColor(painter.getPort(outputs).getColor());
}
Location pt = painter.getInstance().getPortLocation(outputs);
g.drawLine(pt.getX(), pt.getY(), pt.getX() + 2 * dx, pt.getY() + 2 * dy);
}
if (enable) {
Location en = painter.getInstance().getPortLocation(outputs + 1);
int len = outputs == 2 ? 6 : 4;
if (painter.getShowState()) {
g.setColor(painter.getPort(outputs + 1).getColor());
}
g.drawLine(en.getX(), en.getY(), en.getX() + len * dx, en.getY() + len * dy);
}
GraphicsUtil.switchToWidth(g, 1);
// draw a circle indicating where the select input is located
Multiplexer.drawSelectCircle(g, bds, painter.getInstance().getPortLocation(outputs));
// draw "0"
int x0;
int y0;
int halign;
if (facing == Direction.WEST) {
x0 = 3;
y0 = 15;
halign = GraphicsUtil.H_LEFT;
} else if (facing == Direction.NORTH) {
x0 = 10;
y0 = 15;
halign = GraphicsUtil.H_CENTER;
} else if (facing == Direction.SOUTH) {
x0 = 10;
y0 = bds.getHeight() - 3;
halign = GraphicsUtil.H_CENTER;
} else {
x0 = bds.getWidth() - 3;
y0 = 15;
halign = GraphicsUtil.H_RIGHT;
}
g.setColor(Color.GRAY);
GraphicsUtil.drawText(g, "0", bds.getX() + x0, bds.getY() + y0, halign, GraphicsUtil.V_BASELINE);
// draw trapezoid, "Decd", and ports
g.setColor(Color.BLACK);
Plexers.drawTrapezoid(g, bds, facing.reverse(), outputs == 2 ? 10 : 20);
GraphicsUtil.drawCenteredText(g, "Decd", bds.getX() + bds.getWidth() / 2, bds.getY() + bds.getHeight() / 2);
painter.drawPorts();
}
示例13: paintInstance
import com.cburch.logisim.util.GraphicsUtil; //导入方法依赖的package包/类
@Override
public void paintInstance(InstancePainter painter) {
Graphics g = painter.getGraphics();
Bounds bds = painter.getBounds();
Direction facing = painter.getAttributeValue(StdAttr.FACING);
BitWidth select = painter.getAttributeValue(Plexers.ATTR_SELECT);
boolean enable = painter.getAttributeValue(Plexers.ATTR_ENABLE).booleanValue();
int outputs = 1 << select.getWidth();
// draw select and enable inputs
GraphicsUtil.switchToWidth(g, 3);
boolean vertical = facing == Direction.NORTH || facing == Direction.SOUTH;
Object selectLoc = painter.getAttributeValue(Plexers.ATTR_SELECT_LOC);
int selMult = selectLoc == Plexers.SELECT_BOTTOM_LEFT ? 1 : -1;
int dx = vertical ? selMult : 0;
int dy = vertical ? 0 : -selMult;
if (outputs == 2) { // draw select wire
Location sel = painter.getInstance().getPortLocation(outputs);
if (painter.getShowState()) {
g.setColor(painter.getPort(outputs).getColor());
}
g.drawLine(sel.getX(), sel.getY(), sel.getX() + 2 * dx, sel.getY() + 2 * dy);
}
if (enable) {
Location en = painter.getInstance().getPortLocation(outputs + 1);
if (painter.getShowState()) {
g.setColor(painter.getPort(outputs + 1).getColor());
}
int len = outputs == 2 ? 6 : 4;
g.drawLine(en.getX(), en.getY(), en.getX() + len * dx, en.getY() + len * dy);
}
GraphicsUtil.switchToWidth(g, 1);
// draw a circle indicating where the select input is located
Multiplexer.drawSelectCircle(g, bds, painter.getInstance().getPortLocation(outputs));
// draw "0" next to first input
int x0;
int y0;
int halign;
if (facing == Direction.WEST) {
x0 = 3;
y0 = 15;
halign = GraphicsUtil.H_LEFT;
} else if (facing == Direction.NORTH) {
x0 = 10;
y0 = 15;
halign = GraphicsUtil.H_CENTER;
} else if (facing == Direction.SOUTH) {
x0 = 10;
y0 = bds.getHeight() - 3;
halign = GraphicsUtil.H_CENTER;
} else {
x0 = bds.getWidth() - 3;
y0 = 15;
halign = GraphicsUtil.H_RIGHT;
}
g.setColor(Color.GRAY);
GraphicsUtil.drawText(g, "0", bds.getX() + x0, bds.getY() + y0, halign, GraphicsUtil.V_BASELINE);
// draw trapezoid, "DMX" label, and ports
g.setColor(Color.BLACK);
Plexers.drawTrapezoid(g, bds, facing.reverse(), select.getWidth() == 1 ? 10 : 20);
GraphicsUtil.drawCenteredText(g, "DMX", bds.getX() + bds.getWidth() / 2, bds.getY() + bds.getHeight() / 2);
painter.drawPorts();
}
示例14: drawLabels
import com.cburch.logisim.util.GraphicsUtil; //导入方法依赖的package包/类
static void drawLabels(ComponentDrawContext context, SplitterAttributes attrs, Location origin) {
// compute labels
String[] ends = new String[attrs.fanout + 1];
int curEnd = -1;
int cur0 = 0;
for (int i = 0, n = attrs.bit_end.length; i <= n; i++) {
int bit = i == n ? -1 : attrs.bit_end[i];
if (bit != curEnd) {
int cur1 = i - 1;
String toAdd;
if (curEnd <= 0) {
toAdd = null;
} else if (cur0 == cur1) {
toAdd = "" + cur0;
} else {
toAdd = cur0 + "-" + cur1;
}
if (toAdd != null) {
String old = ends[curEnd];
if (old == null) {
ends[curEnd] = toAdd;
} else {
ends[curEnd] = old + "," + toAdd;
}
}
curEnd = bit;
cur0 = i;
}
}
Graphics g = context.getGraphics().create();
Font font = g.getFont();
g.setFont(font.deriveFont(7.0f));
SplitterParameters parms = attrs.getParameters();
int x = origin.getX() + parms.getEnd0X() + parms.getEndToSpineDeltaX();
int y = origin.getY() + parms.getEnd0Y() + parms.getEndToSpineDeltaY();
int dx = parms.getEndToEndDeltaX();
int dy = parms.getEndToEndDeltaY();
if (parms.getTextAngle() != 0) {
((Graphics2D) g).rotate(Math.PI / 2.0);
int t;
t = -x;
x = y;
y = t;
t = -dx;
dx = dy;
dy = t;
}
int halign = parms.getTextHorzAlign();
int valign = parms.getTextVertAlign();
x += (halign == GraphicsUtil.H_RIGHT ? -1 : 1) * (SPINE_WIDTH / 2 + 1);
y += valign == GraphicsUtil.V_TOP ? 0 : -3;
for (int i = 0, n = attrs.fanout; i < n; i++) {
String text = ends[i + 1];
if (text != null) {
GraphicsUtil.drawText(g, text, x, y, halign, valign);
}
x += dx;
y += dy;
}
g.dispose();
}