Package com.cburch.logisim.data

Examples of com.cburch.logisim.data.Bounds


  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();
  }
View Full Code Here


  @Override
  public void paintGhost(InstancePainter painter) {
    Graphics g = painter.getGraphics();
    GraphicsUtil.switchToWidth(g, 2);
    Bounds bds = painter.getBounds();
    g.drawRoundRect(bds.getX(), bds.getY(), bds.getWidth(), bds.getHeight(),
        10, 10);
  }
View Full Code Here

  @Override
  public void paintInstance(InstancePainter painter) {
    boolean showState = painter.getShowState();
    Graphics g = painter.getGraphics();
    Bounds bds = painter.getBounds();
    painter.drawClock(CK, Direction.EAST);
    if (painter.shouldDrawColor()) {
      g.setColor(painter.getAttributeValue(Io.ATTR_BACKGROUND));
      g.fillRoundRect(bds.getX(), bds.getY(), bds.getWidth(), bds.getHeight(),
          10, 10);
    }
    GraphicsUtil.switchToWidth(g, 2);
    g.setColor(Color.BLACK);
    g.drawRoundRect(bds.getX(), bds.getY(), bds.getWidth(), bds.getHeight(),
        2 * BORDER, 2 * BORDER);
    GraphicsUtil.switchToWidth(g, 1);
    painter.drawPort(CLR);
    painter.drawPort(WE);
    painter.drawPort(IN);
   
    int rows = getRowCount(painter.getAttributeValue(ATTR_ROWS));
    int cols = getColumnCount(painter.getAttributeValue(ATTR_COLUMNS));

    if (showState) {
      String[] rowData = new String[rows];
      int curRow;
      int curCol;
      TtyState state = getTtyState(painter);
      synchronized(state) {
        for (int i = 0; i < rows; i++) {
          rowData[i] = state.getRowString(i);
        }
        curRow = state.getCursorRow();
        curCol = state.getCursorColumn();
      }

      g.setFont(DEFAULT_FONT);
      g.setColor(painter.getAttributeValue(Io.ATTR_COLOR));
      FontMetrics fm = g.getFontMetrics();
      int x = bds.getX() + BORDER;
      int y = bds.getY() + BORDER + (ROW_HEIGHT + fm.getAscent()) / 2;
      for (int i = 0; i < rows; i++) {
        g.drawString(rowData[i], x, y);
        if (i == curRow) {
          int x0 = x + fm.stringWidth(rowData[i].substring(0, curCol));
          g.drawLine(x0, y - fm.getAscent(), x0, y);
        }
        y += ROW_HEIGHT;
      }
    } else {
      String str = Strings.get("ttyDesc", "" + rows, "" + cols);
      FontMetrics fm = g.getFontMetrics();
      int strWidth = fm.stringWidth(str);
      if (strWidth + BORDER > bds.getWidth()) {
        str = Strings.get("ttyDescShort");
        strWidth = fm.stringWidth(str);
      }
      int x = bds.getX() + (bds.getWidth() - strWidth) / 2;
      int y = bds.getY() + (bds.getHeight() + fm.getAscent()) / 2;
      g.drawString(str, x, y);
    }
  }
View Full Code Here

  /** Draws an indicator that the caret is being selected. Here, we'll draw
   * a red rectangle around the value. */
  @Override
  public void paint(InstancePainter painter) {
    Bounds bds = painter.getBounds();
    BitWidth width = painter.getAttributeValue(StdAttr.WIDTH);
    int len = (width.getWidth() + 3) / 4;

    Graphics g = painter.getGraphics();
    g.setColor(Color.RED);
    int wid = 7 * len + 2; // width of caret rectangle
    int ht = 16; // height of caret rectangle
    g.drawRect(bds.getX() + (bds.getWidth() - wid) / 2,
        bds.getY() + (bds.getHeight() - ht) / 2, wid, ht);
    g.setColor(Color.BLACK);
  }
View Full Code Here

   * sometimes you need to do something particular to each instance, so you
   * would override the method. In this case, we need to set up the location
   * for its label. */
  @Override
  protected void configureNewInstance(Instance instance) {
    Bounds bds = instance.getBounds();
    instance.setTextField(StdAttr.LABEL, StdAttr.LABEL_FONT,
        bds.getX() + bds.getWidth() / 2, bds.getY() - 3,
        GraphicsUtil.H_CENTER, GraphicsUtil.V_BASELINE);
  }
View Full Code Here

    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);
    }
  }
View Full Code Here

    // 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);
    }
  }
View Full Code Here

 
  @Override
  protected void paintComponent(Graphics g) {
    if (circuitState != null) {
      Circuit circuit = circuitState.getCircuit();
      Bounds bds = circuit.getBounds(g);
      Dimension size = getSize();
      double scaleX = (double) (size.width - 2 * BORDER) / bds.getWidth();
      double scaleY = (double) (size.height - 2 * BORDER) / bds.getHeight();
      double scale = Math.min(1.0, Math.min(scaleX, scaleY));
     
      Graphics gCopy = g.create();
      int borderX = (int) ((size.width - bds.getWidth() * scale) / 2);
      int borderY = (int) ((size.height - bds.getHeight() * scale) / 2);
      gCopy.translate(borderX, borderY);
      if (scale != 1.0 && g instanceof Graphics2D) {
        ((Graphics2D) gCopy).scale(scale, scale);
      }
      gCopy.translate(-bds.getX(), -bds.getY());
     
      ComponentDrawContext context = new ComponentDrawContext(this, circuit,
          circuitState, g, gCopy);
      context.setShowState(false);
      context.setShowColor(false);
      circuit.draw(context, Collections.<Component>emptySet());
      if (ports != null) {
        gCopy.setColor(AppearancePort.COLOR);
        int width = Math.max(4, (int) ((2 / scale) + 0.5));
        GraphicsUtil.switchToWidth(gCopy, width);
        for (Instance port : ports) {
          Bounds b = port.getBounds();
          int x = b.getX();
          int y = b.getY();
          int w = b.getWidth();
          int h = b.getHeight();
          if (Pin.FACTORY.isInputPin(port)) {
            gCopy.drawRect(x, y, w, h);
          } else {
            if (b.getWidth() > 25) {
              gCopy.drawRoundRect(x, y, w, h, 4, 4);
            } else {
              gCopy.drawOval(x, y, w, h);
            }
          }
View Full Code Here

  public WireSet getWireSet(Wire start) {
    return wires.getWireSet(start);
  }

  public Bounds getBounds() {
    Bounds wireBounds = wires.getWireBounds();
    Iterator<Component> it = comps.iterator();
    if (!it.hasNext()) return wireBounds;
    Component first = it.next();
    Bounds firstBounds = first.getBounds();
    int xMin = firstBounds.getX();
    int yMin = firstBounds.getY();
    int xMax = xMin + firstBounds.getWidth();
    int yMax = yMin + firstBounds.getHeight();
    while (it.hasNext()) {
      Component c = it.next();
      Bounds bds = c.getBounds();
      int x0 = bds.getX(); int x1 = x0 + bds.getWidth();
      int y0 = bds.getY(); int y1 = y0 + bds.getHeight();
      if (x0 < xMin) xMin = x0;
      if (x1 > xMax) xMax = x1;
      if (y0 < yMin) yMin = y0;
      if (y1 > yMax) yMax = y1;
    }
    Bounds compBounds = Bounds.create(xMin, yMin, xMax - xMin, yMax - yMin);
    if (wireBounds.getWidth() == 0 || wireBounds.getHeight() == 0) {
      return compBounds;
    } else {
      return compBounds.add(wireBounds);
    }
  }
View Full Code Here

      return compBounds.add(wireBounds);
    }
  }

  public Bounds getBounds(Graphics g) {
    Bounds ret = wires.getWireBounds();
    int xMin = ret.getX();
    int yMin = ret.getY();
    int xMax = xMin + ret.getWidth();
    int yMax = yMin + ret.getHeight();
    if (ret == Bounds.EMPTY_BOUNDS) {
      xMin = Integer.MAX_VALUE;
      yMin = Integer.MAX_VALUE;
      xMax = Integer.MIN_VALUE;
      yMax = Integer.MIN_VALUE;
    }
    for (Component c : comps) {
      Bounds bds = c.getBounds(g);
      if (bds != null && bds != Bounds.EMPTY_BOUNDS) {
        int x0 = bds.getX(); int x1 = x0 + bds.getWidth();
        int y0 = bds.getY(); int y1 = y0 + bds.getHeight();
        if (x0 < xMin) xMin = x0;
        if (x1 > xMax) xMax = x1;
        if (y0 < yMin) yMin = y0;
        if (y1 > yMax) yMax = y1;
      }
View Full Code Here

TOP

Related Classes of com.cburch.logisim.data.Bounds

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.