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