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.PaletteView;
016
017import hdf.view.DataView.DataViewManager;
018import hdf.view.ImageView.ImageView;
019import hdf.view.Tools;
020import hdf.view.ViewProperties;
021
022import org.slf4j.Logger;
023import org.slf4j.LoggerFactory;
024
025import org.eclipse.swt.widgets.Shell;
026
027/**
028 * A simple Factory class which returns concrete instances of the default
029 * PaletteView.
030 *
031 * @author jhenderson
032 * @version 1.0 4/18/2018
033 */
034public class DefaultPaletteViewFactory extends PaletteViewFactory {
035
036    private static final Logger log = LoggerFactory.getLogger(DefaultPaletteViewFactory.class);
037
038    @Override
039    public PaletteView getPaletteView(Shell parent, DataViewManager viewer, ImageView theImageView)
040        throws ClassNotFoundException
041    {
042        String dataViewName = null;
043        Object[] initargs;
044        PaletteView theView = null;
045
046        dataViewName = ViewProperties.DEFAULT_PALETTEVIEW_NAME;
047
048        Class<?> theClass = null;
049        try {
050            log.trace("getPaletteView(): Class.forName({})", dataViewName);
051
052            /* Attempt to load the class by the given name */
053            theClass = Class.forName(dataViewName);
054        }
055        catch (Exception ex) {
056            log.debug("getPaletteView(): unable to load default PaletteView class by name({})", dataViewName);
057            theClass = null;
058        }
059
060        if (theClass == null)
061            throw new ClassNotFoundException();
062
063        try {
064            initargs = new Object[] {parent, viewer, theImageView};
065
066            theView = (PaletteView)Tools.newInstance(theClass, initargs);
067
068            log.trace("getPaletteView(): returning PaletteView instance {}", theView);
069        }
070        catch (Exception ex) {
071            log.debug("getPaletteView(): Error instantiating class:", ex);
072            theView = null;
073        }
074
075        return theView;
076    }
077}