Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

PatternFormatting.java 6.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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.LittleEndianInput;
  19. import org.apache.poi.util.LittleEndianOutput;
  20. /**
  21. * Pattern Formatting Block of the Conditional Formatting Rule Record.
  22. */
  23. public final class PatternFormatting implements Cloneable {
  24. /** No background */
  25. public final static short NO_FILL = 0 ;
  26. /** Solidly filled */
  27. public final static short SOLID_FOREGROUND = 1 ;
  28. /** Small fine dots */
  29. public final static short FINE_DOTS = 2 ;
  30. /** Wide dots */
  31. public final static short ALT_BARS = 3 ;
  32. /** Sparse dots */
  33. public final static short SPARSE_DOTS = 4 ;
  34. /** Thick horizontal bands */
  35. public final static short THICK_HORZ_BANDS = 5 ;
  36. /** Thick vertical bands */
  37. public final static short THICK_VERT_BANDS = 6 ;
  38. /** Thick backward facing diagonals */
  39. public final static short THICK_BACKWARD_DIAG = 7 ;
  40. /** Thick forward facing diagonals */
  41. public final static short THICK_FORWARD_DIAG = 8 ;
  42. /** Large spots */
  43. public final static short BIG_SPOTS = 9 ;
  44. /** Brick-like layout */
  45. public final static short BRICKS = 10 ;
  46. /** Thin horizontal bands */
  47. public final static short THIN_HORZ_BANDS = 11 ;
  48. /** Thin vertical bands */
  49. public final static short THIN_VERT_BANDS = 12 ;
  50. /** Thin backward diagonal */
  51. public final static short THIN_BACKWARD_DIAG = 13 ;
  52. /** Thin forward diagonal */
  53. public final static short THIN_FORWARD_DIAG = 14 ;
  54. /** Squares */
  55. public final static short SQUARES = 15 ;
  56. /** Diamonds */
  57. public final static short DIAMONDS = 16 ;
  58. /** Less Dots */
  59. public final static short LESS_DOTS = 17 ;
  60. /** Least Dots */
  61. public final static short LEAST_DOTS = 18 ;
  62. // PATTERN FORMATING BLOCK
  63. // For Pattern Styles see constants at HSSFCellStyle (from NO_FILL to LEAST_DOTS)
  64. private int field_15_pattern_style;
  65. private static final BitField fillPatternStyle = BitFieldFactory.getInstance(0xFC00);
  66. private int field_16_pattern_color_indexes;
  67. private static final BitField patternColorIndex = BitFieldFactory.getInstance(0x007F);
  68. private static final BitField patternBackgroundColorIndex = BitFieldFactory.getInstance(0x3F80);
  69. public PatternFormatting() {
  70. field_15_pattern_style = 0;
  71. field_16_pattern_color_indexes = 0;
  72. }
  73. /** Creates new FontFormatting */
  74. public PatternFormatting(LittleEndianInput in) {
  75. field_15_pattern_style = in.readUShort();
  76. field_16_pattern_color_indexes = in.readUShort();
  77. }
  78. public int getDataLength() {
  79. return 4;
  80. }
  81. /**
  82. * setting fill pattern
  83. *
  84. * @see #NO_FILL
  85. * @see #SOLID_FOREGROUND
  86. * @see #FINE_DOTS
  87. * @see #ALT_BARS
  88. * @see #SPARSE_DOTS
  89. * @see #THICK_HORZ_BANDS
  90. * @see #THICK_VERT_BANDS
  91. * @see #THICK_BACKWARD_DIAG
  92. * @see #THICK_FORWARD_DIAG
  93. * @see #BIG_SPOTS
  94. * @see #BRICKS
  95. * @see #THIN_HORZ_BANDS
  96. * @see #THIN_VERT_BANDS
  97. * @see #THIN_BACKWARD_DIAG
  98. * @see #THIN_FORWARD_DIAG
  99. * @see #SQUARES
  100. * @see #DIAMONDS
  101. *
  102. * @param fp fill pattern
  103. */
  104. public void setFillPattern(int fp) {
  105. field_15_pattern_style = fillPatternStyle.setValue(field_15_pattern_style, fp);
  106. }
  107. /**
  108. * @return fill pattern
  109. */
  110. public int getFillPattern() {
  111. return fillPatternStyle.getValue(field_15_pattern_style);
  112. }
  113. /**
  114. * set the background fill color.
  115. */
  116. public void setFillBackgroundColor(int bg) {
  117. field_16_pattern_color_indexes = patternBackgroundColorIndex.setValue(field_16_pattern_color_indexes,bg);
  118. }
  119. /**
  120. * @see org.apache.poi.hssf.usermodel.HSSFPalette#getColor(short)
  121. * @return get the background fill color
  122. */
  123. public int getFillBackgroundColor() {
  124. return patternBackgroundColorIndex.getValue(field_16_pattern_color_indexes);
  125. }
  126. /**
  127. * set the foreground fill color
  128. */
  129. public void setFillForegroundColor(int fg) {
  130. field_16_pattern_color_indexes = patternColorIndex.setValue(field_16_pattern_color_indexes,fg);
  131. }
  132. /**
  133. * @see org.apache.poi.hssf.usermodel.HSSFPalette#getColor(short)
  134. * @return get the foreground fill color
  135. */
  136. public int getFillForegroundColor() {
  137. return patternColorIndex.getValue(field_16_pattern_color_indexes);
  138. }
  139. public String toString() {
  140. StringBuffer buffer = new StringBuffer();
  141. buffer.append(" [Pattern Formatting]\n");
  142. buffer.append(" .fillpattern= ").append(Integer.toHexString(getFillPattern())).append("\n");
  143. buffer.append(" .fgcoloridx= ").append(Integer.toHexString(getFillForegroundColor())).append("\n");
  144. buffer.append(" .bgcoloridx= ").append(Integer.toHexString(getFillBackgroundColor())).append("\n");
  145. buffer.append(" [/Pattern Formatting]\n");
  146. return buffer.toString();
  147. }
  148. public Object clone() {
  149. PatternFormatting rec = new PatternFormatting();
  150. rec.field_15_pattern_style = field_15_pattern_style;
  151. rec.field_16_pattern_color_indexes = field_16_pattern_color_indexes;
  152. return rec;
  153. }
  154. public void serialize(LittleEndianOutput out) {
  155. out.writeShort(field_15_pattern_style);
  156. out.writeShort(field_16_pattern_color_indexes);
  157. }
  158. }