Search in sources :

Example 6 with SlideAtomsSet

use of org.apache.poi.hslf.record.SlideListWithText.SlideAtomsSet in project poi by apache.

the class HSLFSlideShow method removeSlide.

/**
	 * Removes the slide at the given index (0-based).
	 * <p>
	 * Shifts any subsequent slides to the left (subtracts one from their slide
	 * numbers).
	 * </p>
	 *
	 * @param index
	 *            the index of the slide to remove (0-based)
	 * @return the slide that was removed from the slide show.
	 */
public HSLFSlide removeSlide(int index) {
    int lastSlideIdx = _slides.size() - 1;
    if (index < 0 || index > lastSlideIdx) {
        throw new IllegalArgumentException("Slide index (" + index + ") is out of range (0.." + lastSlideIdx + ")");
    }
    SlideListWithText slwt = _documentRecord.getSlideSlideListWithText();
    SlideAtomsSet[] sas = slwt.getSlideAtomsSets();
    List<Record> records = new ArrayList<Record>();
    List<SlideAtomsSet> sa = new ArrayList<SlideAtomsSet>(Arrays.asList(sas));
    HSLFSlide removedSlide = _slides.remove(index);
    _notes.remove(removedSlide.getNotes());
    sa.remove(index);
    int i = 0;
    for (HSLFSlide s : _slides) {
        s.setSlideNumber(i++);
    }
    for (SlideAtomsSet s : sa) {
        records.add(s.getSlidePersistAtom());
        records.addAll(Arrays.asList(s.getSlideRecords()));
    }
    if (sa.isEmpty()) {
        _documentRecord.removeSlideListWithText(slwt);
    } else {
        slwt.setSlideAtomsSets(sa.toArray(new SlideAtomsSet[sa.size()]));
        slwt.setChildRecord(records.toArray(new Record[records.size()]));
    }
    // if the removed slide had notes - remove references to them too
    int notesId = removedSlide.getSlideRecord().getSlideAtom().getNotesID();
    if (notesId != 0) {
        SlideListWithText nslwt = _documentRecord.getNotesSlideListWithText();
        records = new ArrayList<Record>();
        ArrayList<SlideAtomsSet> na = new ArrayList<SlideAtomsSet>();
        for (SlideAtomsSet ns : nslwt.getSlideAtomsSets()) {
            if (ns.getSlidePersistAtom().getSlideIdentifier() == notesId) {
                continue;
            }
            na.add(ns);
            records.add(ns.getSlidePersistAtom());
            if (ns.getSlideRecords() != null) {
                records.addAll(Arrays.asList(ns.getSlideRecords()));
            }
        }
        if (na.isEmpty()) {
            _documentRecord.removeSlideListWithText(nslwt);
        } else {
            nslwt.setSlideAtomsSets(na.toArray(new SlideAtomsSet[na.size()]));
            nslwt.setChildRecord(records.toArray(new Record[records.size()]));
        }
    }
    return removedSlide;
}
Also used : ArrayList(java.util.ArrayList) SlideAtomsSet(org.apache.poi.hslf.record.SlideListWithText.SlideAtomsSet) EscherBSERecord(org.apache.poi.ddf.EscherBSERecord) EscherOptRecord(org.apache.poi.ddf.EscherOptRecord) EscherContainerRecord(org.apache.poi.ddf.EscherContainerRecord)

Example 7 with SlideAtomsSet

use of org.apache.poi.hslf.record.SlideListWithText.SlideAtomsSet in project poi by apache.

the class HSLFSlideShow method reorderSlide.

/**
	 * Re-orders a slide, to a new position.
	 *
	 * @param oldSlideNumber
	 *            The old slide number (1 based)
	 * @param newSlideNumber
	 *            The new slide number (1 based)
	 */
public void reorderSlide(int oldSlideNumber, int newSlideNumber) {
    // Ensure these numbers are valid
    if (oldSlideNumber < 1 || newSlideNumber < 1) {
        throw new IllegalArgumentException("Old and new slide numbers must be greater than 0");
    }
    if (oldSlideNumber > _slides.size() || newSlideNumber > _slides.size()) {
        throw new IllegalArgumentException("Old and new slide numbers must not exceed the number of slides (" + _slides.size() + ")");
    }
    // The order of slides is defined by the order of slide atom sets in the
    // SlideListWithText container.
    SlideListWithText slwt = _documentRecord.getSlideSlideListWithText();
    SlideAtomsSet[] sas = slwt.getSlideAtomsSets();
    SlideAtomsSet tmp = sas[oldSlideNumber - 1];
    sas[oldSlideNumber - 1] = sas[newSlideNumber - 1];
    sas[newSlideNumber - 1] = tmp;
    Collections.swap(_slides, oldSlideNumber - 1, newSlideNumber - 1);
    _slides.get(newSlideNumber - 1).setSlideNumber(newSlideNumber);
    _slides.get(oldSlideNumber - 1).setSlideNumber(oldSlideNumber);
    ArrayList<Record> lst = new ArrayList<Record>();
    for (SlideAtomsSet s : sas) {
        lst.add(s.getSlidePersistAtom());
        lst.addAll(Arrays.asList(s.getSlideRecords()));
    }
    Record[] r = lst.toArray(new Record[lst.size()]);
    slwt.setChildRecord(r);
}
Also used : ArrayList(java.util.ArrayList) SlideAtomsSet(org.apache.poi.hslf.record.SlideListWithText.SlideAtomsSet) EscherBSERecord(org.apache.poi.ddf.EscherBSERecord) EscherOptRecord(org.apache.poi.ddf.EscherOptRecord) EscherContainerRecord(org.apache.poi.ddf.EscherContainerRecord)

Aggregations

SlideAtomsSet (org.apache.poi.hslf.record.SlideListWithText.SlideAtomsSet)7 EscherBSERecord (org.apache.poi.ddf.EscherBSERecord)5 EscherContainerRecord (org.apache.poi.ddf.EscherContainerRecord)5 EscherOptRecord (org.apache.poi.ddf.EscherOptRecord)5 ArrayList (java.util.ArrayList)2 AbstractEscherOptRecord (org.apache.poi.ddf.AbstractEscherOptRecord)1 Document (org.apache.poi.hslf.record.Document)1 Record (org.apache.poi.hslf.record.Record)1 SlideListWithText (org.apache.poi.hslf.record.SlideListWithText)1 TextHeaderAtom (org.apache.poi.hslf.record.TextHeaderAtom)1 DrawPaint (org.apache.poi.sl.draw.DrawPaint)1 SolidPaint (org.apache.poi.sl.usermodel.PaintStyle.SolidPaint)1 Test (org.junit.Test)1