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.

WindowProtectRecord.java 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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;
  16. import java.util.Map;
  17. import java.util.function.Supplier;
  18. import org.apache.poi.util.BitField;
  19. import org.apache.poi.util.BitFieldFactory;
  20. import org.apache.poi.util.GenericRecordUtil;
  21. import org.apache.poi.util.LittleEndianOutput;
  22. /**
  23. * Flags whether workbook windows are protected
  24. */
  25. public final class WindowProtectRecord extends StandardRecord {
  26. public static final short sid = 0x0019;
  27. private static final BitField settingsProtectedFlag = BitFieldFactory.getInstance(0x0001);
  28. private int _options;
  29. public WindowProtectRecord(int options) {
  30. _options = options;
  31. }
  32. public WindowProtectRecord(WindowProtectRecord other) {
  33. super(other);
  34. _options = other._options;
  35. }
  36. public WindowProtectRecord(RecordInputStream in) {
  37. this(in.readUShort());
  38. }
  39. public WindowProtectRecord(boolean protect) {
  40. this(0);
  41. setProtect(protect);
  42. }
  43. /**
  44. * set whether this window should be protected or not
  45. * @param protect or not
  46. */
  47. public void setProtect(boolean protect) {
  48. _options = settingsProtectedFlag.setBoolean(_options, protect);
  49. }
  50. /**
  51. * is this window protected or not
  52. *
  53. * @return protected or not
  54. */
  55. public boolean getProtect() {
  56. return settingsProtectedFlag.isSet(_options);
  57. }
  58. public void serialize(LittleEndianOutput out) {
  59. out.writeShort(_options);
  60. }
  61. protected int getDataSize() {
  62. return 2;
  63. }
  64. public short getSid()
  65. {
  66. return sid;
  67. }
  68. @Override
  69. public WindowProtectRecord copy() {
  70. return new WindowProtectRecord(this);
  71. }
  72. @Override
  73. public HSSFRecordTypes getGenericRecordType() {
  74. return HSSFRecordTypes.WINDOW_PROTECT;
  75. }
  76. @Override
  77. public Map<String, Supplier<?>> getGenericProperties() {
  78. return GenericRecordUtil.getGenericProperties(
  79. "options", () -> _options,
  80. "protect", this::getProtect
  81. );
  82. }
  83. }