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.

HSSFShape.java 6.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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.hssf.usermodel;
  16. import org.apache.poi.ddf.EscherContainerRecord;
  17. import org.apache.poi.hssf.record.ObjRecord;
  18. /**
  19. * An abstract shape.
  20. *
  21. * @author Glen Stampoultzis (glens at apache.org)
  22. */
  23. public abstract class HSSFShape {
  24. public static final int LINEWIDTH_ONE_PT = 12700;
  25. public static final int LINEWIDTH_DEFAULT = 9525;
  26. public static final int LINESTYLE_SOLID = 0; // Solid (continuous) pen
  27. public static final int LINESTYLE_DASHSYS = 1; // PS_DASH system dash style
  28. public static final int LINESTYLE_DOTSYS = 2; // PS_DOT system dash style
  29. public static final int LINESTYLE_DASHDOTSYS = 3; // PS_DASHDOT system dash style
  30. public static final int LINESTYLE_DASHDOTDOTSYS = 4; // PS_DASHDOTDOT system dash style
  31. public static final int LINESTYLE_DOTGEL = 5; // square dot style
  32. public static final int LINESTYLE_DASHGEL = 6; // dash style
  33. public static final int LINESTYLE_LONGDASHGEL = 7; // long dash style
  34. public static final int LINESTYLE_DASHDOTGEL = 8; // dash short dash
  35. public static final int LINESTYLE_LONGDASHDOTGEL = 9; // long dash short dash
  36. public static final int LINESTYLE_LONGDASHDOTDOTGEL = 10; // long dash short dash short dash
  37. public static final int LINESTYLE_NONE = -1;
  38. // TODO - make all these fields private
  39. HSSFShape parent;
  40. HSSFAnchor anchor;
  41. HSSFPatriarch _patriarch;
  42. private int _lineStyleColor = 0x08000040;
  43. int _fillColor = 0x08000009;
  44. private int _lineWidth = LINEWIDTH_DEFAULT; // 12700 = 1pt
  45. private int _lineStyle = LINESTYLE_SOLID;
  46. private boolean _noFill = false;
  47. private EscherContainerRecord spContainer;
  48. private ObjRecord objRecord;
  49. public HSSFShape(EscherContainerRecord spContainer, ObjRecord objRecord){
  50. this.spContainer = spContainer;
  51. this.objRecord = objRecord;
  52. }
  53. /**
  54. * Create a new shape with the specified parent and anchor.
  55. */
  56. public HSSFShape( HSSFShape parent, HSSFAnchor anchor )
  57. {
  58. this.parent = parent;
  59. this.anchor = anchor;
  60. }
  61. public EscherContainerRecord getSpContainer() {
  62. return spContainer;
  63. }
  64. public ObjRecord getObjRecord() {
  65. return objRecord;
  66. }
  67. /**
  68. * Gets the parent shape.
  69. */
  70. public HSSFShape getParent()
  71. {
  72. return parent;
  73. }
  74. /**
  75. * @return the anchor that is used by this shape.
  76. */
  77. public HSSFAnchor getAnchor()
  78. {
  79. return anchor;
  80. }
  81. /**
  82. * Sets a particular anchor. A top-level shape must have an anchor of
  83. * HSSFClientAnchor. A child anchor must have an anchor of HSSFChildAnchor
  84. *
  85. * @param anchor the anchor to use.
  86. * @throws IllegalArgumentException when the wrong anchor is used for
  87. * this particular shape.
  88. *
  89. * @see HSSFChildAnchor
  90. * @see HSSFClientAnchor
  91. */
  92. public void setAnchor( HSSFAnchor anchor )
  93. {
  94. if ( parent == null )
  95. {
  96. if ( anchor instanceof HSSFChildAnchor )
  97. throw new IllegalArgumentException( "Must use client anchors for shapes directly attached to sheet." );
  98. }
  99. else
  100. {
  101. if ( anchor instanceof HSSFClientAnchor )
  102. throw new IllegalArgumentException( "Must use child anchors for shapes attached to groups." );
  103. }
  104. this.anchor = anchor;
  105. }
  106. /**
  107. * The color applied to the lines of this shape.
  108. */
  109. public int getLineStyleColor() {
  110. return _lineStyleColor;
  111. }
  112. /**
  113. * The color applied to the lines of this shape.
  114. */
  115. public void setLineStyleColor(int lineStyleColor) {
  116. _lineStyleColor = lineStyleColor;
  117. }
  118. /**
  119. * The color applied to the lines of this shape.
  120. */
  121. public void setLineStyleColor(int red, int green, int blue) {
  122. this._lineStyleColor = ((blue) << 16) | ((green) << 8) | red;
  123. }
  124. /**
  125. * The color used to fill this shape.
  126. */
  127. public int getFillColor()
  128. {
  129. return _fillColor;
  130. }
  131. /**
  132. * The color used to fill this shape.
  133. */
  134. public void setFillColor(int fillColor) {
  135. _fillColor = fillColor;
  136. }
  137. /**
  138. * The color used to fill this shape.
  139. */
  140. public void setFillColor( int red, int green, int blue )
  141. {
  142. this._fillColor = ((blue) << 16) | ((green) << 8) | red;
  143. }
  144. /**
  145. * @return returns with width of the line in EMUs. 12700 = 1 pt.
  146. */
  147. public int getLineWidth() {
  148. return _lineWidth;
  149. }
  150. /**
  151. * Sets the width of the line. 12700 = 1 pt.
  152. *
  153. * @param lineWidth width in EMU's. 12700EMU's = 1 pt
  154. *
  155. * @see HSSFShape#LINEWIDTH_ONE_PT
  156. */
  157. public void setLineWidth(int lineWidth) {
  158. _lineWidth = lineWidth;
  159. }
  160. /**
  161. * @return One of the constants in LINESTYLE_*
  162. */
  163. public int getLineStyle() {
  164. return _lineStyle;
  165. }
  166. /**
  167. * Sets the line style.
  168. *
  169. * @param lineStyle One of the constants in LINESTYLE_*
  170. */
  171. public void setLineStyle(int lineStyle) {
  172. _lineStyle = lineStyle;
  173. }
  174. /**
  175. * @return <code>true</code> if this shape is not filled with a color.
  176. */
  177. public boolean isNoFill() {
  178. return _noFill;
  179. }
  180. /**
  181. * Sets whether this shape is filled or transparent.
  182. */
  183. public void setNoFill(boolean noFill) {
  184. _noFill = noFill;
  185. }
  186. /**
  187. * Count of all children and their children's children.
  188. */
  189. public int countOfAllChildren() {
  190. return 1;
  191. }
  192. }