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