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.

CellPart.java 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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.table;
  19. import org.apache.fop.fo.flow.table.PrimaryGridUnit;
  20. /**
  21. * Represents a non-divisible part of a grid unit. Used by the table stepper.
  22. */
  23. class CellPart {
  24. /** Primary grid unit */
  25. protected PrimaryGridUnit pgu;
  26. /** Index of the starting element of this part */
  27. protected int start;
  28. /** Index of the ending element of this part */
  29. protected int end;
  30. private int condBeforeContentLength;
  31. private int length;
  32. private int condAfterContentLength;
  33. private int bpBeforeNormal;
  34. private int bpBeforeFirst;
  35. private int bpAfterNormal;
  36. private int bpAfterLast;
  37. private boolean isLast;
  38. /**
  39. * Creates a new CellPart.
  40. *
  41. * @param pgu Primary grid unit
  42. * @param start starting element
  43. * @param end ending element
  44. * @param last true if this cell part is the last one for the cell
  45. * @param condBeforeContentLength length of the additional content that will have to
  46. * be displayed if this part will be the first one on the page
  47. * @param length length of the content represented by this cell part
  48. * @param condAfterContentLength length of the additional content that will have to be
  49. * displayed if this part will be the last one on the page
  50. * @param bpBeforeNormal width of border- and padding-before in the normal case
  51. * @param bpBeforeFirst width of (possibly optional) border- and padding-before if
  52. * this part will be the first one on the page
  53. * @param bpAfterNormal width of border- and padding-after in the normal case
  54. * @param bpAfterLast width of (possibly optional) border- and padding-after if this
  55. * part will be the last one on the page
  56. */
  57. protected CellPart(PrimaryGridUnit pgu, int start, int end, boolean last,
  58. int condBeforeContentLength, int length, int condAfterContentLength,
  59. int bpBeforeNormal, int bpBeforeFirst,
  60. int bpAfterNormal, int bpAfterLast) {
  61. this.pgu = pgu;
  62. this.start = start;
  63. this.end = end;
  64. this.isLast = last;
  65. this.condBeforeContentLength = condBeforeContentLength;
  66. this.length = length;
  67. this.condAfterContentLength = condAfterContentLength;
  68. this.bpBeforeNormal = bpBeforeNormal;
  69. this.bpBeforeFirst = bpBeforeFirst;
  70. this.bpAfterNormal = bpAfterNormal;
  71. this.bpAfterLast = bpAfterLast;
  72. }
  73. /** @return true if this part is the first part of a cell */
  74. public boolean isFirstPart() {
  75. return (start == 0);
  76. }
  77. /** @return true if this part is the last part of a cell */
  78. boolean isLastPart() {
  79. return isLast;
  80. }
  81. int getBorderPaddingBefore(boolean firstOnPage) {
  82. if (firstOnPage) {
  83. return bpBeforeFirst;
  84. } else {
  85. return bpBeforeNormal;
  86. }
  87. }
  88. int getBorderPaddingAfter(boolean lastOnPage) {
  89. if (lastOnPage) {
  90. return bpAfterLast;
  91. } else {
  92. return bpAfterNormal;
  93. }
  94. }
  95. int getConditionalBeforeContentLength() {
  96. return condBeforeContentLength;
  97. }
  98. int getLength() {
  99. return length;
  100. }
  101. int getConditionalAfterContentLength() {
  102. return condAfterContentLength;
  103. }
  104. /** {@inheritDoc} */
  105. public String toString() {
  106. StringBuffer sb = new StringBuffer("Part: ");
  107. sb.append(start).append("-").append(end);
  108. sb.append(" [").append(isFirstPart() ? "F" : "-").append(isLastPart() ? "L" : "-");
  109. sb.append("] ").append(pgu);
  110. return sb.toString();
  111. }
  112. }