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