Пример #1
0
  //
  // graphics methods
  //
  @Override
  public void paintInstance(InstancePainter painter) {
    Graphics g = painter.getGraphics();
    FontMetrics fm = g.getFontMetrics();
    int asc = fm.getAscent();

    painter.drawBounds();

    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);
  }
Пример #2
0
  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;
      }
    }
  }
Пример #3
0
  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);
    }
  }