예제 #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
  private void drawInstance(InstancePainter painter, boolean isGhost) {
    Bounds bds = painter.getBounds();
    Object powerLoc = painter.getAttributeValue(Wiring.ATTR_GATE);
    Direction facing = painter.getAttributeValue(StdAttr.FACING);
    boolean flip =
        (facing == Direction.SOUTH || facing == Direction.WEST)
            == (powerLoc == Wiring.GATE_TOP_LEFT);

    int degrees = Direction.WEST.toDegrees() - facing.toDegrees();
    if (flip) {
      degrees += 180;
    }

    double radians = Math.toRadians((degrees + 360) % 360);

    Graphics2D g = (Graphics2D) painter.getGraphics().create();
    g.rotate(radians, bds.getX() + 20, bds.getY() + 20);
    g.translate(bds.getX(), bds.getY());
    GraphicsUtil.switchToWidth(g, Wire.WIDTH);

    Color gate0 = g.getColor();
    Color gate1 = gate0;
    Color input = gate0;
    Color output = gate0;
    Color platform = gate0;
    if (!isGhost && painter.getShowState()) {
      gate0 = painter.getPort(GATE0).getColor();
      gate1 = painter.getPort(GATE0).getColor();
      input = painter.getPort(INPUT).getColor();
      output = painter.getPort(OUTPUT).getColor();
      platform = computeOutput(painter).getColor();
    }

    g.setColor(flip ? input : output);
    g.drawLine(0, 20, 11, 20);
    g.drawLine(11, 13, 11, 27);

    g.setColor(flip ? output : input);
    g.drawLine(29, 20, 40, 20);
    g.drawLine(29, 13, 29, 27);

    g.setColor(gate0);
    g.drawLine(20, 35, 20, 40);
    GraphicsUtil.switchToWidth(g, 1);
    g.drawOval(18, 30, 4, 4);
    g.drawLine(10, 30, 30, 30);
    GraphicsUtil.switchToWidth(g, Wire.WIDTH);

    g.setColor(gate1);
    g.drawLine(20, 9, 20, 0);
    GraphicsUtil.switchToWidth(g, 1);
    g.drawLine(10, 10, 30, 10);

    g.setColor(platform);
    g.drawLine(9, 12, 31, 12);
    g.drawLine(9, 28, 31, 28);
    // arrow
    if (flip) {
      g.drawLine(18, 17, 21, 20);
      g.drawLine(18, 23, 21, 20);
    } else {
      g.drawLine(22, 17, 19, 20);
      g.drawLine(22, 23, 19, 20);
    }

    g.dispose();
  }