1 19 20 package jxl.write.biff; 21 22 import java.io.IOException ; 23 import java.util.ArrayList ; 24 import java.util.Iterator ; 25 26 import common.Logger; 27 import common.Assert; 28 import jxl.WorkbookSettings; 29 30 34 public class DataValidation 35 { 36 39 private final static Logger logger = Logger.getLogger(DataValidation.class); 40 41 44 private DataValidityListRecord validityList; 45 46 49 private ArrayList validitySettings; 50 51 54 private int pos; 55 56 59 private WritableWorkbookImpl workbook; 60 61 64 private WorkbookSettings workbookSettings; 65 66 71 DataValidation(jxl.read.biff.DataValidation dv, 72 WritableWorkbookImpl w, 73 WorkbookSettings ws) 74 { 75 workbook = w; 76 workbookSettings = ws; 77 validityList = new DataValidityListRecord(dv.getDataValidityList()); 78 79 jxl.read.biff.DataValiditySettingsRecord[] settings = 80 dv.getDataValiditySettings(); 81 82 validitySettings = new ArrayList (settings.length); 83 for (int i = 0; i < settings.length ; i++) 84 { 85 validitySettings.add(new DataValiditySettingsRecord(settings[i], 86 workbook, 87 workbookSettings)); 88 } 89 } 90 91 96 DataValidation(DataValidation dv, 97 WritableWorkbookImpl w, 98 WorkbookSettings ws) 99 100 { 101 workbook = w; 102 workbookSettings = ws; 103 validityList = new DataValidityListRecord(dv.validityList); 104 105 validitySettings = new ArrayList (dv.validitySettings.size()); 106 107 for (Iterator i = dv.validitySettings.iterator(); i.hasNext(); ) 108 { 109 DataValiditySettingsRecord dvsr = (DataValiditySettingsRecord) i.next(); 110 validitySettings.add 111 (new DataValiditySettingsRecord(dvsr, 112 workbook, 113 workbookSettings)); 114 } 115 } 116 117 118 124 public void write(File outputFile) throws IOException 125 { 126 if (!validityList.hasDVRecords()) 127 { 128 return; 129 } 130 131 outputFile.write(validityList); 132 133 for (Iterator i = validitySettings.iterator(); i.hasNext() ; ) 134 { 135 DataValiditySettingsRecord dv = (DataValiditySettingsRecord) i.next(); 136 outputFile.write(dv); 137 } 138 } 139 140 145 public void insertRow(int row) 146 { 147 for (Iterator i = validitySettings.iterator(); i.hasNext() ; ) 148 { 149 DataValiditySettingsRecord dv = (DataValiditySettingsRecord) i.next(); 150 dv.insertRow(row); 151 } 152 } 153 154 159 public void removeRow(int row) 160 { 161 for (Iterator i = validitySettings.iterator(); i.hasNext() ; ) 162 { 163 DataValiditySettingsRecord dv = (DataValiditySettingsRecord) i.next(); 164 165 if (dv.getFirstRow() == row && dv.getLastRow() == row) 166 { 167 i.remove(); 168 validityList.dvRemoved(); 169 } 170 else 171 { 172 dv.removeRow(row); 173 } 174 } 175 } 176 177 182 public void insertColumn(int col) 183 { 184 for (Iterator i = validitySettings.iterator(); i.hasNext() ; ) 185 { 186 DataValiditySettingsRecord dv = (DataValiditySettingsRecord) i.next(); 187 dv.insertColumn(col); 188 } 189 } 190 191 196 public void removeColumn(int col) 197 { 198 for (Iterator i = validitySettings.iterator(); i.hasNext() ; ) 199 { 200 DataValiditySettingsRecord dv = (DataValiditySettingsRecord) i.next(); 201 202 if (dv.getFirstColumn() == col && dv.getLastColumn() == col) 203 { 204 i.remove(); 205 validityList.dvRemoved(); 206 } 207 else 208 { 209 dv.removeColumn(col); 210 } 211 } 212 } 213 } 214 | Popular Tags |