001/***************************************************************************** 002 * Copyright by The HDF Group. * 003 * Copyright by the Board of Trustees of the University of Illinois. * 004 * All rights reserved. * 005 * * 006 * This file is part of the HDF Java Products distribution. * 007 * The full copyright notice, including terms governing use, modification, * 008 * and redistribution, is contained in the files COPYING and Copyright.html. * 009 * COPYING can be found at the root of the source code distribution tree. * 010 * Or, see https://support.hdfgroup.org/products/licenses.html * 011 * If you do not have access to either file, you may request a copy from * 012 * help@hdfgroup.org. * 013 ****************************************************************************/ 014 015package hdf.view.PaletteView; 016 017import org.eclipse.swt.widgets.Shell; 018 019import hdf.view.Tools; 020import hdf.view.ViewProperties; 021import hdf.view.DataView.DataViewManager; 022import hdf.view.ImageView.ImageView; 023 024/** 025 * A simple Factory class which returns concrete instances of the default 026 * PaletteView. 027 * 028 * @author jhenderson 029 * @version 1.0 4/18/2018 030 */ 031public class DefaultPaletteViewFactory extends PaletteViewFactory { 032 033 private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(DefaultPaletteViewFactory.class); 034 035 @Override 036 public PaletteView getPaletteView(Shell parent, DataViewManager viewer, ImageView theImageView) throws ClassNotFoundException { 037 String dataViewName = null; 038 Object[] initargs; 039 PaletteView theView = null; 040 041 dataViewName = ViewProperties.DEFAULT_PALETTEVIEW_NAME; 042 043 Class<?> theClass = null; 044 try { 045 log.trace("getPaletteView(): Class.forName({})", dataViewName); 046 047 /* Attempt to load the class by the given name */ 048 theClass = Class.forName(dataViewName); 049 } 050 catch (Exception ex) { 051 log.debug("getPaletteView(): unable to load default PaletteView class by name({})", dataViewName); 052 theClass = null; 053 } 054 055 if (theClass == null) throw new ClassNotFoundException(); 056 057 try { 058 initargs = new Object[] { parent, viewer, theImageView }; 059 060 theView = (PaletteView) Tools.newInstance(theClass, initargs); 061 062 log.trace("getPaletteView(): returning PaletteView instance {}", theView); 063 } 064 catch (Exception ex) { 065 log.debug("getPaletteView(): Error instantiating class:", ex); 066 theView = null; 067 } 068 069 return theView; 070 } 071 072}