<!-- Don't forget to update status.xml too! -->
<release version="3.0.3-beta1" date="2008-04-??">
+ <action dev="POI-DEVELOPERS" type="add">Implement Sheet.removeShape(Shape shape) in HSLF</action>
<action dev="POI-DEVELOPERS" type="add">Various fixes: Recognising var-arg built-in functions #44675, ExternalNameRecord serialisation bug #44695, PMT() bug #44691</action>
<action dev="POI-DEVELOPERS" type="add">30311 - More work on Conditional Formatting</action>
<action dev="POI-DEVELOPERS" type="add">Move the Formula Evaluator code out of scratchpad</action>
<li><link href="#Bullets">How to create bulleted lists</link></li>
<li><link href="#Hyperlinks">Hyperlinks</link></li>
<li><link href="#Tables">Tables</link></li>
+ <li><link href="#RemoveShape">How to remove shapes</link></li>
</ul>
</section>
<section><title>Features</title>
</source>
</section>
+ <anchor id="RemoveShape"/>
+ <section><title>How to remove shapes from a slide</title>
+ <source>
+
+ Shape[] shape = slide.getShapes();
+ for (int i = 0; i < shape.length; i++) {
+
+ //remove the shape
+ boolean ok = slide.removeShape(shape[i]);
+ if(ok){
+ //the shape was removed. Do something.
+ }
+ }
+ </source>
+ </section>
+
</section>
</section>
</body>
<!-- Don't forget to update changes.xml too! -->
<changes>
<release version="3.0.3-beta1" date="2008-04-??">
+ <action dev="POI-DEVELOPERS" type="add">Implement Sheet.removeShape(Shape shape) in HSLF</action>
<action dev="POI-DEVELOPERS" type="add">Various fixes: Recognising var-arg built-in functions #44675, ExternalNameRecord serialisation bug #44695, PMT() bug #44691</action>
<action dev="POI-DEVELOPERS" type="add">30311 - More work on Conditional Formatting</action>
<action dev="POI-DEVELOPERS" type="add">Move the Formula Evaluator code out of scratchpad</action>
}
}
+ /**
+ * Removes the specified shape from this sheet.
+ *
+ * @param shape shape to be removed from this sheet, if present.
+ * @return <tt>true</tt> if the shape was deleted.
+ */
+ public boolean removeShape(Shape shape) {
+ PPDrawing ppdrawing = getPPDrawing();
+
+ EscherContainerRecord dg = (EscherContainerRecord) ppdrawing.getEscherRecords()[0];
+ EscherContainerRecord spgr = null;
+
+ for (Iterator it = dg.getChildRecords().iterator(); it.hasNext();) {
+ EscherRecord rec = (EscherRecord) it.next();
+ if (rec.getRecordId() == EscherContainerRecord.SPGR_CONTAINER) {
+ spgr = (EscherContainerRecord) rec;
+ break;
+ }
+ }
+ if(spgr == null) return false;
+
+ List lst = spgr.getChildRecords();
+ return lst.remove(shape.getSpContainer());
+ }
+
/**
* Return the master sheet .
*/
import java.io.ByteArrayOutputStream;
import java.io.ByteArrayInputStream;
import java.io.File;
+import java.io.IOException;
import java.util.ArrayList;
/**
line = (Line)grshape[1];
assertEquals(new Rectangle(300, 300, 500, 0), line.getAnchor());
}
+
+ /**
+ * Test functionality of Sheet.removeShape(Shape shape)
+ */
+ public void testRemoveShapes() throws IOException {
+ String file = System.getProperty("HSLF.testdata.path")+ "/with_textbox.ppt";
+ SlideShow ppt = new SlideShow(new HSLFSlideShow(file));
+ Slide sl = ppt.getSlides()[0];
+ Shape[] sh = sl.getShapes();
+ assertEquals("expected four shaped in " + file, 4, sh.length);
+ //remove all
+ for (int i = 0; i < sh.length; i++) {
+ boolean ok = sl.removeShape(sh[i]);
+ assertTrue("Failed to delete shape #" + i, ok);
+ }
+ //now Slide.getShapes() should return an empty array
+ assertEquals("expected 0 shaped in " + file, 0, sl.getShapes().length);
+
+ //serialize and read again. The file should be readable and contain no shapes
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ ppt.write(out);
+ out.close();
+
+ ppt = new SlideShow(new ByteArrayInputStream(out.toByteArray()));
+ sl = ppt.getSlides()[0];
+ assertEquals("expected 0 shaped in " + file, 0, sl.getShapes().length);
+ }
}