1 51 52 package com.lowagie.text.rtf; 53 54 import java.io.IOException ; 55 import java.io.OutputStream ; 56 57 import com.lowagie.text.Chunk; 58 import com.lowagie.text.DocumentException; 59 import com.lowagie.text.ExceptionConverter; 60 import com.lowagie.text.Font; 61 62 76 public class RtfTOC extends Chunk implements RtfField { 77 78 79 private String defaultText = "Klicken Sie mit der rechten Maustaste auf diesen Text, um das Inhaltsverzeichnis zu aktualisieren!"; 80 81 private boolean addTOCAsTOCEntry = false; 82 83 private Font entryFont = null; 84 private String entryName = null; 85 86 87 91 public RtfTOC( String tocName, Font tocFont ) { 92 super( tocName, tocFont ); 93 } 94 95 98 public void write( RtfWriter writer, OutputStream out ) throws IOException { 99 100 writer.writeInitialFontSignature( out, this ); 101 out.write( RtfWriter.filterSpecialChar( getContent(), true ).getBytes() ); 102 writer.writeFinishingFontSignature( out, this ); 103 104 if (addTOCAsTOCEntry) { 105 RtfTOCEntry entry = new RtfTOCEntry( entryName, entryFont ); 106 entry.hideText(); 107 try { 108 writer.add( entry ); 109 } catch ( DocumentException de ) { 110 throw new ExceptionConverter(de); 111 } 112 } 113 114 out.write( RtfWriter.escape ); 116 out.write( RtfWriter.paragraph ); 117 out.write( RtfWriter.delimiter ); 118 119 out.write( RtfWriter.openGroup ); 121 out.write( RtfWriter.escape ); 122 out.write( RtfWriter.field ); 123 out.write( RtfWriter.openGroup ); 125 out.write( RtfWriter.escape ); 126 out.write( RtfWriter.fieldContent ); 127 out.write( RtfWriter.delimiter ); 128 out.write( "TOC".getBytes() ); 129 out.write( RtfWriter.delimiter ); 131 out.write( RtfWriter.escape ); 132 out.write( RtfWriter.escape ); 133 out.write( "f".getBytes() ); 134 out.write( RtfWriter.delimiter ); 135 out.write( RtfWriter.escape ); 137 out.write( RtfWriter.escape ); 138 out.write( "h".getBytes() ); 139 out.write( RtfWriter.delimiter ); 140 out.write( RtfWriter.delimiter ); 142 out.write( RtfWriter.escape ); 143 out.write( RtfWriter.escape ); 144 out.write( "u".getBytes() ); 145 out.write( RtfWriter.delimiter ); 146 out.write( RtfWriter.delimiter ); 148 out.write( RtfWriter.escape ); 149 out.write( RtfWriter.escape ); 150 out.write( "o".getBytes() ); 151 out.write( RtfWriter.delimiter ); 152 out.write( "\"1-5\"".getBytes() ); 153 out.write( RtfWriter.delimiter ); 154 out.write( RtfWriter.closeGroup ); 155 156 out.write( RtfWriter.openGroup ); 158 out.write( RtfWriter.escape ); 159 out.write( RtfWriter.fieldDisplay ); 160 out.write( RtfWriter.delimiter ); 161 out.write( defaultText.getBytes() ); 162 out.write( RtfWriter.delimiter ); 163 out.write( RtfWriter.closeGroup ); 164 out.write( RtfWriter.closeGroup ); 165 } 166 167 168 173 public void addTOCAsTOCEntry( String entryName, Font entryFont ) { 174 this.addTOCAsTOCEntry = true; 175 this.entryFont = entryFont; 176 this.entryName = entryName; 177 } 178 179 180 184 public void setDefaultText( String text ) { 185 this.defaultText = text; 186 } 187 } 188 | Popular Tags |