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