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