001/***************************************************************************** 002 * Copyright by The HDF Group. * 003 * Copyright by the Board of Trustees of the University of Illinois. * 004 * All rights reserved. * 005 * * 006 * This file is part of the HDF Java Products distribution. * 007 * The full copyright notice, including terms governing use, modification, * 008 * and redistribution, is contained in the files COPYING and Copyright.html. * 009 * COPYING can be found at the root of the source code distribution tree. * 010 * Or, see https://support.hdfgroup.org/products/licenses.html * 011 * If you do not have access to either file, you may request a copy from * 012 * help@hdfgroup.org. * 013 ****************************************************************************/ 014 015package hdf.view; 016 017import java.io.File; 018import java.io.IOException; 019import java.io.InputStream; 020import java.net.MalformedURLException; 021import java.net.URL; 022import java.net.URLClassLoader; 023import java.util.ArrayList; 024import java.util.Arrays; 025import java.util.Enumeration; 026import java.util.List; 027import java.util.jar.JarEntry; 028import java.util.jar.JarFile; 029 030import org.eclipse.jface.preference.PreferenceStore; 031import org.eclipse.swt.graphics.Image; 032 033import hdf.HDFVersions; 034import hdf.object.FileFormat; 035import hdf.view.ImageView.ImageViewFactory; 036import hdf.view.MetaDataView.MetaDataViewFactory; 037import hdf.view.PaletteView.PaletteViewFactory; 038import hdf.view.TableView.TableViewFactory; 039import hdf.view.TreeView.TreeViewFactory; 040 041public class ViewProperties extends PreferenceStore { 042 private static final long serialVersionUID = -6411465283887959066L; 043 044 private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(ViewProperties.class); 045 046 /** the version of the HDFViewer */ 047 public static final String VERSION = HDFVersions.getPropertyVersionView(); 048 049 /** the local property file name */ 050 private static final String USER_PROPERTY_FILE = ".hdfview" + VERSION; 051 052 /** the maximum number of most recent files */ 053 public static final int MAX_RECENT_FILES = 15; 054 055 /** name of the tab delimiter */ 056 public static final String DELIMITER_TAB = "Tab"; 057 058 /** name of the tab delimiter */ 059 public static final String DELIMITER_COMMA = "Comma"; 060 061 /** name of the tab delimiter */ 062 public static final String DELIMITER_SPACE = "Space"; 063 064 /** name of the tab delimiter */ 065 public static final String DELIMITER_COLON = "Colon"; 066 067 /** image origin: UpperLeft */ 068 public static final String ORIGIN_UL = "UpperLeft"; 069 070 /** image origin: LowerLeft */ 071 public static final String ORIGIN_LL = "LowerLeft"; 072 073 /** image origin: UpperRight */ 074 public static final String ORIGIN_UR = "UpperRight"; 075 076 /** image origin: LowerRight */ 077 public static final String ORIGIN_LR = "LowerRight"; 078 079 /** name of the tab delimiter */ 080 public static final String DELIMITER_SEMI_COLON = "Semi-Colon"; 081 082 /** 083 * The names of the various default classes for each HDFView module interface 084 */ 085 086 /** Text for default selection of modules */ 087 public static final String DEFAULT_MODULE_TEXT = "Default"; 088 089 /** Default TreeView class names */ 090 public static final String DEFAULT_TREEVIEW_NAME = "hdf.view.TreeView.DefaultTreeView"; 091 092 /** Default TableView class names */ 093 public static final String DEFAULT_SCALAR_DATASET_TABLEVIEW_NAME = "hdf.view.TableView.DefaultScalarDSTableView"; 094 public static final String DEFAULT_SCALAR_ATTRIBUTE_TABLEVIEW_NAME = "hdf.view.TableView.DefaultScalarAttributeTableView"; 095 public static final String DEFAULT_COMPOUND_DATASET_TABLEVIEW_NAME = "hdf.view.TableView.DefaultCompoundDSTableView"; 096 097 /** Default MetaDataView class names */ 098 public static final String DEFAULT_GROUP_METADATAVIEW_NAME = "hdf.view.MetaDataView.DefaultGroupMetaDataView"; 099 public static final String DEFAULT_DATASET_METADATAVIEW_NAME = "hdf.view.MetaDataView.DefaultDatasetMetaDataView"; 100 public static final String DEFAULT_DATATYPE_METADATAVIEW_NAME = "hdf.view.MetaDataView.DefaultDatatypeMetaDataView"; 101 public static final String DEFAULT_LINK_METADATAVIEW_NAME = "hdf.view.MetaDataView.DefaultLinkMetaDataView"; 102 103 /** Default ImageView class names */ 104 public static final String DEFAULT_IMAGEVIEW_NAME = "hdf.view.ImageView.DefaultImageView"; 105 106 /** Default PaletteView class names */ 107 public static final String DEFAULT_PALETTEVIEW_NAME = "hdf.view.PaletteView.DefaultPaletteView"; 108 109 /** 110 * Used to create different DataViews for a given HObject. 111 */ 112 public static enum DataViewType { 113 TABLE, IMAGE, PALETTE, METADATA, TREEVIEW 114 } 115 116 /** 117 * Property keys control how the data is displayed. 118 */ 119 public static enum DATA_VIEW_KEY { 120 CHAR, CONVERTBYTE, TRANSPOSED, READONLY, OBJECT, BITMASK, BITMASKOP, BORDER, INFO, INDEXBASE1, VIEW_NAME 121 } 122 123 /** 124 * Property keys control how the data is displayed. 125 */ 126 public static enum BITMASK_OP { 127 AND, EXTRACT 128 } 129 130 /** the root directory of the HDFView */ 131 private static String rootDir = System.getProperty("user.dir"); 132 133 /** user's guide */ 134 private static String usersGuide = "/share/doc/UsersGuide/index.html"; 135 136 /** the font size */ 137 private static int fontSize = 12; 138 139 /** the font type */ 140 private static String fontType = "Serif"; 141 142 /** the full path of H4toH5 converter */ 143 private static String h4toh5 = ""; 144 145 /** data delimiter */ 146 private static String delimiter = DELIMITER_TAB; 147 148 /** image origin */ 149 private static String origin = ORIGIN_UL; 150 151 /** default index type */ 152 private static String indexType = "H5_INDEX_NAME"; 153 154 /** default index order */ 155 private static String indexOrder = "H5_ITER_INC"; 156 157 /** a list of most recent files */ 158 private static ArrayList<String> recentFiles = new ArrayList<>(MAX_RECENT_FILES + 5); 159 160 /** default starting file directory */ 161 private static String workDir = System.getProperty("user.home"); 162 163 /** default HDF file extensions */ 164 private static String fileExt = "hdf, h4, hdf4, h5, hdf5, he2, he5"; 165 166 private static ClassLoader extClassLoader = null; 167 168 /** a list of srb accounts */ 169 private static ArrayList<String[]> srbAccountList = new ArrayList<>(5); 170 171 /** 172 * flag to indicate if auto contrast is used in image processing. Do not use 173 * autocontrast by default (2.6 change). 174 */ 175 private static boolean isAutoContrast = false; 176 177 private static boolean showImageValues = false; 178 179 private static boolean showRegRefValues = false; 180 181 /** 182 * flag to indicate if default open file mode is read only. By default, use read 183 * only to prevent accidental modifications to the file. 184 */ 185 private static boolean isReadOnly = true; 186 187 private static String EarlyLib = "Latest"; 188 189 private static String LateLib = "Latest"; 190 191 /** a list of palette files */ 192 private static ArrayList<String> paletteList = new ArrayList<>(5); 193 194 /** flag to indicate if enum data is converted to strings */ 195 private static boolean convertEnum = true; 196 197 /** flag to indicate if data is 1-based index */ 198 private static boolean isIndexBase1 = false; 199 200 /** 201 * Current Java applications such as HDFView cannot handle files with a large 202 * number of objects such as 1,000,000 objects. max_members defines the maximum 203 * number of objects that will be loaded into memory. 204 */ 205 private static int maxMembers = Integer.MAX_VALUE; // load all by default 206 /** 207 * Current Java applications such as HDFView cannot handle files with a large 208 * number of objects such 1,000,000 objects. start_members defines the 209 * starting index of objects that will be loaded into memory. 210 */ 211 private static int startMembers = 0; 212 213 private static Image hdfIcon, h4Icon, h4IconR, h5Icon, h5IconR, ncIcon, ncIconR, 214 largeHdfIcon, blankIcon, helpIcon, fileopenIcon, filesaveIcon, filenewIcon, filecloseIcon, foldercloseIcon, 215 folderopenIcon, foldercloseIconA, folderopenIconA, datasetIcon, imageIcon, tableIcon, textIcon, datasetIconA, 216 imageIconA, tableIconA, textIconA, zoominIcon, zoomoutIcon, paletteIcon, chartIcon, brightIcon, autocontrastIcon, 217 copyIcon, cutIcon, pasteIcon, previousIcon, nextIcon, firstIcon, lastIcon, animationIcon, datatypeIcon, 218 datatypeIconA, linkIcon, iconAPPS, iconURL, iconVIDEO, iconXLS, iconPDF, iconAUDIO, questionIcon; 219 220 private static String propertyFile; 221 222 /** a list of treeview modules */ 223 private static ArrayList<String> moduleListTreeView = new ArrayList<>(5); 224 225 /** a list of metaview modules */ 226 private static ArrayList<String> moduleListMetaDataView = new ArrayList<>(5); 227 228 /** a list of tableview modules */ 229 private static ArrayList<String> moduleListTableView = new ArrayList<>(5); 230 231 /** a list of imageview modules */ 232 private static ArrayList<String> moduleListImageView = new ArrayList<>(5); 233 234 /** a list of paletteview modules */ 235 private static ArrayList<String> moduleListPaletteView = new ArrayList<>(5); 236 237 /** a list of helpview modules */ 238 private static ArrayList<String> moduleListHelpView = new ArrayList<>(5); 239 240 /** 241 * Creates a property list with given root directory of the HDFView. 242 * 243 * @param viewRoot 244 * the root directory of the HDFView 245 */ 246 public ViewProperties(String viewRoot) { 247 super(); 248 249 // look for the property file in the user's home directory 250 String propertyFileName = USER_PROPERTY_FILE; 251 String userHomeFile = System.getProperty("user.home") + File.separator + propertyFileName; 252 String userDirFile = System.getProperty("user.dir") + File.separator + propertyFileName; 253 254 setFilename(createPropertyFile(userHomeFile, userDirFile)); 255 256 setRootDir(viewRoot); 257 log.trace("rootDir is {}", rootDir); 258 259 setUsersGuide(rootDir + usersGuide); 260 261 setDefault("users.guide", System.getProperty("user.dir") + "/UsersGuide/index.html"); 262 setDefault("image.contrast", false); 263 setDefault("image.showvalues", false); 264 setDefault("file.mode", "r"); 265 setDefault("lib.lowversion", "Earliest"); 266 setDefault("lib.highversion", "Latest"); 267 setDefault("enum.conversion", false); 268 setDefault("regref.showvalues", false); 269 setDefault("index.base1", false); 270 setDefault("image.origin", ORIGIN_UL); 271 setDefault("h5file.indexType", "H5_INDEX_NAME"); 272 setDefault("h5file.indexOrder", "H5_ITER_INC"); 273 setDefault("h4toh5.converter", ""); 274 setDefault("work.dir", System.getProperty("user.home")); 275 setDefault("file.extension", "hdf, h4, hdf4, h5, hdf5, he2, he5"); 276 setDefault("font.size", 12); 277 setDefault("font.type", "Serif"); 278 setDefault("max.members", Integer.MAX_VALUE); 279 setDefault("recent.file", ""); 280 setDefault("palette.file", ""); 281 setDefault("data.delimiter", DELIMITER_TAB); 282 } 283 284 public static String createPropertyFile(String userHomeFile, String userDirFile) { 285 String propFile = System.getProperty("hdfview.propfile"); 286 287 if ((propFile != null) && ((new File(propFile)).exists())) { 288 propertyFile = propFile; 289 } 290 else if ((new File(userHomeFile)).exists()) { 291 propertyFile = userHomeFile; 292 } 293 else if ((new File(userDirFile)).exists()) { 294 propertyFile = userDirFile; 295 } 296 else { 297 File pFile = null; 298 299 // If the user specified a property file, but it didn't exist, 300 // try to create a new one where specified. 301 if (propFile != null) { 302 pFile = new File(propFile); 303 304 try { 305 pFile.createNewFile(); 306 propertyFile = propFile; 307 } 308 catch (Exception ex) { 309 log.debug("createPropertyFile(): unable to create property file {}", propFile); 310 pFile = null; 311 } 312 } 313 314 if (pFile == null) { 315 // Create new property file at user home directory 316 pFile = new File(userHomeFile); 317 try { 318 pFile.createNewFile(); 319 propertyFile = userHomeFile; 320 } 321 catch (Exception ex) { 322 log.debug("createPropertyFile(): unable to create property file in home directory"); 323 propertyFile = null; 324 } 325 } 326 } 327 328 log.trace("propertyFile is {}", propertyFile); 329 return propertyFile; 330 } 331 332 /** 333 * load module classes 334 * 335 * @return the ClassLoader 336 */ 337 public static ClassLoader loadExtClass() { 338 if (extClassLoader != null) { 339 return extClassLoader; 340 } 341 else { 342 // default classloader 343 extClassLoader = ClassLoader.getSystemClassLoader(); 344 } 345 log.trace("loadExtClass: default classloader is {}", extClassLoader); 346 347 String rootPath = System.getProperty("hdfview.root"); 348 if (rootPath == null) { 349 rootPath = rootDir; 350 log.debug("loadExtClass: rootDir rootPath is {}", rootPath); 351 } 352 log.debug("loadExtClass: rootPath is {}", rootPath); 353 354 String dirname = rootPath + File.separator + "lib" + File.separator + "ext" + File.separator; 355 String[] jars = null; 356 File extdir = null; 357 try { 358 extdir = new File(dirname); 359 jars = extdir.list(); 360 log.trace("loadExtClass: dirname is {} with {} jars", dirname, jars.length); 361 } 362 catch (Exception ex0) { 363 log.debug("loadExtClass: load dirname: {}+lib/ext failed", rootPath, ex0); 364 } 365 366 if ((jars == null) || (jars.length <= 0)) { 367 return extClassLoader; 368 } 369 370 ArrayList<String> jarList = new ArrayList<>(50); 371 ArrayList<String> classList = new ArrayList<>(50); 372 for (int i = 0; i < jars.length; i++) { 373 log.trace("loadExtClass: load jar[{}]", i); 374 if (jars[i].endsWith(".jar")) { 375 jarList.add(jars[i]); 376 // add class names to the list of classes 377 File tmpFile = new File(extdir, jars[i]); 378 try (JarFile jarFile = new JarFile(tmpFile, false, JarFile.OPEN_READ)) { 379 Enumeration<?> emu = jarFile.entries(); 380 while (emu.hasMoreElements()) { 381 JarEntry jarEntry = (JarEntry) emu.nextElement(); 382 String entryName = jarEntry.getName(); 383 log.trace("loadExtClass: reading jar[{}] class={}", i, entryName); 384 int idx = entryName.indexOf(".class"); 385 if ((idx > 0) && (entryName.indexOf('$') <= 0)) { 386 entryName = entryName.replace('/', '.'); 387 classList.add(entryName.substring(0, idx)); 388 } 389 } 390 } 391 catch (Exception ex) { 392 log.debug("loadExtClass: load jar[{}] failed", i, ex); 393 } 394 } // (jars[i].endsWith(".jar")) 395 } // (int i=0; i<jars.length; i++) 396 397 int n = jarList.size(); 398 if (n <= 0) { 399 log.debug("loadExtClass: jarList empty"); 400 return extClassLoader; 401 } 402 403 URL[] urls = new URL[n]; 404 for (int i = 0; i < n; i++) { 405 try { 406 urls[i] = new URL("file:///" + rootPath + "/lib/ext/" + jarList.get(i)); 407 log.trace("loadExtClass: load urls[{}] is {}", i, urls[i]); 408 } 409 catch (MalformedURLException mfu) { 410 log.debug("loadExtClass: load urls[{}] failed", i, mfu); 411 } 412 } 413 414 try { 415 extClassLoader = URLClassLoader.newInstance(urls); 416 } 417 catch (Exception ex) { 418 ex.printStackTrace(); 419 } 420 421 // load user modules into their list 422 n = classList.size(); 423 for (int i = 0; i < n; i++) { 424 String theName = classList.get(i); 425 log.trace("loadExtClass: load classList[{}] is {}", i, theName); 426 try { 427 // enables use of JHDF5 in JNLP (Web Start) applications, the 428 // system class loader with reflection first. 429 Class<?> theClass = null; 430 try { 431 theClass = Class.forName(theName); 432 } 433 catch (Exception ex) { 434 try { 435 theClass = extClassLoader.loadClass(theName); 436 } 437 catch (Exception exc) { 438 log.debug("load: loadClass({}) failed", theName, ex); 439 } 440 } 441 442 if(theClass != null) { 443 if (TableViewFactory.class.isAssignableFrom(theClass)) { 444 if (!moduleListTableView.contains(theName)) 445 moduleListTableView.add(theName); 446 log.trace("loadExtClass: TableViewFactory class {}", theName); 447 } 448 else if (MetaDataViewFactory.class.isAssignableFrom(theClass)) { 449 if (!moduleListMetaDataView.contains(theName)) 450 moduleListMetaDataView.add(theName); 451 log.trace("loadExtClass: MetaDataViewFactory class {}", theName); 452 } 453 else if (ImageViewFactory.class.isAssignableFrom(theClass)) { 454 if (!moduleListImageView.contains(theName)) 455 moduleListImageView.add(theName); 456 log.trace("loadExtClass: ImageViewFactory class {}", theName); 457 } 458 else if (TreeViewFactory.class.isAssignableFrom(theClass)) { 459 if (!moduleListTreeView.contains(theName)) 460 moduleListTreeView.add(theName); 461 log.trace("loadExtClass: TreeViewFactory class {}", theName); 462 } 463 else if (PaletteViewFactory.class.isAssignableFrom(theClass)) { 464 if (!moduleListPaletteView.contains(theName)) 465 moduleListPaletteView.add(theName); 466 log.trace("loadExtClass: PaletteViewFactory class {}", theName); 467 } 468 } 469 } 470 catch (Exception ex) { 471 log.debug("loadExtClass: load classList[{}] of {} failed", i, theName, ex); 472 } 473 } // (int i=0; i<n; i++) 474 475 return extClassLoader; 476 } 477 478 public static Image getFoldercloseIcon() { 479 return foldercloseIcon; 480 } 481 482 public static Image getFoldercloseIconA() { 483 return foldercloseIconA; 484 } 485 486 public static Image getFolderopenIcon() { 487 return folderopenIcon; 488 } 489 490 public static Image getFolderopenIconA() { 491 return folderopenIconA; 492 } 493 494 public static Image getHdfIcon() { 495 return hdfIcon; 496 } 497 498 public static Image getH4Icon() { 499 return h4Icon; 500 } 501 502 public static Image getH4IconR() { 503 return h4IconR; 504 } 505 506 public static Image getH5Icon() { 507 return h5Icon; 508 } 509 510 public static Image getH5IconR() { 511 return h5IconR; 512 } 513 514 public static Image getNC3Icon() { 515 return ncIcon; 516 } 517 518 public static Image getNC3IconR() { 519 return ncIconR; 520 } 521 522 public static Image getDatasetIcon() { 523 return datasetIcon; 524 } 525 526 public static Image getDatasetIconA() { 527 return datasetIconA; 528 } 529 530 public static Image getDatatypeIcon() { 531 return datatypeIcon; 532 } 533 534 public static Image getDatatypeIconA() { 535 return datatypeIconA; 536 } 537 538 public static Image getLinkIcon() { 539 return linkIcon; 540 } 541 542 public static Image getFileopenIcon() { 543 return fileopenIcon; 544 } 545 546 public static Image getFilesaveIcon() { 547 return filesaveIcon; 548 } 549 550 public static Image getFilenewIcon() { 551 return filenewIcon; 552 } 553 554 public static Image getFilecloseIcon() { 555 return filecloseIcon; 556 } 557 558 public static Image getPaletteIcon() { 559 return paletteIcon; 560 } 561 562 public static Image getBrightIcon() { 563 return brightIcon; 564 } 565 566 public static Image getAutocontrastIcon() { 567 return autocontrastIcon; 568 } 569 570 public static Image getImageIcon() { 571 return imageIcon; 572 } 573 574 public static Image getTableIcon() { 575 return tableIcon; 576 } 577 578 public static Image getTextIcon() { 579 return textIcon; 580 } 581 582 public static Image getImageIconA() { 583 return imageIconA; 584 } 585 586 public static Image getTableIconA() { 587 return tableIconA; 588 } 589 590 public static Image getTextIconA() { 591 return textIconA; 592 } 593 594 public static Image getZoominIcon() { 595 return zoominIcon; 596 } 597 598 public static Image getZoomoutIcon() { 599 return zoomoutIcon; 600 } 601 602 public static Image getBlankIcon() { 603 return blankIcon; 604 } 605 606 public static Image getHelpIcon() { 607 return helpIcon; 608 } 609 610 public static Image getCopyIcon() { 611 return copyIcon; 612 } 613 614 public static Image getCutIcon() { 615 return cutIcon; 616 } 617 618 public static Image getPasteIcon() { 619 return pasteIcon; 620 } 621 622 public static Image getLargeHdfIcon() { 623 return largeHdfIcon; 624 } 625 626 public static Image getPreviousIcon() { 627 return previousIcon; 628 } 629 630 public static Image getNextIcon() { 631 return nextIcon; 632 } 633 634 public static Image getFirstIcon() { 635 return firstIcon; 636 } 637 638 public static Image getLastIcon() { 639 return lastIcon; 640 } 641 642 public static Image getChartIcon() { 643 return chartIcon; 644 } 645 646 public static Image getAnimationIcon() { 647 return animationIcon; 648 } 649 650 public static Image getAppsIcon() { 651 return iconAPPS; 652 } 653 654 public static Image getUrlIcon() { 655 return iconURL; 656 } 657 658 public static Image getVideoIcon() { 659 return iconVIDEO; 660 } 661 662 public static Image getXlsIcon() { 663 return iconXLS; 664 } 665 666 public static Image getPdfIcon() { 667 return iconPDF; 668 } 669 670 public static Image getAudioIcon() { 671 return iconAUDIO; 672 } 673 674 public static Image getQuestionIcon() { 675 return questionIcon; 676 } 677 678 public static void loadIcons() { 679 InputStream s = null; 680 // load icon images 681 try { 682 s = ViewProperties.class.getResourceAsStream("icons/hdf.gif"); 683 hdfIcon = new Image(null, s); 684 } 685 catch (Exception ex) { 686 hdfIcon = null; 687 log.trace("hdfIcon: null"); 688 } 689 690 try { 691 s = ViewProperties.class.getResourceAsStream("icons/hdf4.gif"); 692 h4Icon = new Image(null, s); 693 } 694 catch (Exception ex) { 695 h4Icon = null; 696 log.trace("h4Icon: null"); 697 } 698 699 try { 700 s = ViewProperties.class.getResourceAsStream("icons/hdf4R.gif"); 701 h4IconR = new Image(null, s); 702 } 703 catch (Exception ex) { 704 h4IconR = null; 705 log.trace("h4IconR: null"); 706 } 707 708 try { 709 s = ViewProperties.class.getResourceAsStream("icons/hdf5.gif"); 710 h5Icon = new Image(null, s); 711 } 712 catch (Exception ex) { 713 h5Icon = null; 714 log.trace("h5Icon: null"); 715 } 716 717 try { 718 s = ViewProperties.class.getResourceAsStream("icons/hdf5R.gif"); 719 h5IconR = new Image(null, s); 720 } 721 catch (Exception ex) { 722 h5IconR = null; 723 log.trace("h5IconR: null"); 724 } 725 726 try { 727 s = ViewProperties.class.getResourceAsStream("icons/hdfnc.gif"); 728 ncIcon = new Image(null, s); 729 } 730 catch (Exception ex) { 731 ncIcon = null; 732 log.trace("ncIcon: null"); 733 } 734 735 try { 736 s = ViewProperties.class.getResourceAsStream("icons/hdfncR.gif"); 737 ncIconR = new Image(null, s); 738 } 739 catch (Exception ex) { 740 ncIconR = null; 741 log.trace("ncIconR: null"); 742 } 743 744 try { 745 s = ViewProperties.class.getResourceAsStream("icons/folderclose.gif"); 746 foldercloseIcon = new Image(null, s); 747 } 748 catch (Exception ex) { 749 foldercloseIcon = null; 750 log.trace("foldercloseIcon: null"); 751 } 752 753 try { 754 s = ViewProperties.class.getResourceAsStream("icons/foldercloseA.gif"); 755 foldercloseIconA = new Image(null, s); 756 } 757 catch (Exception ex) { 758 foldercloseIconA = null; 759 log.trace("foldercloseIconA: null"); 760 } 761 762 try { 763 s = ViewProperties.class.getResourceAsStream("icons/folderopen.gif"); 764 folderopenIcon = new Image(null, s); 765 } 766 catch (Exception ex) { 767 folderopenIcon = null; 768 log.trace("folderopenIcon: null"); 769 } 770 771 try { 772 s = ViewProperties.class.getResourceAsStream("icons/folderopenA.gif"); 773 folderopenIconA = new Image(null, s); 774 } 775 catch (Exception ex) { 776 folderopenIconA = null; 777 log.trace("folderopenIconA: null"); 778 } 779 780 try { 781 s = ViewProperties.class.getResourceAsStream("icons/dataset.gif"); 782 datasetIcon = new Image(null, s); 783 } 784 catch (Exception ex) { 785 datasetIcon = null; 786 log.trace("datasetIcon: null"); 787 } 788 789 try { 790 s = ViewProperties.class.getResourceAsStream("icons/datasetA.gif"); 791 datasetIconA = new Image(null, s); 792 } 793 catch (Exception ex) { 794 datasetIconA = null; 795 log.trace("datasetIconA: null"); 796 } 797 798 try { 799 s = ViewProperties.class.getResourceAsStream("icons/datatype.gif"); 800 datatypeIcon = new Image(null, s); 801 } 802 catch (Exception ex) { 803 datatypeIcon = null; 804 log.trace("datatypeIcon: null"); 805 } 806 807 try { 808 s = ViewProperties.class.getResourceAsStream("icons/datatypeA.gif"); 809 datatypeIconA = new Image(null, s); 810 } 811 catch (Exception ex) { 812 datatypeIconA = null; 813 log.trace("datatypeIconA: null"); 814 } 815 816 try { 817 s = ViewProperties.class.getResourceAsStream("icons/link.gif"); 818 linkIcon = new Image(null, s); 819 } 820 catch (Exception ex) { 821 linkIcon = null; 822 log.trace("linkIcon: null"); 823 } 824 825 try { 826 s = ViewProperties.class.getResourceAsStream("icons/fileopen.gif"); 827 fileopenIcon = new Image(null, s); 828 } 829 catch (Exception ex) { 830 fileopenIcon = null; 831 log.trace("fileopenIcon: null"); 832 } 833 834 try { 835 s = ViewProperties.class.getResourceAsStream("icons/filesave.gif"); 836 filesaveIcon = new Image(null, s); 837 } 838 catch (Exception ex) { 839 filesaveIcon = null; 840 log.trace("filesaveIcon: null"); 841 } 842 843 try { 844 s = ViewProperties.class.getResourceAsStream("icons/filenew.gif"); 845 filenewIcon = new Image(null, s); 846 } 847 catch (Exception ex) { 848 filenewIcon = null; 849 log.trace("filenewIcon: null"); 850 } 851 852 try { 853 s = ViewProperties.class.getResourceAsStream("icons/fileclose.gif"); 854 filecloseIcon = new Image(null, s); 855 } 856 catch (Exception ex) { 857 filecloseIcon = null; 858 log.trace("filecloseIcon: null"); 859 } 860 861 try { 862 s = ViewProperties.class.getResourceAsStream("icons/palette.gif"); 863 paletteIcon = new Image(null, s); 864 } 865 catch (Exception ex) { 866 paletteIcon = null; 867 log.trace("paletteIcon: null"); 868 } 869 870 try { 871 s = ViewProperties.class.getResourceAsStream("icons/brightness.gif"); 872 brightIcon = new Image(null, s); 873 } 874 catch (Exception ex) { 875 brightIcon = null; 876 log.trace("brightIcon: null"); 877 } 878 879 try { 880 s = ViewProperties.class.getResourceAsStream("icons/autocontrast.gif"); 881 autocontrastIcon = new Image(null, s); 882 } 883 catch (Exception ex) { 884 autocontrastIcon = null; 885 log.trace("autocontrastIcon: null"); 886 } 887 888 try { 889 s = ViewProperties.class.getResourceAsStream("icons/image.gif"); 890 imageIcon = new Image(null, s); 891 } 892 catch (Exception ex) { 893 imageIcon = null; 894 log.trace("imageIcon: null"); 895 } 896 897 try { 898 s = ViewProperties.class.getResourceAsStream("icons/imageA.gif"); 899 imageIconA = new Image(null, s); 900 } 901 catch (Exception ex) { 902 imageIconA = null; 903 log.trace("imageIconA: null"); 904 } 905 906 try { 907 s = ViewProperties.class.getResourceAsStream("icons/table.gif"); 908 tableIcon = new Image(null, s); 909 } 910 catch (Exception ex) { 911 tableIcon = null; 912 log.trace("tableIcon: null"); 913 } 914 915 try { 916 s = ViewProperties.class.getResourceAsStream("icons/tableA.gif"); 917 tableIconA = new Image(null, s); 918 } 919 catch (Exception ex) { 920 tableIconA = null; 921 log.trace("tableIconA: null"); 922 } 923 924 try { 925 s = ViewProperties.class.getResourceAsStream("icons/text.gif"); 926 textIcon = new Image(null, s); 927 } 928 catch (Exception ex) { 929 textIcon = null; 930 log.trace("textIcon: null"); 931 } 932 933 try { 934 s = ViewProperties.class.getResourceAsStream("icons/textA.gif"); 935 textIconA = new Image(null, s); 936 } 937 catch (Exception ex) { 938 textIconA = null; 939 log.trace("textIconA: null"); 940 } 941 942 try { 943 s = ViewProperties.class.getResourceAsStream("icons/zoomin.gif"); 944 zoominIcon = new Image(null, s); 945 } 946 catch (Exception ex) { 947 zoominIcon = null; 948 log.trace("iconAUzoominIconDIO: null"); 949 } 950 951 try { 952 s = ViewProperties.class.getResourceAsStream("icons/zoomout.gif"); 953 zoomoutIcon = new Image(null, s); 954 } 955 catch (Exception ex) { 956 zoomoutIcon = null; 957 log.trace("zoomoutIcon: null"); 958 } 959 960 try { 961 s = ViewProperties.class.getResourceAsStream("icons/blank.gif"); 962 blankIcon = new Image(null, s); 963 } 964 catch (Exception ex) { 965 blankIcon = null; 966 log.trace("blankIcon: null"); 967 } 968 969 try { 970 s = ViewProperties.class.getResourceAsStream("icons/help.gif"); 971 helpIcon = new Image(null, s); 972 } 973 catch (Exception ex) { 974 helpIcon = null; 975 log.trace("helpIcon: null"); 976 } 977 978 try { 979 s = ViewProperties.class.getResourceAsStream("icons/copy.gif"); 980 copyIcon = new Image(null, s); 981 } 982 catch (Exception ex) { 983 copyIcon = null; 984 log.trace("copyIcon: null"); 985 } 986 987 try { 988 s = ViewProperties.class.getResourceAsStream("icons/cut.gif"); 989 cutIcon = new Image(null, s); 990 } 991 catch (Exception ex) { 992 cutIcon = null; 993 log.trace("cutIcon: null"); 994 } 995 996 try { 997 s = ViewProperties.class.getResourceAsStream("icons/paste.gif"); 998 pasteIcon = new Image(null, s); 999 } 1000 catch (Exception ex) { 1001 pasteIcon = null; 1002 log.trace("pasteIcon: null"); 1003 } 1004 1005 try { 1006 s = ViewProperties.class.getResourceAsStream("icons/hdf_large.gif"); 1007 largeHdfIcon = new Image(null, s); 1008 } 1009 catch (Exception ex) { 1010 largeHdfIcon = null; 1011 log.trace("largeHdfIcon: null"); 1012 } 1013 1014 try { 1015 s = ViewProperties.class.getResourceAsStream("icons/previous.gif"); 1016 previousIcon = new Image(null, s); 1017 } 1018 catch (Exception ex) { 1019 previousIcon = null; 1020 log.trace("previousIcon: null"); 1021 } 1022 1023 try { 1024 s = ViewProperties.class.getResourceAsStream("icons/next.gif"); 1025 nextIcon = new Image(null, s); 1026 } 1027 catch (Exception ex) { 1028 nextIcon = null; 1029 log.trace("nextIcon: null"); 1030 } 1031 1032 try { 1033 s = ViewProperties.class.getResourceAsStream("icons/first.gif"); 1034 firstIcon = new Image(null, s); 1035 } 1036 catch (Exception ex) { 1037 firstIcon = null; 1038 log.trace("firstIcon: null"); 1039 } 1040 1041 try { 1042 s = ViewProperties.class.getResourceAsStream("icons/last.gif"); 1043 lastIcon = new Image(null, s); 1044 } 1045 catch (Exception ex) { 1046 lastIcon = null; 1047 log.trace("lastIcon: null"); 1048 } 1049 1050 try { 1051 s = ViewProperties.class.getResourceAsStream("icons/chart.gif"); 1052 chartIcon = new Image(null, s); 1053 } 1054 catch (Exception ex) { 1055 chartIcon = null; 1056 log.trace("chartIcon: null"); 1057 } 1058 1059 try { 1060 s = ViewProperties.class.getResourceAsStream("icons/animation.gif"); 1061 animationIcon = new Image(null, s); 1062 } 1063 catch (Exception ex) { 1064 animationIcon = null; 1065 log.trace("animationIcon: null"); 1066 } 1067 1068 try { 1069 s = ViewProperties.class.getResourceAsStream("icons/question.gif"); 1070 questionIcon = new Image(null, s); 1071 } 1072 catch (Exception ex) { 1073 questionIcon = null; 1074 log.trace("questionIcon: null"); 1075 } 1076 1077 try { 1078 s = ViewProperties.class.getResourceAsStream("icons/audio.gif"); 1079 iconAUDIO = new Image(null, s); 1080 } 1081 catch (Exception ex) { 1082 iconAUDIO = null; 1083 log.trace("iconAUDIO: null"); 1084 } 1085 1086 try { 1087 s = ViewProperties.class.getResourceAsStream("icons/xls.gif"); 1088 iconXLS = new Image(null, s); 1089 } 1090 catch (Exception ex) { 1091 iconXLS = null; 1092 log.trace("iconXLS: null"); 1093 } 1094 1095 try { 1096 s = ViewProperties.class.getResourceAsStream("icons/pdf.gif"); 1097 iconPDF = new Image(null, s); 1098 } 1099 catch (Exception ex) { 1100 iconPDF = null; 1101 log.trace("iconPDF: null"); 1102 } 1103 1104 try { 1105 s = ViewProperties.class.getResourceAsStream("icons/apps.gif"); 1106 iconAPPS = new Image(null, s); 1107 } 1108 catch (Exception ex) { 1109 iconAPPS = null; 1110 log.trace("iconAPPS: null"); 1111 } 1112 1113 try { 1114 s = ViewProperties.class.getResourceAsStream("icons/url.gif"); 1115 iconURL = new Image(null, s); 1116 } 1117 catch (Exception ex) { 1118 iconURL = null; 1119 log.trace("iconURL: null"); 1120 } 1121 1122 try { 1123 s = ViewProperties.class.getResourceAsStream("icons/video.gif"); 1124 iconVIDEO = new Image(null, s); 1125 } 1126 catch (Exception ex) { 1127 iconVIDEO = null; 1128 log.trace("iconVIDEO: null"); 1129 } 1130 } 1131 1132 /** 1133 * Load user properties from property file 1134 * 1135 * @throws IOException 1136 * if a failure occurred 1137 */ 1138 @Override 1139 @SuppressWarnings({ "rawtypes", "unchecked" }) 1140 public void load() throws IOException { 1141 super.load(); 1142 1143 if (propertyFile == null) 1144 return; 1145 1146 String propVal = null; 1147 1148 // add default module. 1149 log.trace("load user properties: add default modules"); 1150 String[] moduleKeys = { "module.treeview", "module.metadataview", "module.tableview", 1151 "module.imageview", "module.paletteview" }; 1152 ArrayList[] moduleList = { moduleListTreeView, moduleListMetaDataView, moduleListTableView, 1153 moduleListImageView, moduleListPaletteView }; 1154 String[] moduleNames = { DEFAULT_MODULE_TEXT, DEFAULT_MODULE_TEXT, DEFAULT_MODULE_TEXT, 1155 DEFAULT_MODULE_TEXT, DEFAULT_MODULE_TEXT }; 1156 1157 // add default implementation of modules 1158 log.trace("load user properties: modules"); 1159 for (int i = 0; i < moduleNames.length; i++) { 1160 if (!moduleList[i].contains(moduleNames[i])) 1161 moduleList[i].add(moduleNames[i]); 1162 log.trace("load: add default moduleList[{}] is {}", i, moduleNames[i]); 1163 } 1164 log.trace("load Ext Class modules"); 1165 if (extClassLoader == null) loadExtClass(); 1166 1167 // set default selection of data views 1168 log.trace("load user properties: set default selection of data views"); 1169 for (int i = 0; i < moduleNames.length; i++) { 1170 ArrayList<String> theList = moduleList[i]; 1171 propVal = getString(moduleKeys[i]); 1172 if (log.isTraceEnabled()) { 1173 log.trace("load: default theList is {}", Arrays.toString(theList.toArray())); 1174 } 1175 1176 if ((propVal != null) && (propVal.length() > 0)) { 1177 // set default to the module specified in property file 1178 if (theList.size() > 1) { 1179 if (theList.contains(propVal)) 1180 theList.remove(propVal); 1181 theList.add(0, propVal); 1182 } 1183 log.trace("load user properties: module[{}]={}", i, propVal); 1184 } 1185 else { 1186 // use default module 1187 if (theList.size() > 1) { 1188 if (theList.contains(moduleNames[i])) 1189 theList.remove(moduleNames[i]); 1190 theList.add(0, moduleNames[i]); 1191 } 1192 log.trace("load user properties: default module[{}]={}", i, moduleNames[i]); 1193 } 1194 if (log.isTraceEnabled()) { 1195 log.trace("load: final theList is {}", Arrays.toString(theList.toArray())); 1196 } 1197 } 1198 1199 // add fileformat modules 1200 log.trace("load user properties: fileformat modules"); 1201 String[] localEnum = this.preferenceNames(); 1202 String fExt = null; 1203 for (String theKey : localEnum) { 1204 log.trace("load: add prop {}", theKey); 1205 if (theKey.startsWith("module.fileformat")) { 1206 fExt = theKey.substring(18); 1207 try { 1208 // enables use of JHDF5 in JNLP (Web Start) applications, 1209 // the system class loader with reflection first. 1210 String className = getString(theKey); 1211 Class theClass = null; 1212 try { 1213 theClass = Class.forName(className); 1214 } 1215 catch (Exception ex) { 1216 try { 1217 theClass = extClassLoader.loadClass(className); 1218 } 1219 catch (Exception ex2) { 1220 log.debug("load: extClassLoader.loadClass({}) failed", className, ex2); 1221 } 1222 } 1223 1224 Object theObject = theClass.newInstance(); 1225 if (theObject instanceof FileFormat) { 1226 FileFormat.addFileFormat(fExt, (FileFormat) theObject); 1227 } 1228 } 1229 catch (Exception err) { 1230 log.debug("load: load file format failed", err); 1231 } 1232 } 1233 } 1234 1235 propVal = getString("users.guide"); 1236 if (!isDefault("users.guide")) 1237 setUsersGuide(propVal); 1238 1239 propVal = getString("image.contrast"); 1240 if (!isDefault("image.contrast")) 1241 setAutoContrast("auto".equalsIgnoreCase(propVal)); 1242 1243 setShowImageValue(getBoolean("image.showvalues")); 1244 1245 propVal = getString("file.mode"); 1246 if (!isDefault("file.mode")) 1247 setReadOnly("r".equalsIgnoreCase(propVal)); 1248 1249 setEarlyLib(getString("lib.lowversion")); 1250 1251 setLateLib(getString("lib.highversion")); 1252 1253 setConvertEnum(getBoolean("enum.conversion")); 1254 1255 setShowRegRefValue(getBoolean("regref.showvalues")); 1256 1257 setIndexBase1(getBoolean("index.base1")); 1258 1259 propVal = getString("data.delimiter"); 1260 if (!isDefault("data.delimiter")) 1261 setDataDelimiter(propVal); 1262 1263 propVal = getString("image.origin"); 1264 if (!isDefault("image.origin")) 1265 setImageOrigin(propVal); 1266 1267 propVal = getString("h5file.indexType"); 1268 if (!isDefault("h5file.indexType")) 1269 setIndexType(propVal); 1270 1271 propVal = getString("h5file.indexOrder"); 1272 if (!isDefault("h5file.indexOrder")) 1273 setIndexOrder(propVal); 1274 1275 propVal = getString("h4toh5.converter"); 1276 if (!isDefault("h4toh5.converter")) 1277 setH4toH5(propVal); 1278 1279 propVal = getString("work.dir"); 1280 if (!isDefault("work.dir")) 1281 setWorkDir(propVal); 1282 1283 propVal = getString("file.extension"); 1284 if (!isDefault("file.extension")) { 1285 setFileExtension(propVal); 1286 FileFormat.addFileExtension(fileExt); 1287 } 1288 1289 setFontSize(getInt("font.size")); 1290 1291 propVal = getString("font.type"); 1292 if (!isDefault("font.type")) 1293 setFontType(propVal.trim()); 1294 1295 setMaxMembers(getInt("max.members")); 1296 1297 // load the most recent file list from the property file 1298 log.trace("load user properties: most recent file list"); 1299 String theFile = null; 1300 for (int i = 0; i < MAX_RECENT_FILES; i++) { 1301 theFile = getString("recent.file" + i); 1302 if ((theFile != null) && !recentFiles.contains(theFile)) { 1303 if (theFile.startsWith("http://") || theFile.startsWith("ftp://") || (new File(theFile)).exists()) { 1304 recentFiles.add(theFile); 1305 } 1306 } 1307 } 1308 1309 // load the most recent palette file list from the property file 1310 log.trace("load user properties: most recent palette file list"); 1311 for (int i = 0; i < MAX_RECENT_FILES; i++) { 1312 theFile = getString("palette.file" + i); 1313 if (theFile != null) theFile = theFile.trim(); 1314 1315 if ((theFile != null && theFile.length() > 0) && !paletteList.contains(theFile)) { 1316 if ((new File(theFile)).exists()) { 1317 paletteList.add(theFile); 1318 } 1319 } 1320 } 1321 1322 // load srb account 1323 // log.trace("load user properties: srb account"); 1324 // propVal = null; 1325 // String srbaccount[] = new String[7]; 1326 // (int i = 0; i < MAX_RECENT_FILES; i++) { 1327 // (null == (srbaccount[0] = getString("srbaccount" + i + ".host"))) 1328 // continue; 1329 // 1330 // (null == (srbaccount[1] = getString("srbaccount" + i + ".port"))) 1331 // continue; 1332 // 1333 // (null == (srbaccount[2] = getString("srbaccount" + i + ".user"))) 1334 // continue; 1335 // 1336 // (null == (srbaccount[3] = getString("srbaccount" + i + ".password"))) 1337 // continue; 1338 // 1339 // (null == (srbaccount[4] = getString("srbaccount" + i + ".home"))) 1340 // continue; 1341 // 1342 // (null == (srbaccount[5] = getString("srbaccount" + i + ".domain"))) 1343 // continue; 1344 // 1345 // (null == (srbaccount[6] = getString("srbaccount" + i + ".resource"))) 1346 // continue; 1347 // 1348 // srbAccountList.add(srbaccount); 1349 // srbaccount = new String[7]; 1350 // } 1351 } 1352 1353 /** 1354 * Save user properties into property file 1355 * 1356 * @throws IOException 1357 * if a failure occurred 1358 */ 1359 @Override 1360 public void save() throws IOException { 1361 if (propertyFile == null) 1362 return; 1363 1364 // update data saving options 1365 if (delimiter == null) 1366 setDefault("data.delimiter", DELIMITER_TAB); 1367 else 1368 setValue("data.delimiter", delimiter); 1369 1370 if (origin == null) 1371 setDefault("image.origin", ORIGIN_UL); 1372 else 1373 setValue("image.origin", origin); 1374 1375 if (indexType != null) setValue("h5file.indexType", indexType); 1376 1377 if (indexOrder != null) setValue("h5file.indexOrder", indexOrder); 1378 1379 if (usersGuide != null) setValue("users.guide", usersGuide); 1380 1381 if (workDir != null) setValue("work.dir", workDir); 1382 1383 if (fileExt != null) setValue("file.extension", fileExt); 1384 1385 if (h4toh5 != null) setValue("h4toh5.converter", h4toh5); 1386 1387 setValue("font.size", fontSize); 1388 1389 if (fontType != null) setValue("font.type", fontType); 1390 1391 setValue("max.members", maxMembers); 1392 1393 if (isAutoContrast) 1394 setValue("image.contrast", "auto"); 1395 else 1396 setValue("image.contrast", "general"); 1397 1398 setValue("image.showvalues", showImageValues); 1399 1400 if (isReadOnly) 1401 setValue("file.mode", "r"); 1402 else 1403 setValue("file.mode", "rw"); 1404 1405 log.trace("save user properties: lib.lowversion={}", EarlyLib); 1406 setValue("lib.lowversion", EarlyLib); 1407 log.trace("save user properties: lib.highversion={}", LateLib); 1408 setValue("lib.highversion", LateLib); 1409 1410 setValue("enum.conversion", convertEnum); 1411 setValue("regref.showvalues", showRegRefValues); 1412 setValue("index.base1", isIndexBase1); 1413 1414 // save the list of most recent files 1415 log.trace("save user properties: most recent files"); 1416 String theFile; 1417 int size = recentFiles.size(); 1418 int minSize = Math.min(size, MAX_RECENT_FILES); 1419 log.trace("save user properties: most recent files size={}", size); 1420 for (int i = 0; i < minSize; i++) { 1421 theFile = recentFiles.get(i); 1422 if ((theFile != null) && (theFile.length() > 0)) setValue("recent.file" + i, theFile); 1423 } 1424 1425 // save the list of most recent palette files 1426 log.trace("save user properties: most recent palette files"); 1427 size = paletteList.size(); 1428 minSize = Math.min(size, MAX_RECENT_FILES); 1429 for (int i = 0; i < minSize; i++) { 1430 theFile = paletteList.get(i); 1431 if ((theFile != null) && (theFile.length() > 0)) setValue("palette.file" + i, theFile); 1432 } 1433 1434 // save srb account 1435 // log.trace("save user properties: srb account"); 1436 // String srbaccount[] = null; 1437 // size = srbAccountList.size(); 1438 // minSize = Math.min(size, MAX_RECENT_FILES); 1439 // (int i = 0; i < minSize; i++) { 1440 // srbaccount = srbAccountList.get(i); 1441 // ((srbaccount[0] != null) && (srbaccount[1] != null) && (srbaccount[2] != 1442 // null) 1443 // && (srbaccount[3] != null) && (srbaccount[4] != null) && (srbaccount[5] != 1444 // null) 1445 // && (srbaccount[6] != null)) { 1446 // setValue("srbaccount" + i + ".host", srbaccount[0]); 1447 // setValue("srbaccount" + i + ".port", srbaccount[1]); 1448 // setValue("srbaccount" + i + ".user", srbaccount[2]); 1449 // setValue("srbaccount" + i + ".password", srbaccount[3]); 1450 // setValue("srbaccount" + i + ".home", srbaccount[4]); 1451 // setValue("srbaccount" + i + ".domain", srbaccount[5]); 1452 // setValue("srbaccount" + i + ".resource", srbaccount[6]); 1453 // } 1454 // } 1455 1456 // save default modules 1457 log.trace("save user properties: default modules"); 1458 String moduleName = moduleListTreeView.get(0); 1459 if ((moduleName != null) && (moduleName.length() > 0)) setValue("module.treeview", moduleName); 1460 log.trace("save user properties: module.treeview={}", moduleName); 1461 1462 moduleName = moduleListMetaDataView.get(0); 1463 if ((moduleName != null) && (moduleName.length() > 0)) setValue("module.metadataview", moduleName); 1464 log.trace("save user properties: module.metadataview={}", moduleName); 1465 1466 moduleName = moduleListTableView.get(0); 1467 if ((moduleName != null) && (moduleName.length() > 0)) setValue("module.tableview", moduleName); 1468 log.trace("save user properties: module.tableview={}", moduleName); 1469 1470 moduleName = moduleListImageView.get(0); 1471 if ((moduleName != null) && (moduleName.length() > 0)) setValue("module.imageview", moduleName); 1472 log.trace("save user properties: module.imageview={}", moduleName); 1473 1474 moduleName = moduleListPaletteView.get(0); 1475 if ((moduleName != null) && (moduleName.length() > 0)) setValue("module.paletteview", moduleName); 1476 log.trace("save user properties: module.paletteview={}", moduleName); 1477 1478 // save the current supported fileformat 1479 log.trace("save user properties: supported fileformat"); 1480 Enumeration<?> keys = FileFormat.getFileFormatKeys(); 1481 String theKey = null; 1482 while (keys.hasMoreElements()) { 1483 theKey = (String) keys.nextElement(); 1484 FileFormat theformat = FileFormat.getFileFormat(theKey); 1485 setValue("module.fileformat." + theKey, theformat.getClass().getName()); 1486 } 1487 1488 super.save(); 1489 } 1490 1491 /** @return the name of the user property file */ 1492 public static String getPropertyFile() { 1493 return propertyFile; 1494 } 1495 1496 /** @return the root directory where the HDFView is installed. */ 1497 public static String getViewRoot() { 1498 return rootDir; 1499 } 1500 1501 /** @return the default work directory, where the open file starts. */ 1502 public static String getWorkDir() { 1503 String workPath = workDir; 1504 log.trace("getWorkDir: workDir={}", workDir); 1505 if (workPath == null) { 1506 workPath = System.getProperty("hdfview.workdir"); 1507 log.trace("getWorkDir: hdfview.workdir={}", workPath); 1508 if (workPath == null) { 1509 workPath = System.getProperty("user.home"); 1510 } 1511 } 1512 log.trace("getWorkDir: final workPath={}", workPath); 1513 return workPath; 1514 } 1515 1516 /** @return the maximum number of the most recent file */ 1517 public static int getMaxRecentFiles() { 1518 return MAX_RECENT_FILES; 1519 } 1520 1521 /** @return the path of the HDFView users guide */ 1522 public static String getUsersGuide() { 1523 return usersGuide; 1524 }; 1525 1526 /** @return the delimiter of data values */ 1527 public static String getDataDelimiter() { 1528 return delimiter; 1529 } 1530 1531 /** @return the image origin */ 1532 public static String getImageOrigin() { 1533 return origin; 1534 } 1535 1536 /** @return the default index type for display */ 1537 public static String getIndexType() { 1538 return indexType; 1539 } 1540 1541 /** @return the default index order for display */ 1542 public static String getIndexOrder() { 1543 return indexOrder; 1544 } 1545 1546 /** @return the font size */ 1547 public static int getFontSize() { 1548 return fontSize; 1549 } 1550 1551 /** @return the font type */ 1552 public static String getFontType() { 1553 return fontType; 1554 } 1555 1556 /** @return the file extensions of supported file formats */ 1557 public static String getFileExtension() { 1558 return fileExt; 1559 } 1560 1561 /** sets the font size 1562 * 1563 * @param fsize 1564 * the font size 1565 */ 1566 public static void setFontSize(int fsize) { 1567 fontSize = (fsize / 2) * 2; 1568 1569 if (fontSize < 8) { 1570 fontSize = 8; 1571 } 1572 } 1573 1574 /** sets the font type 1575 * 1576 * @param ftype 1577 * the font type 1578 */ 1579 public static void setFontType(String ftype) { 1580 if (ftype != null) { 1581 fontType = ftype.trim(); 1582 } 1583 } 1584 1585 /** @return the path of the H5toH5 converter */ 1586 public static String getH4toH5() { 1587 return h4toh5; 1588 } 1589 1590 /** @return the list of most recent files */ 1591 public static List<String> getMRF() { 1592 return recentFiles; 1593 } 1594 1595 /** @return the list of palette files */ 1596 public static List<String> getPaletteList() { 1597 return paletteList; 1598 } 1599 1600 public static List<String[]> getSrbAccount() { 1601 return srbAccountList; 1602 } 1603 1604 /** @return a list of treeview modules */ 1605 public static List<String> getTreeViewList() { 1606 return moduleListTreeView; 1607 } 1608 1609 /** @return a list of metadataview modules */ 1610 public static List<String> getMetaDataViewList() { 1611 return moduleListMetaDataView; 1612 } 1613 1614 /** @return a list of tableview modules */ 1615 public static List<String> getTableViewList() { 1616 return moduleListTableView; 1617 } 1618 1619 /** @return a list of imageview modules */ 1620 public static List<String> getImageViewList() { 1621 return moduleListImageView; 1622 } 1623 1624 /** @return a list of paletteview modules */ 1625 public static List<String> getPaletteViewList() { 1626 return moduleListPaletteView; 1627 } 1628 1629 /** @return a list of helpview modules */ 1630 public static List<String> getHelpViewList() { 1631 return moduleListHelpView; 1632 } 1633 1634 /** set the path of H5View User's guide 1635 * 1636 * @param str 1637 * the path 1638 */ 1639 public static void setUsersGuide(String str) { 1640 if ((str == null) || (str.length() <= 0)) { 1641 return; 1642 } 1643 usersGuide = str; 1644 } 1645 1646 /** set the path of the H4 to H5 converter 1647 * 1648 * @param tool 1649 * the path of the H4 to H5 converter 1650 */ 1651 public static void setH4toH5(String tool) { 1652 h4toh5 = tool; 1653 } 1654 1655 /** 1656 * set the path of the default root directory 1657 * 1658 * @param rDir 1659 * the default root directory 1660 */ 1661 public static void setRootDir(String rDir) { 1662 log.trace("ViewProperties:setRootDir rDir={}", rDir); 1663 rootDir = rDir; 1664 } 1665 1666 /** set the path of the default work directory 1667 * 1668 * @param wDir 1669 * the default work directory 1670 */ 1671 public static void setWorkDir(String wDir) { 1672 log.trace("ViewProperties:setWorkDir wDir={}", wDir); 1673 workDir = wDir; 1674 } 1675 1676 /** set the file extension 1677 * 1678 * @param ext 1679 * the file extension 1680 */ 1681 public static void setFileExtension(String ext) { 1682 fileExt = ext; 1683 } 1684 1685 /** set the delimiter of data values 1686 * 1687 * @param delim 1688 * the delimiter of data values 1689 */ 1690 public static void setDataDelimiter(String delim) { 1691 delimiter = delim; 1692 } 1693 1694 /** set the image origin 1695 * 1696 * @param o 1697 * the image origin 1698 */ 1699 public static void setImageOrigin(String o) { 1700 origin = o; 1701 } 1702 1703 /** set the index type 1704 * 1705 * @param idxType 1706 * the index type 1707 */ 1708 public static void setIndexType(String idxType) { 1709 indexType = idxType; 1710 } 1711 1712 /** set the index order 1713 * 1714 * @param idxOrder 1715 * the index order 1716 */ 1717 public static void setIndexOrder(String idxOrder) { 1718 indexOrder = idxOrder; 1719 } 1720 1721 /** 1722 * Current Java applications such as HDFView cannot handle files with large 1723 * number of objects such as 1,000,000 objects. setMaxMembers() sets the 1724 * maximum number of objects that will be loaded into memory. 1725 * 1726 * @param n 1727 * the maximum number of objects to load into memory 1728 */ 1729 public static void setMaxMembers(int n) { 1730 maxMembers = n; 1731 } 1732 1733 /** 1734 * Current Java applications such as HDFView cannot handle files with large 1735 * number of objects such as 1,000,000 objects. setStartMember() sets the 1736 * starting index of objects that will be loaded into memory. 1737 * 1738 * @param idx 1739 * the maximum number of objects to load into memory 1740 */ 1741 public static void setStartMembers(int idx) { 1742 if (idx < 0) { 1743 idx = 0; 1744 } 1745 1746 startMembers = idx; 1747 } 1748 1749 /** 1750 * Current Java applications such as HDFView cannot handle files with large 1751 * number of objects such as 1,000,000 objects. getMaxMembers() returns the 1752 * maximum number of objects that will be loaded into memory. 1753 * 1754 * @return the maximum members 1755 */ 1756 public static int getMaxMembers() { 1757 if (maxMembers < 0) 1758 return Integer.MAX_VALUE; // load the whole file 1759 1760 return maxMembers; 1761 } 1762 1763 /** 1764 * Current Java applications such as HDFView cannot handle files with large 1765 * number of objects such as 1,000,000 objects. getStartMembers() returns the 1766 * starting index of objects that will be loaded into memory. 1767 * 1768 * @return the start members 1769 */ 1770 public static int getStartMembers() { 1771 return startMembers; 1772 } 1773 1774 /** 1775 * Returns true if auto contrast is used in image processing. 1776 * 1777 * @return true if auto contrast is used in image processing; otherwise, 1778 * returns false. 1779 */ 1780 public static boolean isAutoContrast() { 1781 return isAutoContrast; 1782 } 1783 1784 /** 1785 * Returns true if "show image values" is set. 1786 * 1787 * @return true if "show image values" is set; otherwise, returns false. 1788 */ 1789 public static boolean showImageValues() { 1790 return showImageValues; 1791 } 1792 1793 /** 1794 * Set the flag to indicate if auto contrast is used in image process. 1795 * 1796 * @param b 1797 * the flag to indicate if auto contrast is used in image 1798 * process. 1799 */ 1800 public static void setAutoContrast(boolean b) { 1801 isAutoContrast = b; 1802 } 1803 1804 /** 1805 * Set the flag to indicate if "show image values" is set. 1806 * 1807 * @param b 1808 * the flag to indicate if if "show image values" is set. 1809 */ 1810 public static void setShowImageValue(boolean b) { 1811 showImageValues = b; 1812 } 1813 1814 /** 1815 * Returns true if default file access is read only. 1816 * 1817 * @return true if default file access is read only; otherwise, returns 1818 * false. 1819 */ 1820 public static boolean isReadOnly() { 1821 return isReadOnly; 1822 } 1823 1824 /** 1825 * Set the flag to indicate if default file access is read only. 1826 * 1827 * @param b 1828 * the flag to indicate if default file access is read only. 1829 */ 1830 public static void setReadOnly(boolean b) { 1831 isReadOnly = b; 1832 } 1833 1834 /** 1835 * Returns value of default lib version for the earliest. 1836 * 1837 * @return value of default lib version for the earliest. 1838 */ 1839 public static String getEarlyLib() { 1840 return EarlyLib; 1841 } 1842 1843 /** 1844 * Set the value of default lib version for the earliest. 1845 * 1846 * @param vers 1847 * the value of default lib version for the earliest. 1848 */ 1849 public static void setEarlyLib(String vers) { 1850 EarlyLib = vers; 1851 } 1852 1853 /** 1854 * Returns value of default lib version for the latest. 1855 * 1856 * @return value of default lib version for the latest. 1857 */ 1858 public static String getLateLib() { 1859 return LateLib; 1860 } 1861 1862 /** 1863 * Set the value of default lib version for the latest. 1864 * 1865 * @param vers 1866 * the value of default lib version for the latest. 1867 */ 1868 public static void setLateLib(String vers) { 1869 LateLib = vers; 1870 } 1871 1872 /** 1873 * @return the convertEnum 1874 */ 1875 public static boolean isConvertEnum() { 1876 return convertEnum; 1877 } 1878 1879 /** 1880 * Returns true if "show regref values" is set. 1881 * 1882 * @return true if "show regref values" is set; otherwise, returns false. 1883 */ 1884 public static boolean showRegRefValues() { 1885 return showRegRefValues; 1886 } 1887 1888 /** 1889 * @return the isIndexBase1 1890 */ 1891 public static boolean isIndexBase1() { 1892 return isIndexBase1; 1893 } 1894 1895 /** 1896 * @param convertEnum 1897 * the convertEnum to set 1898 */ 1899 public static void setConvertEnum(boolean convertEnum) { 1900 ViewProperties.convertEnum = convertEnum; 1901 } 1902 1903 /** 1904 * Set the flag to indicate if "show RegRef values" is set. 1905 * 1906 * @param b 1907 * the flag to indicate if if "show RegRef values" is set. 1908 */ 1909 public static void setShowRegRefValue(boolean b) { 1910 showRegRefValues = b; 1911 } 1912 1913 /** 1914 * Set the flag to indicate if IndexBase should start at 1. 1915 * 1916 * @param b 1917 * the flag to indicate if IndexBase should start at 1. 1918 */ 1919 public static void setIndexBase1(boolean b) { 1920 ViewProperties.isIndexBase1 = b; 1921 } 1922 1923 /** 1924 * Sets the list of most recently accessed files. 1925 * 1926 * @param recentFilesList 1927 * The list of most recently accessed files. 1928 */ 1929 public static void setRecentFiles(ArrayList<String> recentFilesList) { 1930 recentFiles = recentFilesList; 1931 } 1932}