1 19 20 package jxl; 21 22 import java.util.Locale ; 23 import java.util.HashMap ; 24 25 import common.Logger; 26 27 import jxl.biff.formula.FunctionNames; 28 import jxl.biff.CountryCode; 29 30 36 public final class WorkbookSettings 37 { 38 41 private static Logger logger = Logger.getLogger(WorkbookSettings.class); 42 43 48 private int initialFileSize; 49 50 54 private int arrayGrowSize; 55 56 62 private boolean drawingsDisabled; 63 64 70 private boolean namesDisabled; 71 72 76 private boolean formulaReferenceAdjustDisabled; 77 78 90 private boolean gcDisabled; 91 92 99 private boolean rationalizationDisabled; 100 101 105 private boolean propertySetsDisabled; 106 107 112 private boolean ignoreBlankCells; 113 114 123 private Locale locale; 124 125 128 private FunctionNames functionNames; 129 130 135 private String encoding; 136 137 140 private int characterSet; 141 142 145 private String excelDisplayLanguage; 146 147 150 private String excelRegionalSettings; 151 152 155 private HashMap localeFunctionNames; 156 157 private static final int defaultInitialFileSize = 5 * 1024 * 1024; 161 private static final int defaultArrayGrowSize = 1024 * 1024; 164 167 public WorkbookSettings() 168 { 169 initialFileSize = defaultInitialFileSize; 170 arrayGrowSize = defaultArrayGrowSize; 171 localeFunctionNames = new HashMap (); 172 excelDisplayLanguage = CountryCode.USA.getCode(); 173 excelRegionalSettings = CountryCode.UK.getCode(); 174 175 try 177 { 178 boolean suppressWarnings = Boolean.getBoolean("jxl.nowarnings"); 179 setSuppressWarnings(suppressWarnings); 180 drawingsDisabled = Boolean.getBoolean("jxl.nodrawings"); 181 namesDisabled = Boolean.getBoolean("jxl.nonames"); 182 gcDisabled = Boolean.getBoolean("jxl.nogc"); 183 rationalizationDisabled = Boolean.getBoolean("jxl.norat"); 184 formulaReferenceAdjustDisabled = 185 Boolean.getBoolean("jxl.noformulaadjust"); 186 propertySetsDisabled = Boolean.getBoolean("jxl.nopropertysets"); 187 ignoreBlankCells = Boolean.getBoolean("jxl.ignoreblanks"); 188 189 encoding = System.getProperty("file.encoding"); 190 } 191 catch (SecurityException e) 192 { 193 logger.warn("Error accessing system properties.", e); 194 } 195 196 try 198 { 199 if (System.getProperty("jxl.lang") == null || 200 System.getProperty("jxl.country") == null) 201 { 202 locale = Locale.getDefault(); 203 } 204 else 205 { 206 locale = new Locale (System.getProperty("jxl.lang"), 207 System.getProperty("jxl.country")); 208 } 209 210 if (System.getProperty("jxl.encoding") != null) 211 { 212 encoding = System.getProperty("jxl.encoding"); 213 } 214 } 215 catch (SecurityException e) 216 { 217 logger.warn("Error accessing system properties.", e); 218 locale = Locale.getDefault(); 219 } 220 } 221 222 231 public void setArrayGrowSize(int sz) 232 { 233 arrayGrowSize = sz; 234 } 235 236 241 public int getArrayGrowSize() 242 { 243 return arrayGrowSize; 244 } 245 246 254 public void setInitialFileSize(int sz) 255 { 256 initialFileSize = sz; 257 } 258 259 264 public int getInitialFileSize() 265 { 266 return initialFileSize; 267 } 268 269 274 public boolean getDrawingsDisabled() 275 { 276 return drawingsDisabled; 277 } 278 279 284 public boolean getGCDisabled() 285 { 286 return gcDisabled; 287 } 288 289 294 public boolean getNamesDisabled() 295 { 296 return namesDisabled; 297 } 298 299 304 public void setNamesDisabled(boolean b) 305 { 306 namesDisabled = b; 307 } 308 309 314 public void setDrawingsDisabled(boolean b) 315 { 316 drawingsDisabled = b; 317 } 318 319 325 public void setRationalization(boolean r) 326 { 327 rationalizationDisabled = !r; 328 } 329 330 335 public boolean getRationalizationDisabled() 336 { 337 return rationalizationDisabled; 338 } 339 340 348 public void setPropertySets(boolean r) 349 { 350 propertySetsDisabled = !r; 351 } 352 353 358 public boolean getPropertySetsDisabled() 359 { 360 return propertySetsDisabled; 361 } 362 363 370 public void setSuppressWarnings(boolean w) 371 { 372 logger.setSuppressWarnings(w); 373 } 374 375 381 public boolean getFormulaAdjust() 382 { 383 return !formulaReferenceAdjustDisabled; 384 } 385 386 391 public void setFormulaAdjust(boolean b) 392 { 393 formulaReferenceAdjustDisabled = !b; 394 } 395 396 403 public void setLocale(Locale l) 404 { 405 locale = l; 406 } 407 408 413 public Locale getLocale() 414 { 415 return locale; 416 } 417 418 423 public String getEncoding() 424 { 425 return encoding; 426 } 427 428 433 public void setEncoding(String enc) 434 { 435 encoding = enc; 436 } 437 438 445 public FunctionNames getFunctionNames() 446 { 447 if (functionNames == null) 448 { 449 functionNames = (FunctionNames) localeFunctionNames.get(locale); 450 451 if (functionNames == null) 454 { 455 functionNames = new FunctionNames(locale); 456 localeFunctionNames.put(locale, functionNames); 457 } 458 } 459 460 return functionNames; 461 } 462 463 469 public int getCharacterSet() 470 { 471 return characterSet; 472 } 473 474 480 public void setCharacterSet(int cs) 481 { 482 characterSet = cs; 483 } 484 485 490 public void setGCDisabled(boolean disabled) 491 { 492 gcDisabled = disabled; 493 } 494 495 500 public void setIgnoreBlanks(boolean ignoreBlanks) 501 { 502 ignoreBlankCells = ignoreBlanks; 503 } 504 505 510 public boolean getIgnoreBlanks() 511 { 512 return ignoreBlankCells; 513 } 514 515 519 public String getExcelDisplayLanguage() 520 { 521 return excelDisplayLanguage; 522 } 523 524 528 public String getExcelRegionalSettings() 529 { 530 return excelRegionalSettings; 531 } 532 533 538 public void setExcelDisplayLanguage(String code) 539 { 540 excelDisplayLanguage = code; 541 } 542 543 548 public void setExcelRegionalSettings(String code) 549 { 550 excelRegionalSettings = code; 551 } 552 } 553 | Popular Tags |