001 /* 002 * This file is part of McIDAS-V 003 * 004 * Copyright 2007-2013 005 * Space Science and Engineering Center (SSEC) 006 * University of Wisconsin - Madison 007 * 1225 W. Dayton Street, Madison, WI 53706, USA 008 * https://www.ssec.wisc.edu/mcidas 009 * 010 * All Rights Reserved 011 * 012 * McIDAS-V is built on Unidata's IDV and SSEC's VisAD libraries, and 013 * some McIDAS-V source code is based on IDV and VisAD source code. 014 * 015 * McIDAS-V is free software; you can redistribute it and/or modify 016 * it under the terms of the GNU Lesser Public License as published by 017 * the Free Software Foundation; either version 3 of the License, or 018 * (at your option) any later version. 019 * 020 * McIDAS-V is distributed in the hope that it will be useful, 021 * but WITHOUT ANY WARRANTY; without even the implied warranty of 022 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 023 * GNU Lesser Public License for more details. 024 * 025 * You should have received a copy of the GNU Lesser Public License 026 * along with this program. If not, see http://www.gnu.org/licenses. 027 */ 028 029 package edu.wisc.ssec.mcidasv.data.hydra; 030 031 import ucar.unidata.data.DataSelection; 032 import ucar.unidata.data.DataSource; 033 import ucar.unidata.data.DataChoice; 034 import ucar.unidata.data.DataCategory; 035 import java.util.HashMap; 036 import java.util.Iterator; 037 import java.util.Set; 038 039 public class HydraContext { 040 041 private static HashMap<DataSource, HydraContext> dataSourceToContextMap = new HashMap<DataSource, HydraContext>(); 042 private static HashMap<DataChoice, HydraContext> dataChoiceToContextMap = new HashMap<DataChoice, HydraContext>(); 043 private static HashMap<DataCategory, HydraContext> dataCategoryToContextMap = new HashMap<DataCategory, HydraContext>(); 044 045 private static HashMap<DataSource, HashMap<DataCategory, HydraContext>> contextMap = new HashMap<DataSource, HashMap<DataCategory, HydraContext>>(); 046 047 private static HydraContext hydraContext = null; 048 private boolean useSubset = false; 049 private MultiDimensionSubset subset = null; 050 private Object selectBox = null; 051 052 public static HydraContext getHydraContext(DataSource source, DataCategory dataCategory) { 053 if (dataCategory == null) { 054 return getHydraContext(source); 055 } 056 if (contextMap.containsKey(source)) { 057 if ((contextMap.get(source)).containsKey(dataCategory)) { 058 return contextMap.get(source).get(dataCategory); 059 } 060 else { 061 HashMap catMap = contextMap.get(source); 062 HydraContext hydraContext = new HydraContext(); 063 catMap.put(dataCategory, hydraContext); 064 return hydraContext; 065 } 066 } 067 else { 068 HydraContext hydraContext = new HydraContext(); 069 HashMap catMap = new HashMap(); 070 catMap.put(dataCategory, hydraContext); 071 contextMap.put(source, catMap); 072 return hydraContext; 073 } 074 } 075 076 public static HydraContext getHydraContext(DataSource source) { 077 if (dataSourceToContextMap.isEmpty()) { 078 HydraContext hydraContext = new HydraContext(); 079 dataSourceToContextMap.put(source, hydraContext); 080 return hydraContext; 081 } 082 083 if (dataSourceToContextMap.containsKey(source)) { 084 return dataSourceToContextMap.get(source); 085 } 086 else { 087 HydraContext hydraContext = new HydraContext(); 088 dataSourceToContextMap.put(source, hydraContext); 089 return hydraContext; 090 } 091 } 092 093 public static HydraContext getHydraContext(DataChoice choice) { 094 if (dataChoiceToContextMap.isEmpty()) { 095 HydraContext hydraContext = new HydraContext(); 096 dataChoiceToContextMap.put(choice, hydraContext); 097 return hydraContext; 098 } 099 100 if (dataChoiceToContextMap.containsKey(choice)) { 101 return dataChoiceToContextMap.get(choice); 102 } 103 else { 104 HydraContext hydraContext = new HydraContext(); 105 dataChoiceToContextMap.put(choice, hydraContext); 106 return hydraContext; 107 } 108 } 109 110 public static HydraContext getHydraContext(DataCategory choice) { 111 if (dataCategoryToContextMap.isEmpty()) { 112 HydraContext hydraContext = new HydraContext(); 113 dataCategoryToContextMap.put(choice, hydraContext); 114 return hydraContext; 115 } 116 117 if (dataCategoryToContextMap.containsKey(choice)) { 118 return dataCategoryToContextMap.get(choice); 119 } 120 else { 121 HydraContext hydraContext = new HydraContext(); 122 dataCategoryToContextMap.put(choice, hydraContext); 123 return hydraContext; 124 } 125 } 126 127 128 public static HydraContext getHydraContext() { 129 if (hydraContext == null) { 130 hydraContext = new HydraContext(); 131 } 132 return hydraContext; 133 } 134 135 136 public HydraContext() { 137 } 138 139 140 public synchronized void setMultiDimensionSubset(MultiDimensionSubset subset) { 141 this.subset = subset; 142 } 143 144 public void setSelectBox(Object box) { 145 selectBox = box; 146 } 147 148 public Object getSelectBox() { 149 return selectBox; 150 } 151 152 public synchronized MultiDimensionSubset getMultiDimensionSubset() { 153 return subset; 154 } 155 156 157 }