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

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