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.ImageView; 016 017import java.util.BitSet; 018import java.util.HashMap; 019 020import hdf.view.DataView.DataViewManager; 021import hdf.view.Tools; 022import hdf.view.ViewProperties; 023 024import org.slf4j.Logger; 025import org.slf4j.LoggerFactory; 026 027/** 028 * A simple Factory class which returns concrete instances of the default 029 * ImageView. 030 * 031 * @author jhenderson 032 * @version 1.0 4/18/2018 033 */ 034public class DefaultImageViewFactory extends ImageViewFactory { 035 036 private static final Logger log = LoggerFactory.getLogger(DefaultImageViewFactory.class); 037 038 @SuppressWarnings({"rawtypes", "unchecked"}) 039 @Override 040 public ImageView getImageView(DataViewManager viewer, HashMap dataPropertiesMap) 041 throws ClassNotFoundException 042 { 043 String dataViewName = null; 044 Object[] initargs = {viewer, dataPropertiesMap}; 045 ImageView theView = null; 046 047 /* 048 * If the name of a specific ImageView class to use has been passed in via the 049 * data options map, retrieve its name now, otherwise use the default ImageView 050 * class. 051 */ 052 dataViewName = (String)dataPropertiesMap.get(ViewProperties.DATA_VIEW_KEY.VIEW_NAME); 053 if (dataViewName == null || dataViewName.equals(ViewProperties.DEFAULT_MODULE_TEXT)) { 054 dataViewName = ViewProperties.DEFAULT_IMAGEVIEW_NAME; 055 } 056 057 Class<?> theClass = null; 058 try { 059 log.trace("getImageView(): Class.forName({})", dataViewName); 060 061 /* Attempt to load the class by the given name */ 062 theClass = Class.forName(dataViewName); 063 } 064 catch (Exception ex) { 065 log.debug("getImageView(): unable to load default ImageView class by name({})", dataViewName); 066 theClass = null; 067 } 068 069 if (theClass == null) 070 throw new ClassNotFoundException(); 071 072 /* Add some data display properties if using the default ImageView */ 073 if (dataViewName.startsWith(ViewProperties.DEFAULT_IMAGEVIEW_NAME)) { 074 BitSet bitmask = (BitSet)dataPropertiesMap.get(ViewProperties.DATA_VIEW_KEY.BITMASK); 075 dataPropertiesMap.put(ViewProperties.DATA_VIEW_KEY.CONVERTBYTE, 076 Boolean.valueOf((bitmask != null))); 077 } 078 079 try { 080 theView = (ImageView)Tools.newInstance(theClass, initargs); 081 082 log.trace("getImageView(): returning ImageView instance {}", theView); 083 } 084 catch (Exception ex) { 085 log.debug("getImageView(): Error instantiating class:", ex); 086 theView = null; 087 } 088 089 return theView; 090 } 091}