Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

ColumnNumberPropertyMaker.java 4.8KB

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.fo.properties;
  19. import org.apache.commons.logging.Log;
  20. import org.apache.commons.logging.LogFactory;
  21. import org.apache.fop.fo.Constants;
  22. import org.apache.fop.fo.FObj;
  23. import org.apache.fop.fo.PropertyList;
  24. import org.apache.fop.fo.expr.PropertyException;
  25. import org.apache.fop.fo.flow.TableBody;
  26. import org.apache.fop.fo.flow.TableFObj;
  27. /**
  28. * PropertyMaker subclass for the column-number property
  29. *
  30. */
  31. public class ColumnNumberPropertyMaker extends NumberProperty.Maker {
  32. /**
  33. * Constructor
  34. * @param propId the id of the property for which the maker should
  35. * be created
  36. */
  37. public ColumnNumberPropertyMaker(int propId) {
  38. super(propId);
  39. }
  40. /**
  41. * {@inheritDoc}
  42. */
  43. public Property make(PropertyList propertyList)
  44. throws PropertyException {
  45. FObj fo = propertyList.getFObj();
  46. if (fo.getNameId() == Constants.FO_TABLE_CELL
  47. || fo.getNameId() == Constants.FO_TABLE_COLUMN) {
  48. if (fo.getNameId() == Constants.FO_TABLE_CELL
  49. && fo.getParent().getNameId() != Constants.FO_TABLE_ROW
  50. && (propertyList.get(Constants.PR_STARTS_ROW).getEnum()
  51. == Constants.EN_TRUE)) {
  52. TableBody parent = (TableBody) fo.getParent();
  53. if (!parent.previousCellEndedRow()) {
  54. parent.resetColumnIndex();
  55. }
  56. }
  57. }
  58. return NumberProperty.getInstance(
  59. ((TableFObj) fo.getParent()).getCurrentColumnIndex());
  60. }
  61. /**
  62. * Check the value of the column-number property.
  63. * Return the parent's column index (initial value) in case
  64. * of a negative or zero value
  65. *
  66. * {@inheritDoc}
  67. */
  68. public Property make(PropertyList propertyList, String value, FObj fo)
  69. throws PropertyException {
  70. Property p = super.make(propertyList, value, fo);
  71. TableFObj parent = (TableFObj) propertyList.getParentFObj();
  72. int columnIndex = p.getNumeric().getValue();
  73. if (columnIndex <= 0) {
  74. Log log = LogFactory.getLog(TableFObj.class);
  75. log.warn("Specified negative or zero value for "
  76. + "column-number on " + fo.getName() + ": "
  77. + columnIndex + " forced to "
  78. + parent.getCurrentColumnIndex());
  79. return NumberProperty.getInstance(parent.getCurrentColumnIndex());
  80. } else {
  81. double tmpIndex = p.getNumeric().getNumericValue();
  82. if (tmpIndex - columnIndex > 0.0) {
  83. columnIndex = (int) Math.round(tmpIndex);
  84. Log log = LogFactory.getLog(TableFObj.class);
  85. log.warn("Rounding specified column-number of "
  86. + tmpIndex + " to " + columnIndex);
  87. p = NumberProperty.getInstance(columnIndex);
  88. }
  89. }
  90. parent.setCurrentColumnIndex(columnIndex);
  91. int colSpan = propertyList.get(Constants.PR_NUMBER_COLUMNS_SPANNED)
  92. .getNumeric().getValue();
  93. int i = -1;
  94. while (++i < colSpan) {
  95. if (parent.isColumnNumberUsed(columnIndex + i)) {
  96. /* if column-number is already in use by another
  97. * cell/column => error!
  98. */
  99. StringBuffer errorMessage = new StringBuffer();
  100. errorMessage.append(fo.getName() + " overlaps in column ")
  101. .append(columnIndex + i);
  102. org.xml.sax.Locator loc = fo.getLocator();
  103. if (loc != null && loc.getLineNumber() != -1) {
  104. errorMessage.append(" (line #")
  105. .append(loc.getLineNumber()).append(", column #")
  106. .append(loc.getColumnNumber()).append(")");
  107. }
  108. throw new PropertyException(errorMessage.toString());
  109. }
  110. }
  111. return p;
  112. }
  113. }