1 9 package com.vladium.emma.report.html.doc; 10 11 15 public 16 final class HTMLTable extends IElement.Factory.ElementImpl 17 { 18 20 public static interface ICell extends IElement 21 { 22 ICell setColspan (final int span); 23 24 } 26 public static interface IRow extends IElement 27 { 28 ICell newCell (); 29 30 } 32 public HTMLTable (final String width, final String border, final String cellpadding, final String cellspacing) 33 { 34 super (Tag.TABLE, AttributeSet.create ()); 35 36 final AttributeSet attrs = getAttributes (); 37 38 if (width != null) attrs.set (Attribute.WIDTH, width); 39 if (border != null) attrs.set (Attribute.BORDER, border); 40 if (cellpadding != null) attrs.set (Attribute.CELLPADDING, cellpadding); 41 if (cellspacing != null) attrs.set (Attribute.CELLSPACING, cellspacing); 42 43 } 45 46 public void setCaption (final String align, final String text, final boolean nbsp) 47 { 48 m_caption = IElement.Factory.create (Tag.CAPTION); 49 50 m_caption.getAttributes ().set (Attribute.ALIGN, align); 51 m_caption.setText (text, nbsp); 52 } 53 54 public IRow newTitleRow () 55 { 56 final Row row = new Row (true); 57 add (row); 58 59 return row; 60 } 61 62 public IRow newRow () 63 { 64 final Row row = new Row (false); 65 add (row); 66 67 return row; 68 } 69 70 public void emit (final HTMLWriter out) 71 { 72 if (m_caption != null) 73 { 74 add (0, m_caption); 75 } 76 77 super.emit(out); 78 } 79 80 82 84 86 87 private static class Cell extends IElement.Factory.ElementImpl 88 implements ICell 89 { 90 public ICell setColspan (final int span) 91 { 92 getAttributes ().set (Attribute.COLSPAN, span); 93 94 return this; 95 } 96 97 Cell (Tag tag) 98 { 99 super (tag, AttributeSet.create ()); 100 } 101 102 } 104 105 private static class Row extends IElement.Factory.ElementImpl 106 implements IRow 107 { 108 public ICell newCell () 109 { 110 final ICell cell = new Cell (m_th ? Tag.TH : Tag.TD); 111 add (cell); 112 113 return cell; 114 } 115 116 Row (final boolean th) 117 { 118 super (Tag.TR, AttributeSet.create ()); 119 120 m_th = th; 121 } 122 123 124 private final boolean m_th; 125 126 } 128 129 private IElement m_caption; 130 131 } | Popular Tags |