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.

HSLFSimpleShape.java 22KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605
  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.hslf.usermodel;
  16. import java.awt.Color;
  17. import org.apache.poi.ddf.AbstractEscherOptRecord;
  18. import org.apache.poi.ddf.EscherChildAnchorRecord;
  19. import org.apache.poi.ddf.EscherClientAnchorRecord;
  20. import org.apache.poi.ddf.EscherContainerRecord;
  21. import org.apache.poi.ddf.EscherOptRecord;
  22. import org.apache.poi.ddf.EscherProperties;
  23. import org.apache.poi.ddf.EscherProperty;
  24. import org.apache.poi.ddf.EscherRecord;
  25. import org.apache.poi.ddf.EscherSimpleProperty;
  26. import org.apache.poi.ddf.EscherSpRecord;
  27. import org.apache.poi.hslf.exceptions.HSLFException;
  28. import org.apache.poi.sl.draw.DrawPaint;
  29. import org.apache.poi.sl.draw.geom.CustomGeometry;
  30. import org.apache.poi.sl.draw.geom.Guide;
  31. import org.apache.poi.sl.draw.geom.PresetGeometries;
  32. import org.apache.poi.sl.usermodel.LineDecoration;
  33. import org.apache.poi.sl.usermodel.LineDecoration.DecorationShape;
  34. import org.apache.poi.sl.usermodel.LineDecoration.DecorationSize;
  35. import org.apache.poi.sl.usermodel.PaintStyle;
  36. import org.apache.poi.sl.usermodel.PaintStyle.SolidPaint;
  37. import org.apache.poi.sl.usermodel.Placeholder;
  38. import org.apache.poi.sl.usermodel.Shadow;
  39. import org.apache.poi.sl.usermodel.ShapeContainer;
  40. import org.apache.poi.sl.usermodel.ShapeType;
  41. import org.apache.poi.sl.usermodel.SimpleShape;
  42. import org.apache.poi.sl.usermodel.StrokeStyle;
  43. import org.apache.poi.sl.usermodel.StrokeStyle.LineCap;
  44. import org.apache.poi.sl.usermodel.StrokeStyle.LineCompound;
  45. import org.apache.poi.sl.usermodel.StrokeStyle.LineDash;
  46. import org.apache.poi.util.LittleEndian;
  47. import org.apache.poi.util.POILogFactory;
  48. import org.apache.poi.util.POILogger;
  49. import org.apache.poi.util.Units;
  50. /**
  51. * An abstract simple (non-group) shape.
  52. * This is the parent class for all primitive shapes like Line, Rectangle, etc.
  53. */
  54. public abstract class HSLFSimpleShape extends HSLFShape implements SimpleShape<HSLFShape,HSLFTextParagraph> {
  55. private static final POILogger LOG = POILogFactory.getLogger(HSLFSimpleShape.class);
  56. public final static double DEFAULT_LINE_WIDTH = 0.75;
  57. /**
  58. * Hyperlink
  59. */
  60. protected HSLFHyperlink _hyperlink;
  61. /**
  62. * Create a SimpleShape object and initialize it from the supplied Record container.
  63. *
  64. * @param escherRecord <code>EscherSpContainer</code> container which holds information about this shape
  65. * @param parent the parent of the shape
  66. */
  67. protected HSLFSimpleShape(EscherContainerRecord escherRecord, ShapeContainer<HSLFShape,HSLFTextParagraph> parent){
  68. super(escherRecord, parent);
  69. }
  70. /**
  71. * Create a new Shape
  72. *
  73. * @param isChild <code>true</code> if the Line is inside a group, <code>false</code> otherwise
  74. * @return the record container which holds this shape
  75. */
  76. @Override
  77. protected EscherContainerRecord createSpContainer(boolean isChild) {
  78. EscherContainerRecord ecr = super.createSpContainer(isChild);
  79. ecr.setRecordId( EscherContainerRecord.SP_CONTAINER );
  80. EscherSpRecord sp = new EscherSpRecord();
  81. int flags = EscherSpRecord.FLAG_HAVEANCHOR | EscherSpRecord.FLAG_HASSHAPETYPE;
  82. if (isChild) {
  83. flags |= EscherSpRecord.FLAG_CHILD;
  84. }
  85. sp.setFlags(flags);
  86. ecr.addChildRecord(sp);
  87. AbstractEscherOptRecord opt = new EscherOptRecord();
  88. opt.setRecordId(EscherOptRecord.RECORD_ID);
  89. ecr.addChildRecord(opt);
  90. EscherRecord anchor;
  91. if(isChild) {
  92. anchor = new EscherChildAnchorRecord();
  93. } else {
  94. anchor = new EscherClientAnchorRecord();
  95. //hack. internal variable EscherClientAnchorRecord.shortRecord can be
  96. //initialized only in fillFields(). We need to set shortRecord=false;
  97. byte[] header = new byte[16];
  98. LittleEndian.putUShort(header, 0, 0);
  99. LittleEndian.putUShort(header, 2, 0);
  100. LittleEndian.putInt(header, 4, 8);
  101. anchor.fillFields(header, 0, null);
  102. }
  103. ecr.addChildRecord(anchor);
  104. return ecr;
  105. }
  106. /**
  107. * Returns width of the line in in points
  108. */
  109. public double getLineWidth(){
  110. AbstractEscherOptRecord opt = getEscherOptRecord();
  111. EscherSimpleProperty prop = getEscherProperty(opt, EscherProperties.LINESTYLE__LINEWIDTH);
  112. return (prop == null) ? DEFAULT_LINE_WIDTH : Units.toPoints(prop.getPropertyValue());
  113. }
  114. /**
  115. * Sets the width of line in in points
  116. * @param width the width of line in in points
  117. */
  118. public void setLineWidth(double width){
  119. AbstractEscherOptRecord opt = getEscherOptRecord();
  120. setEscherProperty(opt, EscherProperties.LINESTYLE__LINEWIDTH, Units.toEMU(width));
  121. }
  122. /**
  123. * Sets the color of line
  124. *
  125. * @param color new color of the line
  126. */
  127. public void setLineColor(Color color){
  128. AbstractEscherOptRecord opt = getEscherOptRecord();
  129. if (color == null) {
  130. setEscherProperty(opt, EscherProperties.LINESTYLE__NOLINEDRAWDASH, 0x80000);
  131. } else {
  132. int rgb = new Color(color.getBlue(), color.getGreen(), color.getRed(), 0).getRGB();
  133. setEscherProperty(opt, EscherProperties.LINESTYLE__COLOR, rgb);
  134. setEscherProperty(opt, EscherProperties.LINESTYLE__NOLINEDRAWDASH, 0x180018);
  135. }
  136. }
  137. /**
  138. * @return color of the line. If color is not set returns {@code null}
  139. */
  140. public Color getLineColor(){
  141. AbstractEscherOptRecord opt = getEscherOptRecord();
  142. EscherSimpleProperty p = getEscherProperty(opt, EscherProperties.LINESTYLE__NOLINEDRAWDASH);
  143. if(p != null && (p.getPropertyValue() & 0x8) == 0) {
  144. return null;
  145. }
  146. Color clr = getColor(EscherProperties.LINESTYLE__COLOR, EscherProperties.LINESTYLE__OPACITY);
  147. return clr == null ? null : clr;
  148. }
  149. /**
  150. * @return background color of the line. If color is not set returns {@code null}
  151. */
  152. public Color getLineBackgroundColor(){
  153. AbstractEscherOptRecord opt = getEscherOptRecord();
  154. EscherSimpleProperty p = getEscherProperty(opt, EscherProperties.LINESTYLE__NOLINEDRAWDASH);
  155. if(p != null && (p.getPropertyValue() & 0x8) == 0) {
  156. return null;
  157. }
  158. Color clr = getColor(EscherProperties.LINESTYLE__BACKCOLOR, EscherProperties.LINESTYLE__OPACITY);
  159. return clr == null ? null : clr;
  160. }
  161. /**
  162. * Sets the background color of line
  163. *
  164. * @param color new background color of the line
  165. */
  166. public void setLineBackgroundColor(Color color){
  167. AbstractEscherOptRecord opt = getEscherOptRecord();
  168. if (color == null) {
  169. setEscherProperty(opt, EscherProperties.LINESTYLE__NOLINEDRAWDASH, 0x80000);
  170. opt.removeEscherProperty(EscherProperties.LINESTYLE__BACKCOLOR);
  171. } else {
  172. int rgb = new Color(color.getBlue(), color.getGreen(), color.getRed(), 0).getRGB();
  173. setEscherProperty(opt, EscherProperties.LINESTYLE__BACKCOLOR, rgb);
  174. setEscherProperty(opt, EscherProperties.LINESTYLE__NOLINEDRAWDASH, 0x180018);
  175. }
  176. }
  177. /**
  178. * Gets line cap.
  179. *
  180. * @return cap of the line.
  181. */
  182. public LineCap getLineCap(){
  183. AbstractEscherOptRecord opt = getEscherOptRecord();
  184. EscherSimpleProperty prop = getEscherProperty(opt, EscherProperties.LINESTYLE__LINEENDCAPSTYLE);
  185. return (prop == null) ? LineCap.FLAT : LineCap.fromNativeId(prop.getPropertyValue());
  186. }
  187. /**
  188. * Sets line cap.
  189. *
  190. * @param pen new style of the line.
  191. */
  192. public void setLineCap(LineCap pen){
  193. AbstractEscherOptRecord opt = getEscherOptRecord();
  194. setEscherProperty(opt, EscherProperties.LINESTYLE__LINEENDCAPSTYLE, pen == LineCap.FLAT ? -1 : pen.nativeId);
  195. }
  196. /**
  197. * Gets line dashing.
  198. *
  199. * @return dashing of the line.
  200. */
  201. public LineDash getLineDash(){
  202. AbstractEscherOptRecord opt = getEscherOptRecord();
  203. EscherSimpleProperty prop = getEscherProperty(opt, EscherProperties.LINESTYLE__LINEDASHING);
  204. return (prop == null) ? LineDash.SOLID : LineDash.fromNativeId(prop.getPropertyValue());
  205. }
  206. /**
  207. * Sets line dashing.
  208. *
  209. * @param pen new style of the line.
  210. */
  211. public void setLineDash(LineDash pen){
  212. AbstractEscherOptRecord opt = getEscherOptRecord();
  213. setEscherProperty(opt, EscherProperties.LINESTYLE__LINEDASHING, pen == LineDash.SOLID ? -1 : pen.nativeId);
  214. }
  215. /**
  216. * Gets the line compound style
  217. *
  218. * @return the compound style of the line.
  219. */
  220. public LineCompound getLineCompound() {
  221. AbstractEscherOptRecord opt = getEscherOptRecord();
  222. EscherSimpleProperty prop = getEscherProperty(opt, EscherProperties.LINESTYLE__LINESTYLE);
  223. return (prop == null) ? LineCompound.SINGLE : LineCompound.fromNativeId(prop.getPropertyValue());
  224. }
  225. /**
  226. * Sets the line compound style
  227. *
  228. * @param style new compound style of the line.
  229. */
  230. public void setLineCompound(LineCompound style){
  231. AbstractEscherOptRecord opt = getEscherOptRecord();
  232. setEscherProperty(opt, EscherProperties.LINESTYLE__LINESTYLE, style == LineCompound.SINGLE ? -1 : style.nativeId);
  233. }
  234. /**
  235. * Returns line style. One of the constants defined in this class.
  236. *
  237. * @return style of the line.
  238. */
  239. @Override
  240. public StrokeStyle getStrokeStyle(){
  241. return new StrokeStyle() {
  242. @Override
  243. public PaintStyle getPaint() {
  244. return DrawPaint.createSolidPaint(HSLFSimpleShape.this.getLineColor());
  245. }
  246. @Override
  247. public LineCap getLineCap() {
  248. return null;
  249. }
  250. @Override
  251. public LineDash getLineDash() {
  252. return HSLFSimpleShape.this.getLineDash();
  253. }
  254. @Override
  255. public LineCompound getLineCompound() {
  256. return HSLFSimpleShape.this.getLineCompound();
  257. }
  258. @Override
  259. public double getLineWidth() {
  260. return HSLFSimpleShape.this.getLineWidth();
  261. }
  262. };
  263. }
  264. @Override
  265. public Color getFillColor() {
  266. return getFill().getForegroundColor();
  267. }
  268. @Override
  269. public void setFillColor(Color color) {
  270. getFill().setForegroundColor(color);
  271. }
  272. @Override
  273. public Guide getAdjustValue(String name) {
  274. if (name == null || !name.matches("adj([1-9]|10)?")) {
  275. LOG.log(POILogger.INFO, "Adjust value '"+name+"' not supported. Using default value.");
  276. return null;
  277. }
  278. name = name.replace("adj", "");
  279. if (name.isEmpty()) {
  280. name = "1";
  281. }
  282. short escherProp;
  283. switch (Integer.parseInt(name)) {
  284. case 1: escherProp = EscherProperties.GEOMETRY__ADJUSTVALUE; break;
  285. case 2: escherProp = EscherProperties.GEOMETRY__ADJUST2VALUE; break;
  286. case 3: escherProp = EscherProperties.GEOMETRY__ADJUST3VALUE; break;
  287. case 4: escherProp = EscherProperties.GEOMETRY__ADJUST4VALUE; break;
  288. case 5: escherProp = EscherProperties.GEOMETRY__ADJUST5VALUE; break;
  289. case 6: escherProp = EscherProperties.GEOMETRY__ADJUST6VALUE; break;
  290. case 7: escherProp = EscherProperties.GEOMETRY__ADJUST7VALUE; break;
  291. case 8: escherProp = EscherProperties.GEOMETRY__ADJUST8VALUE; break;
  292. case 9: escherProp = EscherProperties.GEOMETRY__ADJUST9VALUE; break;
  293. case 10: escherProp = EscherProperties.GEOMETRY__ADJUST10VALUE; break;
  294. default: throw new HSLFException();
  295. }
  296. // TODO: the adjust values need to be corrected somehow depending on the shape width/height
  297. // see https://social.msdn.microsoft.com/Forums/en-US/3f69ebb3-62a0-4fdd-b367-64790dfb2491/presetshapedefinitionsxml-does-not-specify-width-and-height-form-some-autoshapes?forum=os_binaryfile
  298. // the adjust value can be format dependent, e.g. hexagon has different values,
  299. // other shape types have the same adjust values in OOXML and native
  300. int adjval = getEscherProperty(escherProp, -1);
  301. return (adjval == -1) ? null : new Guide(name, "val "+adjval);
  302. }
  303. @Override
  304. public CustomGeometry getGeometry() {
  305. PresetGeometries dict = PresetGeometries.getInstance();
  306. ShapeType st = getShapeType();
  307. String name = (st != null) ? st.getOoxmlName() : null;
  308. CustomGeometry geom = dict.get(name);
  309. if (geom == null) {
  310. if (name == null) {
  311. name = (st != null) ? st.toString() : "<unknown>";
  312. }
  313. LOG.log(POILogger.WARN, "No preset shape definition for shapeType: "+name);
  314. }
  315. return geom;
  316. }
  317. public double getShadowAngle() {
  318. AbstractEscherOptRecord opt = getEscherOptRecord();
  319. EscherSimpleProperty prop = getEscherProperty(opt, EscherProperties.SHADOWSTYLE__OFFSETX);
  320. int offX = (prop == null) ? 0 : prop.getPropertyValue();
  321. prop = getEscherProperty(opt, EscherProperties.SHADOWSTYLE__OFFSETY);
  322. int offY = (prop == null) ? 0 : prop.getPropertyValue();
  323. return Math.toDegrees(Math.atan2(offY, offX));
  324. }
  325. public double getShadowDistance() {
  326. AbstractEscherOptRecord opt = getEscherOptRecord();
  327. EscherSimpleProperty prop = getEscherProperty(opt, EscherProperties.SHADOWSTYLE__OFFSETX);
  328. int offX = (prop == null) ? 0 : prop.getPropertyValue();
  329. prop = getEscherProperty(opt, EscherProperties.SHADOWSTYLE__OFFSETY);
  330. int offY = (prop == null) ? 0 : prop.getPropertyValue();
  331. return Units.toPoints((long)Math.hypot(offX, offY));
  332. }
  333. /**
  334. * @return color of the line. If color is not set returns <code>java.awt.Color.black</code>
  335. */
  336. public Color getShadowColor(){
  337. Color clr = getColor(EscherProperties.SHADOWSTYLE__COLOR, EscherProperties.SHADOWSTYLE__OPACITY);
  338. return clr == null ? Color.black : clr;
  339. }
  340. @Override
  341. public Shadow<HSLFShape,HSLFTextParagraph> getShadow() {
  342. AbstractEscherOptRecord opt = getEscherOptRecord();
  343. if (opt == null) {
  344. return null;
  345. }
  346. EscherProperty shadowType = opt.lookup(EscherProperties.SHADOWSTYLE__TYPE);
  347. if (shadowType == null) {
  348. return null;
  349. }
  350. return new Shadow<HSLFShape,HSLFTextParagraph>(){
  351. @Override
  352. public SimpleShape<HSLFShape,HSLFTextParagraph> getShadowParent() {
  353. return HSLFSimpleShape.this;
  354. }
  355. @Override
  356. public double getDistance() {
  357. return getShadowDistance();
  358. }
  359. @Override
  360. public double getAngle() {
  361. return getShadowAngle();
  362. }
  363. @Override
  364. public double getBlur() {
  365. // TODO Auto-generated method stub
  366. return 0;
  367. }
  368. @Override
  369. public SolidPaint getFillStyle() {
  370. return DrawPaint.createSolidPaint(getShadowColor());
  371. }
  372. };
  373. }
  374. public DecorationShape getLineHeadDecoration(){
  375. AbstractEscherOptRecord opt = getEscherOptRecord();
  376. EscherSimpleProperty prop = getEscherProperty(opt, EscherProperties.LINESTYLE__LINESTARTARROWHEAD);
  377. return (prop == null) ? null : DecorationShape.fromNativeId(prop.getPropertyValue());
  378. }
  379. public void setLineHeadDecoration(DecorationShape decoShape){
  380. AbstractEscherOptRecord opt = getEscherOptRecord();
  381. setEscherProperty(opt, EscherProperties.LINESTYLE__LINESTARTARROWHEAD, decoShape == null ? -1 : decoShape.nativeId);
  382. }
  383. public DecorationSize getLineHeadWidth(){
  384. AbstractEscherOptRecord opt = getEscherOptRecord();
  385. EscherSimpleProperty prop = getEscherProperty(opt, EscherProperties.LINESTYLE__LINESTARTARROWWIDTH);
  386. return (prop == null) ? null : DecorationSize.fromNativeId(prop.getPropertyValue());
  387. }
  388. public void setLineHeadWidth(DecorationSize decoSize){
  389. AbstractEscherOptRecord opt = getEscherOptRecord();
  390. setEscherProperty(opt, EscherProperties.LINESTYLE__LINESTARTARROWWIDTH, decoSize == null ? -1 : decoSize.nativeId);
  391. }
  392. public DecorationSize getLineHeadLength(){
  393. AbstractEscherOptRecord opt = getEscherOptRecord();
  394. EscherSimpleProperty prop = getEscherProperty(opt, EscherProperties.LINESTYLE__LINESTARTARROWLENGTH);
  395. return (prop == null) ? null : DecorationSize.fromNativeId(prop.getPropertyValue());
  396. }
  397. public void setLineHeadLength(DecorationSize decoSize){
  398. AbstractEscherOptRecord opt = getEscherOptRecord();
  399. setEscherProperty(opt, EscherProperties.LINESTYLE__LINESTARTARROWLENGTH, decoSize == null ? -1 : decoSize.nativeId);
  400. }
  401. public DecorationShape getLineTailDecoration(){
  402. AbstractEscherOptRecord opt = getEscherOptRecord();
  403. EscherSimpleProperty prop = getEscherProperty(opt, EscherProperties.LINESTYLE__LINEENDARROWHEAD);
  404. return (prop == null) ? null : DecorationShape.fromNativeId(prop.getPropertyValue());
  405. }
  406. public void setLineTailDecoration(DecorationShape decoShape){
  407. AbstractEscherOptRecord opt = getEscherOptRecord();
  408. setEscherProperty(opt, EscherProperties.LINESTYLE__LINEENDARROWHEAD, decoShape == null ? -1 : decoShape.nativeId);
  409. }
  410. public DecorationSize getLineTailWidth(){
  411. AbstractEscherOptRecord opt = getEscherOptRecord();
  412. EscherSimpleProperty prop = getEscherProperty(opt, EscherProperties.LINESTYLE__LINEENDARROWWIDTH);
  413. return (prop == null) ? null : DecorationSize.fromNativeId(prop.getPropertyValue());
  414. }
  415. public void setLineTailWidth(DecorationSize decoSize){
  416. AbstractEscherOptRecord opt = getEscherOptRecord();
  417. setEscherProperty(opt, EscherProperties.LINESTYLE__LINEENDARROWWIDTH, decoSize == null ? -1 : decoSize.nativeId);
  418. }
  419. public DecorationSize getLineTailLength(){
  420. AbstractEscherOptRecord opt = getEscherOptRecord();
  421. EscherSimpleProperty prop = getEscherProperty(opt, EscherProperties.LINESTYLE__LINEENDARROWLENGTH);
  422. return (prop == null) ? null : DecorationSize.fromNativeId(prop.getPropertyValue());
  423. }
  424. public void setLineTailLength(DecorationSize decoSize){
  425. AbstractEscherOptRecord opt = getEscherOptRecord();
  426. setEscherProperty(opt, EscherProperties.LINESTYLE__LINEENDARROWLENGTH, decoSize == null ? -1 : decoSize.nativeId);
  427. }
  428. @Override
  429. public LineDecoration getLineDecoration() {
  430. return new LineDecoration() {
  431. @Override
  432. public DecorationShape getHeadShape() {
  433. return HSLFSimpleShape.this.getLineHeadDecoration();
  434. }
  435. @Override
  436. public DecorationSize getHeadWidth() {
  437. return HSLFSimpleShape.this.getLineHeadWidth();
  438. }
  439. @Override
  440. public DecorationSize getHeadLength() {
  441. return HSLFSimpleShape.this.getLineHeadLength();
  442. }
  443. @Override
  444. public DecorationShape getTailShape() {
  445. return HSLFSimpleShape.this.getLineTailDecoration();
  446. }
  447. @Override
  448. public DecorationSize getTailWidth() {
  449. return HSLFSimpleShape.this.getLineTailWidth();
  450. }
  451. @Override
  452. public DecorationSize getTailLength() {
  453. return HSLFSimpleShape.this.getLineTailLength();
  454. }
  455. };
  456. }
  457. @Override
  458. public HSLFShapePlaceholderDetails getPlaceholderDetails() {
  459. return new HSLFShapePlaceholderDetails(this);
  460. }
  461. @Override
  462. public Placeholder getPlaceholder() {
  463. return getPlaceholderDetails().getPlaceholder();
  464. }
  465. @Override
  466. public void setPlaceholder(Placeholder placeholder) {
  467. getPlaceholderDetails().setPlaceholder(placeholder);
  468. }
  469. @Override
  470. public void setStrokeStyle(Object... styles) {
  471. if (styles.length == 0) {
  472. // remove stroke
  473. setLineColor(null);
  474. return;
  475. }
  476. // TODO: handle PaintStyle
  477. for (Object st : styles) {
  478. if (st instanceof Number) {
  479. setLineWidth(((Number)st).doubleValue());
  480. } else if (st instanceof LineCap) {
  481. setLineCap((LineCap)st);
  482. } else if (st instanceof LineDash) {
  483. setLineDash((LineDash)st);
  484. } else if (st instanceof LineCompound) {
  485. setLineCompound((LineCompound)st);
  486. } else if (st instanceof Color) {
  487. setLineColor((Color)st);
  488. }
  489. }
  490. }
  491. @Override
  492. public HSLFHyperlink getHyperlink(){
  493. return _hyperlink;
  494. }
  495. @Override
  496. public HSLFHyperlink createHyperlink() {
  497. if (_hyperlink == null) {
  498. _hyperlink = HSLFHyperlink.createHyperlink(this);
  499. }
  500. return _hyperlink;
  501. }
  502. /**
  503. * Sets the hyperlink - used when the document is parsed
  504. *
  505. * @param link the hyperlink
  506. */
  507. protected void setHyperlink(HSLFHyperlink link) {
  508. _hyperlink = link;
  509. }
  510. @Override
  511. public boolean isPlaceholder() {
  512. // currently we only identify TextShapes as placeholders
  513. return false;
  514. }
  515. }