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