1 package jimm.datavision; 2 import jimm.util.I18N; 3 import jimm.util.XMLWriter; 4 import java.util.*; 5 6 12 public class SectionArea implements Writeable { 13 14 public static final int REPORT_HEADER = 0; 15 public static final int REPORT_FOOTER = 1; 16 public static final int PAGE_HEADER = 2; 17 public static final int PAGE_FOOTER = 3; 18 public static final int DETAIL = 4; 19 public static final int GROUP_HEADER = 5; 20 public static final int GROUP_FOOTER = 6; 21 22 26 protected static final String [] AREA_NAME_KEYS = { 27 "Report.report_header", 28 "Report.report_footer", 29 "Report.page_header", 30 "Report.page_footer", 31 "Report.detail", 32 "Report.group_header", 33 "Report.group_footer" 34 }; 35 36 List sections; 37 38 int area; 39 40 46 public static String nameFromArea(int area) { 47 return I18N.get(AREA_NAME_KEYS[area]); 48 } 49 50 55 public SectionArea(int area) { 56 this.area = area; 57 sections = new ArrayList(); 58 } 59 60 public int getArea() { 61 return area; 62 } 63 64 public int indexOf(Section s) { 65 return sections.indexOf(s); 66 } 67 68 public Section get(int index) { 69 return (Section)sections.get(index); 70 } 71 72 public Section first() { 73 return (Section)sections.get(0); 74 } 75 76 82 public void add(Section s) { 83 sections.add(s); 84 imprint(s); 85 } 86 87 93 public void add(int index, Section s) { 94 sections.add(index, s); 95 imprint(s); 96 } 97 98 107 public Section insertAfter(Section section, Section afterThis) { 108 if (section == null) { 109 if (afterThis != null) 110 section = new Section(afterThis.getReport()); 111 else 112 throw new IllegalArgumentException ("SectionArea.insertAfter:" + 113 " both section and afterThis" + 114 " can't be null"); 115 } 116 117 sections.add(sections.indexOf(afterThis) + 1, section); 118 imprint(section); 119 return section; 120 } 121 122 127 protected void imprint(Section section) { 128 section.setArea(this); 129 } 130 131 136 public boolean isDetail() { 137 return area == DETAIL; 138 } 139 140 145 public void remove(Section s) { 146 sections.remove(s); 147 s.setArea(null); 148 } 149 150 156 public boolean contains(Section s) { 157 return sections.contains(s); 158 } 159 160 165 public String getName() { 166 return nameFromArea(area); 167 } 168 169 174 public List sections() { 175 return Collections.unmodifiableList(sections); 176 } 177 178 public Iterator iterator() { 179 return sections.iterator(); 180 } 181 182 public int size() { 183 return sections.size(); 184 } 185 186 public boolean isEmpty() { 187 return sections.isEmpty(); 188 } 189 190 public void clear() { 191 for (Iterator iter = sections.iterator(); iter.hasNext(); ) 192 ((Section)iter.next()).setArea(null); 193 sections.clear(); 194 } 195 196 public void withSectionsDo(SectionWalker s) { 197 for (Iterator iter = sections.iterator(); iter.hasNext(); ) 198 s.step((Section)iter.next()); 199 } 200 201 public void writeXML(XMLWriter out) { 202 ListWriter.writeList(out, sections); 203 } 204 205 } 206 | Popular Tags |