You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ye...@apache.org on 2009/02/01 16:07:25 UTC

svn commit: r739775 - in /poi/trunk/src: documentation/content/xdocs/ scratchpad/src/org/apache/poi/hslf/record/ scratchpad/src/org/apache/poi/hslf/usermodel/ scratchpad/testcases/org/apache/poi/hslf/usermodel/

Author: yegor
Date: Sun Feb  1 15:07:25 2009
New Revision: 739775

URL: http://svn.apache.org/viewvc?rev=739775&view=rev
Log:
added a method to remove slides

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

Modified: poi/trunk/src/documentation/content/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/poi/trunk/src/documentation/content/xdocs/changes.xml?rev=739775&r1=739774&r2=739775&view=diff
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/changes.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/changes.xml Sun Feb  1 15:07:25 2009
@@ -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>

Modified: poi/trunk/src/documentation/content/xdocs/status.xml
URL: http://svn.apache.org/viewvc/poi/trunk/src/documentation/content/xdocs/status.xml?rev=739775&r1=739774&r2=739775&view=diff
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/status.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/status.xml Sun Feb  1 15:07:25 2009
@@ -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>

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/SlideListWithText.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/SlideListWithText.java?rev=739775&r1=739774&r2=739775&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/SlideListWithText.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/SlideListWithText.java Sun Feb  1 15:07:25 2009
@@ -163,6 +163,11 @@
 	 */
 	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
 	 */

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/SlideShow.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/SlideShow.java?rev=739775&r1=739774&r2=739775&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/SlideShow.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/SlideShow.java Sun Feb  1 15:07:25 2009
@@ -569,7 +569,46 @@
         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
 	 * ===============================================================
 	 */

Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestAddingSlides.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestAddingSlides.java?rev=739775&r1=739774&r2=739775&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestAddingSlides.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestAddingSlides.java Sun Feb  1 15:07:25 2009
@@ -225,4 +225,48 @@
 		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);
+    }
+
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org