]> source.dussan.org Git - poi.git/commitdiff
added a method to remove slides
authorYegor Kozlov <yegor@apache.org>
Sun, 1 Feb 2009 15:07:25 +0000 (15:07 +0000)
committerYegor Kozlov <yegor@apache.org>
Sun, 1 Feb 2009 15:07:25 +0000 (15:07 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@739775 13f79535-47bb-0310-9956-ffa450edef68

src/documentation/content/xdocs/changes.xml
src/documentation/content/xdocs/status.xml
src/scratchpad/src/org/apache/poi/hslf/record/SlideListWithText.java
src/scratchpad/src/org/apache/poi/hslf/usermodel/SlideShow.java
src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestAddingSlides.java

index 0e2a141d688deb0dcca2d5019501963766b8d73d..17a02ee598a05bb162bbc4c02af1946f210d2e46 100644 (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>
index 4bd2067fac2838d7affb41a7788c00fad7a125b5..c4c22452d3c75fbc129de275191bfe2008df5125 100644 (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>
index 13ffa707527b4070488e643890603c72aca872c7..03f5778139526ccdfb0edd5995fb21ff7f885a75 100644 (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
         */
index 7672923ad565222b8ee6f314492aa4433cfd3a25..6414d177ce53aad2b04ede739d31d6ca1c29e2aa 100644 (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
         * ===============================================================
         */
index 02c6beb53b046f826682ebe1e6f7de0f72a199ac..17f8fcb68c5529ab4a50b46f337e7f02b6f6a0b2 100644 (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);
+    }
+
 }