import org.apache.poi.util.Beta;\r
import org.apache.poi.util.Units;\r
import org.apache.xmlbeans.XmlObject;\r
-import org.openxmlformats.schemas.drawingml.x2006.main.CTBlip;\r
import org.openxmlformats.schemas.drawingml.x2006.main.CTGroupShapeProperties;\r
import org.openxmlformats.schemas.drawingml.x2006.main.CTGroupTransform2D;\r
import org.openxmlformats.schemas.drawingml.x2006.main.CTNonVisualDrawingProps;\r
import org.openxmlformats.schemas.presentationml.x2006.main.CTConnector;\r
import org.openxmlformats.schemas.presentationml.x2006.main.CTGroupShape;\r
import org.openxmlformats.schemas.presentationml.x2006.main.CTGroupShapeNonVisual;\r
-import org.openxmlformats.schemas.presentationml.x2006.main.CTPicture;\r
import org.openxmlformats.schemas.presentationml.x2006.main.CTShape;\r
\r
import java.awt.Graphics2D;\r
import java.awt.geom.AffineTransform;\r
import java.awt.geom.Rectangle2D;\r
+import java.util.Iterator;\r
import java.util.List;\r
import java.util.regex.Pattern;\r
\r
* @author Yegor Kozlov\r
*/\r
@Beta\r
-public class XSLFGroupShape extends XSLFShape {\r
+public class XSLFGroupShape extends XSLFShape implements XSLFShapeContainer {\r
private final CTGroupShape _shape;\r
private final XSLFSheet _sheet;\r
private final List<XSLFShape> _shapes;\r
return _shapes.toArray(new XSLFShape[_shapes.size()]);\r
}\r
\r
+ /**\r
+ * Returns an iterator over the shapes in this sheet\r
+ *\r
+ * @return an iterator over the shapes in this sheet\r
+ */\r
+ public Iterator<XSLFShape> iterator(){\r
+ return _shapes.iterator();\r
+ }\r
+\r
/**\r
* Remove the specified shape from this group\r
*/\r
}\r
}\r
\r
+ /**\r
+ * Removes all of the elements from this container (optional operation).\r
+ * The container will be empty after this call returns.\r
+ */\r
+ public void clear() {\r
+ for(XSLFShape shape : getShapes()){\r
+ removeShape(shape);\r
+ }\r
+ }\r
+\r
}
\ No newline at end of file
--- /dev/null
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ====================================================================
+ */
+
+package org.apache.poi.xslf.usermodel;
+
+/**
+ * Common interface for shape containers, e.g. sheets or groups of shapes
+ */
+public interface XSLFShapeContainer extends Iterable<XSLFShape> {
+
+ /**
+ * create a new shape with a predefined geometry and add it to this shape container
+ */
+ XSLFAutoShape createAutoShape();
+
+ /**
+ * create a new shape with a custom geometry
+ */
+ XSLFFreeformShape createFreeform();
+
+ /**
+ * create a text box
+ */
+ XSLFTextBox createTextBox();
+
+ /**
+ *
+ * create a connector
+ */
+ XSLFConnectorShape createConnector();
+
+ /**
+ * create a group of shapes belonging to this container
+ */
+ XSLFGroupShape createGroup();
+
+ /**
+ * create a picture belonging to this container
+ *
+ * @param pictureIndex
+ * @return
+ */
+ XSLFPictureShape createPicture(int pictureIndex);
+
+ /**
+ * Returns an array containing all of the elements in this container in proper
+ * sequence (from first to last element).
+ *
+ * @return an array containing all of the elements in this container in proper
+ * sequence
+ */
+ XSLFShape[] getShapes();
+
+ /**
+ * Removes the specified shape from this sheet, if it is present
+ * (optional operation). If this sheet does not contain the element,
+ * it is unchanged.
+ *
+ * @param xShape shape to be removed from this sheet, if present
+ * @return <tt>true</tt> if this sheet contained the specified element
+ * @throws IllegalArgumentException if the type of the specified shape
+ * is incompatible with this sheet (optional)
+ */
+ boolean removeShape(XSLFShape xShape) ;
+
+ /**
+ * Removes all of the elements from this container (optional operation).
+ * The container will be empty after this call returns.
+ */
+ void clear();
+}
import java.util.regex.Pattern;
@Beta
-public abstract class XSLFSheet extends POIXMLDocumentPart implements Iterable<XSLFShape> {
+public abstract class XSLFSheet extends POIXMLDocumentPart implements XSLFShapeContainer {
private XSLFCommonSlideData _commonSlideData;
private XSLFDrawing _drawing;
private List<XSLFShape> _shapes;
return getShapeList().remove(xShape);
}
+ /**
+ * Removes all of the elements from this container (optional operation).
+ * The container will be empty after this call returns.
+ */
+ public void clear() {
+ for(XSLFShape shape : getShapes()){
+ removeShape(shape);
+ }
+ }
+
protected abstract String getRootElementName();
protected CTGroupShape getSpTree(){
--- /dev/null
+/*\r
+ * ====================================================================\r
+ * Licensed to the Apache Software Foundation (ASF) under one or more\r
+ * contributor license agreements. See the NOTICE file distributed with\r
+ * this work for additional information regarding copyright ownership.\r
+ * The ASF licenses this file to You under the Apache License, Version 2.0\r
+ * (the "License"); you may not use this file except in compliance with\r
+ * the License. You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ====================================================================\r
+ */\r
+package org.apache.poi.xslf.usermodel;\r
+\r
+import junit.framework.TestCase;\r
+import org.apache.poi.xslf.XSLFTestDataSamples;\r
+\r
+import java.awt.*;\r
+import java.awt.geom.Rectangle2D;\r
+\r
+/**\r
+ * test common operatrions on containers of shapes (sheets and groups of shapes)\r
+ *\r
+ * @author Yegor Kozlov\r
+ */\r
+public class TestXSLFShapeContainer extends TestCase {\r
+\r
+ public void verifyContainer(XSLFShapeContainer container) {\r
+ container.clear();\r
+ assertEquals(0, container.getShapes().length);\r
+\r
+ XSLFGroupShape shape1 = container.createGroup();\r
+ assertEquals(1, container.getShapes().length);\r
+\r
+ XSLFTextBox shape2 = container.createTextBox();\r
+ assertEquals(2, container.getShapes().length);\r
+\r
+ XSLFAutoShape shape3 = container.createAutoShape();\r
+ assertEquals(3, container.getShapes().length);\r
+\r
+ XSLFConnectorShape shape4 = container.createConnector();\r
+ assertEquals(4, container.getShapes().length);\r
+\r
+ container.clear();\r
+ assertEquals(0, container.getShapes().length);\r
+ }\r
+\r
+ public void testSheet() {\r
+ XMLSlideShow ppt = new XMLSlideShow();\r
+ XSLFSheet sheet = ppt.createSlide();\r
+ verifyContainer(sheet);\r
+\r
+\r
+ XSLFGroupShape group = sheet.createGroup();\r
+ verifyContainer(group);\r
+\r
+ }\r
+}
\ No newline at end of file