PageRenderTime 34ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 0ms

/pptx/src/org/apache/poi/xslf/usermodel/XSLFDrawing.java

https://github.com/minstrelsy/POI-Android
Java | 110 lines | 78 code | 12 blank | 20 comment | 1 complexity | 88f503638871e547730cf002e54b3503 MD5 | raw file
  1. /* ====================================================================
  2. Licensed to the Apache Software Foundation (ASF) under one or more
  3. contributor license agreements. See the NOTICE file distributed with
  4. this work for additional information regarding copyright ownership.
  5. The ASF licenses this file to You under the Apache License, Version 2.0
  6. (the "License"); you may not use this file except in compliance with
  7. the License. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. ==================================================================== */
  15. package org.apache.poi.xslf.usermodel;
  16. import org.apache.poi.util.Beta;
  17. import org.apache.xmlbeans.XmlObject;
  18. import org.openxmlformats.schemas.drawingml.x2006.main.CTNonVisualDrawingProps;
  19. //import org.openxmlformats.schemas.drawingml.x2006.main.CTNonVisualDrawingProps;
  20. import org.openxmlformats.schemas.presentationml.x2006.main.CTConnector;
  21. import org.openxmlformats.schemas.presentationml.x2006.main.CTGraphicalObjectFrame;
  22. import org.openxmlformats.schemas.presentationml.x2006.main.CTGroupShape;
  23. import org.openxmlformats.schemas.presentationml.x2006.main.CTPicture;
  24. import org.openxmlformats.schemas.presentationml.x2006.main.CTShape;
  25. import and.awt.Color;
  26. import and.awt.Rectangle;
  27. /**
  28. * @author Yegor Kozlov
  29. */
  30. @Beta
  31. public class XSLFDrawing {
  32. private XSLFSheet _sheet;
  33. private int _shapeId = 1;
  34. private CTGroupShape _spTree;
  35. /*package*/ XSLFDrawing(XSLFSheet sheet, CTGroupShape spTree){
  36. _sheet = sheet;
  37. _spTree = spTree;
  38. XmlObject[] cNvPr = sheet.getSpTree().selectPath(
  39. "declare namespace p='http://schemas.openxmlformats.org/presentationml/2006/main' .//*/p:cNvPr");
  40. for(XmlObject o : cNvPr) {
  41. CTNonVisualDrawingProps p = (CTNonVisualDrawingProps)o;
  42. _shapeId = (int)Math.max(_shapeId, p.getId());
  43. }
  44. }
  45. public XSLFAutoShape createAutoShape(){
  46. CTShape sp = _spTree.addNewSp();
  47. sp.set(XSLFAutoShape.prototype(_shapeId++));
  48. XSLFAutoShape shape = new XSLFAutoShape(sp, _sheet);
  49. shape.setAnchor(new Rectangle());
  50. return shape;
  51. }
  52. public XSLFFreeformShape createFreeform(){
  53. CTShape sp = _spTree.addNewSp();
  54. sp.set(XSLFFreeformShape.prototype(_shapeId++));
  55. XSLFFreeformShape shape = new XSLFFreeformShape(sp, _sheet);
  56. shape.setAnchor(new Rectangle());
  57. return shape;
  58. }
  59. public XSLFTextBox createTextBox(){
  60. CTShape sp = _spTree.addNewSp();
  61. sp.set(XSLFTextBox.prototype(_shapeId++));
  62. XSLFTextBox shape = new XSLFTextBox(sp, _sheet);
  63. shape.setAnchor(new Rectangle());
  64. return shape;
  65. }
  66. public XSLFConnectorShape createConnector(){
  67. CTConnector sp = _spTree.addNewCxnSp();
  68. sp.set(XSLFConnectorShape.prototype(_shapeId++));
  69. XSLFConnectorShape shape = new XSLFConnectorShape(sp, _sheet);
  70. shape.setAnchor(new Rectangle());
  71. shape.setLineColor(Color.black);
  72. shape.setLineWidth(0.75);
  73. return shape;
  74. }
  75. public XSLFGroupShape createGroup(){
  76. CTGroupShape obj = _spTree.addNewGrpSp();
  77. obj.set(XSLFGroupShape.prototype(_shapeId++));
  78. XSLFGroupShape shape = new XSLFGroupShape(obj, _sheet);
  79. shape.setAnchor(new Rectangle());
  80. return shape;
  81. }
  82. public XSLFPictureShape createPicture(String rel){
  83. CTPicture obj = _spTree.addNewPic();
  84. obj.set(XSLFPictureShape.prototype(_shapeId++, rel));
  85. XSLFPictureShape shape = new XSLFPictureShape(obj, _sheet);
  86. shape.setAnchor(new Rectangle());
  87. return shape;
  88. }
  89. public XSLFTable createTable(){
  90. CTGraphicalObjectFrame obj = _spTree.addNewGraphicFrame();
  91. obj.set(XSLFTable.prototype(_shapeId++));
  92. XSLFTable shape = new XSLFTable(obj, _sheet);
  93. shape.setAnchor(new Rectangle());
  94. return shape;
  95. }
  96. }