1 50 51 package com.lowagie.text.rtf.list; 52 53 import java.io.ByteArrayOutputStream ; 54 import java.io.IOException ; 55 import java.io.OutputStream ; 56 57 import com.lowagie.text.ListItem; 58 import com.lowagie.text.rtf.RtfBasicElement; 59 import com.lowagie.text.rtf.document.RtfDocument; 60 import com.lowagie.text.rtf.style.RtfParagraphStyle; 61 import com.lowagie.text.rtf.text.RtfChunk; 62 import com.lowagie.text.rtf.text.RtfParagraph; 63 64 65 72 public class RtfListItem extends RtfParagraph { 73 74 77 private RtfList parentList = null; 78 81 private boolean containsInnerList = false; 82 83 89 public RtfListItem(RtfDocument doc, ListItem listItem) { 90 super(doc, listItem); 91 } 92 93 99 public byte[] write() 100 { 101 ByteArrayOutputStream result = new ByteArrayOutputStream (); 102 try { 103 writeContent(result); 104 } catch(IOException ioe) { 105 ioe.printStackTrace(); 106 } 107 return result.toByteArray(); 108 } 109 112 public void writeContent(final OutputStream result) throws IOException 113 { 114 if(this.paragraphStyle.getSpacingBefore() > 0) { 115 result.write(RtfParagraphStyle.SPACING_BEFORE); 116 result.write(intToByteArray(paragraphStyle.getSpacingBefore())); 117 } 118 if(this.paragraphStyle.getSpacingAfter() > 0) { 119 result.write(RtfParagraphStyle.SPACING_AFTER); 120 result.write(intToByteArray(this.paragraphStyle.getSpacingAfter())); 121 } 122 for(int i = 0; i < chunks.size(); i++) { 123 RtfBasicElement rtfElement = (RtfBasicElement) chunks.get(i); 124 if(rtfElement instanceof RtfChunk) { 125 ((RtfChunk) rtfElement).setSoftLineBreaks(true); 126 } else if(rtfElement instanceof RtfList) { 127 result.write(RtfParagraph.PARAGRAPH); 128 this.containsInnerList = true; 129 } 130 rtfElement.writeContent(result); 132 if(rtfElement instanceof RtfList) { 133 result.write(this.parentList.writeListBeginning()); 134 result.write("\\tab".getBytes()); 135 } 136 } 137 } 138 139 146 public byte[] writeDefinition() { 147 for(int i = 0; i < chunks.size(); i++) { 148 RtfBasicElement rtfElement = (RtfBasicElement) chunks.get(i); 149 if(rtfElement instanceof RtfList) { 150 return ((RtfList) rtfElement).writeDefinition(); 151 } 152 } 153 return new byte[0]; 154 } 155 165 public boolean writeDefinition(OutputStream out) throws IOException 166 { 167 for(int i = 0; i < chunks.size(); i++) { 168 RtfBasicElement rtfElement = (RtfBasicElement)chunks.get(i); 169 if(rtfElement instanceof RtfList) { 170 RtfList rl = (RtfList)rtfElement; 171 rl.writeDefinition(out); 172 return(true); 173 } 174 } 175 return(false); 176 } 177 178 185 public void inheritListSettings(int listNumber, int listLevel) { 186 for(int i = 0; i < chunks.size(); i++) { 187 RtfBasicElement rtfElement = (RtfBasicElement) chunks.get(i); 188 if(rtfElement instanceof RtfList) { 189 ((RtfList) rtfElement).setListNumber(listNumber); 190 ((RtfList) rtfElement).setListLevel(listLevel); 191 ((RtfList) rtfElement).setParent(this.parentList); 192 } 193 } 194 } 195 196 200 protected void correctIndentation() { 201 for(int i = 0; i < chunks.size(); i++) { 202 RtfBasicElement rtfElement = (RtfBasicElement) chunks.get(i); 203 if(rtfElement instanceof RtfList) { 204 ((RtfList) rtfElement).correctIndentation(); 205 } 206 } 207 } 208 209 214 public void setParent(RtfList parentList) { 215 this.parentList = parentList; 216 } 217 218 223 public boolean isContainsInnerList() { 224 return this.containsInnerList; 225 } 226 } 227 | Popular Tags |