001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: /* $Id: RtfList.java 426576 2006-07-28 15:44:37Z jeremias $ */
019:
020: package org.apache.fop.render.rtf.rtflib.rtfdoc;
021:
022: /*
023: * This file is part of the RTF library of the FOP project, which was originally
024: * created by Bertrand Delacretaz <bdelacretaz@codeconsult.ch> and by other
025: * contributors to the jfor project (www.jfor.org), who agreed to donate jfor to
026: * the FOP project.
027: */
028:
029: import java.io.Writer;
030: import java.io.IOException;
031: import java.util.Date;
032: import java.util.Random;
033:
034: /**
035: * Model of an RTF list, which can contain RTF list items
036: * @author Bertrand Delacretaz bdelacretaz@codeconsult.ch
037: * @author Christopher Scott, scottc@westinghouse.com
038: * @author Peter Herweg, pherweg@web.de
039: */
040: public class RtfList extends RtfContainer {
041: private RtfListItem item;
042: private RtfListTable listTable;
043: private final boolean hasTableParent;
044: private RtfListStyle defaultListStyle;
045: private Integer listTemplateId = null;
046: private Integer listId = null;
047: private static Random listIdGenerator = new Random(0);
048:
049: /** Create an RTF list as a child of given container with given attributes */
050: RtfList(RtfContainer parent, Writer w, RtfAttributes attr)
051: throws IOException {
052: super ((RtfContainer) parent, w, attr);
053:
054: //random number generator for ids
055: listId = new Integer(listIdGenerator.nextInt());
056: listTemplateId = new Integer(listIdGenerator.nextInt());
057:
058: //create a new list table entry for the list
059: listTable = getRtfFile().startListTable(attr);
060: listTable.addList(this );
061:
062: // find out if we are nested in a table
063: hasTableParent = this .getParentOfClass(RtfTable.class) != null;
064:
065: this .setRtfListStyle(new RtfListStyleBullet());
066: }
067:
068: /**
069: * Close current list item and start a new one
070: * @return new RtfListItem
071: * @throws IOException for I/O problems
072: */
073: public RtfListItem newListItem() throws IOException {
074: if (item != null) {
075: item.close();
076: }
077: item = new RtfListItem(this , writer);
078: return item;
079: }
080:
081: /**
082: * Returns the Id of the list.
083: * @return Id of the list
084: */
085: public Integer getListId() {
086: return listId;
087: }
088:
089: /**
090: * Returns the Id of the list template.
091: * @return Id of the list template
092: */
093: public Integer getListTemplateId() {
094: return listTemplateId;
095: }
096:
097: /**
098: * Change list style
099: * @param ls ListStyle to set
100: */
101: public void setRtfListStyle(RtfListStyle ls) {
102: defaultListStyle = ls;
103: }
104:
105: /**
106: * Get list style
107: * @return ListSytle of the List
108: */
109: public RtfListStyle getRtfListStyle() {
110: return defaultListStyle;
111: }
112:
113: /**
114: * Returns true, if the list has a parent table.
115: * @return true, if the list has a parent table
116: */
117: public boolean getHasTableParent() {
118: return hasTableParent;
119: }
120: }
|