PageRenderTime 67ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/components/forks/poi/src/loci/poi/hssf/usermodel/HSSFFooter.java

http://github.com/openmicroscopy/bioformats
Java | 279 lines | 116 code | 26 blank | 137 comment | 13 complexity | 5ff4707f30030f3aa145734784a4dcea MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, Apache-2.0, BSD-2-Clause, MPL-2.0-no-copyleft-exception
  1. /*
  2. * #%L
  3. * Fork of Apache Jakarta POI.
  4. * %%
  5. * Copyright (C) 2008 - 2013 Open Microscopy Environment:
  6. * - Board of Regents of the University of Wisconsin-Madison
  7. * - Glencoe Software, Inc.
  8. * - University of Dundee
  9. * %%
  10. * Licensed under the Apache License, Version 2.0 (the "License");
  11. * you may not use this file except in compliance with the License.
  12. * You may obtain a copy of the License at
  13. *
  14. * http://www.apache.org/licenses/LICENSE-2.0
  15. *
  16. * Unless required by applicable law or agreed to in writing, software
  17. * distributed under the License is distributed on an "AS IS" BASIS,
  18. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  19. * See the License for the specific language governing permissions and
  20. * limitations under the License.
  21. * #L%
  22. */
  23. /* ====================================================================
  24. Licensed to the Apache Software Foundation (ASF) under one or more
  25. contributor license agreements. See the NOTICE file distributed with
  26. this work for additional information regarding copyright ownership.
  27. The ASF licenses this file to You under the Apache License, Version 2.0
  28. (the "License"); you may not use this file except in compliance with
  29. the License. You may obtain a copy of the License at
  30. http://www.apache.org/licenses/LICENSE-2.0
  31. Unless required by applicable law or agreed to in writing, software
  32. distributed under the License is distributed on an "AS IS" BASIS,
  33. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  34. See the License for the specific language governing permissions and
  35. limitations under the License.
  36. ==================================================================== */
  37. package loci.poi.hssf.usermodel;
  38. import loci.poi.hssf.record.FooterRecord;
  39. /**
  40. * Class to read and manipulate the footer.
  41. * <P>
  42. * The footer works by having a left, center, and right side. The total cannot
  43. * be more that 255 bytes long. One uses this class by getting the HSSFFooter
  44. * from HSSFSheet and then getting or setting the left, center, and right side.
  45. * For special things (such as page numbers and date), one can use a the methods
  46. * that return the characters used to represent these. One can also change the
  47. * fonts by using similar methods.
  48. * <P>
  49. * @author Shawn Laubach (slaubach at apache dot org)
  50. */
  51. public class HSSFFooter extends Object {
  52. FooterRecord footerRecord;
  53. String left;
  54. String center;
  55. String right;
  56. /**
  57. * Constructor. Creates a new footer interface from a footer record
  58. * @param footerRecord Footer record to create the footer with
  59. */
  60. protected HSSFFooter(FooterRecord footerRecord) {
  61. this.footerRecord = footerRecord;
  62. String foot = footerRecord.getFooter();
  63. while (foot != null && foot.length() > 1) {
  64. int pos = foot.length();
  65. switch (foot.substring(1, 2).charAt(0)) {
  66. case 'L' :
  67. if (foot.indexOf("&C") >= 0) {
  68. pos = Math.min(pos, foot.indexOf("&C"));
  69. }
  70. if (foot.indexOf("&R") >= 0) {
  71. pos = Math.min(pos, foot.indexOf("&R"));
  72. }
  73. left = foot.substring(2, pos);
  74. foot = foot.substring(pos);
  75. break;
  76. case 'C' :
  77. if (foot.indexOf("&L") >= 0) {
  78. pos = Math.min(pos, foot.indexOf("&L"));
  79. }
  80. if (foot.indexOf("&R") >= 0) {
  81. pos = Math.min(pos, foot.indexOf("&R"));
  82. }
  83. center = foot.substring(2, pos);
  84. foot = foot.substring(pos);
  85. break;
  86. case 'R' :
  87. if (foot.indexOf("&C") >= 0) {
  88. pos = Math.min(pos, foot.indexOf("&C"));
  89. }
  90. if (foot.indexOf("&L") >= 0) {
  91. pos = Math.min(pos, foot.indexOf("&L"));
  92. }
  93. right = foot.substring(2, pos);
  94. foot = foot.substring(pos);
  95. break;
  96. default : foot = null;
  97. }
  98. }
  99. }
  100. /**
  101. * Get the left side of the footer.
  102. * @return The string representing the left side.
  103. */
  104. public String getLeft() {
  105. return left;
  106. }
  107. /**
  108. * Sets the left string.
  109. * @param newLeft The string to set as the left side.
  110. */
  111. public void setLeft(String newLeft) {
  112. left = newLeft;
  113. createFooterString();
  114. }
  115. /**
  116. * Get the center of the footer.
  117. * @return The string representing the center.
  118. */
  119. public String getCenter() {
  120. return center;
  121. }
  122. /**
  123. * Sets the center string.
  124. * @param newCenter The string to set as the center.
  125. */
  126. public void setCenter(String newCenter) {
  127. center = newCenter;
  128. createFooterString();
  129. }
  130. /**
  131. * Get the right side of the footer.
  132. * @return The string representing the right side.
  133. */
  134. public String getRight() {
  135. return right;
  136. }
  137. /**
  138. * Sets the right string.
  139. * @param newRight The string to set as the right side.
  140. */
  141. public void setRight(String newRight) {
  142. right = newRight;
  143. createFooterString();
  144. }
  145. /**
  146. * Creates the complete footer string based on the left, center, and middle
  147. * strings.
  148. */
  149. private void createFooterString() {
  150. footerRecord.setFooter(
  151. "&C" + (center == null ? "" : center) +
  152. "&L" + (left == null ? "" : left) +
  153. "&R" + (right == null ? "" : right));
  154. footerRecord.setFooterLength((byte)footerRecord.getFooter().length());
  155. }
  156. /**
  157. * Returns the string that represents the change in font size.
  158. * @param size the new font size
  159. * @return The special string to represent a new font size
  160. */
  161. public static String fontSize(short size) {
  162. return "&" + size;
  163. }
  164. /**
  165. * Returns the string that represents the change in font.
  166. * @param font the new font
  167. * @param style the fonts style
  168. * @return The special string to represent a new font size
  169. */
  170. public static String font(String font, String style) {
  171. return "&\"" + font + "," + style + "\"";
  172. }
  173. /**
  174. * Returns the string representing the current page number
  175. * @return The special string for page number
  176. */
  177. public static String page() {
  178. return "&P";
  179. }
  180. /**
  181. * Returns the string representing the number of pages.
  182. * @return The special string for the number of pages
  183. */
  184. public static String numPages() {
  185. return "&N";
  186. }
  187. /**
  188. * Returns the string representing the current date
  189. * @return The special string for the date
  190. */
  191. public static String date() {
  192. return "&D";
  193. }
  194. /**
  195. * Returns the string representing the current time
  196. * @return The special string for the time
  197. */
  198. public static String time() {
  199. return "&T";
  200. }
  201. /**
  202. * Returns the string representing the current file name
  203. * @return The special string for the file name
  204. */
  205. public static String file() {
  206. return "&F";
  207. }
  208. /**
  209. * Returns the string representing the current tab (sheet) name
  210. * @return The special string for tab name
  211. */
  212. public static String tab() {
  213. return "&A";
  214. }
  215. /**
  216. * Returns the string representing the start underline
  217. *
  218. * @return The special string for start underline
  219. */
  220. public static String startUnderline()
  221. {
  222. return "&U";
  223. }
  224. /**
  225. * Returns the string representing the end underline
  226. *
  227. * @return The special string for end underline
  228. */
  229. public static String endUnderline()
  230. {
  231. return "&U";
  232. }
  233. /**
  234. * Returns the string representing the start double underline
  235. *
  236. * @return The special string for start double underline
  237. */
  238. public static String startDoubleUnderline()
  239. {
  240. return "&E";
  241. }
  242. /**
  243. * Returns the string representing the end double underline
  244. *
  245. * @return The special string for end double underline
  246. */
  247. public static String endDoubleUnderline()
  248. {
  249. return "&E";
  250. }
  251. }