    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 org.slf4j.Logger;
    018import org.slf4j.LoggerFactory;
    019
    020import org.eclipse.swt.widgets.Shell;
    021
    022import hdf.view.Tools;
    023import hdf.view.ViewProperties;
    024import hdf.view.DataView.DataViewManager;
    025import hdf.view.ImageView.ImageView;
    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) throws ClassNotFoundException {
    040        String dataViewName = null;
    041        Object[] initargs;
    042        PaletteView theView = null;
    043
    044        dataViewName = ViewProperties.DEFAULT_PALETTEVIEW_NAME;
    045
    046        Class<?> theClass = null;
    047        try {
    048            log.trace("getPaletteView(): Class.forName({})", dataViewName);
    049
    050            /* Attempt to load the class by the given name */
    051            theClass = Class.forName(dataViewName);
    052        }
    053        catch (Exception ex) {
    054            log.debug("getPaletteView(): unable to load default PaletteView class by name({})", dataViewName);
    055            theClass = null;
    056        }
    057
    058        if (theClass == null) throw new ClassNotFoundException();
    059
    060        try {
    061            initargs = new Object[] { parent, viewer, theImageView };
    062
    063            theView = (PaletteView) Tools.newInstance(theClass, initargs);
    064
    065            log.trace("getPaletteView(): returning PaletteView instance {}", theView);
    066        }
    067        catch (Exception ex) {
    068            log.debug("getPaletteView(): Error instantiating class:", ex);
    069            theView = null;
    070        }
    071
    072        return theView;
    073    }
    074
    075}