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