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.

SHD80AbstractType.java 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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.hwpf.model.types;
  16. import java.util.Objects;
  17. import org.apache.poi.util.BitField;
  18. import org.apache.poi.util.Internal;
  19. import org.apache.poi.util.LittleEndian;
  20. /**
  21. * The Shd80 structure specifies the colors and pattern that are used for background shading.
  22. * As an exception to the constraints that are specified by Ico and Ipat,
  23. * a Shd80 can be set to Shd80Nil and specifies that no shading is applied.
  24. */
  25. @SuppressWarnings("unused")
  26. @Internal
  27. public abstract class SHD80AbstractType {
  28. private static final BitField icoFore = new BitField(0x001F);
  29. private static final BitField icoBack = new BitField(0x03E0);
  30. private static final BitField ipat = new BitField(0xFC00);
  31. protected short field_1_value;
  32. protected SHD80AbstractType() { }
  33. protected SHD80AbstractType(SHD80AbstractType other) {
  34. field_1_value = other.field_1_value;
  35. }
  36. protected void fillFields( byte[] data, int offset )
  37. {
  38. field_1_value = LittleEndian.getShort( data, 0x0 + offset );
  39. }
  40. public void serialize( byte[] data, int offset )
  41. {
  42. LittleEndian.putShort( data, 0x0 + offset, field_1_value );
  43. }
  44. public byte[] serialize()
  45. {
  46. final byte[] result = new byte[ getSize() ];
  47. serialize( result, 0 );
  48. return result;
  49. }
  50. /**
  51. * Size of record
  52. */
  53. public static int getSize()
  54. {
  55. return 0 + 2;
  56. }
  57. @Override
  58. public boolean equals( Object obj )
  59. {
  60. if ( this == obj )
  61. return true;
  62. if ( obj == null )
  63. return false;
  64. if ( getClass() != obj.getClass() )
  65. return false;
  66. SHD80AbstractType other = (SHD80AbstractType) obj;
  67. if ( field_1_value != other.field_1_value )
  68. return false;
  69. return true;
  70. }
  71. @Override
  72. public int hashCode() {
  73. return Objects.hash(field_1_value);
  74. }
  75. public String toString()
  76. {
  77. StringBuilder builder = new StringBuilder();
  78. builder.append("[SHD80]\n");
  79. builder.append(" .value = ");
  80. builder.append(" (").append(getValue()).append(" )\n");
  81. builder.append(" .icoFore = ").append(getIcoFore()).append('\n');
  82. builder.append(" .icoBack = ").append(getIcoBack()).append('\n');
  83. builder.append(" .ipat = ").append(getIpat()).append('\n');
  84. builder.append("[/SHD80]\n");
  85. return builder.toString();
  86. }
  87. /**
  88. * Get the value field for the SHD80 record.
  89. */
  90. @Internal
  91. public short getValue()
  92. {
  93. return field_1_value;
  94. }
  95. /**
  96. * Set the value field for the SHD80 record.
  97. */
  98. @Internal
  99. public void setValue( short field_1_value )
  100. {
  101. this.field_1_value = field_1_value;
  102. }
  103. /**
  104. * Sets the icoFore field value.
  105. * Foreground color
  106. */
  107. @Internal
  108. public void setIcoFore( byte value )
  109. {
  110. field_1_value = (short)icoFore.setValue(field_1_value, value);
  111. }
  112. /**
  113. * Foreground color
  114. * @return the icoFore field value.
  115. */
  116. @Internal
  117. public byte getIcoFore()
  118. {
  119. return ( byte )icoFore.getValue(field_1_value);
  120. }
  121. /**
  122. * Sets the icoBack field value.
  123. * Background color
  124. */
  125. @Internal
  126. public void setIcoBack( byte value )
  127. {
  128. field_1_value = (short)icoBack.setValue(field_1_value, value);
  129. }
  130. /**
  131. * Background color
  132. * @return the icoBack field value.
  133. */
  134. @Internal
  135. public byte getIcoBack()
  136. {
  137. return ( byte )icoBack.getValue(field_1_value);
  138. }
  139. /**
  140. * Sets the ipat field value.
  141. * Shading pattern
  142. */
  143. @Internal
  144. public void setIpat( byte value )
  145. {
  146. field_1_value = (short)ipat.setValue(field_1_value, value);
  147. }
  148. /**
  149. * Shading pattern
  150. * @return the ipat field value.
  151. */
  152. @Internal
  153. public byte getIpat()
  154. {
  155. return ( byte )ipat.getValue(field_1_value);
  156. }
  157. }