From 40e79175606adb072acee4aa3272b28ddfe216c6 Mon Sep 17 00:00:00 2001 From: Yegor Kozlov Date: Fri, 16 Dec 2011 10:00:11 +0000 Subject: [PATCH] more xlsf docs and samples git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1215077 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/poi/xslf/usermodel/Tutorial7.java | 85 ++++++++++++++ .../poi/xslf/usermodel/ListAutoNumber.java | 105 ++++++++++++++++++ .../poi/xslf/usermodel/XSLFTextParagraph.java | 32 +++--- .../poi/xslf/usermodel/XSLFTextShape.java | 2 +- 4 files changed, 207 insertions(+), 17 deletions(-) create mode 100755 src/examples/src/org/apache/poi/xslf/usermodel/Tutorial7.java create mode 100644 src/ooxml/java/org/apache/poi/xslf/usermodel/ListAutoNumber.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 index 0000000000..a80f23cad7 --- /dev/null +++ b/src/examples/src/org/apache/poi/xslf/usermodel/Tutorial7.java @@ -0,0 +1,85 @@ +/* + * ==================================================================== + * 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; + +import java.awt.*; +import java.io.FileOutputStream; +import java.io.IOException; + +/** + * Bullets and numbering + * + * @author Yegor Kozlov + */ +public class Tutorial7 { + + public static void main(String[] args) throws IOException{ + XMLSlideShow ppt = new XMLSlideShow(); + + XSLFSlide slide = ppt.createSlide(); + XSLFTextBox shape = slide.createTextBox(); + shape.setAnchor(new Rectangle(50, 50, 400, 200)); + + XSLFTextParagraph p1 = shape.addNewTextParagraph(); + p1.setLevel(0); + p1.setBullet(true); + XSLFTextRun r1 = p1.addNewTextRun(); + r1.setText("Bullet1"); + + XSLFTextParagraph p2 = shape.addNewTextParagraph(); + // indentation before text + p2.setLeftMargin(60); + // the bullet is set 40 pt before the text + p2.setIndent(-40); + p2.setBullet(true); + // customize bullets + p2.setBulletFontColor(Color.red); + p2.setBulletFont("Wingdings"); + p2.setBulletCharacter("\u0075"); + p2.setLevel(1); + XSLFTextRun r2 = p2.addNewTextRun(); + r2.setText("Bullet2"); + + // the next three paragraphs form an auto-numbered list + XSLFTextParagraph p3 = shape.addNewTextParagraph(); + p3.setBulletAutoNumber(ListAutoNumber.ALPHA_LC_PARENT_R, 1); + p3.setLevel(2); + XSLFTextRun r3 = p3.addNewTextRun(); + r3.setText("Numbered List Item - 1"); + + XSLFTextParagraph p4 = shape.addNewTextParagraph(); + p4.setBulletAutoNumber(ListAutoNumber.ALPHA_LC_PARENT_R, 2); + p4.setLevel(2); + XSLFTextRun r4 = p4.addNewTextRun(); + r4.setText("Numbered List Item - 2"); + + XSLFTextParagraph p5 = shape.addNewTextParagraph(); + p5.setBulletAutoNumber(ListAutoNumber.ALPHA_LC_PARENT_R, 3); + p5.setLevel(2); + XSLFTextRun r5 = p5.addNewTextRun(); + r5.setText("Numbered List Item - 3"); + + shape.resizeToFitText(); + + FileOutputStream out = new FileOutputStream("list.pptx"); + ppt.write(out); + out.close(); + } +} 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 index 0000000000..aa1e25ba9c --- /dev/null +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/ListAutoNumber.java @@ -0,0 +1,105 @@ +/* + * ==================================================================== + * 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; + +/** + * Specifies type of automatic numbered bullet points that should be applied to a paragraph. + * + * @author Yegor Kozlov + */ +public enum ListAutoNumber { + /** + * (a), (b), (c), ... + */ + ALPHA_LC_PARENT_BOTH, + /** + * (A), (B), (C), ... + */ + ALPHA_UC_PARENT_BOTH, + /** + * a), b), c), ... + */ + ALPHA_LC_PARENT_R, + /** + * A), B), C), ... + */ + ALPHA_UC_PARENT_R, + /** + * a., b., c., ... + */ + ALPHA_LC_PERIOD, + /** + * A., B., C., ... + */ + ALPHA_UC_PERIOD, + /** + * (1), (2), (3), ... + */ + ARABIC_PARENT_BOTH, + /** + * 1), 2), 3), ... + */ + ARABIC_PARENT_R, + + /** + * 1., 2., 3., ... + */ + ARABIC_PERIOD, + /** + * 1, 2, 3, ... + */ + ARABIC_PLAIN, + + /** + * (i), (ii), (iii), ... + */ + ROMAN_LC_PARENT_BOTH, + /** + * (I), (II), (III), ... + */ + ROMAN_UC_PARENT_BOTH, + /** + * i), ii), iii), ... + */ + ROMAN_LC_PARENT_R, + /** + * I), II), III), ... + */ + ROMAN_UC_PARENT_R, + /** + * i., ii., iii., ... + */ + ROMAN_LC_PERIOD , + /** + * I., II., III., ... + */ + ROMAN_UC_PERIOD, + /** + * Dbl-byte circle numbers + */ + CIRCLE_NUM_DB_PLAIN, + /** + * Wingdings black circle numbers + */ + CIRCLE_NUM_WD_BLACK_PLAIN, + /** + * Wingdings white circle numbers + */ + CIRCLE_NUM_WD_WHITE_PLAIN +} diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextParagraph.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextParagraph.java index b7901c4f12..44a20bd1a9 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextParagraph.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextParagraph.java @@ -21,22 +21,7 @@ import org.apache.poi.util.Internal; import org.apache.poi.util.Units; import org.apache.poi.xslf.model.ParagraphPropertyFetcher; import org.apache.xmlbeans.XmlObject; -import org.openxmlformats.schemas.drawingml.x2006.main.CTRegularTextRun; -import org.openxmlformats.schemas.drawingml.x2006.main.CTTextField; -import org.openxmlformats.schemas.drawingml.x2006.main.CTTextParagraph; -import org.openxmlformats.schemas.drawingml.x2006.main.CTTextParagraphProperties; -import org.openxmlformats.schemas.drawingml.x2006.main.CTTextSpacing; -import org.openxmlformats.schemas.drawingml.x2006.main.CTTextTabStop; -import org.openxmlformats.schemas.drawingml.x2006.main.CTTextTabStopList; -import org.openxmlformats.schemas.drawingml.x2006.main.STTextAlignType; -import org.openxmlformats.schemas.drawingml.x2006.main.CTTextFont; -import org.openxmlformats.schemas.drawingml.x2006.main.CTTextCharBullet; -import org.openxmlformats.schemas.drawingml.x2006.main.CTColor; -import org.openxmlformats.schemas.drawingml.x2006.main.CTSRgbColor; -import org.openxmlformats.schemas.drawingml.x2006.main.CTTextBulletSizePoint; -import org.openxmlformats.schemas.drawingml.x2006.main.CTTextLineBreak; -import org.openxmlformats.schemas.drawingml.x2006.main.CTTextNormalAutofit; -import org.openxmlformats.schemas.drawingml.x2006.main.CTTextCharacterProperties; +import org.openxmlformats.schemas.drawingml.x2006.main.*; import org.openxmlformats.schemas.presentationml.x2006.main.CTPlaceholder; import org.openxmlformats.schemas.presentationml.x2006.main.STPlaceholderType; @@ -617,6 +602,21 @@ public class XSLFTextParagraph implements Iterable{ } } + /** + * Specifies that automatic numbered bullet points should be applied to this paragraph + * + * @param scheme type of auto-numbering + * @param startAt the number that will start number for a given sequence of automatically + numbered bullets (1-based). + */ + public void setBulletAutoNumber(ListAutoNumber scheme, int startAt) { + if(startAt < 1) throw new IllegalArgumentException("Start Number must be greater or equal that 1") ; + CTTextParagraphProperties pr = _p.isSetPPr() ? _p.getPPr() : _p.addNewPPr(); + CTTextAutonumberBullet lst = pr.isSetBuAutoNum() ? pr.getBuAutoNum() : pr.addNewBuAutoNum(); + lst.setType(STTextAutonumberScheme.Enum.forInt(scheme.ordinal() + 1)); + lst.setStartAt(startAt); + } + @Override public String toString(){ return "[" + getClass() + "]" + getText(); diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextShape.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextShape.java index b22d195103..98f63fa72c 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextShape.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextShape.java @@ -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 Rectangle2D that is the bounds of this TextShape. + * @return a Rectangle2D that is the bounds of this shape. */ public Rectangle2D resizeToFitText(){ Rectangle2D anchor = getAnchor();