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.

XSSFConnector.java 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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.xssf.usermodel;
  16. import org.openxmlformats.schemas.drawingml.x2006.main.CTFontReference;
  17. import org.openxmlformats.schemas.drawingml.x2006.main.CTNonVisualDrawingProps;
  18. import org.openxmlformats.schemas.drawingml.x2006.main.CTPoint2D;
  19. import org.openxmlformats.schemas.drawingml.x2006.main.CTPositiveSize2D;
  20. import org.openxmlformats.schemas.drawingml.x2006.main.CTPresetGeometry2D;
  21. import org.openxmlformats.schemas.drawingml.x2006.main.CTSchemeColor;
  22. import org.openxmlformats.schemas.drawingml.x2006.main.CTShapeProperties;
  23. import org.openxmlformats.schemas.drawingml.x2006.main.CTShapeStyle;
  24. import org.openxmlformats.schemas.drawingml.x2006.main.CTStyleMatrixReference;
  25. import org.openxmlformats.schemas.drawingml.x2006.main.CTTransform2D;
  26. import org.openxmlformats.schemas.drawingml.x2006.main.STFontCollectionIndex;
  27. import org.openxmlformats.schemas.drawingml.x2006.main.STSchemeColorVal;
  28. import org.openxmlformats.schemas.drawingml.x2006.main.STShapeType;
  29. import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTConnector;
  30. import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTConnectorNonVisual;
  31. import org.apache.poi.util.Internal;
  32. /**
  33. * A connection shape drawing element. A connection shape is a line, etc.
  34. * that connects two other shapes in this drawing.
  35. */
  36. public final class XSSFConnector extends XSSFShape {
  37. private static CTConnector prototype;
  38. private final CTConnector ctShape;
  39. /**
  40. * Construct a new XSSFConnector object.
  41. *
  42. * @param drawing the XSSFDrawing that owns this shape
  43. * @param ctShape the shape bean that holds all the shape properties
  44. */
  45. protected XSSFConnector(XSSFDrawing drawing, CTConnector ctShape) {
  46. this.drawing = drawing;
  47. this.ctShape = ctShape;
  48. }
  49. /**
  50. * Initialize default structure of a new auto-shape
  51. *
  52. */
  53. protected static CTConnector prototype() {
  54. if(prototype == null) {
  55. CTConnector shape = CTConnector.Factory.newInstance();
  56. CTConnectorNonVisual nv = shape.addNewNvCxnSpPr();
  57. CTNonVisualDrawingProps nvp = nv.addNewCNvPr();
  58. nvp.setId(1);
  59. nvp.setName("Shape 1");
  60. nv.addNewCNvCxnSpPr();
  61. CTShapeProperties sp = shape.addNewSpPr();
  62. CTTransform2D t2d = sp.addNewXfrm();
  63. CTPositiveSize2D p1 = t2d.addNewExt();
  64. p1.setCx(0);
  65. p1.setCy(0);
  66. CTPoint2D p2 = t2d.addNewOff();
  67. p2.setX(0);
  68. p2.setY(0);
  69. CTPresetGeometry2D geom = sp.addNewPrstGeom();
  70. geom.setPrst(STShapeType.LINE);
  71. geom.addNewAvLst();
  72. CTShapeStyle style = shape.addNewStyle();
  73. CTSchemeColor scheme = style.addNewLnRef().addNewSchemeClr();
  74. scheme.setVal(STSchemeColorVal.ACCENT_1);
  75. style.getLnRef().setIdx(1);
  76. CTStyleMatrixReference fillref = style.addNewFillRef();
  77. fillref.setIdx(0);
  78. fillref.addNewSchemeClr().setVal(STSchemeColorVal.ACCENT_1);
  79. CTStyleMatrixReference effectRef = style.addNewEffectRef();
  80. effectRef.setIdx(0);
  81. effectRef.addNewSchemeClr().setVal(STSchemeColorVal.ACCENT_1);
  82. CTFontReference fontRef = style.addNewFontRef();
  83. fontRef.setIdx(STFontCollectionIndex.MINOR);
  84. fontRef.addNewSchemeClr().setVal(STSchemeColorVal.TX_1);
  85. prototype = shape;
  86. }
  87. return prototype;
  88. }
  89. @Internal
  90. public CTConnector getCTConnector(){
  91. return ctShape;
  92. }
  93. /**
  94. * Gets the shape type, one of the constants defined in {@link org.apache.poi.ss.usermodel.ShapeTypes}.
  95. *
  96. * @return the shape type
  97. * @see org.apache.poi.ss.usermodel.ShapeTypes
  98. */
  99. public int getShapeType() {
  100. return ctShape.getSpPr().getPrstGeom().getPrst().intValue();
  101. }
  102. /**
  103. * Sets the shape types.
  104. *
  105. * @param type the shape type, one of the constants defined in {@link org.apache.poi.ss.usermodel.ShapeTypes}.
  106. * @see org.apache.poi.ss.usermodel.ShapeTypes
  107. */
  108. public void setShapeType(int type) {
  109. ctShape.getSpPr().getPrstGeom().setPrst(STShapeType.Enum.forInt(type));
  110. }
  111. @Override
  112. protected CTShapeProperties getShapeProperties(){
  113. return ctShape.getSpPr();
  114. }
  115. @Override
  116. public String getShapeName() {
  117. return ctShape.getNvCxnSpPr().getCNvPr().getName();
  118. }
  119. }