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 35 36 public class RtfSection 37 extends RtfContainer 38 implements 39 IRtfParagraphContainer, 40 IRtfTableContainer, 41 IRtfListContainer, 42 IRtfExternalGraphicContainer, 43 IRtfBeforeContainer, 44 IRtfParagraphKeepTogetherContainer, 45 IRtfAfterContainer, 46 IRtfJforCmdContainer, 47 IRtfTextrunContainer { 48 private RtfParagraph paragraph; 49 private RtfTable table; 50 private RtfList list; 51 private RtfExternalGraphic externalGraphic; 52 private RtfBefore before; 53 private RtfAfter after; 54 private RtfJforCmd jforCmd; 55 56 57 RtfSection(RtfDocumentArea parent, Writer w) throws IOException { 58 super(parent, w); 59 } 60 61 66 public RtfExternalGraphic newImage() throws IOException { 67 closeAll(); 68 externalGraphic = new RtfExternalGraphic(this, writer); 69 return externalGraphic; 70 } 71 72 78 public RtfParagraph newParagraph(RtfAttributes attrs) throws IOException { 79 closeAll(); 80 paragraph = new RtfParagraph(this, writer, attrs); 81 return paragraph; 82 } 83 84 89 public RtfParagraph newParagraph() throws IOException { 90 return newParagraph(null); 91 } 92 93 98 public RtfParagraphKeepTogether newParagraphKeepTogether() throws IOException { 99 return new RtfParagraphKeepTogether(this, writer); 100 } 101 102 109 public RtfTable newTable(ITableColumnsInfo tc) throws IOException { 110 closeAll(); 111 table = new RtfTable(this, writer, tc); 112 return table; 113 } 114 115 123 public RtfTable newTable(RtfAttributes attrs, ITableColumnsInfo tc) throws IOException { 124 closeAll(); 125 table = new RtfTable(this, writer, attrs, tc); 126 return table; 127 } 128 129 135 public RtfList newList(RtfAttributes attrs) throws IOException { 136 closeAll(); 137 list = new RtfList(this, writer, attrs); 138 return list; 139 } 140 141 147 public RtfBefore newBefore(RtfAttributes attrs) throws IOException { 148 closeAll(); 149 before = new RtfBefore(this, writer, attrs); 150 return before; 151 } 152 153 159 public RtfAfter newAfter(RtfAttributes attrs) throws IOException { 160 closeAll(); 161 after = new RtfAfter(this, writer, attrs); 162 return after; 163 } 164 165 171 public RtfJforCmd newJforCmd(RtfAttributes attrs) throws IOException { 172 jforCmd = new RtfJforCmd(this, writer, attrs); 173 return jforCmd; 174 } 175 176 177 178 182 protected void writeRtfPrefix() throws IOException { 183 writeAttributes(attrib, RtfPage.PAGE_ATTR); 184 newLine(); 185 writeControlWord("sectd"); 186 } 187 188 192 protected void writeRtfSuffix() throws IOException { 193 writeControlWord("sect"); 194 } 195 196 private void closeCurrentTable() throws IOException { 197 if (table != null) { 198 table.close(); 199 } 200 } 201 202 private void closeCurrentParagraph() throws IOException { 203 if (paragraph != null) { 204 paragraph.close(); 205 } 206 } 207 208 private void closeCurrentList() throws IOException { 209 if (list != null) { 210 list.close(); 211 } 212 } 213 214 private void closeCurrentExternalGraphic() throws IOException { 215 if (externalGraphic != null) { 216 externalGraphic.close(); 217 } 218 } 219 220 private void closeCurrentBefore() throws IOException { 221 if (before != null) { 222 before.close(); 223 } 224 } 225 226 private void closeAll() 227 throws IOException { 228 closeCurrentTable(); 229 closeCurrentParagraph(); 230 closeCurrentList(); 231 closeCurrentExternalGraphic(); 232 closeCurrentBefore(); 233 } 234 235 240 public RtfTextrun getTextrun() 241 throws IOException { 242 return RtfTextrun.getTextrun(this, writer, null); 243 } 244 } 245 | Popular Tags |