]> source.dussan.org Git - poi.git/commitdiff
more xlsf docs and samples
authorYegor Kozlov <yegor@apache.org>
Fri, 16 Dec 2011 10:00:11 +0000 (10:00 +0000)
committerYegor Kozlov <yegor@apache.org>
Fri, 16 Dec 2011 10:00:11 +0000 (10:00 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1215077 13f79535-47bb-0310-9956-ffa450edef68

src/examples/src/org/apache/poi/xslf/usermodel/Tutorial7.java [new file with mode: 0755]
src/ooxml/java/org/apache/poi/xslf/usermodel/ListAutoNumber.java [new file with mode: 0644]
src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextParagraph.java
src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextShape.java

diff --git a/src/examples/src/org/apache/poi/xslf/usermodel/Tutorial7.java b/src/examples/src/org/apache/poi/xslf/usermodel/Tutorial7.java
new file mode 100755 (executable)
index 0000000..a80f23c
--- /dev/null
@@ -0,0 +1,85 @@
+/*\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
+\r
+package org.apache.poi.xslf.usermodel;\r
+\r
+import java.awt.*;\r
+import java.io.FileOutputStream;\r
+import java.io.IOException;\r
+\r
+/**\r
+ * Bullets and numbering\r
+ *\r
+ * @author Yegor Kozlov\r
+ */\r
+public class Tutorial7 {\r
+\r
+    public static void main(String[] args) throws IOException{\r
+        XMLSlideShow ppt = new XMLSlideShow();\r
+\r
+        XSLFSlide slide = ppt.createSlide();\r
+        XSLFTextBox shape = slide.createTextBox();\r
+        shape.setAnchor(new Rectangle(50, 50, 400, 200));\r
+\r
+        XSLFTextParagraph p1 = shape.addNewTextParagraph();\r
+        p1.setLevel(0);\r
+        p1.setBullet(true);\r
+        XSLFTextRun r1 = p1.addNewTextRun();\r
+        r1.setText("Bullet1");\r
+\r
+        XSLFTextParagraph p2 = shape.addNewTextParagraph();\r
+        // indentation before text\r
+        p2.setLeftMargin(60);\r
+        // the bullet is set 40 pt before the text\r
+        p2.setIndent(-40);\r
+        p2.setBullet(true);\r
+        // customize bullets\r
+        p2.setBulletFontColor(Color.red);\r
+        p2.setBulletFont("Wingdings");\r
+        p2.setBulletCharacter("\u0075");\r
+        p2.setLevel(1);\r
+        XSLFTextRun r2 = p2.addNewTextRun();\r
+        r2.setText("Bullet2");\r
+\r
+        // the next three paragraphs form an auto-numbered list\r
+        XSLFTextParagraph p3 = shape.addNewTextParagraph();\r
+        p3.setBulletAutoNumber(ListAutoNumber.ALPHA_LC_PARENT_R, 1);\r
+        p3.setLevel(2);\r
+        XSLFTextRun r3 = p3.addNewTextRun();\r
+        r3.setText("Numbered List Item - 1");\r
+\r
+        XSLFTextParagraph p4 = shape.addNewTextParagraph();\r
+        p4.setBulletAutoNumber(ListAutoNumber.ALPHA_LC_PARENT_R, 2);\r
+        p4.setLevel(2);\r
+        XSLFTextRun r4 = p4.addNewTextRun();\r
+        r4.setText("Numbered List Item - 2");\r
+\r
+        XSLFTextParagraph p5 = shape.addNewTextParagraph();\r
+        p5.setBulletAutoNumber(ListAutoNumber.ALPHA_LC_PARENT_R, 3);\r
+        p5.setLevel(2);\r
+        XSLFTextRun r5 = p5.addNewTextRun();\r
+        r5.setText("Numbered List Item - 3");\r
+\r
+        shape.resizeToFitText();\r
+\r
+        FileOutputStream out = new FileOutputStream("list.pptx");\r
+        ppt.write(out);\r
+        out.close();\r
+    }\r
+}\r
diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/ListAutoNumber.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/ListAutoNumber.java
new file mode 100644 (file)
index 0000000..aa1e25b
--- /dev/null
@@ -0,0 +1,105 @@
+/*\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
+/**\r
+ * Specifies type of automatic numbered bullet points that should be applied to a paragraph.\r
+ *\r
+ * @author Yegor Kozlov\r
+ */\r
+public enum ListAutoNumber {\r
+    /**\r
+     * (a), (b), (c), ...\r
+     */\r
+    ALPHA_LC_PARENT_BOTH,\r
+    /**\r
+     * (A), (B), (C), ...\r
+     */\r
+    ALPHA_UC_PARENT_BOTH,\r
+    /**\r
+     * a), b), c), ...\r
+     */\r
+    ALPHA_LC_PARENT_R,\r
+    /**\r
+     * A), B), C), ...\r
+     */\r
+    ALPHA_UC_PARENT_R,\r
+    /**\r
+     *  a., b., c., ...\r
+     */\r
+    ALPHA_LC_PERIOD,\r
+    /**\r
+     * A., B., C., ...\r
+     */\r
+    ALPHA_UC_PERIOD,\r
+    /**\r
+     * (1), (2), (3), ...\r
+     */\r
+    ARABIC_PARENT_BOTH,\r
+    /**\r
+     * 1), 2), 3), ...\r
+     */\r
+    ARABIC_PARENT_R,\r
+\r
+    /**\r
+     * 1., 2., 3., ...\r
+     */\r
+    ARABIC_PERIOD,\r
+    /**\r
+     * 1, 2, 3, ...\r
+     */\r
+    ARABIC_PLAIN,\r
+\r
+    /**\r
+     * (i), (ii), (iii), ...\r
+     */\r
+    ROMAN_LC_PARENT_BOTH,\r
+    /**\r
+     * (I), (II), (III), ...\r
+     */\r
+    ROMAN_UC_PARENT_BOTH,\r
+    /**\r
+     * i), ii), iii), ...\r
+     */\r
+    ROMAN_LC_PARENT_R,\r
+    /**\r
+     * I), II), III), ...\r
+     */\r
+    ROMAN_UC_PARENT_R,\r
+    /**\r
+     *  i., ii., iii., ...\r
+     */\r
+    ROMAN_LC_PERIOD ,\r
+    /**\r
+     * I., II., III., ...\r
+     */\r
+    ROMAN_UC_PERIOD,\r
+    /**\r
+     * Dbl-byte circle numbers\r
+     */\r
+    CIRCLE_NUM_DB_PLAIN,\r
+    /**\r
+     * Wingdings black circle numbers\r
+     */\r
+    CIRCLE_NUM_WD_BLACK_PLAIN,\r
+    /**\r
+     * Wingdings white circle numbers\r
+     */\r
+    CIRCLE_NUM_WD_WHITE_PLAIN\r
+}\r
index b7901c4f124656d766c6e3f974bb60ed2e359107..44a20bd1a913225d3959e0ced7c29dc83c2212f6 100644 (file)
@@ -21,22 +21,7 @@ import org.apache.poi.util.Internal;
 import org.apache.poi.util.Units;\r
 import org.apache.poi.xslf.model.ParagraphPropertyFetcher;\r
 import org.apache.xmlbeans.XmlObject;\r
-import org.openxmlformats.schemas.drawingml.x2006.main.CTRegularTextRun;\r
-import org.openxmlformats.schemas.drawingml.x2006.main.CTTextField;\r
-import org.openxmlformats.schemas.drawingml.x2006.main.CTTextParagraph;\r
-import org.openxmlformats.schemas.drawingml.x2006.main.CTTextParagraphProperties;\r
-import org.openxmlformats.schemas.drawingml.x2006.main.CTTextSpacing;\r
-import org.openxmlformats.schemas.drawingml.x2006.main.CTTextTabStop;\r
-import org.openxmlformats.schemas.drawingml.x2006.main.CTTextTabStopList;\r
-import org.openxmlformats.schemas.drawingml.x2006.main.STTextAlignType;\r
-import org.openxmlformats.schemas.drawingml.x2006.main.CTTextFont;\r
-import org.openxmlformats.schemas.drawingml.x2006.main.CTTextCharBullet;\r
-import org.openxmlformats.schemas.drawingml.x2006.main.CTColor;\r
-import org.openxmlformats.schemas.drawingml.x2006.main.CTSRgbColor;\r
-import org.openxmlformats.schemas.drawingml.x2006.main.CTTextBulletSizePoint;\r
-import org.openxmlformats.schemas.drawingml.x2006.main.CTTextLineBreak;\r
-import org.openxmlformats.schemas.drawingml.x2006.main.CTTextNormalAutofit;\r
-import org.openxmlformats.schemas.drawingml.x2006.main.CTTextCharacterProperties;\r
+import org.openxmlformats.schemas.drawingml.x2006.main.*;\r
 import org.openxmlformats.schemas.presentationml.x2006.main.CTPlaceholder;\r
 import org.openxmlformats.schemas.presentationml.x2006.main.STPlaceholderType;\r
 \r
@@ -617,6 +602,21 @@ public class XSLFTextParagraph implements Iterable<XSLFTextRun>{
         }\r
     }\r
 \r
+    /**\r
+     * Specifies that automatic numbered bullet points should be applied to this paragraph\r
+     *\r
+     * @param scheme type of auto-numbering\r
+     * @param startAt the number that will start number for a given sequence of automatically\r
+    numbered bullets (1-based).\r
+     */\r
+    public void setBulletAutoNumber(ListAutoNumber scheme, int startAt) {\r
+        if(startAt < 1) throw new IllegalArgumentException("Start Number must be greater or equal that 1") ;\r
+        CTTextParagraphProperties pr = _p.isSetPPr() ? _p.getPPr() : _p.addNewPPr();\r
+        CTTextAutonumberBullet lst = pr.isSetBuAutoNum() ? pr.getBuAutoNum() : pr.addNewBuAutoNum();\r
+        lst.setType(STTextAutonumberScheme.Enum.forInt(scheme.ordinal() + 1));\r
+        lst.setStartAt(startAt);\r
+    }\r
+\r
     @Override\r
     public String toString(){\r
         return "[" + getClass() + "]" + getText();\r
index b22d19510375345ea1b6b90aafbcd1e002ab8f23..98f63fa72c52afddad86da918a4398a9bd7bc5b6 100644 (file)
@@ -458,7 +458,7 @@ public abstract class XSLFTextShape extends XSLFSimpleShape implements Iterable<
     /**
      * Adjust the size of the shape so it encompasses the text inside it.
      *
-     * @return a <code>Rectangle2D</code> that is the bounds of this <code>TextShape</code>.
+     * @return a <code>Rectangle2D</code> that is the bounds of this shape.
      */
     public Rectangle2D resizeToFitText(){
         Rectangle2D anchor = getAnchor();