Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

WhitespaceManagementPenalty.java 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. /* $Id$ */
  18. package org.apache.fop.layoutmgr;
  19. import java.util.ArrayList;
  20. import java.util.List;
  21. import org.apache.fop.layoutmgr.MultiSwitchLayoutManager.WhitespaceManagementPosition;
  22. /**
  23. * A special penalty used to specify content having multiple variants. At most
  24. * only one variant will be inserted into the final document. If none of the
  25. * variants fit into the remaining space on the current page, the dynamic
  26. * content will be completely ignored.
  27. */
  28. public class WhitespaceManagementPenalty extends KnuthPenalty {
  29. public class Variant {
  30. public final List<ListElement> knuthList;
  31. public final int width;
  32. private final KnuthPenalty penalty;
  33. public Variant(List<ListElement> knuthList, int width) {
  34. this.knuthList = knuthList;
  35. this.width = width;
  36. this.penalty = new KnuthPenalty(width, 0, false, null, false);
  37. }
  38. public KnuthElement getPenalty() {
  39. return penalty;
  40. }
  41. public WhitespaceManagementPenalty getWhitespaceManagementPenalty() {
  42. return WhitespaceManagementPenalty.this;
  43. }
  44. }
  45. private final WhitespaceManagementPosition whitespaceManagementPosition;
  46. private final List<Variant> variantList;
  47. public WhitespaceManagementPenalty(WhitespaceManagementPosition pos) {
  48. super(0, 0, false, pos, false);
  49. this.whitespaceManagementPosition = pos;
  50. variantList = new ArrayList<Variant>();
  51. }
  52. public void addVariant(Variant variant) {
  53. variantList.add(variant);
  54. }
  55. public void setActiveVariant(Variant bestVariant) {
  56. whitespaceManagementPosition.setKnuthList(bestVariant.knuthList);
  57. }
  58. public boolean hasActiveVariant() {
  59. return whitespaceManagementPosition.getKnuthList() != null;
  60. }
  61. public List<Variant> getVariants() {
  62. return variantList;
  63. }
  64. @Override
  65. public String toString() {
  66. String str = super.toString();
  67. StringBuffer buffer = new StringBuffer(64);
  68. buffer.append(" number of variants = " + variantList.size());
  69. return str + buffer;
  70. }
  71. }