You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

XSLFTextBox.java 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * ====================================================================
  3. * Licensed to the Apache Software Foundation (ASF) under one or more
  4. * contributor license agreements. See the NOTICE file distributed with
  5. * this work for additional information regarding copyright ownership.
  6. * The ASF licenses this file to You under the Apache License, Version 2.0
  7. * (the "License"); you may not use this file except in compliance with
  8. * the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. * ====================================================================
  18. */
  19. package org.apache.poi.xslf.usermodel;
  20. import org.apache.poi.sl.usermodel.ShapeContainer;
  21. import org.apache.poi.util.Beta;
  22. import org.apache.poi.util.Units;
  23. import org.openxmlformats.schemas.drawingml.x2006.main.CTNonVisualDrawingProps;
  24. import org.openxmlformats.schemas.drawingml.x2006.main.CTPresetGeometry2D;
  25. import org.openxmlformats.schemas.drawingml.x2006.main.CTShapeProperties;
  26. import org.openxmlformats.schemas.drawingml.x2006.main.CTTextBody;
  27. import org.openxmlformats.schemas.drawingml.x2006.main.STShapeType;
  28. import org.openxmlformats.schemas.drawingml.x2006.main.CTTransform2D;
  29. import org.openxmlformats.schemas.drawingml.x2006.main.CTPoint2D;
  30. import org.openxmlformats.schemas.drawingml.x2006.main.CTPositiveSize2D;
  31. import org.openxmlformats.schemas.presentationml.x2006.main.CTApplicationNonVisualDrawingProps;
  32. import org.openxmlformats.schemas.presentationml.x2006.main.CTPlaceholder;
  33. import org.openxmlformats.schemas.presentationml.x2006.main.CTShape;
  34. import org.openxmlformats.schemas.presentationml.x2006.main.CTShapeNonVisual;
  35. import org.openxmlformats.schemas.presentationml.x2006.main.STPlaceholderType;
  36. import java.awt.geom.Rectangle2D;
  37. /**
  38. * @author Yegor Kozlov
  39. */
  40. @Beta
  41. public class XSLFTextBox extends XSLFAutoShape {
  42. /*package*/ XSLFTextBox(CTShape shape, XSLFSheet sheet){
  43. super(shape, sheet);
  44. }
  45. /**
  46. *
  47. * @param shapeId 1-based shapeId
  48. */
  49. static CTShape prototype(int shapeId){
  50. CTShape ct = CTShape.Factory.newInstance();
  51. CTShapeNonVisual nvSpPr = ct.addNewNvSpPr();
  52. CTNonVisualDrawingProps cnv = nvSpPr.addNewCNvPr();
  53. cnv.setName("TextBox " + shapeId);
  54. cnv.setId(shapeId + 1);
  55. nvSpPr.addNewCNvSpPr().setTxBox(true);
  56. nvSpPr.addNewNvPr();
  57. CTShapeProperties spPr = ct.addNewSpPr();
  58. CTPresetGeometry2D prst = spPr.addNewPrstGeom();
  59. prst.setPrst(STShapeType.RECT);
  60. prst.addNewAvLst();
  61. CTTextBody txBody = ct.addNewTxBody();
  62. txBody.addNewBodyPr();
  63. txBody.addNewLstStyle();
  64. return ct;
  65. }
  66. /**
  67. * Specifies that the corresponding shape should be represented by the generating application
  68. * as a placeholder. When a shape is considered a placeholder by the generating application
  69. * it can have special properties to alert the user that they may enter content into the shape.
  70. * Different types of placeholders are allowed and can be specified by using the placeholder
  71. * type attribute for this element
  72. *
  73. * @param placeholder
  74. */
  75. public void setPlaceholder(Placeholder placeholder){
  76. CTShape sh = (CTShape)getXmlObject();
  77. CTApplicationNonVisualDrawingProps nv = sh.getNvSpPr().getNvPr();
  78. if(placeholder == null) {
  79. if(nv.isSetPh()) nv.unsetPh();
  80. } else {
  81. nv.addNewPh().setType(STPlaceholderType.Enum.forInt(placeholder.ordinal() + 1));
  82. }
  83. }
  84. }