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