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;
}
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);
}
Aggregations