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.

ConditionalFormattingThreshold.java 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*
  2. * ====================================================================
  3. * Licensed to the Apache Software Foundation (ASF) under one or more
  4. * contributor license agreements. See the NOTICE file distributed with
  5. * this work for additional information regarding copyright ownership.
  6. * The ASF licenses this file to You under the Apache License, Version 2.0
  7. * (the "License"); you may not use this file except in compliance with
  8. * the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. * ====================================================================
  18. */
  19. package org.apache.poi.ss.usermodel;
  20. /**
  21. * The Threshold / CFVO / Conditional Formatting Value Object.
  22. * <p>This defines how to calculate the ranges for a conditional
  23. * formatting rule, eg which values get a Green Traffic Light
  24. * icon and which Yellow or Red.</p>
  25. */
  26. public interface ConditionalFormattingThreshold {
  27. public enum RangeType {
  28. /** Number / Parameter */
  29. NUMBER(1, "num"),
  30. /** The minimum value from the range */
  31. MIN(2, "min"),
  32. /** The maximum value from the range */
  33. MAX(3, "max"),
  34. /** Percent of the way from the mi to the max value in the range */
  35. PERCENT(4, "percent"),
  36. /** The minimum value of the cell that is in X percentile of the range */
  37. PERCENTILE(5, "percentile"),
  38. UNALLOCATED(6, null),
  39. /** Formula result */
  40. FORMULA(7, "formula");
  41. /** Numeric ID of the type */
  42. public final int id;
  43. /** Name (system) of the type */
  44. public final String name;
  45. public String toString() {
  46. return id + " - " + name;
  47. }
  48. public static RangeType byId(int id) {
  49. return values()[id-1]; // 1-based IDs
  50. }
  51. public static RangeType byName(String name) {
  52. for (RangeType t : values()) {
  53. if (t.name.equals(name)) return t;
  54. }
  55. return null;
  56. }
  57. private RangeType(int id, String name) {
  58. this.id = id; this.name = name;
  59. }
  60. }
  61. /**
  62. * Get the Range Type used
  63. */
  64. RangeType getRangeType();
  65. /**
  66. * Changes the Range Type used
  67. *
  68. * <p>If you change the range type, you need to
  69. * ensure that the Formula and Value parameters
  70. * are compatible with it before saving</p>
  71. */
  72. void setRangeType(RangeType type);
  73. /**
  74. * Formula to use to calculate the threshold,
  75. * or <code>null</code> if no formula
  76. */
  77. String getFormula();
  78. /**
  79. * Sets the formula used to calculate the threshold,
  80. * or unsets it if <code>null</code> is given.
  81. */
  82. void setFormula(String formula);
  83. /**
  84. * Gets the value used for the threshold, or
  85. * <code>null</code> if there isn't one.
  86. */
  87. Double getValue();
  88. /**
  89. * Sets the value used for the threshold.
  90. * <p>If the type is {@link RangeType#PERCENT} or
  91. * {@link RangeType#PERCENTILE} it must be between 0 and 100.
  92. * <p>If the type is {@link RangeType#MIN} or {@link RangeType#MAX}
  93. * or {@link RangeType#FORMULA} it shouldn't be set.
  94. * <p>Use <code>null</code> to unset
  95. */
  96. void setValue(Double value);
  97. }