本文整理汇总了Java中com.cburch.logisim.util.GraphicsUtil.drawCenteredText方法的典型用法代码示例。如果您正苦于以下问题:Java GraphicsUtil.drawCenteredText方法的具体用法?Java GraphicsUtil.drawCenteredText怎么用?Java GraphicsUtil.drawCenteredText使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.cburch.logisim.util.GraphicsUtil
的用法示例。
在下文中一共展示了GraphicsUtil.drawCenteredText方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: paintInstance
import com.cburch.logisim.util.GraphicsUtil; //导入方法依赖的package包/类
@Override
public void paintInstance(InstancePainter painter) {
painter.drawRoundBounds(Color.WHITE);
painter.drawClock(0, Direction.EAST); // draw a triangle on port 0
painter.drawPort(1); // draw port 1 as just a dot
// Display the current counter value centered within the rectangle.
// However, if the context says not to show state (as when generating
// printer output), then skip this.
if (painter.getShowState()) {
CounterData state = CounterData.get(painter, BIT_WIDTH);
Bounds bds = painter.getBounds();
GraphicsUtil.drawCenteredText(painter.getGraphics(),
StringUtil.toHexString(BIT_WIDTH.getWidth(), state.getValue().toIntValue()),
bds.getX() + bds.getWidth() / 2, bds.getY() + bds.getHeight() / 2);
}
}
示例2: paintInstance
import com.cburch.logisim.util.GraphicsUtil; //导入方法依赖的package包/类
@Override
public void paintInstance(InstancePainter painter) {
PlaRomData data = getPlaRomData(painter);
Graphics g = painter.getGraphics();
painter.drawRoundBounds(Color.WHITE);
Bounds bds = painter.getBounds();
g.setFont(new Font("sans serif", Font.BOLD, 11));
GraphicsUtil.drawCenteredText(g, Strings.getter("PlaRomComponent").toString(), bds.getX() + bds.getWidth() / 2,
bds.getY() + bds.getHeight() / 4);
GraphicsUtil.drawCenteredText(g, data.getSizeString(), bds.getX() + bds.getWidth() / 2,
bds.getY() + bds.getHeight() * 2 / 5);
g.setColor(Color.WHITE);
g.fillRect(bds.getX() + 4, bds.getY() + bds.getHeight() - bds.getHeight() / 4 - 11, 72, 16);
g.setColor(Color.BLACK);
g.drawRect(bds.getX() + 4, bds.getY() + bds.getHeight() - bds.getHeight() / 4 - 12, 72, 16);
GraphicsUtil.drawCenteredText(g, com.cburch.logisim.gui.menu.Strings.get("editMenu"),
bds.getX() + bds.getWidth() / 2, bds.getY() + bds.getHeight() - bds.getHeight() / 4 - 6);
painter.drawPort(0);
painter.drawPort(1);
g.setColor(Color.GRAY);
painter.drawPort(2, Strings.get("ramClrLabel"), Direction.SOUTH);
painter.drawPort(3, Strings.get("ramCSLabel"), Direction.NORTH);
}
示例3: paintRectangularBase
import com.cburch.logisim.util.GraphicsUtil; //导入方法依赖的package包/类
private void paintRectangularBase(Graphics g, InstancePainter painter) {
GraphicsUtil.switchToWidth(g, 2);
if (painter.getAttributeValue(ATTR_SIZE) == SIZE_NARROW) {
if (AppPreferences.FILL_COMPONENT_BACKGROUND.getBoolean()) {
g.setColor(Color.WHITE);
g.fillRoundRect(-20, -9, 14, 18, 5, 5);
g.fillOval(-6, -3, 6, 6);
g.setColor(Color.BLACK);
}
g.drawRoundRect(-20, -9, 14, 18, 5, 5);
GraphicsUtil.drawCenteredText(g, RECT_LABEL, -13, -2);
g.drawOval(-6, -3, 6, 6);
} else {
if (AppPreferences.FILL_COMPONENT_BACKGROUND.getBoolean()) {
g.setColor(Color.WHITE);
g.fillRoundRect(-30, -9, 20, 18, 10, 10);
g.fillOval(-10, -5, 9, 9);
g.setColor(Color.BLACK);
}
g.drawRoundRect(-30, -9, 20, 18, 10, 10);
GraphicsUtil.drawCenteredText(g, RECT_LABEL, -20, -2);
g.drawOval(-10, -5, 9, 9);
}
GraphicsUtil.switchToWidth(g, 1);
}
示例4: paintInternal
import com.cburch.logisim.util.GraphicsUtil; //导入方法依赖的package包/类
@Override
public void paintInternal(InstancePainter painter, int x, int y, int height, boolean up) {
Graphics g = painter.getGraphics();
super.paintBase(painter, false, false);
Drawgates.paintPortNames(painter, x, y, height, new String[] { "ShLd", "CK", "P4", "P5", "P6", "P7", "Q7n",
"Q7", "SER", "P0", "P1", "P2", "P3", "CkIh" });
ShiftRegisterData data = getData(painter);
String s = "";
for (int i = 0; i < 8; i++)
s += data.get(7 - i).toHexString();
g.setFont(new Font(Font.DIALOG_INPUT, Font.PLAIN, 14));
GraphicsUtil.drawCenteredText(g, s, x + 80, y + height / 2 - 3);
}
示例5: paint
import com.cburch.logisim.util.GraphicsUtil; //导入方法依赖的package包/类
@Override
public void paint(InstancePainter painter) {
Graphics g = painter.getGraphics();
Bounds bds = painter.getBounds();
g.setFont(new Font("sans serif", Font.BOLD, 11));
g.setColor((isPressed) ? Color.LIGHT_GRAY : Color.WHITE);
g.fillRect(bds.getX() + 4, bds.getY() + bds.getHeight() - bds.getHeight() / 4 - 12, 72, 16);
g.setColor(Color.BLACK);
g.drawRect(bds.getX() + 4, bds.getY() + bds.getHeight() - bds.getHeight() / 4 - 12, 72, 16);
GraphicsUtil.drawCenteredText(g, com.cburch.logisim.gui.menu.Strings.get("editMenu"),
bds.getX() + bds.getWidth() / 2, bds.getY() + bds.getHeight() - bds.getHeight() / 4 - 6);
}
示例6: paintInstance
import com.cburch.logisim.util.GraphicsUtil; //导入方法依赖的package包/类
@Override
public void paintInstance(InstancePainter painter) {
Value value = getValue(painter);
Graphics g = painter.getGraphics();
Bounds bds = painter.getBounds(); // intentionally with no graphics
// object - we don't want label
// included
int x = bds.getX();
int y = bds.getY();
g.setColor(Color.WHITE);
g.fillRect(x + 5, y + 5, bds.getWidth() - 10, bds.getHeight() - 10);
g.setColor(Color.GRAY);
if (value.getWidth() <= 1) {
g.drawOval(x, y, bds.getWidth(), bds.getHeight());
} else {
g.drawRoundRect(x, y, bds.getWidth(), bds.getHeight(), 10, 10);
}
painter.drawLabel();
if (!painter.getShowState()) {
if (value.getWidth() > 0) {
GraphicsUtil.drawCenteredText(g, "x" + value.getWidth(), bds.getX() + bds.getWidth() / 2,
bds.getY() + bds.getHeight() / 2);
}
} else {
paintValue(painter, value);
}
painter.drawPorts();
}
示例7: paintPortNames
import com.cburch.logisim.util.GraphicsUtil; //导入方法依赖的package包/类
static void paintPortNames(InstancePainter painter, int x, int y, int height, String[] portnames) {
Graphics g = painter.getGraphics();
g.drawRect(x + 10, y + AbstractTtlGate.pinheight + 10, portnames.length * 10,
height - 2 * AbstractTtlGate.pinheight - 20);
for (int i = 0; i < 2; i++) {
for (int j = 0; j < portnames.length / 2; j++) {
GraphicsUtil.drawCenteredText(g, portnames[j + (i * 7)],
i == 0 ? x + 10 + j * 20 : x + 160 - j * 20 - 10,
y + height - AbstractTtlGate.pinheight - 7 - i * (height - 2 * AbstractTtlGate.pinheight - 11));
}
}
}
示例8: paintGhost
import com.cburch.logisim.util.GraphicsUtil; //导入方法依赖的package包/类
@Override
public void paintGhost(InstancePainter painter) {
int v = painter.getAttributeValue(ATTR_VALUE).intValue();
String vStr = Integer.toHexString(v);
Bounds bds = getOffsetBounds(painter.getAttributeSet());
Graphics g = painter.getGraphics();
GraphicsUtil.switchToWidth(g, 2);
g.fillOval(-2, -2, 4, 4);
GraphicsUtil.drawCenteredText(g, vStr, bds.getX() + bds.getWidth() / 2, bds.getY() + bds.getHeight() / 2 - 2);
}
示例9: paintIcon
import com.cburch.logisim.util.GraphicsUtil; //导入方法依赖的package包/类
@Override
public void paintIcon(InstancePainter painter) {
int w = painter.getAttributeValue(StdAttr.WIDTH).getWidth();
int pinx = 17;
int piny = 8;
Direction dir = painter.getAttributeValue(StdAttr.FACING);
if (dir == Direction.EAST) {
} // keep defaults
else if (dir == Direction.WEST) {
pinx = 0;
} else if (dir == Direction.NORTH) {
pinx = 8;
piny = 2;
} else if (dir == Direction.SOUTH) {
pinx = 8;
piny = 15;
}
Graphics g = painter.getGraphics();
g.setColor(BACKGROUND_COLOR);
g.fillRoundRect(2, 3, 16, 14, 3, 3);
g.setColor(Color.BLACK);
if (w == 1) {
int v = painter.getAttributeValue(ATTR_VALUE).intValue();
Value val = v == 1 ? Value.TRUE : Value.FALSE;
g.setColor(val.getColor());
GraphicsUtil.drawCenteredText(g, "" + v, 11, 8);
} else {
g.setFont(g.getFont().deriveFont(9.0f));
GraphicsUtil.drawCenteredText(g, "x" + w, 11, 8);
}
g.fillOval(pinx, piny, 3, 3);
}
示例10: paintIconRectangular
import com.cburch.logisim.util.GraphicsUtil; //导入方法依赖的package包/类
protected void paintIconRectangular(InstancePainter painter) {
Graphics g = painter.getGraphics();
g.drawRect(1, 2, 16, 16);
if (negateOutput)
g.drawOval(16, 8, 4, 4);
String label = getRectangularLabel(painter.getAttributeSet());
GraphicsUtil.drawCenteredText(g, label, 9, 8);
}
示例11: paintInstance
import com.cburch.logisim.util.GraphicsUtil; //导入方法依赖的package包/类
@Override
public void paintInstance(InstancePainter painter) {
Direction dir = painter.getAttributeValue(StdAttr.FACING);
Graphics g = painter.getGraphics();
painter.drawRoundBounds(Color.WHITE);
Bounds bds = painter.getBounds();
int nports = 11 + (painter.getAttributeValue(MULTI_BIT) ? 1 : 4);
boolean multibit = painter.getAttributeValue(MULTI_BIT);
String text = (painter.getPort(7) == Value.FALSE) ? "!" + Strings.get("memEnableLabel")
: painter
.getPort(nports - 2) == Value.FALSE
? "BI"
: painter.getPort(nports - 3) == Value.FALSE ? "LI"
: painter.getPort(nports - 1) == Value.FALSE
&& getdecval(painter, multibit, 8, 8, 9, 10, 11) == 0
? "RBI"
: (getdecval(painter, multibit, 8, 8, 9, 10, 11) != -1)
? Integer.toString(
getdecval(painter, multibit, 8, 8, 9, 10, 11))
: "-";
GraphicsUtil.drawCenteredText(g, text, bds.getX() + bds.getWidth() / 2, bds.getY() + bds.getHeight() / 2);
for (int i = 0; i < nports - 3; i++) {
if (i != 7)
painter.drawPort(i);
}
g.setColor(Color.GRAY);
painter.drawPort(7, Strings.get("memEnableLabel"),
(dir == Direction.NORTH || dir == Direction.SOUTH) ? Direction.EAST : Direction.NORTH);
if (dir == Direction.NORTH || dir == Direction.SOUTH) {// write the port name only if horizontal to not overlap
painter.drawPort(nports - 3, Strings.get("LT"), Direction.WEST);
painter.drawPort(nports - 2, Strings.get("BI"), Direction.WEST);
painter.drawPort(nports - 1, Strings.get("RBI"), Direction.WEST);
} else {
painter.drawPort(nports - 3);
painter.drawPort(nports - 2);
painter.drawPort(nports - 1);
}
}
示例12: 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();
}
示例13: paintInstance
import com.cburch.logisim.util.GraphicsUtil; //导入方法依赖的package包/类
@Override
public void paintInstance(InstancePainter painter) {
Graphics g = painter.getGraphics();
Direction facing = painter.getAttributeValue(StdAttr.FACING);
Plexers.drawTrapezoid(g, painter.getBounds(), facing, 9);
Bounds bds = painter.getBounds();
g.setColor(Color.BLACK);
GraphicsUtil.drawCenteredText(g, "Sel", bds.getX() + bds.getWidth() / 2, bds.getY() + bds.getHeight() / 2);
painter.drawPorts();
}
示例14: paintInstance
import com.cburch.logisim.util.GraphicsUtil; //导入方法依赖的package包/类
@Override
public void paintInstance(InstancePainter painter) {
Graphics g = painter.getGraphics();
Bounds bds = painter.getBounds();
// draw boundary
painter.drawRoundBounds(Color.WHITE);
// draw contents
if (painter.getShowState()) {
MemState state = getState(painter);
state.paint(painter.getGraphics(), bds.getX(), bds.getY());
} else {
BitWidth addr = painter.getAttributeValue(ADDR_ATTR);
int addrBits = addr.getWidth();
int bytes = 1 << addrBits;
String label;
if (this instanceof Rom) {
if (addrBits >= 30) {
label = StringUtil.format(Strings.get("romGigabyteLabel"), "" + (bytes >>> 30));
} else if (addrBits >= 20) {
label = StringUtil.format(Strings.get("romMegabyteLabel"), "" + (bytes >> 20));
} else if (addrBits >= 10) {
label = StringUtil.format(Strings.get("romKilobyteLabel"), "" + (bytes >> 10));
} else {
label = StringUtil.format(Strings.get("romByteLabel"), "" + bytes);
}
} else {
if (addrBits >= 30) {
label = StringUtil.format(Strings.get("ramGigabyteLabel"), "" + (bytes >>> 30));
} else if (addrBits >= 20) {
label = StringUtil.format(Strings.get("ramMegabyteLabel"), "" + (bytes >> 20));
} else if (addrBits >= 10) {
label = StringUtil.format(Strings.get("ramKilobyteLabel"), "" + (bytes >> 10));
} else {
label = StringUtil.format(Strings.get("ramByteLabel"), "" + bytes);
}
}
GraphicsUtil.drawCenteredText(g, label, bds.getX() + bds.getWidth() / 2, bds.getY() + bds.getHeight() / 2);
}
// draw input and output ports
painter.drawPort(DATA, Strings.get("ramDataLabel"), Direction.WEST);
painter.drawPort(ADDR, Strings.get("ramAddrLabel"), Direction.EAST);
g.setColor(Color.GRAY);
painter.drawPort(CS, Strings.get("ramCSLabel"), Direction.SOUTH);
}
示例15: paintComponent
import com.cburch.logisim.util.GraphicsUtil; //导入方法依赖的package包/类
@Override
public void paintComponent(Graphics g) {
if (AppPreferences.ANTI_ALIASING.getBoolean()) {
Graphics2D g2 = (Graphics2D) g;
g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
}
super.paintComponent(g);
int inputs = data.getInputs();
int outputs = data.getOutputs();
int and = data.getAnd();
GraphicsUtil.switchToWidth(g, 2);
g.setColor(Color.DARK_GRAY);
g.setFont(new Font("sans serif", Font.BOLD, 14));
GraphicsUtil.drawCenteredText(g, "\u2190" + Strings.getter("demultiplexerInTip").toString(),
40 * (inputs + 1) - (20 - IMAGE_BORDER) + 5, IMAGE_BORDER);
GraphicsUtil.drawCenteredText(g, Strings.getter("multiplexerOutTip").toString() + "\u2192",
IMAGE_BORDER + 20 + 40 * inputs - 10, IMAGE_BORDER + 100 + 40 * and);
for (Integer i = 1; i <= inputs; i++) {
Color inputColor = data.getInputValue(i - 1).getColor();
Color notColor = data.getInputValue(i - 1).not().getColor();
g.setColor(inputColor);
// draw input value
GraphicsUtil.drawCenteredText(g, data.getInputValue(i - 1).toString(), 40 * i - (20 - IMAGE_BORDER),
IMAGE_BORDER);
g.drawLine(40 * i - (20 - IMAGE_BORDER), IMAGE_BORDER + 15, 40 * i - (20 - IMAGE_BORDER),
IMAGE_BORDER + 22);
g.drawLine(40 * i - (30 - IMAGE_BORDER), IMAGE_BORDER + 22, 40 * i - (10 - IMAGE_BORDER),
IMAGE_BORDER + 22);
g.drawLine(40 * i - (30 - IMAGE_BORDER), IMAGE_BORDER + 22, 40 * i - (30 - IMAGE_BORDER),
IMAGE_BORDER + 30);
g.drawLine(40 * i - (10 - IMAGE_BORDER), IMAGE_BORDER + 22, 40 * i - (10 - IMAGE_BORDER),
IMAGE_BORDER + 70 + 40 * (and - 1));
g.setColor(notColor);
g.drawLine(40 * i - (30 - IMAGE_BORDER), IMAGE_BORDER + 50, 40 * i - (30 - IMAGE_BORDER),
IMAGE_BORDER + 70 + 40 * (and - 1));
g.setColor(Color.BLACK);
drawNot(g, 40 * i - (30 - IMAGE_BORDER), IMAGE_BORDER + 30);
}
for (Integer i = 1; i <= and; i++) {
g.drawLine(IMAGE_BORDER + 10, IMAGE_BORDER + 30 + 40 * i, IMAGE_BORDER + 4 + 40 * inputs,
IMAGE_BORDER + 30 + 40 * i);
g.setColor(data.getAndValue(i - 1).getColor());
g.drawLine(IMAGE_BORDER + 36 + 40 * inputs, IMAGE_BORDER + 30 + 40 * i,
IMAGE_BORDER + 40 * (inputs + 1) + 20 + 40 * (outputs - 1), IMAGE_BORDER + 30 + 40 * i);
g.setColor(Color.BLACK);
Drawgates.paintAnd(g, IMAGE_BORDER + 36 + 40 * inputs, IMAGE_BORDER + 30 + 40 * i, 32, 32, false);
}
for (Integer i = 1; i <= outputs; i++) {
g.drawLine(IMAGE_BORDER + 20 + 40 * (inputs + i), IMAGE_BORDER + 70, IMAGE_BORDER + 20 + 40 * (inputs + i),
IMAGE_BORDER + 54 + 40 * and);
g.setColor(data.getOutputValue(i - 1).getColor());
g.drawLine(IMAGE_BORDER + 20 + 40 * (inputs + i), IMAGE_BORDER + 82 + 40 * and,
IMAGE_BORDER + 20 + 40 * (inputs + i), IMAGE_BORDER + 89 + 40 * and);
GraphicsUtil.drawCenteredText(g, data.getOutputValue(i - 1).toString(),
IMAGE_BORDER + 20 + 40 * (inputs + i), IMAGE_BORDER + 100 + 40 * and);
g.setColor(Color.BLACK);
drawOr(g, IMAGE_BORDER + 20 + 40 * (inputs + i), IMAGE_BORDER + 54 + 40 * and);
}
for (int i = 0; i < and; i++) {
for (int j = 0; j < inputs * 2; j++) {
if (data.getInputAndValue(i, j)) {
g.setColor(Color.WHITE);
g.fillOval(IMAGE_BORDER + 10 + 20 * j - 4, IMAGE_BORDER + 70 + 40 * i - 4, 8, 8);
g.setColor(Color.BLACK);
g.drawOval(IMAGE_BORDER + 10 + 20 * j - 4, IMAGE_BORDER + 70 + 40 * i - 4, 8, 8);
}
}
for (int k = 0; k < outputs; k++) {
if (data.getAndOutputValue(i, k)) {
g.setColor(Color.WHITE);
g.fillOval(IMAGE_BORDER + 20 + 40 * (inputs + 1) + 40 * k - 4, IMAGE_BORDER + 70 + 40 * i - 4, 8,
8);
g.setColor(Color.BLACK);
g.drawOval(IMAGE_BORDER + 20 + 40 * (inputs + 1) + 40 * k - 4, IMAGE_BORDER + 70 + 40 * i - 4, 8,
8);
}
}
}
}