added a method to remove slides

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@739775 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Yegor Kozlov 2009-02-01 15:07:25 +00:00
parent d01cd80981
commit f6fae6e2d1
5 changed files with 91 additions and 1 deletions

View File

@ -37,6 +37,7 @@
<!-- Don't forget to update status.xml too! -->
<release version="3.5-beta5" date="2008-??-??">
<action dev="POI-DEVELOPERS" type="add">46635 - Added a method to remove slides</action>
<action dev="POI-DEVELOPERS" type="fix">46520 - Fixed HSSFFont.applyFont() to properly apply font to overlapping regions</action>
<action dev="POI-DEVELOPERS" type="fix">46545 - Fixed ObjRecord to ignore excessive padding written by previous POI versions</action>
<action dev="POI-DEVELOPERS" type="fix">46613 - Fixed evaluator to perform case insensitive string comparisons</action>

View File

@ -34,6 +34,7 @@
<!-- Don't forget to update changes.xml too! -->
<changes>
<release version="3.5-beta5" date="2008-??-??">
<action dev="POI-DEVELOPERS" type="add">46635 - Added a method to remove slides</action>
<action dev="POI-DEVELOPERS" type="fix">46520 - Fixed HSSFFont.applyFont() to properly apply font to overlapping regions</action>
<action dev="POI-DEVELOPERS" type="fix">46545 - Fixed ObjRecord to ignore excessive padding written by previous POI versions</action>
<action dev="POI-DEVELOPERS" type="fix">46613 - Fixed evaluator to perform case insensitive string comparisons</action>

View File

@ -163,6 +163,11 @@ public class SlideListWithText extends RecordContainer
*/
public SlideAtomsSet[] getSlideAtomsSets() { return slideAtomsSets; }
/**
* Get access to the SlideAtomsSets of the children of this record
*/
public void setSlideAtomsSets( SlideAtomsSet[] sas ) { slideAtomsSets = sas; }
/**
* Return the value we were given at creation
*/

View File

@ -569,7 +569,46 @@ public final class SlideShow {
slwt.setChildRecord(r);
}
/* ===============================================================
/**
* 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 Slide removeSlide(int index) {
int lastSlideIdx = _slides.length - 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();
Slide removedSlide = null;
ArrayList<Record> records = new ArrayList<Record>();
ArrayList<SlideAtomsSet> sa = new ArrayList<SlideAtomsSet>();
ArrayList<Slide> sl = new ArrayList<Slide>();
for (int i = 0, num = 0; i < _slides.length; i++){
if(i != index) {
sl.add(_slides[i]);
sa.add(sas[i]);
_slides[i].setSlideNumber(num++);
records.add(sas[i].getSlidePersistAtom());
records.addAll(Arrays.asList(sas[i].getSlideRecords()));
} else {
removedSlide = _slides[i];
}
}
slwt.setSlideAtomsSets( sa.toArray(new SlideAtomsSet[sa.size()]) );
slwt.setChildRecord(records.toArray(new Record[records.size()]));
_slides = sl.toArray(new Slide[sl.size()]);
return removedSlide;
}
/* ===============================================================
* Addition Code
* ===============================================================
*/

View File

@ -225,4 +225,48 @@ public final class TestAddingSlides extends TestCase {
assertEquals(8, s3._getSheetRefId());
assertEquals(3, s3.getSlideNumber());
}
/**
* Test SlideShow#removeSlide
*/
public void testRemoving() throws Exception {
SlideShow ppt = new SlideShow();
Slide slide1 = ppt.createSlide();
Slide slide2 = ppt.createSlide();
Slide[] s1 = ppt.getSlides();
assertEquals(2, s1.length);
try {
ppt.removeSlide(-1);
fail("expected exception");
} catch (Exception e){
;
}
try {
ppt.removeSlide(2);
fail("expected exception");
} catch (Exception e){
;
}
assertEquals(1, slide1.getSlideNumber());
Slide removedSlide = ppt.removeSlide(0);
Slide[] s2 = ppt.getSlides();
assertEquals(1, s2.length);
assertSame(slide1, removedSlide);
assertSame(slide2, s2[0]);
assertEquals(0, slide2.getSlideNumber());
ByteArrayOutputStream out = new ByteArrayOutputStream();
ppt.write(out);
ppt = new SlideShow(new ByteArrayInputStream(out.toByteArray()));
Slide[] s3 = ppt.getSlides();
assertEquals(1, s3.length);
}
}