Examples of Bounds


Examples of com.cburch.logisim.data.Bounds

      double imWidth = format.getImageableWidth();
      double imHeight = format.getImageableHeight();
     
      // Correct coordinate system for page, including
      // translation and possible rotation.
      Bounds bds = circ.getBounds(g).expand(4);
      double scale = Math.min(imWidth / bds.getWidth(),
          (imHeight - headHeight) / bds.getHeight());
      if (g2 != null) {
        g2.translate(format.getImageableX(), format.getImageableY());
        if (rotateToFit && scale < 1.0 / 1.1) {
          double scale2 = Math.min(imHeight / bds.getWidth(),
              (imWidth - headHeight) / bds.getHeight());
          if (scale2 >= scale * 1.1) { // will rotate
            scale = scale2;
            if (imHeight > imWidth) { // portrait -> landscape
              g2.translate(0, imHeight);
              g2.rotate(-Math.PI / 2);
            } else { // landscape -> portrait
              g2.translate(imWidth, 0);
              g2.rotate(Math.PI / 2);
            }
            double t = imHeight;
            imHeight = imWidth;
            imWidth = t;
          }
        }
      }
     
      // Draw the header line if appropriate
      if (head != null) {
        g.drawString(head,
            (int) Math.round((imWidth - fm.stringWidth(head)) / 2),
            fm.getAscent());
        if (g2 != null) {
          imHeight -= headHeight;
          g2.translate(0, headHeight);
        }
      }
     
      // Now change coordinate system for circuit, including
      // translation and possible scaling
      if (g2 != null) {
        if (scale < 1.0) {
          g2.scale(scale, scale);
          imWidth /= scale;
          imHeight /= scale;
        }
        double dx = Math.max(0.0, (imWidth - bds.getWidth()) / 2);
        g2.translate(-bds.getX() + dx, -bds.getY());
      }
     
      // Ensure that the circuit is eligible to be drawn
      Rectangle clip = g.getClipBounds();
      clip.add(bds.getX(), bds.getY());
      clip.add(bds.getX() + bds.getWidth(),
          bds.getY() + bds.getHeight());
      g.setClip(clip);
     
      // And finally draw the circuit onto the page
      ComponentDrawContext context = new ComponentDrawContext(
          proj.getFrame().getCanvas(), circ, circState,
View Full Code Here

Examples of com.cburch.logisim.data.Bounds

      if (x < x0) x0 = x;
      if (x > x1) x1 = x;
      if (y < y0) y0 = y;
      if (y > y1) y1 = y;
    }
    Bounds bds = Bounds.create(x0, y0, x1 - x0 + 1, y1 - y0 + 1);
    int stroke = getStrokeWidth();
    bounds = stroke < 2 ? bds : bds.expand(stroke / 2);
  }
View Full Code Here

Examples of com.cburch.logisim.data.Bounds

    proj.getSimulator().requestPropagate();
    // repaint will occur after propagation completes
  }

  public void computeSize(boolean immediate) {
    Bounds bounds = proj.getCurrentCircuit().getBounds();
    int width = bounds.getX() + bounds.getWidth() + BOUNDS_BUFFER;
    int height = bounds.getY() + bounds.getHeight() + BOUNDS_BUFFER;
    Dimension dim;
    if (canvasPane == null) {
      dim = new Dimension(width, height);
    } else {
      dim = canvasPane.supportPreferredSize(width, height);
    }
    if (!immediate) {
      Bounds old = oldPreferredSize;
      if (old != null
          && Math.abs(old.getWidth() - dim.width) < THRESH_SIZE_UPDATE
          && Math.abs(old.getHeight() - dim.height) < THRESH_SIZE_UPDATE) {
        return;
      }
    }
    oldPreferredSize = Bounds.create(0, 0, dim.width, dim.height);
    setPreferredSize(dim);
View Full Code Here

Examples of com.cburch.logisim.data.Bounds

    Rectangle viewableBase;
    Rectangle viewable;
    if (canvasPane != null) {
      viewableBase = canvasPane.getViewport().getViewRect();
    } else {
      Bounds bds = proj.getCurrentCircuit().getBounds();
      viewableBase = new Rectangle(0, 0, bds.getWidth(), bds.getHeight());
    }
    double zoom = getZoomFactor();
    if (zoom == 1.0) {
      viewable = viewableBase;
    } else {
View Full Code Here

Examples of com.cburch.logisim.data.Bounds

    setPorts(ps);
  }
 
  @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

Examples of com.cburch.logisim.data.Bounds

  }

  @Override
  public void paintInstance(InstancePainter painter) {
    Graphics g = painter.getGraphics();
    Bounds bds = painter.getBounds();
    StateData state = (StateData) painter.getData();
    BitWidth widthVal = painter.getAttributeValue(StdAttr.WIDTH);
    int width = widthVal == null ? 8 : widthVal.getWidth();

    // draw boundary, label
    painter.drawBounds();
    painter.drawLabel();

    // draw input and output ports
    painter.drawPort(OUT, "Q", Direction.WEST);
    painter.drawPort(RST);
    painter.drawPort(NXT);
    painter.drawClock(CK, Direction.EAST);

    // draw contents
    if (painter.getShowState()) {
      int val = state == null ? 0 : state.value;
      String str = StringUtil.toHexString(width, val);
      if (str.length() <= 4) {
        GraphicsUtil.drawText(g, str,
            bds.getX() + 15, bds.getY() + 4,
            GraphicsUtil.H_CENTER, GraphicsUtil.V_TOP);
      } else {
        int split = str.length() - 4;
        GraphicsUtil.drawText(g, str.substring(0, split),
            bds.getX() + 15, bds.getY() + 3,
            GraphicsUtil.H_CENTER, GraphicsUtil.V_TOP);
        GraphicsUtil.drawText(g, str.substring(split),
            bds.getX() + 15, bds.getY() + 15,
            GraphicsUtil.H_CENTER, GraphicsUtil.V_TOP);
      }
    }
  }
View Full Code Here

Examples of com.cburch.logisim.data.Bounds

    TextAttributes attrs = (TextAttributes) attrsBase;
    String text = attrs.getText();
    if (text == null || text.equals("")) {
      return Bounds.EMPTY_BOUNDS;
    } else {
      Bounds bds = attrs.getOffsetBounds();
      if (bds == null) {
        bds = estimateBounds(attrs);
        attrs.setOffsetBounds(bds);
      }
      return bds == null ? Bounds.EMPTY_BOUNDS : bds;
View Full Code Here

Examples of com.cburch.logisim.data.Bounds

    Font old = g.getFont();
    g.setFont(attrs.getFont());
    GraphicsUtil.drawText(g, text, 0, 0, halign, valign);
   
    String textTrim = text.endsWith(" ") ? text.substring(0, text.length() - 1) : text;
    Bounds newBds;
    if (textTrim.equals("")) {
      newBds = Bounds.EMPTY_BOUNDS;
    } else {
      Rectangle bdsOut = GraphicsUtil.getTextBounds(g, textTrim, 0, 0,
          halign, valign);
View Full Code Here

Examples of com.cburch.logisim.data.Bounds

  public abstract Bounds getBounds();

  public Bounds getBounds(Graphics g) { return getBounds(); }

  public boolean contains(Location pt) {
    Bounds bds = getBounds();
    if (bds == null) return false;
    return bds.contains(pt, 1);
  }
View Full Code Here

Examples of com.cburch.logisim.data.Bounds

    if (bds == null) return false;
    return bds.contains(pt, 1);
  }

  public boolean contains(Location pt, Graphics g) {
    Bounds bds = getBounds(g);
    if (bds == null) return false;
    return bds.contains(pt, 1);
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.