KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > fop > render > rtf > rtflib > rtfdoc > RtfListStyleText


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
18 /* $Id: RtfListStyleText.java 426576 2006-07-28 15:44:37Z jeremias $ */
19
20 package org.apache.fop.render.rtf.rtflib.rtfdoc;
21
22 /*
23  * This file is part of the RTF library of the FOP project, which was originally
24  * created by Bertrand Delacretaz <bdelacretaz@codeconsult.ch> and by other
25  * contributors to the jfor project (www.jfor.org), who agreed to donate jfor to
26  * the FOP project.
27  */

28
29 //Java
30
import java.io.IOException JavaDoc;
31
32 //FOP
33
import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfElement;
34
35 /**
36  * Class to handle text list style.
37  */

38 public class RtfListStyleText extends RtfListStyle {
39     private String JavaDoc text;
40     
41     /**
42      * Constructs a RtfListStyleText object.
43      * @param s Text to be displayed
44      */

45     public RtfListStyleText(String JavaDoc s) {
46         text = s;
47     }
48     
49     /**
50      * Gets called before a RtfListItem has to be written.
51      * @param item RtfListItem whose prefix has to be written
52      * @see org.apache.fop.render.rtf.rtflib.rtfdoc.RtfListStyle#writeListPrefix(RtfListItem)
53      * @throws IOException Thrown when an IO-problem occurs
54      */

55     public void writeListPrefix(RtfListItem item)
56     throws IOException JavaDoc {
57         // bulleted list
58
item.writeControlWord("pnlvlblt");
59         item.writeControlWord("ilvl0");
60         item.writeOneAttribute(RtfListTable.LIST_NUMBER, new Integer JavaDoc(item.getNumber()));
61         item.writeOneAttribute("pnindent",
62                 item.getParentList().attrib.getValue(RtfListTable.LIST_INDENT));
63         item.writeControlWord("pnf1");
64         item.writeGroupMark(true);
65         //item.writeControlWord("pndec");
66
item.writeOneAttribute(RtfListTable.LIST_FONT_TYPE, "2");
67         item.writeControlWord("pntxtb");
68         RtfStringConverter.getInstance().writeRtfString(item.writer, text);
69         item.writeGroupMark(false);
70     }
71     
72     /**
73      * Gets called before a paragraph, which is contained by a RtfListItem has to be written.
74      *
75      * @param element RtfElement in whose context is to be written
76      * @see org.apache.fop.render.rtf.rtflib.rtfdoc.RtfListStyle#writeParagraphPrefix(RtfElement)
77      * @throws IOException Thrown when an IO-problem occurs
78      */

79     public void writeParagraphPrefix(RtfElement element)
80     throws IOException JavaDoc {
81         element.writeGroupMark(true);
82         element.writeControlWord("pntext");
83         element.writeGroupMark(false);
84     }
85     
86     /**
87      * Gets called when the list table has to be written.
88      *
89      * @param element RtfElement in whose context is to be written
90      * @see org.apache.fop.render.rtf.rtflib.rtfdoc.RtfListStyle#writeLevelGroup(RtfElement)
91      * @throws IOException Thrown when an IO-problem occurs
92      */

93     public void writeLevelGroup(RtfElement element)
94     throws IOException JavaDoc {
95         element.attrib.set(RtfListTable.LIST_NUMBER_TYPE, 23);
96         element.writeGroupMark(true);
97         
98         String JavaDoc sCount;
99         if (text.length() < 10) {
100             sCount = "0" + String.valueOf(text.length());
101         } else {
102             sCount = String.valueOf(Integer.toHexString(text.length()));
103             if (sCount.length() == 1) {
104                 sCount = "0" + sCount;
105             }
106         }
107         element.writeOneAttributeNS(
108                 RtfListTable.LIST_TEXT_FORM, "\\'" + sCount
109                     + RtfStringConverter.getInstance().escape(text));
110         element.writeGroupMark(false);
111             
112         element.writeGroupMark(true);
113         element.writeOneAttributeNS(RtfListTable.LIST_NUM_POSITION, null);
114         element.writeGroupMark(false);
115             
116         element.attrib.set(RtfListTable.LIST_FONT_TYPE, 2);
117     }
118 }
119
Popular Tags