本文整理汇总了Java中com.cburch.logisim.util.GraphicsUtil类的典型用法代码示例。如果您正苦于以下问题:Java GraphicsUtil类的具体用法?Java GraphicsUtil怎么用?Java GraphicsUtil使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
GraphicsUtil类属于com.cburch.logisim.util包,在下文中一共展示了GraphicsUtil类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: paintInstance
import com.cburch.logisim.util.GraphicsUtil; //导入依赖的package包/类
@Override
public void paintInstance(InstancePainter painter) {
InstanceDataSingleton data = (InstanceDataSingleton) painter.getData();
Value val = data == null ? Value.FALSE : (Value) data.getValue();
Bounds bds = painter.getBounds().expand(-1);
Graphics g = painter.getGraphics();
if (painter.getShowState()) {
Color onColor = painter.getAttributeValue(Io.ATTR_ON_COLOR);
Color offColor = painter.getAttributeValue(Io.ATTR_OFF_COLOR);
Boolean activ = painter.getAttributeValue(Io.ATTR_ACTIVE);
Object desired = activ.booleanValue() ? Value.TRUE : Value.FALSE;
g.setColor(val == desired ? onColor : offColor);
g.fillOval(bds.getX(), bds.getY(), bds.getWidth(), bds.getHeight());
}
g.setColor(Color.BLACK);
GraphicsUtil.switchToWidth(g, 2);
g.drawOval(bds.getX(), bds.getY(), bds.getWidth(), bds.getHeight());
GraphicsUtil.switchToWidth(g, 1);
painter.drawLabel();
painter.drawPorts();
}
示例2: setForStroke
import com.cburch.logisim.util.GraphicsUtil; //导入依赖的package包/类
protected boolean setForStroke(Graphics g) {
List<Attribute<?>> attrs = getAttributes();
if (attrs.contains(DrawAttr.PAINT_TYPE)) {
Object value = getValue(DrawAttr.PAINT_TYPE);
if (value == DrawAttr.PAINT_FILL)
return false;
}
Integer width = getValue(DrawAttr.STROKE_WIDTH);
if (width != null && width.intValue() > 0) {
Color color = getValue(DrawAttr.STROKE_COLOR);
if (color != null && color.getAlpha() == 0) {
return false;
} else {
GraphicsUtil.switchToWidth(g, width.intValue());
if (color != null)
g.setColor(color);
return true;
}
} else {
return false;
}
}
示例3: 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);
}
}
示例4: paintInstance
import com.cburch.logisim.util.GraphicsUtil; //导入依赖的package包/类
@Override
public void paintInstance(InstancePainter painter) {
// This is essentially the same as with SimpleGrayCounter, except for
// the invocation of painter.drawLabel to make the label be drawn.
painter.drawRoundBounds(Color.WHITE);
painter.drawClock(0, Direction.EAST);
painter.drawPort(1);
painter.drawLabel();
if (painter.getShowState()) {
BitWidth width = painter.getAttributeValue(StdAttr.WIDTH);
CounterData state = CounterData.get(painter, width);
Bounds bds = painter.getBounds();
GraphicsUtil.drawCenteredText(painter.getGraphics(),
StringUtil.toHexString(width.getWidth(), state.getValue().toIntValue()),
bds.getX() + bds.getWidth() / 2, bds.getY() + bds.getHeight() / 2);
}
}
示例5: 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);
}
示例6: drawInstance
import com.cburch.logisim.util.GraphicsUtil; //导入依赖的package包/类
private void drawInstance(InstancePainter painter, boolean isGhost) {
Graphics2D g = (Graphics2D) painter.getGraphics().create();
Location loc = painter.getLocation();
g.translate(loc.getX(), loc.getY());
Direction from = painter.getAttributeValue(StdAttr.FACING);
int degrees = Direction.EAST.toDegrees() - from.toDegrees();
double radians = Math.toRadians((degrees + 360) % 360);
g.rotate(radians);
GraphicsUtil.switchToWidth(g, Wire.WIDTH);
if (!isGhost && painter.getShowState()) {
g.setColor(painter.getPort(0).getColor());
}
g.drawLine(0, 0, 5, 0);
GraphicsUtil.switchToWidth(g, 1);
if (!isGhost && painter.shouldDrawColor()) {
BitWidth width = painter.getAttributeValue(StdAttr.WIDTH);
g.setColor(Value.repeat(Value.TRUE, width.getWidth()).getColor());
}
g.drawPolygon(new int[] { 6, 14, 6 }, new int[] { -8, 0, 8 }, 3);
g.dispose();
}
示例7: paintGhost
import com.cburch.logisim.util.GraphicsUtil; //导入依赖的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());
}
}
示例8: drawTrapezoid
import com.cburch.logisim.util.GraphicsUtil; //导入依赖的package包/类
static void drawTrapezoid(Graphics g, Bounds bds, Direction facing, int facingLean) {
int wid = bds.getWidth();
int ht = bds.getHeight();
int x0 = bds.getX();
int x1 = x0 + wid;
int y0 = bds.getY();
int y1 = y0 + ht;
int[] xp = { x0, x1, x1, x0 };
int[] yp = { y0, y0, y1, y1 };
if (facing == Direction.WEST) {
yp[0] += facingLean;
yp[3] -= facingLean;
} else if (facing == Direction.NORTH) {
xp[0] += facingLean;
xp[1] -= facingLean;
} else if (facing == Direction.SOUTH) {
xp[2] -= facingLean;
xp[3] += facingLean;
} else {
yp[1] += facingLean;
yp[2] -= facingLean;
}
GraphicsUtil.switchToWidth(g, 2);
g.drawPolygon(xp, yp, 4);
}
示例9: paintOr
import com.cburch.logisim.util.GraphicsUtil; //导入依赖的package包/类
static void paintOr(InstancePainter painter, int width, int height) {
Graphics g = painter.getGraphics();
GraphicsUtil.switchToWidth(g, 2);
/*
* The following, used previous to version 2.5.1, didn't use GeneralPath
* g.setColor(Color.LIGHT_GRAY); if (width < 40) {
* GraphicsUtil.drawCenteredArc(g, -30, -21, 36, -90, 53);
* GraphicsUtil.drawCenteredArc(g, -30, 21, 36, 90, -53); } else if (width < 60)
* { GraphicsUtil.drawCenteredArc(g, -50, -37, 62, -90, 53);
* GraphicsUtil.drawCenteredArc(g, -50, 37, 62, 90, -53); } else {
* GraphicsUtil.drawCenteredArc(g, -70, -50, 85, -90, 53);
* GraphicsUtil.drawCenteredArc(g, -70, 50, 85, 90, -53); } paintShield(g,
* -width, 0, width, height);
*/
GeneralPath path;
if (width < 40) {
path = PATH_NARROW;
} else if (width < 60) {
path = PATH_MEDIUM;
} else {
path = PATH_WIDE;
}
((Graphics2D) g).draw(path);
if (height > width) {
paintShield(g, 0, width, height);
}
}
示例10: paintShield
import com.cburch.logisim.util.GraphicsUtil; //导入依赖的package包/类
private static void paintShield(Graphics g, int xlate, int width, int height) {
GraphicsUtil.switchToWidth(g, 2);
g.translate(xlate, 0);
((Graphics2D) g).draw(computeShield(width, height));
g.translate(-xlate, 0);
/*
* The following, used previous to version 2.5.1, didn't use GeneralPath if
* (width < 40) { GraphicsUtil.drawCenteredArc(g, x - 26, y, 30, -30, 60); }
* else if (width < 60) { GraphicsUtil.drawCenteredArc(g, x - 43, y, 50, -30,
* 60); } else { GraphicsUtil.drawCenteredArc(g, x - 60, y, 70, -30, 60); } if
* (height > width) { // we need to draw the shield
* GraphicsUtil.drawCenteredArc(g, x - dx, y - (width + extra) / 2, extra, -30,
* 60); GraphicsUtil.drawCenteredArc(g, x - dx, y + (width + extra) / 2, extra,
* -30, 60); }
*/
}
示例11: drawRoundRectangle
import com.cburch.logisim.util.GraphicsUtil; //导入依赖的package包/类
public void drawRoundRectangle(ComponentFactory source, int x, int y, int width, int height, String label,
Color color) {
GraphicsUtil.switchToWidth(g, 2);
if (color != null && AppPreferences.FILL_COMPONENT_BACKGROUND.getBoolean()) {
g.setColor(color);
g.fillRoundRect(x, y, width, height, 10, 10);
}
g.setColor(Color.BLACK);
g.drawRoundRect(x + 1, y + 1, width - 1, height - 1, 10, 10);
if (label != null && !label.equals("")) {
FontMetrics fm = base.getFontMetrics(g.getFont());
int lwid = fm.stringWidth(label);
if (height > 20) { // centered at top edge
g.drawString(label, x + (width - lwid) / 2, y + 2 + fm.getAscent());
} else { // centered overall
g.drawString(label, x + (width - lwid) / 2, y + (height + fm.getAscent()) / 2 - 1);
}
}
}
示例12: 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);
}
示例13: paintInstance
import com.cburch.logisim.util.GraphicsUtil; //导入依赖的package包/类
@Override
public void paintInstance(InstancePainter painter) {
Graphics g = painter.getGraphics();
painter.drawRoundBounds(Color.WHITE);
g.setColor(Color.GRAY);
painter.drawPort(IN0);
painter.drawPort(IN1);
painter.drawPort(OUT);
painter.drawPort(C_IN, "c in", Direction.NORTH);
painter.drawPort(C_OUT, "c out", Direction.SOUTH);
Location loc = painter.getLocation();
int x = loc.getX();
int y = loc.getY();
GraphicsUtil.switchToWidth(g, 2);
g.setColor(Color.BLACK);
g.drawLine(x - 15, y - 5, x - 5, y + 5);
g.drawLine(x - 15, y + 5, x - 5, y - 5);
GraphicsUtil.switchToWidth(g, 1);
}
示例14: paintInstance
import com.cburch.logisim.util.GraphicsUtil; //导入依赖的package包/类
@Override
public void paintInstance(InstancePainter painter) {
Graphics g = painter.getGraphics();
painter.drawRoundBounds(Color.WHITE);
g.setColor(Color.GRAY);
painter.drawPort(IN0);
painter.drawPort(IN1);
painter.drawPort(OUT);
painter.drawPort(UPPER, Strings.get("dividerUpperInput"), Direction.NORTH);
painter.drawPort(REM, Strings.get("dividerRemainderOutput"), Direction.SOUTH);
Location loc = painter.getLocation();
int x = loc.getX();
int y = loc.getY();
GraphicsUtil.switchToWidth(g, 2);
g.setColor(Color.BLACK);
g.fillOval(x - 12, y - 7, 4, 4);
g.drawLine(x - 15, y, x - 5, y);
g.fillOval(x - 12, y + 3, 4, 4);
GraphicsUtil.switchToWidth(g, 1);
}
示例15: paintInstance
import com.cburch.logisim.util.GraphicsUtil; //导入依赖的package包/类
@Override
public void paintInstance(InstancePainter painter) {
Graphics g = painter.getGraphics();
painter.drawRoundBounds(Color.WHITE);
g.setColor(Color.GRAY);
painter.drawPort(IN0);
painter.drawPort(IN1);
painter.drawPort(OUT);
painter.drawPort(C_IN, "c in", Direction.NORTH);
painter.drawPort(C_OUT, "c out", Direction.SOUTH);
Location loc = painter.getLocation();
int x = loc.getX();
int y = loc.getY();
GraphicsUtil.switchToWidth(g, 2);
g.setColor(Color.BLACK);
g.drawLine(x - 15, y, x - 5, y);
g.drawLine(x - 10, y - 5, x - 10, y + 5);
GraphicsUtil.switchToWidth(g, 1);
}