⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 drawinggroup.java

📁 jxtl API Java中Excel的生成与导入解析参考文档
💻 JAVA
📖 第 1 页 / 共 2 页
字号:

  /**
   * Interface method to remove a drawing from the group
   *
   * @param d the drawing to remove
   */
  public void remove(DrawingGroupObject d)
  {
    // Unless there are real images or some such, it is possible that
    // a BStoreContainer will not be present.  In that case simply return
    if (getBStoreContainer() == null)
    {
      return;
    }

    if (origin == Origin.READ)
    {
      origin = Origin.READ_WRITE;
      numBlips = getBStoreContainer().getNumBlips();
      Dgg dgg = (Dgg) escherData.getChildren()[0];
      drawingGroupId = dgg.getCluster(1).drawingGroupId - numBlips - 1;
    }

    // Get the blip
    EscherRecord[] children = getBStoreContainer().getChildren();
    BlipStoreEntry bse = (BlipStoreEntry) children[d.getBlipId() - 1];

    bse.dereference();

    if (bse.getReferenceCount() == 0)
    {
      // Remove the blip
      getBStoreContainer().remove(bse);

      // Adjust blipId on the other blips
      for (Iterator i = drawings.iterator(); i.hasNext();)
      {
        DrawingGroupObject drawing = (DrawingGroupObject) i.next();

        if (drawing.getBlipId() > d.getBlipId())
        {
          drawing.setObjectId(drawing.getObjectId(),
                              drawing.getBlipId() - 1,
                              drawing.getShapeId());
        }
      }

      numBlips--;
    }
  }


  /**
   * Initializes the drawing data from the escher record read in
   */
  private void initialize()
  {
    EscherRecordData er = new EscherRecordData(this, 0);

    Assert.verify(er.isContainer());

    escherData = new EscherContainer(er);

    Assert.verify(escherData.getLength() == drawingData.length);
    Assert.verify(escherData.getType() == EscherRecordType.DGG_CONTAINER);

    initialized = true;
  }

  /**
   * Gets hold of the BStore container from the Escher data
   *
   * @return the BStore container
   */
  private BStoreContainer getBStoreContainer()
  {
    if (bstoreContainer == null)
    {
      if (!initialized)
      {
        initialize();
      }

      EscherRecord[] children = escherData.getChildren();
      if (children.length > 1 &&
          children[1].getType() == EscherRecordType.BSTORE_CONTAINER)
      {
        bstoreContainer = (BStoreContainer) children[1];
      }
    }

    return bstoreContainer;
  }

  /**
   * Gets hold of the binary data
   *
   * @return the data
   */
  public byte[] getData()
  {
    return drawingData;
  }

  /**
   * Writes the drawing group to the output file
   *
   * @param outputFile the file to write to
   * @exception IOException
   */
  public void write(File outputFile) throws IOException
  {
    if (origin == Origin.WRITE)
    {
      DggContainer dggContainer = new DggContainer();

      Dgg dgg = new Dgg(numBlips + numCharts + 1, numBlips);

      dgg.addCluster(1, 0);
      dgg.addCluster(numBlips + 1, 0);

      dggContainer.add(dgg);

      int drawingsAdded = 0;
      BStoreContainer bstoreCont = new BStoreContainer();

      // Create a blip entry for each drawing
      for (Iterator i = drawings.iterator(); i.hasNext();)
      {
        Object o = i.next();
        if (o instanceof Drawing)
        {
          Drawing d = (Drawing) o;
          BlipStoreEntry bse = new BlipStoreEntry(d);

          bstoreCont.add(bse);
          drawingsAdded++;
        }
      }
      if (drawingsAdded > 0)
      {
        bstoreCont.setNumBlips(drawingsAdded);
        dggContainer.add(bstoreCont);
      }

      Opt opt = new Opt();

      dggContainer.add(opt);

      SplitMenuColors splitMenuColors = new SplitMenuColors();
      dggContainer.add(splitMenuColors);

      drawingData = dggContainer.getData();
    }
    else if (origin == Origin.READ_WRITE)
    {
      DggContainer dggContainer = new DggContainer();

      Dgg dgg = new Dgg(numBlips + numCharts + 1, numBlips);

      dgg.addCluster(1, 0);
      dgg.addCluster(drawingGroupId + numBlips + 1, 0);

      dggContainer.add(dgg);

      BStoreContainer bstoreCont = new BStoreContainer();
      bstoreCont.setNumBlips(numBlips);

      // Create a blip entry for each drawing that was read in
      BStoreContainer readBStoreContainer = getBStoreContainer();

      if (readBStoreContainer != null)
      {
        EscherRecord[] children = readBStoreContainer.getChildren();
        for (int i = 0; i < children.length; i++)
        {
          BlipStoreEntry bse = (BlipStoreEntry) children[i];
          bstoreCont.add(bse);
        }
      }

      // Create a blip entry for each drawing that has been added
      for (Iterator i = drawings.iterator(); i.hasNext();)
      {
        DrawingGroupObject dgo = (DrawingGroupObject) i.next();
        if (dgo instanceof Drawing)
        {
          Drawing d = (Drawing) dgo;
          if (d.getOrigin() == Origin.WRITE)
          {
            BlipStoreEntry bse = new BlipStoreEntry(d);
            bstoreCont.add(bse);
          }
        }
      }

      dggContainer.add(bstoreCont);

      Opt opt = new Opt();

      opt.addProperty(191, false, false, 524296);
      opt.addProperty(385, false, false, 134217737);
      opt.addProperty(448, false, false, 134217792);

      dggContainer.add(opt);

      SplitMenuColors splitMenuColors = new SplitMenuColors();
      dggContainer.add(splitMenuColors);

      drawingData = dggContainer.getData();
    }

    MsoDrawingGroupRecord msodg = new MsoDrawingGroupRecord(drawingData);
    outputFile.write(msodg);
  }

  /**
   * Accessor for the number of blips in the drawing group
   *
   * @return the number of blips
   */
  final int getNumberOfBlips()
  {
    return numBlips;
  }

  /**
   * Gets the drawing data for the given blip id.  Called by the Drawing
   * object
   *
   * @param blipId the blipId
   * @return the drawing data
   */
  byte[] getImageData(int blipId)
  {
    numBlips = getBStoreContainer().getNumBlips();

    Assert.verify(blipId <= numBlips);
    Assert.verify(origin == Origin.READ || origin == Origin.READ_WRITE);

    // Get the blip
    EscherRecord[] children = getBStoreContainer().getChildren();
    BlipStoreEntry bse = (BlipStoreEntry) children[blipId - 1];

    return bse.getImageData();
  }

  /**
   * Indicates that at least one of the drawings has been omitted from
   * the worksheet

   * @param mso the mso record
   * @param obj the obj record
   */
  public void setDrawingsOmitted(MsoDrawingRecord mso, ObjRecord obj)
  {
    drawingsOmitted = true;

    if (obj != null)
    {
      maxObjectId = Math.max(maxObjectId, obj.getObjectId());
    }
  }

  /**
   * Accessor for the drawingsOmitted flag
   *
   * @return TRUE if a drawing has been omitted, FALSE otherwise
   */
  public boolean hasDrawingsOmitted()
  {
    return drawingsOmitted;
  }

  /**
   * Updates this with the appropriate data from the drawing group passed in
   * This is called during the copy process:  this is first initialised as
   * an empty object, but during the copy, the source DrawingGroup may
   * change.  After the copy process, this method is then called to update
   * the relevant fields.  Unfortunately, the copy process required the
   * presence of a drawing group
   *
   * @param dg the drawing group containing the updated data
   */
  public void updateData(DrawingGroup dg)
  {
    drawingsOmitted = dg.drawingsOmitted;
    maxObjectId = dg.maxObjectId;
    maxShapeId = dg.maxShapeId;
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -