選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

BorderFormatting.java 16KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465
  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.record.cf;
  16. import org.apache.poi.util.BitField;
  17. import org.apache.poi.util.BitFieldFactory;
  18. import org.apache.poi.util.LittleEndian;
  19. import org.apache.poi.util.LittleEndianInput;
  20. import org.apache.poi.util.LittleEndianOutput;
  21. /**
  22. * Border Formatting Block of the Conditional Formatting Rule Record.
  23. */
  24. public final class BorderFormatting {
  25. /** No border */
  26. public final static short BORDER_NONE = 0x0;
  27. /** Thin border */
  28. public final static short BORDER_THIN = 0x1;
  29. /** Medium border */
  30. public final static short BORDER_MEDIUM = 0x2;
  31. /** dash border */
  32. public final static short BORDER_DASHED = 0x3;
  33. /** dot border */
  34. public final static short BORDER_HAIR = 0x4;
  35. /** Thick border */
  36. public final static short BORDER_THICK = 0x5;
  37. /** double-line border */
  38. public final static short BORDER_DOUBLE = 0x6;
  39. /** hair-line border */
  40. public final static short BORDER_DOTTED = 0x7;
  41. /** Medium dashed border */
  42. public final static short BORDER_MEDIUM_DASHED = 0x8;
  43. /** dash-dot border */
  44. public final static short BORDER_DASH_DOT = 0x9;
  45. /** medium dash-dot border */
  46. public final static short BORDER_MEDIUM_DASH_DOT = 0xA;
  47. /** dash-dot-dot border */
  48. public final static short BORDER_DASH_DOT_DOT = 0xB;
  49. /** medium dash-dot-dot border */
  50. public final static short BORDER_MEDIUM_DASH_DOT_DOT = 0xC;
  51. /** slanted dash-dot border */
  52. public final static short BORDER_SLANTED_DASH_DOT = 0xD;
  53. // BORDER FORMATTING BLOCK
  54. // For Border Line Style codes see HSSFCellStyle.BORDER_XXXXXX
  55. private int field_13_border_styles1;
  56. private static final BitField bordLeftLineStyle = BitFieldFactory.getInstance(0x0000000F);
  57. private static final BitField bordRightLineStyle = BitFieldFactory.getInstance(0x000000F0);
  58. private static final BitField bordTopLineStyle = BitFieldFactory.getInstance(0x00000F00);
  59. private static final BitField bordBottomLineStyle= BitFieldFactory.getInstance(0x0000F000);
  60. private static final BitField bordLeftLineColor = BitFieldFactory.getInstance(0x007F0000);
  61. private static final BitField bordRightLineColor = BitFieldFactory.getInstance(0x3F800000);
  62. private static final BitField bordTlBrLineOnOff = BitFieldFactory.getInstance(0x40000000);
  63. private static final BitField bordBlTrtLineOnOff = BitFieldFactory.getInstance(0x80000000);
  64. private int field_14_border_styles2;
  65. private static final BitField bordTopLineColor = BitFieldFactory.getInstance(0x0000007F);
  66. private static final BitField bordBottomLineColor= BitFieldFactory.getInstance(0x00003f80);
  67. private static final BitField bordDiagLineColor = BitFieldFactory.getInstance(0x001FC000);
  68. private static final BitField bordDiagLineStyle = BitFieldFactory.getInstance(0x01E00000);
  69. public BorderFormatting() {
  70. field_13_border_styles1 = 0;
  71. field_14_border_styles2 = 0;
  72. }
  73. /** Creates new FontFormatting */
  74. public BorderFormatting(LittleEndianInput in) {
  75. field_13_border_styles1 = in.readInt();
  76. field_14_border_styles2 = in.readInt();
  77. }
  78. public int getDataLength() {
  79. return 8;
  80. }
  81. /**
  82. * set the type of border to use for the left border of the cell
  83. * @param border type
  84. * @see #BORDER_NONE
  85. * @see #BORDER_THIN
  86. * @see #BORDER_MEDIUM
  87. * @see #BORDER_DASHED
  88. * @see #BORDER_DOTTED
  89. * @see #BORDER_THICK
  90. * @see #BORDER_DOUBLE
  91. * @see #BORDER_HAIR
  92. * @see #BORDER_MEDIUM_DASHED
  93. * @see #BORDER_DASH_DOT
  94. * @see #BORDER_MEDIUM_DASH_DOT
  95. * @see #BORDER_DASH_DOT_DOT
  96. * @see #BORDER_MEDIUM_DASH_DOT_DOT
  97. * @see #BORDER_SLANTED_DASH_DOT
  98. */
  99. public void setBorderLeft(int border) {
  100. field_13_border_styles1 = bordLeftLineStyle.setValue(field_13_border_styles1, border);
  101. }
  102. /**
  103. * get the type of border to use for the left border of the cell
  104. * @return border type
  105. * @see #BORDER_NONE
  106. * @see #BORDER_THIN
  107. * @see #BORDER_MEDIUM
  108. * @see #BORDER_DASHED
  109. * @see #BORDER_DOTTED
  110. * @see #BORDER_THICK
  111. * @see #BORDER_DOUBLE
  112. * @see #BORDER_HAIR
  113. * @see #BORDER_MEDIUM_DASHED
  114. * @see #BORDER_DASH_DOT
  115. * @see #BORDER_MEDIUM_DASH_DOT
  116. * @see #BORDER_DASH_DOT_DOT
  117. * @see #BORDER_MEDIUM_DASH_DOT_DOT
  118. * @see #BORDER_SLANTED_DASH_DOT
  119. */
  120. public int getBorderLeft() {
  121. return bordLeftLineStyle.getValue(field_13_border_styles1);
  122. }
  123. /**
  124. * set the type of border to use for the right border of the cell
  125. * @param border type
  126. * @see #BORDER_NONE
  127. * @see #BORDER_THIN
  128. * @see #BORDER_MEDIUM
  129. * @see #BORDER_DASHED
  130. * @see #BORDER_DOTTED
  131. * @see #BORDER_THICK
  132. * @see #BORDER_DOUBLE
  133. * @see #BORDER_HAIR
  134. * @see #BORDER_MEDIUM_DASHED
  135. * @see #BORDER_DASH_DOT
  136. * @see #BORDER_MEDIUM_DASH_DOT
  137. * @see #BORDER_DASH_DOT_DOT
  138. * @see #BORDER_MEDIUM_DASH_DOT_DOT
  139. * @see #BORDER_SLANTED_DASH_DOT
  140. */
  141. public void setBorderRight(int border) {
  142. field_13_border_styles1 = bordRightLineStyle.setValue(field_13_border_styles1, border);
  143. }
  144. /**
  145. * get the type of border to use for the right border of the cell
  146. * @return border type
  147. * @see #BORDER_NONE
  148. * @see #BORDER_THIN
  149. * @see #BORDER_MEDIUM
  150. * @see #BORDER_DASHED
  151. * @see #BORDER_DOTTED
  152. * @see #BORDER_THICK
  153. * @see #BORDER_DOUBLE
  154. * @see #BORDER_HAIR
  155. * @see #BORDER_MEDIUM_DASHED
  156. * @see #BORDER_DASH_DOT
  157. * @see #BORDER_MEDIUM_DASH_DOT
  158. * @see #BORDER_DASH_DOT_DOT
  159. * @see #BORDER_MEDIUM_DASH_DOT_DOT
  160. * @see #BORDER_SLANTED_DASH_DOT
  161. */
  162. public int getBorderRight() {
  163. return bordRightLineStyle.getValue(field_13_border_styles1);
  164. }
  165. /**
  166. * set the type of border to use for the top border of the cell
  167. * @param border type
  168. * @see #BORDER_NONE
  169. * @see #BORDER_THIN
  170. * @see #BORDER_MEDIUM
  171. * @see #BORDER_DASHED
  172. * @see #BORDER_DOTTED
  173. * @see #BORDER_THICK
  174. * @see #BORDER_DOUBLE
  175. * @see #BORDER_HAIR
  176. * @see #BORDER_MEDIUM_DASHED
  177. * @see #BORDER_DASH_DOT
  178. * @see #BORDER_MEDIUM_DASH_DOT
  179. * @see #BORDER_DASH_DOT_DOT
  180. * @see #BORDER_MEDIUM_DASH_DOT_DOT
  181. * @see #BORDER_SLANTED_DASH_DOT
  182. */
  183. public void setBorderTop(int border) {
  184. field_13_border_styles1 = bordTopLineStyle.setValue(field_13_border_styles1, border);
  185. }
  186. /**
  187. * get the type of border to use for the top border of the cell
  188. * @return border type
  189. * @see #BORDER_NONE
  190. * @see #BORDER_THIN
  191. * @see #BORDER_MEDIUM
  192. * @see #BORDER_DASHED
  193. * @see #BORDER_DOTTED
  194. * @see #BORDER_THICK
  195. * @see #BORDER_DOUBLE
  196. * @see #BORDER_HAIR
  197. * @see #BORDER_MEDIUM_DASHED
  198. * @see #BORDER_DASH_DOT
  199. * @see #BORDER_MEDIUM_DASH_DOT
  200. * @see #BORDER_DASH_DOT_DOT
  201. * @see #BORDER_MEDIUM_DASH_DOT_DOT
  202. * @see #BORDER_SLANTED_DASH_DOT
  203. */
  204. public int getBorderTop() {
  205. return bordTopLineStyle.getValue(field_13_border_styles1);
  206. }
  207. /**
  208. * set the type of border to use for the bottom border of the cell
  209. * @param border type
  210. * @see #BORDER_NONE
  211. * @see #BORDER_THIN
  212. * @see #BORDER_MEDIUM
  213. * @see #BORDER_DASHED
  214. * @see #BORDER_DOTTED
  215. * @see #BORDER_THICK
  216. * @see #BORDER_DOUBLE
  217. * @see #BORDER_HAIR
  218. * @see #BORDER_MEDIUM_DASHED
  219. * @see #BORDER_DASH_DOT
  220. * @see #BORDER_MEDIUM_DASH_DOT
  221. * @see #BORDER_DASH_DOT_DOT
  222. * @see #BORDER_MEDIUM_DASH_DOT_DOT
  223. * @see #BORDER_SLANTED_DASH_DOT
  224. */
  225. public void setBorderBottom(int border) {
  226. field_13_border_styles1 = bordBottomLineStyle.setValue(field_13_border_styles1, border);
  227. }
  228. /**
  229. * get the type of border to use for the bottom border of the cell
  230. * @return border type
  231. * @see #BORDER_NONE
  232. * @see #BORDER_THIN
  233. * @see #BORDER_MEDIUM
  234. * @see #BORDER_DASHED
  235. * @see #BORDER_DOTTED
  236. * @see #BORDER_THICK
  237. * @see #BORDER_DOUBLE
  238. * @see #BORDER_HAIR
  239. * @see #BORDER_MEDIUM_DASHED
  240. * @see #BORDER_DASH_DOT
  241. * @see #BORDER_MEDIUM_DASH_DOT
  242. * @see #BORDER_DASH_DOT_DOT
  243. * @see #BORDER_MEDIUM_DASH_DOT_DOT
  244. * @see #BORDER_SLANTED_DASH_DOT
  245. */
  246. public int getBorderBottom() {
  247. return bordBottomLineStyle.getValue(field_13_border_styles1);
  248. }
  249. /**
  250. * set the type of border to use for the diagonal border of the cell
  251. * @param border type
  252. * @see #BORDER_NONE
  253. * @see #BORDER_THIN
  254. * @see #BORDER_MEDIUM
  255. * @see #BORDER_DASHED
  256. * @see #BORDER_DOTTED
  257. * @see #BORDER_THICK
  258. * @see #BORDER_DOUBLE
  259. * @see #BORDER_HAIR
  260. * @see #BORDER_MEDIUM_DASHED
  261. * @see #BORDER_DASH_DOT
  262. * @see #BORDER_MEDIUM_DASH_DOT
  263. * @see #BORDER_DASH_DOT_DOT
  264. * @see #BORDER_MEDIUM_DASH_DOT_DOT
  265. * @see #BORDER_SLANTED_DASH_DOT
  266. */
  267. public void setBorderDiagonal(int border) {
  268. field_14_border_styles2 = bordDiagLineStyle.setValue(field_14_border_styles2, border);
  269. }
  270. /**
  271. * get the type of border to use for the diagonal border of the cell
  272. * @return border type
  273. * @see #BORDER_NONE
  274. * @see #BORDER_THIN
  275. * @see #BORDER_MEDIUM
  276. * @see #BORDER_DASHED
  277. * @see #BORDER_DOTTED
  278. * @see #BORDER_THICK
  279. * @see #BORDER_DOUBLE
  280. * @see #BORDER_HAIR
  281. * @see #BORDER_MEDIUM_DASHED
  282. * @see #BORDER_DASH_DOT
  283. * @see #BORDER_MEDIUM_DASH_DOT
  284. * @see #BORDER_DASH_DOT_DOT
  285. * @see #BORDER_MEDIUM_DASH_DOT_DOT
  286. * @see #BORDER_SLANTED_DASH_DOT
  287. */
  288. public int getBorderDiagonal() {
  289. return bordDiagLineStyle.getValue(field_14_border_styles2);
  290. }
  291. /**
  292. * set the color to use for the left border
  293. * @param color The index of the color definition
  294. */
  295. public void setLeftBorderColor(int color) {
  296. field_13_border_styles1 = bordLeftLineColor.setValue(field_13_border_styles1, color);
  297. }
  298. /**
  299. * get the color to use for the left border
  300. * @see org.apache.poi.hssf.usermodel.HSSFPalette#getColor(short)
  301. * @return The index of the color definition
  302. */
  303. public int getLeftBorderColor() {
  304. return bordLeftLineColor.getValue(field_13_border_styles1);
  305. }
  306. /**
  307. * set the color to use for the right border
  308. * @param color The index of the color definition
  309. */
  310. public void setRightBorderColor(int color) {
  311. field_13_border_styles1 = bordRightLineColor.setValue(field_13_border_styles1, color);
  312. }
  313. /**
  314. * get the color to use for the right border
  315. * @see org.apache.poi.hssf.usermodel.HSSFPalette#getColor(short)
  316. * @return The index of the color definition
  317. */
  318. public int getRightBorderColor() {
  319. return bordRightLineColor.getValue(field_13_border_styles1);
  320. }
  321. /**
  322. * set the color to use for the top border
  323. * @param color The index of the color definition
  324. */
  325. public void setTopBorderColor(int color) {
  326. field_14_border_styles2 = bordTopLineColor.setValue(field_14_border_styles2, color);
  327. }
  328. /**
  329. * get the color to use for the top border
  330. * @see org.apache.poi.hssf.usermodel.HSSFPalette#getColor(short)
  331. * @return The index of the color definition
  332. */
  333. public int getTopBorderColor() {
  334. return bordTopLineColor.getValue(field_14_border_styles2);
  335. }
  336. /**
  337. * set the color to use for the bottom border
  338. * @param color The index of the color definition
  339. */
  340. public void setBottomBorderColor(int color)
  341. {
  342. field_14_border_styles2 = bordBottomLineColor.setValue(field_14_border_styles2, color);
  343. }
  344. /**
  345. * get the color to use for the bottom border
  346. * @see org.apache.poi.hssf.usermodel.HSSFPalette#getColor(short)
  347. * @return The index of the color definition
  348. */
  349. public int getBottomBorderColor() {
  350. return bordBottomLineColor.getValue(field_14_border_styles2);
  351. }
  352. /**
  353. * set the color to use for the diagonal borders
  354. * @param color The index of the color definition
  355. */
  356. public void setDiagonalBorderColor(int color) {
  357. field_14_border_styles2 = bordDiagLineColor.setValue(field_14_border_styles2, color);
  358. }
  359. /**
  360. * get the color to use for the diagonal border
  361. * @see org.apache.poi.hssf.usermodel.HSSFPalette#getColor(short)
  362. * @return The index of the color definition
  363. */
  364. public int getDiagonalBorderColor() {
  365. return bordDiagLineColor.getValue(field_14_border_styles2);
  366. }
  367. /**
  368. * Of/off bottom left to top right line
  369. *
  370. * @param on - if <code>true</code> - on, otherwise off
  371. */
  372. public void setForwardDiagonalOn(boolean on) {
  373. field_13_border_styles1 = bordBlTrtLineOnOff.setBoolean(field_13_border_styles1, on);
  374. }
  375. /**
  376. * Of/off top left to bottom right line
  377. *
  378. * @param on - if <code>true</code> - on, otherwise off
  379. */
  380. public void setBackwardDiagonalOn(boolean on) {
  381. field_13_border_styles1 = bordTlBrLineOnOff.setBoolean(field_13_border_styles1, on);
  382. }
  383. /**
  384. * @return <code>true</code> if forward diagonal is on
  385. */
  386. public boolean isForwardDiagonalOn() {
  387. return bordBlTrtLineOnOff.isSet(field_13_border_styles1);
  388. }
  389. /**
  390. * @return <code>true</code> if backward diagonal is on
  391. */
  392. public boolean isBackwardDiagonalOn() {
  393. return bordTlBrLineOnOff.isSet(field_13_border_styles1);
  394. }
  395. public String toString() {
  396. StringBuffer buffer = new StringBuffer();
  397. buffer.append(" [Border Formatting]\n");
  398. buffer.append(" .lftln = ").append(Integer.toHexString(getBorderLeft())).append("\n");
  399. buffer.append(" .rgtln = ").append(Integer.toHexString(getBorderRight())).append("\n");
  400. buffer.append(" .topln = ").append(Integer.toHexString(getBorderTop())).append("\n");
  401. buffer.append(" .btmln = ").append(Integer.toHexString(getBorderBottom())).append("\n");
  402. buffer.append(" .leftborder= ").append(Integer.toHexString(getLeftBorderColor())).append("\n");
  403. buffer.append(" .rghtborder= ").append(Integer.toHexString(getRightBorderColor())).append("\n");
  404. buffer.append(" .topborder= ").append(Integer.toHexString(getTopBorderColor())).append("\n");
  405. buffer.append(" .bottomborder= ").append(Integer.toHexString(getBottomBorderColor())).append("\n");
  406. buffer.append(" .fwdiag= ").append(isForwardDiagonalOn()).append("\n");
  407. buffer.append(" .bwdiag= ").append(isBackwardDiagonalOn()).append("\n");
  408. buffer.append(" [/Border Formatting]\n");
  409. return buffer.toString();
  410. }
  411. public Object clone() {
  412. BorderFormatting rec = new BorderFormatting();
  413. rec.field_13_border_styles1 = field_13_border_styles1;
  414. rec.field_14_border_styles2 = field_14_border_styles2;
  415. return rec;
  416. }
  417. public int serialize(int offset, byte [] data) {
  418. LittleEndian.putInt(data, offset+0, field_13_border_styles1);
  419. LittleEndian.putInt(data, offset+4, field_14_border_styles2);
  420. return 8;
  421. }
  422. public void serialize(LittleEndianOutput out) {
  423. out.writeInt(field_13_border_styles1);
  424. out.writeInt(field_14_border_styles2);
  425. }
  426. }