示例#1
0
  /**
   * Sets the anchor (the bounding box rectangle) of this shape. All coordinates should be expressed
   * in Master units (576 dpi).
   *
   * @param anchor new anchor
   */
  public void setAnchor(java.awt.Rectangle anchor) {

    EscherContainerRecord spContainer =
        (EscherContainerRecord) _escherContainer.getChildRecords().get(0);

    EscherClientAnchorRecord clientAnchor =
        (EscherClientAnchorRecord) getEscherChild(spContainer, EscherClientAnchorRecord.RECORD_ID);
    // hack. internal variable EscherClientAnchorRecord.shortRecord can be
    // initialized only in fillFields(). We need to set shortRecord=false;
    byte[] header = new byte[16];
    LittleEndian.putUShort(header, 0, 0);
    LittleEndian.putUShort(header, 2, 0);
    LittleEndian.putInt(header, 4, 8);
    clientAnchor.fillFields(header, 0, null);

    clientAnchor.setFlag((short) (anchor.y * MASTER_DPI / POINT_DPI));
    clientAnchor.setCol1((short) (anchor.x * MASTER_DPI / POINT_DPI));
    clientAnchor.setDx1((short) ((anchor.width + anchor.x) * MASTER_DPI / POINT_DPI));
    clientAnchor.setRow1((short) ((anchor.height + anchor.y) * MASTER_DPI / POINT_DPI));

    EscherSpgrRecord spgr =
        (EscherSpgrRecord) getEscherChild(spContainer, EscherSpgrRecord.RECORD_ID);

    spgr.setRectX1(anchor.x * MASTER_DPI / POINT_DPI);
    spgr.setRectY1(anchor.y * MASTER_DPI / POINT_DPI);
    spgr.setRectX2((anchor.x + anchor.width) * MASTER_DPI / POINT_DPI);
    spgr.setRectY2((anchor.y + anchor.height) * MASTER_DPI / POINT_DPI);
  }
示例#2
0
  /**
   * Create a new ShapeGroup and create an instance of <code>EscherSpgrContainer</code> which
   * represents a group of shapes
   */
  protected EscherContainerRecord createSpContainer(boolean isChild) {
    EscherContainerRecord spgr = new EscherContainerRecord();
    spgr.setRecordId(EscherContainerRecord.SPGR_CONTAINER);
    spgr.setOptions((short) 15);

    // The group itself is a shape, and always appears as the first EscherSpContainer in the group
    // container.
    EscherContainerRecord spcont = new EscherContainerRecord();
    spcont.setRecordId(EscherContainerRecord.SP_CONTAINER);
    spcont.setOptions((short) 15);

    EscherSpgrRecord spg = new EscherSpgrRecord();
    spg.setOptions((short) 1);
    spcont.addChildRecord(spg);

    EscherSpRecord sp = new EscherSpRecord();
    short type = (ShapeTypes.NotPrimitive << 4) + 2;
    sp.setOptions(type);
    sp.setFlags(EscherSpRecord.FLAG_HAVEANCHOR | EscherSpRecord.FLAG_GROUP);
    spcont.addChildRecord(sp);

    EscherClientAnchorRecord anchor = new EscherClientAnchorRecord();
    spcont.addChildRecord(anchor);

    spgr.addChildRecord(spcont);
    return spgr;
  }
示例#3
0
  /**
   * Sets the coordinate space of this group. All children are constrained to these coordinates.
   *
   * @param anchor the coordinate space of this group
   */
  public void setCoordinates(Rectangle2D anchor) {
    EscherContainerRecord spContainer =
        (EscherContainerRecord) _escherContainer.getChildRecords().get(0);
    EscherSpgrRecord spgr =
        (EscherSpgrRecord) getEscherChild(spContainer, EscherSpgrRecord.RECORD_ID);

    int x1 = (int) Math.round(anchor.getX() * MASTER_DPI / POINT_DPI);
    int y1 = (int) Math.round(anchor.getY() * MASTER_DPI / POINT_DPI);
    int x2 = (int) Math.round((anchor.getX() + anchor.getWidth()) * MASTER_DPI / POINT_DPI);
    int y2 = (int) Math.round((anchor.getY() + anchor.getHeight()) * MASTER_DPI / POINT_DPI);

    spgr.setRectX1(x1);
    spgr.setRectY1(y1);
    spgr.setRectX2(x2);
    spgr.setRectY2(y2);
  }
示例#4
0
  /**
   * Gets the coordinate space of this group. All children are constrained to these coordinates.
   *
   * @return the coordinate space of this group
   */
  public Rectangle2D getCoordinates() {
    EscherContainerRecord spContainer =
        (EscherContainerRecord) _escherContainer.getChildRecords().get(0);
    EscherSpgrRecord spgr =
        (EscherSpgrRecord) getEscherChild(spContainer, EscherSpgrRecord.RECORD_ID);

    Rectangle2D.Float anchor = new Rectangle2D.Float();
    anchor.x = (float) spgr.getRectX1() * POINT_DPI / MASTER_DPI;
    anchor.y = (float) spgr.getRectY1() * POINT_DPI / MASTER_DPI;
    anchor.width = (float) (spgr.getRectX2() - spgr.getRectX1()) * POINT_DPI / MASTER_DPI;
    anchor.height = (float) (spgr.getRectY2() - spgr.getRectY1()) * POINT_DPI / MASTER_DPI;

    return anchor;
  }