1 17 18 19 20 package org.apache.fop.render.rtf.rtflib.rtfdoc; 21 22 28 29 import java.io.Writer ; 30 import java.io.IOException ; 31 32 import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfTextrun; 33 34 38 public class RtfListItem extends RtfContainer 39 implements IRtfTextrunContainer, 40 IRtfListContainer, 41 IRtfParagraphContainer { 42 43 private RtfList parentList; 44 private RtfParagraph paragraph; 45 private RtfListStyle listStyle; 46 private int number = 0; 47 48 51 private class RtfListItemParagraph extends RtfParagraph { 52 53 RtfListItemParagraph(RtfListItem rli, RtfAttributes attrs) 54 throws IOException { 55 super(rli, rli.writer, attrs); 56 } 57 58 protected void writeRtfPrefix() throws IOException { 59 super.writeRtfPrefix(); 60 getRtfListStyle().writeParagraphPrefix(this); 61 } 62 } 63 64 67 public class RtfListItemLabel extends RtfTextrun implements IRtfTextrunContainer { 68 69 private RtfListItem rtfListItem; 70 71 76 public RtfListItemLabel(RtfListItem item) throws IOException { 77 super(null, item.writer, null); 78 79 rtfListItem = item; 80 } 81 82 88 public RtfTextrun getTextrun() throws IOException { 89 return this; 90 } 91 92 97 public void addString(String s) throws IOException { 98 99 final String label = s.trim(); 100 if (label.length() > 0 && Character.isDigit(label.charAt(0))) { 101 rtfListItem.setRtfListStyle(new RtfListStyleNumber()); 102 } else { 103 rtfListItem.setRtfListStyle(new RtfListStyleText(label)); 104 } 105 } 106 } 107 108 109 RtfListItem(RtfList parent, Writer w) throws IOException { 110 super((RtfContainer)parent, w); 111 parentList = parent; 112 } 113 114 120 public RtfParagraph newParagraph(RtfAttributes attrs) throws IOException { 121 if (paragraph != null) { 122 paragraph.close(); 123 } 124 paragraph = new RtfListItemParagraph(this, attrs); 125 return paragraph; 126 } 127 128 133 public RtfParagraph newParagraph() throws IOException { 134 return newParagraph(null); 135 } 136 137 138 RtfListItem(RtfList parent, Writer w, RtfAttributes attr) throws IOException { 139 super((RtfContainer)parent, w, attr); 140 parentList = parent; 141 } 142 143 144 149 public RtfTextrun getTextrun() throws IOException { 150 RtfTextrun textrun = RtfTextrun.getTextrun(this, writer, null); 151 textrun.setRtfListItem(this); 152 return textrun; 153 } 154 155 161 public RtfList newList(RtfAttributes attrs) throws IOException { 162 RtfList list = new RtfList(this, writer, attrs); 163 return list; 164 } 165 166 170 protected void writeRtfPrefix() throws IOException { 171 172 if (!parentList.getHasTableParent()) { 174 writeControlWord("pard"); 175 } 176 177 writeOneAttribute(RtfText.LEFT_INDENT_FIRST, 178 "360"); 180 writeOneAttribute(RtfText.LEFT_INDENT_BODY, 181 attrib.getValue(RtfText.LEFT_INDENT_BODY)); 182 183 writeGroupMark(true); 185 186 writeStarControlWord("pn"); 187 getRtfListStyle().writeListPrefix(this); 190 191 writeGroupMark(false); 192 writeOneAttribute(RtfListTable.LIST_NUMBER, new Integer (number)); 193 } 194 195 199 protected void writeRtfSuffix() throws IOException { 200 super.writeRtfSuffix(); 201 202 206 if (!parentList.getHasTableParent()) { 207 writeControlWord("pard"); 208 } 209 210 } 211 212 216 public void setRtfListStyle(RtfListStyle ls) { 217 listStyle = ls; 218 219 listStyle.setRtfListItem(this); 220 number = getRtfFile().getListTable().addRtfListStyle(ls); 221 } 222 223 227 public RtfListStyle getRtfListStyle() { 228 if (listStyle == null) { 229 return parentList.getRtfListStyle(); 230 } else { 231 return listStyle; 232 } 233 } 234 235 239 public RtfList getParentList() { 240 return parentList; 241 } 242 243 247 public int getNumber() { 248 return number; 249 } 250 } 251 | Popular Tags |