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.

HSSFPatternFormatting.java 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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.hssf.record.CFRuleBase;
  17. import org.apache.poi.hssf.record.cf.PatternFormatting;
  18. import org.apache.poi.hssf.util.HSSFColor;
  19. import org.apache.poi.ss.usermodel.Color;
  20. /**
  21. * High level representation for Conditional Formatting settings
  22. */
  23. public class HSSFPatternFormatting implements org.apache.poi.ss.usermodel.PatternFormatting {
  24. private final HSSFWorkbook workbook;
  25. private final CFRuleBase cfRuleRecord;
  26. private final PatternFormatting patternFormatting;
  27. protected HSSFPatternFormatting(CFRuleBase cfRuleRecord, HSSFWorkbook workbook) {
  28. this.workbook = workbook;
  29. this.cfRuleRecord = cfRuleRecord;
  30. this.patternFormatting = cfRuleRecord.getPatternFormatting();
  31. }
  32. protected PatternFormatting getPatternFormattingBlock()
  33. {
  34. return patternFormatting;
  35. }
  36. public HSSFColor getFillBackgroundColorColor() {
  37. return workbook.getCustomPalette().getColor(getFillBackgroundColor());
  38. }
  39. public HSSFColor getFillForegroundColorColor() {
  40. return workbook.getCustomPalette().getColor(getFillForegroundColor());
  41. }
  42. /**
  43. * @see org.apache.poi.hssf.record.cf.PatternFormatting#getFillBackgroundColor()
  44. */
  45. public short getFillBackgroundColor()
  46. {
  47. return (short)patternFormatting.getFillBackgroundColor();
  48. }
  49. /**
  50. * @see org.apache.poi.hssf.record.cf.PatternFormatting#getFillForegroundColor()
  51. */
  52. public short getFillForegroundColor()
  53. {
  54. return (short)patternFormatting.getFillForegroundColor();
  55. }
  56. /**
  57. * @see org.apache.poi.hssf.record.cf.PatternFormatting#getFillPattern()
  58. */
  59. public short getFillPattern()
  60. {
  61. return (short)patternFormatting.getFillPattern();
  62. }
  63. public void setFillBackgroundColor(Color bg) {
  64. HSSFColor hcolor = HSSFColor.toHSSFColor(bg);
  65. if (hcolor == null) {
  66. setFillBackgroundColor((short)0);
  67. } else {
  68. setFillBackgroundColor(hcolor.getIndex());
  69. }
  70. }
  71. public void setFillForegroundColor(Color fg) {
  72. HSSFColor hcolor = HSSFColor.toHSSFColor(fg);
  73. if (hcolor == null) {
  74. setFillForegroundColor((short)0);
  75. } else {
  76. setFillForegroundColor(hcolor.getIndex());
  77. }
  78. }
  79. /**
  80. * @param bg
  81. * @see org.apache.poi.hssf.record.cf.PatternFormatting#setFillBackgroundColor(int)
  82. */
  83. public void setFillBackgroundColor(short bg)
  84. {
  85. patternFormatting.setFillBackgroundColor(bg);
  86. if( bg != 0)
  87. {
  88. cfRuleRecord.setPatternBackgroundColorModified(true);
  89. }
  90. }
  91. /**
  92. * @param fg
  93. * @see org.apache.poi.hssf.record.cf.PatternFormatting#setFillForegroundColor(int)
  94. */
  95. public void setFillForegroundColor(short fg)
  96. {
  97. patternFormatting.setFillForegroundColor(fg);
  98. if( fg != 0)
  99. {
  100. cfRuleRecord.setPatternColorModified(true);
  101. }
  102. }
  103. /**
  104. * @param fp
  105. * @see org.apache.poi.hssf.record.cf.PatternFormatting#setFillPattern(int)
  106. */
  107. public void setFillPattern(short fp)
  108. {
  109. patternFormatting.setFillPattern(fp);
  110. if( fp != 0)
  111. {
  112. cfRuleRecord.setPatternStyleModified(true);
  113. }
  114. }
  115. }