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.

HSLFPlaceholderDetails.java 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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.hslf.usermodel;
  16. import org.apache.poi.hslf.model.HeadersFooters;
  17. import org.apache.poi.sl.usermodel.Placeholder;
  18. import org.apache.poi.sl.usermodel.PlaceholderDetails;
  19. /**
  20. * Extended placeholder details for HSLF sheets - mainly for headers and footers
  21. *
  22. * @since POI 4.0.0
  23. */
  24. public class HSLFPlaceholderDetails implements PlaceholderDetails {
  25. private final HSLFSheet sheet;
  26. private final Placeholder placeholder;
  27. HSLFPlaceholderDetails(final HSLFSheet sheet, final Placeholder placeholder) {
  28. this.sheet = sheet;
  29. this.placeholder = placeholder;
  30. }
  31. public boolean isVisible() {
  32. final Placeholder ph = getPlaceholder();
  33. if (ph == null) {
  34. return false;
  35. }
  36. final HeadersFooters headersFooters = sheet.getHeadersFooters();
  37. switch (ph) {
  38. case HEADER:
  39. return headersFooters.isHeaderVisible();
  40. case FOOTER:
  41. return headersFooters.isFooterVisible();
  42. case DATETIME:
  43. return headersFooters.isDateTimeVisible();
  44. case TITLE:
  45. return headersFooters.isHeaderVisible();
  46. case SLIDE_NUMBER:
  47. return headersFooters.isSlideNumberVisible();
  48. default:
  49. return false;
  50. }
  51. }
  52. public void setVisible(final boolean isVisible) {
  53. final Placeholder ph = getPlaceholder();
  54. if (ph == null) {
  55. return;
  56. }
  57. final HeadersFooters headersFooters = sheet.getHeadersFooters();
  58. switch (ph) {
  59. case TITLE:
  60. case HEADER:
  61. headersFooters.setHeaderVisible(isVisible);
  62. break;
  63. case FOOTER:
  64. headersFooters.setFooterVisible(isVisible);
  65. break;
  66. case DATETIME:
  67. headersFooters.setDateTimeVisible(isVisible);
  68. break;
  69. case SLIDE_NUMBER:
  70. headersFooters.setSlideNumberVisible(isVisible);
  71. break;
  72. }
  73. }
  74. @Override
  75. public Placeholder getPlaceholder() {
  76. return placeholder;
  77. }
  78. @Override
  79. public void setPlaceholder(Placeholder placeholder) {
  80. throw new UnsupportedOperationException("Only sub class(es) of HSLFPlaceholderDetails allow setting the placeholder");
  81. }
  82. @Override
  83. public PlaceholderSize getSize() {
  84. return PlaceholderSize.full;
  85. }
  86. @Override
  87. public void setSize(PlaceholderSize size) {
  88. throw new UnsupportedOperationException("Only sub class(es) of HSLFPlaceholderDetails allow setting the size");
  89. }
  90. @Override
  91. public String getText() {
  92. final Placeholder ph = getPlaceholder();
  93. if (ph == null) {
  94. return null;
  95. }
  96. final HeadersFooters headersFooters = sheet.getHeadersFooters();
  97. switch (ph) {
  98. case TITLE:
  99. case HEADER:
  100. return headersFooters.getHeaderText();
  101. case FOOTER:
  102. return headersFooters.getFooterText();
  103. case DATETIME:
  104. return headersFooters.getDateTimeText();
  105. case SLIDE_NUMBER:
  106. default:
  107. return null;
  108. }
  109. }
  110. @Override
  111. public void setText(final String text) {
  112. final Placeholder ph = getPlaceholder();
  113. if (ph == null) {
  114. return;
  115. }
  116. final HeadersFooters headersFooters = sheet.getHeadersFooters();
  117. switch (ph) {
  118. case TITLE:
  119. case HEADER:
  120. headersFooters.setHeaderText(text);
  121. break;
  122. case FOOTER:
  123. headersFooters.setFootersText(text);
  124. break;
  125. case DATETIME:
  126. headersFooters.setDateTimeText(text);
  127. break;
  128. case SLIDE_NUMBER:
  129. default:
  130. break;
  131. }
  132. }
  133. }