1 50 51 package com.lowagie.text.rtf.table; 52 53 import java.awt.Color ; 54 import java.io.ByteArrayOutputStream ; 55 import java.io.IOException ; 56 import java.io.OutputStream ; 57 import java.util.Enumeration ; 58 import java.util.Hashtable ; 59 60 import com.lowagie.text.Rectangle; 61 import com.lowagie.text.rtf.RtfElement; 62 import com.lowagie.text.rtf.document.RtfDocument; 63 64 65 73 public class RtfBorderGroup extends RtfElement { 74 78 private int borderType = RtfBorder.ROW_BORDER; 79 82 private Hashtable borders = null; 83 84 87 public RtfBorderGroup() { 88 super(null); 89 this.borders = new Hashtable (); 90 } 91 92 100 public RtfBorderGroup(int bordersToAdd, int borderStyle, float borderWidth, Color borderColor) { 101 super(null); 102 this.borders = new Hashtable (); 103 addBorder(bordersToAdd, borderStyle, borderWidth, borderColor); 104 } 105 106 113 protected RtfBorderGroup(RtfDocument doc, int borderType, RtfBorderGroup borderGroup) { 114 super(doc); 115 this.borders = new Hashtable (); 116 this.borderType = borderType; 117 if(borderGroup != null) { 118 Enumeration borderEnum = borderGroup.getBorders().keys(); 119 while(borderEnum.hasMoreElements()) { 120 Integer borderPos = (Integer ) borderEnum.nextElement(); 121 RtfBorder border = (RtfBorder) borderGroup.getBorders().get(borderPos); 122 this.borders.put(borderPos, new RtfBorder(this.document, this.borderType, border)); 123 } 124 } 125 } 126 127 136 protected RtfBorderGroup(RtfDocument doc, int borderType, int bordersToUse, float borderWidth, Color borderColor) { 137 super(doc); 138 this.borderType = borderType; 139 this.borders = new Hashtable (); 140 addBorder(bordersToUse, RtfBorder.BORDER_SINGLE, borderWidth, borderColor); 141 } 142 143 151 private void setBorder(int borderPosition, int borderStyle, float borderWidth, Color borderColor) { 152 RtfBorder border = new RtfBorder(this.document, this.borderType, borderPosition, borderStyle, borderWidth, borderColor); 153 this.borders.put(new Integer (borderPosition), border); 154 } 155 156 164 public void addBorder(int bordersToAdd, int borderStyle, float borderWidth, Color borderColor) { 165 if((bordersToAdd & Rectangle.LEFT) == Rectangle.LEFT) { 166 setBorder(RtfBorder.LEFT_BORDER, borderStyle, borderWidth, borderColor); 167 } 168 if((bordersToAdd & Rectangle.TOP) == Rectangle.TOP) { 169 setBorder(RtfBorder.TOP_BORDER, borderStyle, borderWidth, borderColor); 170 } 171 if((bordersToAdd & Rectangle.RIGHT) == Rectangle.RIGHT) { 172 setBorder(RtfBorder.RIGHT_BORDER, borderStyle, borderWidth, borderColor); 173 } 174 if((bordersToAdd & Rectangle.BOTTOM) == Rectangle.BOTTOM) { 175 setBorder(RtfBorder.BOTTOM_BORDER, borderStyle, borderWidth, borderColor); 176 } 177 if((bordersToAdd & Rectangle.BOX) == Rectangle.BOX && this.borderType == RtfBorder.ROW_BORDER) { 178 setBorder(RtfBorder.VERTICAL_BORDER, borderStyle, borderWidth, borderColor); 179 setBorder(RtfBorder.HORIZONTAL_BORDER, borderStyle, borderWidth, borderColor); 180 } 181 } 182 183 188 public void removeBorder(int bordersToRemove) { 189 if((bordersToRemove & Rectangle.LEFT) == Rectangle.LEFT) { 190 this.borders.remove(new Integer (RtfBorder.LEFT_BORDER)); 191 } 192 if((bordersToRemove & Rectangle.TOP) == Rectangle.TOP) { 193 this.borders.remove(new Integer (RtfBorder.TOP_BORDER)); 194 } 195 if((bordersToRemove & Rectangle.RIGHT) == Rectangle.RIGHT) { 196 this.borders.remove(new Integer (RtfBorder.RIGHT_BORDER)); 197 } 198 if((bordersToRemove & Rectangle.BOTTOM) == Rectangle.BOTTOM) { 199 this.borders.remove(new Integer (RtfBorder.BOTTOM_BORDER)); 200 } 201 if((bordersToRemove & Rectangle.BOX) == Rectangle.BOX && this.borderType == RtfBorder.ROW_BORDER) { 202 this.borders.remove(new Integer (RtfBorder.VERTICAL_BORDER)); 203 this.borders.remove(new Integer (RtfBorder.HORIZONTAL_BORDER)); 204 } 205 } 206 207 213 public byte[] write() 214 { 215 ByteArrayOutputStream result = new ByteArrayOutputStream (); 216 try { 217 writeContent(result); 218 } catch(IOException ioe) { 219 ioe.printStackTrace(); 220 } 221 return result.toByteArray(); 222 } 223 226 public void writeContent(final OutputStream result) throws IOException 227 { 228 Enumeration borderEnum = this.borders.keys(); 229 while(borderEnum.hasMoreElements()) { 230 RtfBorder rb = (RtfBorder)this.borders.get(borderEnum.nextElement()); 231 rb.writeContent(result); 233 } 234 } 235 236 241 protected Hashtable getBorders() { 242 return this.borders; 243 } 244 } 245 | Popular Tags |