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