Beispiel #1
0
  /**
   * Create a slide and initialize it from the specified layout.
   *
   * @param layout
   * @return created slide
   */
  @SuppressWarnings("deprecation")
  public XSLFSlide createSlide(XSLFSlideLayout layout) {
    int slideNumber = 256, cnt = 1;
    CTSlideIdList slideList;
    if (!_presentation.isSetSldIdLst()) slideList = _presentation.addNewSldIdLst();
    else {
      slideList = _presentation.getSldIdLst();
      for (CTSlideIdListEntry slideId : slideList.getSldIdArray()) {
        slideNumber = (int) Math.max(slideId.getId() + 1, slideNumber);
        cnt++;
      }
    }

    XSLFSlide slide =
        (XSLFSlide) createRelationship(XSLFRelation.SLIDE, XSLFFactory.getInstance(), cnt);

    CTSlideIdListEntry slideId = slideList.addNewSldId();
    slideId.setId(slideNumber);
    slideId.setId2(slide.getPackageRelationship().getId());

    layout.copyLayout(slide);
    slide.addRelation(layout.getPackageRelationship().getId(), layout);

    PackagePartName ppName = layout.getPackagePart().getPartName();
    slide
        .getPackagePart()
        .addRelationship(
            ppName, TargetMode.INTERNAL, layout.getPackageRelationship().getRelationshipType());

    _slides.add(slide);
    return slide;
  }
Beispiel #2
0
  /** @param newIndex 0-based index of the slide */
  @SuppressWarnings("deprecation")
  public void setSlideOrder(XSLFSlide slide, int newIndex) {
    int oldIndex = _slides.indexOf(slide);
    if (oldIndex == -1) throw new IllegalArgumentException("Slide not found");
    if (oldIndex == newIndex) return;

    // fix the usermodel container
    _slides.add(newIndex, _slides.remove(oldIndex));

    // fix ordering in the low-level xml
    CTSlideIdList sldIdLst = _presentation.getSldIdLst();
    CTSlideIdListEntry[] entries = sldIdLst.getSldIdArray();
    CTSlideIdListEntry oldEntry = entries[oldIndex];
    if (oldIndex < newIndex) {
      System.arraycopy(entries, oldIndex + 1, entries, oldIndex, newIndex - oldIndex);
    } else {
      System.arraycopy(entries, newIndex, entries, newIndex + 1, oldIndex - newIndex);
    }
    entries[newIndex] = oldEntry;
    sldIdLst.setSldIdArray(entries);
  }