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.

ClientAnchor.java 9.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  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.ss.usermodel;
  16. import org.apache.poi.util.Internal;
  17. /**
  18. * A client anchor is attached to an excel worksheet. It anchors against
  19. * absolute coordinates, a top-left cell and fixed height and width, or
  20. * a top-left and bottom-right cell, depending on the {@link AnchorType}:
  21. * <ol>
  22. * <li> {@link AnchorType#DONT_MOVE_AND_RESIZE} == absolute top-left coordinates and width/height, no cell references
  23. * <li> {@link AnchorType#MOVE_DONT_RESIZE} == fixed top-left cell reference, absolute width/height
  24. * <li> {@link AnchorType#MOVE_AND_RESIZE} == fixed top-left and bottom-right cell references, dynamic width/height
  25. * </ol>
  26. * Note this class only reports the current values for possibly calculated positions and sizes.
  27. * If the sheet row/column sizes or positions shift, this needs updating via external calculations.
  28. *
  29. */
  30. public interface ClientAnchor {
  31. /**
  32. * @since POI 3.14beta1
  33. */
  34. public static enum AnchorType {
  35. /**
  36. * Move and Resize With Anchor Cells (0)
  37. * <p>
  38. * Specifies that the current drawing shall move and
  39. * resize to maintain its row and column anchors (i.e. the
  40. * object is anchored to the actual from and to row and column)
  41. * </p>
  42. */
  43. MOVE_AND_RESIZE(0),
  44. /**
  45. * Don't Move but do Resize With Anchor Cells (1)
  46. * <p>
  47. * Specifies that the current drawing shall not move with its
  48. * row and column, but should be resized. This option is not normally
  49. * used, but is included for completeness.
  50. * </p>
  51. * Note: Excel has no setting for this combination, nor does the ECMA standard.
  52. */
  53. DONT_MOVE_DO_RESIZE(1),
  54. /**
  55. * Move With Cells but Do Not Resize (2)
  56. * <p>
  57. * Specifies that the current drawing shall move with its
  58. * row and column (i.e. the object is anchored to the
  59. * actual from row and column), but that the size shall remain absolute.
  60. * </p>
  61. * <p>
  62. * If additional rows/columns are added between the from and to locations of the drawing,
  63. * the drawing shall move its to anchors as needed to maintain this same absolute size.
  64. * </p>
  65. */
  66. MOVE_DONT_RESIZE(2),
  67. /**
  68. * Do Not Move or Resize With Underlying Rows/Columns (3)
  69. * <p>
  70. * Specifies that the current start and end positions shall
  71. * be maintained with respect to the distances from the
  72. * absolute start point of the worksheet.
  73. * </p>
  74. * <p>
  75. * If additional rows/columns are added before the
  76. * drawing, the drawing shall move its anchors as needed
  77. * to maintain this same absolute position.
  78. * </p>
  79. */
  80. DONT_MOVE_AND_RESIZE(3);
  81. public final short value;
  82. // disallow non-sequential enum instance creation
  83. private AnchorType(int value) {
  84. this.value = (short) value;
  85. }
  86. /**
  87. * return the AnchorType corresponding to the code
  88. *
  89. * @param value the anchor type code
  90. * @return the anchor type enum
  91. */
  92. @Internal
  93. public static AnchorType byId(int value) {
  94. return values()[value];
  95. }
  96. }
  97. /**
  98. * Returns the column (0 based) of the first cell, or -1 if there is no top-left anchor cell.
  99. * This is the case for absolute positioning {@link AnchorType#MOVE_AND_RESIZE}
  100. *
  101. * @return 0-based column of the first cell or -1 if none.
  102. */
  103. public short getCol1();
  104. /**
  105. * Sets the column (0 based) of the first cell.
  106. *
  107. * @param col1 0-based column of the first cell.
  108. */
  109. public void setCol1(int col1);
  110. /**
  111. * Returns the column (0 based) of the second cell, or -1 if there is no bottom-right anchor cell.
  112. * This is the case for absolute positioning ({@link AnchorType#DONT_MOVE_AND_RESIZE})
  113. * and absolute sizing ({@link AnchorType#MOVE_DONT_RESIZE}.
  114. *
  115. * @return 0-based column of the second cell or -1 if none.
  116. */
  117. public short getCol2();
  118. /**
  119. * Returns the column (0 based) of the second cell.
  120. *
  121. * @param col2 0-based column of the second cell.
  122. */
  123. public void setCol2(int col2);
  124. /**
  125. * Returns the row (0 based) of the first cell, or -1 if there is no bottom-right anchor cell.
  126. * This is the case for absolute positioning ({@link AnchorType#DONT_MOVE_AND_RESIZE}).
  127. *
  128. * @return 0-based row of the first cell or -1 if none.
  129. */
  130. public int getRow1();
  131. /**
  132. * Returns the row (0 based) of the first cell.
  133. *
  134. * @param row1 0-based row of the first cell.
  135. */
  136. public void setRow1(int row1);
  137. /**
  138. * Returns the row (0 based) of the second cell, or -1 if there is no bottom-right anchor cell.
  139. * This is the case for absolute positioning ({@link AnchorType#DONT_MOVE_AND_RESIZE})
  140. * and absolute sizing ({@link AnchorType#MOVE_DONT_RESIZE}.
  141. *
  142. * @return 0-based row of the second cell or -1 if none.
  143. */
  144. public int getRow2();
  145. /**
  146. * Returns the row (0 based) of the first cell.
  147. *
  148. * @param row2 0-based row of the first cell.
  149. */
  150. public void setRow2(int row2);
  151. /**
  152. * Returns the x coordinate within the first cell.
  153. *
  154. * Note - XSSF and HSSF have a slightly different coordinate
  155. * system, values in XSSF are larger by a factor of
  156. * {@link org.apache.poi.util.Units#EMU_PER_PIXEL}
  157. *
  158. * @return the x coordinate within the first cell
  159. */
  160. public int getDx1();
  161. /**
  162. * Sets the x coordinate within the first cell
  163. *
  164. * Note - XSSF and HSSF have a slightly different coordinate
  165. * system, values in XSSF are larger by a factor of
  166. * {@link org.apache.poi.util.Units#EMU_PER_PIXEL}
  167. *
  168. * @param dx1 the x coordinate within the first cell
  169. */
  170. public void setDx1(int dx1);
  171. /**
  172. * Returns the y coordinate within the first cell
  173. *
  174. * Note - XSSF and HSSF have a slightly different coordinate
  175. * system, values in XSSF are larger by a factor of
  176. * {@link org.apache.poi.util.Units#EMU_PER_PIXEL}
  177. *
  178. * @return the y coordinate within the first cell
  179. */
  180. public int getDy1();
  181. /**
  182. * Sets the y coordinate within the first cell
  183. *
  184. * Note - XSSF and HSSF have a slightly different coordinate
  185. * system, values in XSSF are larger by a factor of
  186. * {@link org.apache.poi.util.Units#EMU_PER_PIXEL}
  187. *
  188. * @param dy1 the y coordinate within the first cell
  189. */
  190. public void setDy1(int dy1);
  191. /**
  192. * Sets the y coordinate within the second cell
  193. *
  194. * Note - XSSF and HSSF have a slightly different coordinate
  195. * system, values in XSSF are larger by a factor of
  196. * {@link org.apache.poi.util.Units#EMU_PER_PIXEL}
  197. *
  198. * @return the y coordinate within the second cell
  199. */
  200. public int getDy2();
  201. /**
  202. * Sets the y coordinate within the second cell
  203. *
  204. * Note - XSSF and HSSF have a slightly different coordinate
  205. * system, values in XSSF are larger by a factor of
  206. * {@link org.apache.poi.util.Units#EMU_PER_PIXEL}
  207. *
  208. * @param dy2 the y coordinate within the second cell
  209. */
  210. public void setDy2(int dy2);
  211. /**
  212. * Returns the x coordinate within the second cell
  213. *
  214. * Note - XSSF and HSSF have a slightly different coordinate
  215. * system, values in XSSF are larger by a factor of
  216. * {@link org.apache.poi.util.Units#EMU_PER_PIXEL}
  217. *
  218. * @return the x coordinate within the second cell
  219. */
  220. public int getDx2();
  221. /**
  222. * Sets the x coordinate within the second cell
  223. *
  224. * Note - XSSF and HSSF have a slightly different coordinate
  225. * system, values in XSSF are larger by a factor of
  226. * {@link org.apache.poi.util.Units#EMU_PER_PIXEL}
  227. *
  228. * @param dx2 the x coordinate within the second cell
  229. */
  230. public void setDx2(int dx2);
  231. /**
  232. * Sets the anchor type
  233. * @param anchorType the anchor type to set
  234. * @since POI 3.14
  235. */
  236. public void setAnchorType( AnchorType anchorType );
  237. /**
  238. * Gets the anchor type
  239. * Changed from returning an int to an enum in POI 3.14 beta 1.
  240. * @return the anchor type
  241. */
  242. public AnchorType getAnchorType();
  243. }