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.

RtfList.java 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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.render.rtf.rtflib.rtfdoc;
  19. /*
  20. * This file is part of the RTF library of the FOP project, which was originally
  21. * created by Bertrand Delacretaz bdelacretaz@codeconsult.ch and by other
  22. * contributors to the jfor project (www.jfor.org), who agreed to donate jfor to
  23. * the FOP project.
  24. */
  25. import java.io.IOException;
  26. import java.io.Writer;
  27. import java.util.Random;
  28. /**
  29. * <p>Model of an RTF list, which can contain RTF list items.</p>
  30. *
  31. * <p>This work was authored by Bertrand Delacretaz (bdelacretaz@codeconsult.ch),
  32. * Christopher Scott (scottc@westinghouse.com), and
  33. * Peter Herweg (pherweg@web.de).</p>
  34. */
  35. public class RtfList extends RtfContainer {
  36. private RtfListItem item;
  37. private RtfListTable listTable;
  38. private final boolean hasTableParent;
  39. private RtfListStyle defaultListStyle;
  40. private Integer listTemplateId;
  41. private Integer listId;
  42. private static Random listIdGenerator = new Random(0);
  43. /** Create an RTF list as a child of given container with given attributes */
  44. RtfList(RtfContainer parent, Writer w, RtfAttributes attr) throws IOException {
  45. super(parent, w, attr);
  46. //random number generator for ids
  47. listId = listIdGenerator.nextInt();
  48. listTemplateId = listIdGenerator.nextInt();
  49. //create a new list table entry for the list
  50. listTable = getRtfFile().startListTable(attr);
  51. listTable.addList(this);
  52. // find out if we are nested in a table
  53. hasTableParent = this.getParentOfClass(RtfTable.class) != null;
  54. this.setRtfListStyle(new RtfListStyleBullet());
  55. }
  56. /**
  57. * Close current list item and start a new one
  58. * @return new RtfListItem
  59. * @throws IOException for I/O problems
  60. */
  61. public RtfListItem newListItem() throws IOException {
  62. if (item != null) {
  63. item.close();
  64. }
  65. item = new RtfListItem(this, writer);
  66. return item;
  67. }
  68. /**
  69. * Returns the Id of the list.
  70. * @return Id of the list
  71. */
  72. public Integer getListId() {
  73. return listId;
  74. }
  75. /**
  76. * Returns the Id of the list template.
  77. * @return Id of the list template
  78. */
  79. public Integer getListTemplateId() {
  80. return listTemplateId;
  81. }
  82. /**
  83. * Change list style
  84. * @param ls ListStyle to set
  85. */
  86. public void setRtfListStyle(RtfListStyle ls) {
  87. defaultListStyle = ls;
  88. }
  89. /**
  90. * Get list style
  91. * @return ListSytle of the List
  92. */
  93. public RtfListStyle getRtfListStyle() {
  94. return defaultListStyle;
  95. }
  96. /**
  97. * Returns true, if the list has a parent table.
  98. * @return true, if the list has a parent table
  99. */
  100. public boolean getHasTableParent() {
  101. return hasTableParent;
  102. }
  103. }