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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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 org.apache.poi.util.BitField;
  17. import org.apache.poi.util.BitFieldFactory;
  18. import org.apache.poi.util.HexDump;
  19. import org.apache.poi.util.LittleEndianOutput;
  20. /**
  21. * Title: Window Protect Record (0x0019) <p/>
  22. * Description: flags whether workbook windows are protected<p/>
  23. * REFERENCE: PG 424 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)<p/>
  24. * @author Andrew C. Oliver (acoliver at apache dot org)
  25. */
  26. public final class WindowProtectRecord extends StandardRecord {
  27. public final static short sid = 0x0019;
  28. private static final BitField settingsProtectedFlag = BitFieldFactory.getInstance(0x0001);
  29. private int _options;
  30. public WindowProtectRecord(int options) {
  31. _options = options;
  32. }
  33. public WindowProtectRecord(RecordInputStream in) {
  34. this(in.readUShort());
  35. }
  36. public WindowProtectRecord(boolean protect) {
  37. this(0);
  38. setProtect(protect);
  39. }
  40. /**
  41. * set whether this window should be protected or not
  42. * @param protect or not
  43. */
  44. public void setProtect(boolean protect) {
  45. _options = settingsProtectedFlag.setBoolean(_options, protect);
  46. }
  47. /**
  48. * is this window protected or not
  49. *
  50. * @return protected or not
  51. */
  52. public boolean getProtect() {
  53. return settingsProtectedFlag.isSet(_options);
  54. }
  55. public String toString() {
  56. StringBuffer buffer = new StringBuffer();
  57. buffer.append("[WINDOWPROTECT]\n");
  58. buffer.append(" .options = ").append(HexDump.shortToHex(_options)).append("\n");
  59. buffer.append("[/WINDOWPROTECT]\n");
  60. return buffer.toString();
  61. }
  62. public void serialize(LittleEndianOutput out) {
  63. out.writeShort(_options);
  64. }
  65. protected int getDataSize() {
  66. return 2;
  67. }
  68. public short getSid()
  69. {
  70. return sid;
  71. }
  72. @Override
  73. public Object clone() {
  74. return new WindowProtectRecord(_options);
  75. }
  76. }