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.

TestXSLFConnectorShape.java 7.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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 junit.framework.TestCase;
  17. import org.openxmlformats.schemas.drawingml.x2006.main.*;
  18. import org.openxmlformats.schemas.presentationml.x2006.main.CTConnector;
  19. import java.awt.*;
  20. /**
  21. * @author Yegor Kozlov
  22. */
  23. public class TestXSLFConnectorShape extends TestCase {
  24. public void testLineDecorations() {
  25. XMLSlideShow ppt = new XMLSlideShow();
  26. XSLFSlide slide = ppt.createSlide();
  27. XSLFConnectorShape shape = slide.createConnector();
  28. assertEquals(1, slide.getShapes().length);
  29. assertFalse(shape.getSpPr().getLn().isSetHeadEnd());
  30. assertFalse(shape.getSpPr().getLn().isSetTailEnd());
  31. // line decorations
  32. assertEquals(LineDecoration.NONE, shape.getLineHeadDecoration());
  33. assertEquals(LineDecoration.NONE, shape.getLineTailDecoration());
  34. shape.setLineHeadDecoration(null);
  35. shape.setLineTailDecoration(null);
  36. assertEquals(LineDecoration.NONE, shape.getLineHeadDecoration());
  37. assertEquals(LineDecoration.NONE, shape.getLineTailDecoration());
  38. assertFalse(shape.getSpPr().getLn().getHeadEnd().isSetType());
  39. assertFalse(shape.getSpPr().getLn().getTailEnd().isSetType());
  40. shape.setLineHeadDecoration(LineDecoration.ARROW);
  41. shape.setLineTailDecoration(LineDecoration.DIAMOND);
  42. assertEquals(LineDecoration.ARROW, shape.getLineHeadDecoration());
  43. assertEquals(LineDecoration.DIAMOND, shape.getLineTailDecoration());
  44. assertEquals(STLineEndType.ARROW, shape.getSpPr().getLn().getHeadEnd().getType());
  45. assertEquals(STLineEndType.DIAMOND, shape.getSpPr().getLn().getTailEnd().getType());
  46. shape.setLineHeadDecoration(LineDecoration.DIAMOND);
  47. shape.setLineTailDecoration(LineDecoration.ARROW);
  48. assertEquals(LineDecoration.DIAMOND, shape.getLineHeadDecoration());
  49. assertEquals(LineDecoration.ARROW, shape.getLineTailDecoration());
  50. assertEquals(STLineEndType.DIAMOND, shape.getSpPr().getLn().getHeadEnd().getType());
  51. assertEquals(STLineEndType.ARROW, shape.getSpPr().getLn().getTailEnd().getType());
  52. // line end width
  53. assertEquals(LineEndWidth.MEDIUM, shape.getLineHeadWidth());
  54. assertEquals(LineEndWidth.MEDIUM, shape.getLineTailWidth());
  55. shape.setLineHeadWidth(null);
  56. shape.setLineHeadWidth(null);
  57. assertEquals(LineEndWidth.MEDIUM, shape.getLineHeadWidth());
  58. assertEquals(LineEndWidth.MEDIUM, shape.getLineTailWidth());
  59. assertFalse(shape.getSpPr().getLn().getHeadEnd().isSetW());
  60. assertFalse(shape.getSpPr().getLn().getTailEnd().isSetW());
  61. shape.setLineHeadWidth(LineEndWidth.LARGE);
  62. shape.setLineTailWidth(LineEndWidth.MEDIUM);
  63. assertEquals(LineEndWidth.LARGE, shape.getLineHeadWidth());
  64. assertEquals(LineEndWidth.MEDIUM, shape.getLineTailWidth());
  65. assertEquals(STLineEndWidth.LG, shape.getSpPr().getLn().getHeadEnd().getW());
  66. assertEquals(STLineEndWidth.MED, shape.getSpPr().getLn().getTailEnd().getW());
  67. shape.setLineHeadWidth(LineEndWidth.MEDIUM);
  68. shape.setLineTailWidth(LineEndWidth.LARGE);
  69. assertEquals(LineEndWidth.MEDIUM, shape.getLineHeadWidth());
  70. assertEquals(LineEndWidth.LARGE, shape.getLineTailWidth());
  71. assertEquals(STLineEndWidth.MED, shape.getSpPr().getLn().getHeadEnd().getW());
  72. assertEquals(STLineEndWidth.LG, shape.getSpPr().getLn().getTailEnd().getW());
  73. // line end length
  74. assertEquals(LineEndLength.MEDIUM, shape.getLineHeadLength());
  75. assertEquals(LineEndLength.MEDIUM, shape.getLineTailLength());
  76. shape.setLineHeadLength(null);
  77. shape.setLineTailLength(null);
  78. assertEquals(LineEndLength.MEDIUM, shape.getLineHeadLength());
  79. assertEquals(LineEndLength.MEDIUM, shape.getLineTailLength());
  80. assertFalse(shape.getSpPr().getLn().getHeadEnd().isSetLen());
  81. assertFalse(shape.getSpPr().getLn().getTailEnd().isSetLen());
  82. shape.setLineHeadLength(LineEndLength.LARGE);
  83. shape.setLineTailLength(LineEndLength.MEDIUM);
  84. assertEquals(LineEndLength.LARGE, shape.getLineHeadLength());
  85. assertEquals(LineEndLength.MEDIUM, shape.getLineTailLength());
  86. assertEquals(STLineEndLength.LG, shape.getSpPr().getLn().getHeadEnd().getLen());
  87. assertEquals(STLineEndLength.MED, shape.getSpPr().getLn().getTailEnd().getLen());
  88. shape.setLineHeadLength(LineEndLength.MEDIUM);
  89. shape.setLineTailLength(LineEndLength.LARGE);
  90. assertEquals(LineEndLength.MEDIUM, shape.getLineHeadLength());
  91. assertEquals(LineEndLength.LARGE, shape.getLineTailLength());
  92. assertEquals(STLineEndLength.MED, shape.getSpPr().getLn().getHeadEnd().getLen());
  93. assertEquals(STLineEndLength.LG, shape.getSpPr().getLn().getTailEnd().getLen());
  94. }
  95. public void testAddConnector(){
  96. XMLSlideShow pptx = new XMLSlideShow();
  97. XSLFSlide slide = pptx.createSlide();
  98. XSLFAutoShape rect1 = slide.createAutoShape();
  99. rect1.setShapeType(XSLFShapeType.RECT);
  100. rect1.setAnchor(new Rectangle(100, 100, 100, 100));
  101. rect1.setFillColor(Color.blue);
  102. XSLFAutoShape rect2 = slide.createAutoShape();
  103. rect2.setShapeType(XSLFShapeType.RECT);
  104. rect2.setAnchor(new Rectangle(300, 300, 100, 100));
  105. rect2.setFillColor(Color.red);
  106. XSLFConnectorShape connector1 = slide.createConnector();
  107. connector1.setAnchor(new Rectangle(200, 150, 100, 200));
  108. CTConnector ctConnector = (CTConnector)connector1.getXmlObject();
  109. ctConnector.getSpPr().getPrstGeom().setPrst(STShapeType.BENT_CONNECTOR_3);
  110. CTNonVisualConnectorProperties cx = ctConnector.getNvCxnSpPr().getCNvCxnSpPr();
  111. // connection start
  112. CTConnection stCxn = cx.addNewStCxn();
  113. stCxn.setId(rect1.getShapeId());
  114. // side of the rectangle to attach the connector: left=1, bottom=2,right=3, top=4
  115. stCxn.setIdx(2);
  116. CTConnection end = cx.addNewEndCxn();
  117. end.setId(rect2.getShapeId());
  118. // side of the rectangle to attach the connector: left=1, bottom=2,right=3, top=4
  119. end.setIdx(3);
  120. }
  121. }