1 50 51 package com.lowagie.text.rtf.style; 52 53 import java.io.ByteArrayOutputStream ; 54 import java.io.IOException ; 55 import java.io.OutputStream ; 56 import java.util.ArrayList ; 57 58 import com.lowagie.text.rtf.RtfElement; 59 import com.lowagie.text.rtf.RtfExtendedElement; 60 import com.lowagie.text.rtf.document.RtfDocument; 61 62 63 71 public class RtfColorList extends RtfElement implements RtfExtendedElement { 72 73 76 private static final byte[] COLOR_TABLE = "\\colortbl".getBytes(); 77 78 81 ArrayList colorList = new ArrayList (); 82 83 89 public RtfColorList(RtfDocument doc) { 90 super(doc); 91 colorList.add(new RtfColor(doc, 0, 0, 0, 0)); 92 colorList.add(new RtfColor(doc, 255, 255, 255, 1)); 93 } 94 95 102 public int getColorNumber(RtfColor color) { 103 int colorIndex = -1; 104 for(int i = 0; i < colorList.size(); i++) { 105 if(colorList.get(i).equals(color)) { 106 colorIndex = i; 107 } 108 } 109 if(colorIndex == -1) { 110 colorIndex = colorList.size(); 111 colorList.add(color); 112 } 113 return colorIndex; 114 } 115 116 120 public byte[] write() 121 { 122 return(new byte[0]); 123 } 124 127 public void writeContent(final OutputStream out) throws IOException 128 { 129 } 130 131 138 public byte[] writeDefinition() { 139 ByteArrayOutputStream result = new ByteArrayOutputStream (); 140 try { 141 writeDefinition(result); 142 } catch(IOException ioe) { 143 ioe.printStackTrace(); 144 } 145 return result.toByteArray(); 146 } 147 148 152 public void writeDefinition(final OutputStream result) throws IOException 153 { 154 result.write(OPEN_GROUP); 155 result.write(COLOR_TABLE); 156 for(int i = 0; i < colorList.size(); i++) { 157 RtfColor color = (RtfColor) colorList.get(i); 158 color.writeDefinition(result); 160 } 161 result.write(CLOSE_GROUP); 162 result.write((byte)'\n'); 163 } 164 165 166 } 167 | Popular Tags |