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.chooser.adde; 030 031 import static javax.swing.GroupLayout.DEFAULT_SIZE; 032 import static javax.swing.GroupLayout.PREFERRED_SIZE; 033 import static javax.swing.GroupLayout.Alignment.BASELINE; 034 import static javax.swing.GroupLayout.Alignment.LEADING; 035 import static javax.swing.LayoutStyle.ComponentPlacement.RELATED; 036 037 import java.awt.event.ItemEvent; 038 import java.awt.event.ItemListener; 039 import java.util.Hashtable; 040 import java.util.List; 041 042 import javax.swing.GroupLayout; 043 import javax.swing.JCheckBox; 044 import javax.swing.JComponent; 045 import javax.swing.JLabel; 046 import javax.swing.JPanel; 047 048 import org.w3c.dom.Element; 049 050 import edu.wisc.ssec.mcidas.AreaDirectory; 051 052 import ucar.unidata.data.imagery.BandInfo; 053 import ucar.unidata.idv.chooser.IdvChooserManager; 054 import ucar.unidata.util.TwoFacedObject; 055 import ucar.unidata.xml.XmlObjectStore; 056 057 import edu.wisc.ssec.mcidasv.Constants; 058 import edu.wisc.ssec.mcidasv.util.McVGuiUtils; 059 060 061 /** 062 * Widget to select images from a remote ADDE server 063 * Displays a list of the descriptors (names) of the image datasets 064 * available for a particular ADDE group on the remote server. 065 * 066 * @author Don Murray 067 */ 068 public class AddeImageParameterChooser extends AddeImageChooser implements Constants { 069 070 /** 071 * Public keys for server, group, dataset, user, project. 072 */ 073 public final static String SIZE_KEY = "size"; 074 public final static String BAND_KEY = "band"; 075 public final static String PLACE_KEY = "place"; 076 public final static String LATLON_KEY = "latlon"; 077 public final static String LINELE_KEY = "linele"; 078 public final static String MAG_KEY = "mag"; 079 public final static String UNIT_KEY = "unit"; 080 public final static String PREVIEW_KEY = "preview"; 081 public final static String NAVIGATION_KEY = "navigation"; 082 083 /** Property for image default value unit */ 084 protected static final String PROP_NAV = "NAV"; 085 086 /** Property for image default value unit */ 087 protected static final String PROP_UNIT = "UNIT"; 088 089 /** Property for image default value band */ 090 protected static final String PROP_BAND = "BAND"; 091 092 /** Xml attr name for the defaults */ 093 private static final String ATTR_NAV = "NAV"; 094 private static final String ATTR_UNIT = "UNIT"; 095 private static final String ATTR_BAND = "BAND"; 096 private static final String ATTR_PLACE = "PLACE"; 097 private static final String ATTR_SIZE = "SIZE"; 098 private static final String ATTR_MAG = "MAG"; 099 private static final String ATTR_LATLON = "LATLON"; 100 private static final String ATTR_LINELE = "LINELE"; 101 102 /** string for ALL */ 103 private static final String ALL = "ALL"; 104 105 private static JCheckBox previewBox = null; 106 107 /** 108 * Construct an Adde image selection widget 109 * 110 * 111 * @param mgr The chooser manager 112 * @param root The chooser.xml node 113 */ 114 public AddeImageParameterChooser(IdvChooserManager mgr, Element root) { 115 super(mgr, root); 116 //DAVEP: Hiding parameter set picker for now... revisit after 1.0 117 // showParameterButton(); 118 } 119 120 /** 121 * Return the parameter type associated with this chooser. Override! 122 */ 123 @Override 124 protected String getParameterSetType() { 125 return "addeimagery"; 126 } 127 128 /** 129 * Return the data source ID. Used by extending classes. 130 */ 131 @Override 132 protected String getDataSourceId() { 133 return "ADDE.IMAGE.V"; 134 } 135 136 /** 137 * Restore the selected parameter set using element attributes 138 * 139 * @param restoreElement 140 * @return 141 */ 142 @Override 143 protected boolean restoreParameterSet(Element restoreElement) { 144 boolean okay = super.restoreParameterSet(restoreElement); 145 if (!okay) return okay; 146 147 // Imagery specific restore 148 149 // Restore nav 150 if (restoreElement.hasAttribute(ATTR_NAV)) { 151 String nav = restoreElement.getAttribute(ATTR_NAV); 152 TwoFacedObject tfo = new TwoFacedObject("Default", "X"); 153 navComboBox.setSelectedItem((Object)tfo); 154 if (nav.toUpperCase().equals("LALO")) { 155 tfo = new TwoFacedObject("Lat/Lon", "LALO"); 156 } 157 navComboBox.setSelectedItem((Object)tfo); 158 } 159 return true; 160 } 161 162 /** 163 * Get the list of BandInfos for the current selected images 164 * @return list of BandInfos 165 */ 166 public List<BandInfo> getSelectedBandInfos() { 167 return super.getBandInfos(); 168 } 169 170 /** 171 * Get the value for the given property. This can either be the value 172 * supplied by the end user through the advanced GUI or is the default 173 * 174 * @param prop The property 175 * @param ad The AreaDirectory 176 * 177 * @return The value of the property to use in the request string 178 */ 179 @Override 180 protected String getPropValue(String prop, AreaDirectory ad) { 181 String propValue = super.getPropValue(prop, ad); 182 if (prop.equals(PROP_NAV)) { 183 propValue = TwoFacedObject.getIdString(navComboBox.getSelectedItem()); 184 } 185 return propValue; 186 } 187 188 /** 189 * Optionally override any defaults per parameter chooser 190 * @param property 191 * @return 192 */ 193 @Override 194 protected String getDefault(String property, String dflt) { 195 String paramDefault = super.getDefault(property, dflt); 196 if (property.equals(PROP_NAV)) { 197 if (restoreElement != null) { 198 paramDefault = restoreElement.getAttribute(ATTR_NAV); 199 } 200 } else if (property.equals(PROP_UNIT)) { 201 paramDefault = ""; 202 } else if (property.equals(PROP_BAND)) { 203 paramDefault = ALL; 204 } else if (property.equals(PROP_PLACE)) { 205 paramDefault = ""; 206 } 207 return paramDefault; 208 } 209 210 /** 211 * Get the DataSource properties 212 * 213 * @param ht 214 * Hashtable of properties 215 */ 216 @Override 217 protected void getDataSourceProperties(Hashtable ht) { 218 super.getDataSourceProperties(ht); 219 if (restoreElement != null) { 220 if (restoreElement.hasAttribute(ATTR_BAND)) { 221 ht.put(BAND_KEY, (Object)(restoreElement.getAttribute(ATTR_BAND))); 222 } 223 if (restoreElement.hasAttribute(ATTR_LATLON)) { 224 ht.put(LATLON_KEY, (Object)(restoreElement.getAttribute(ATTR_LATLON))); 225 } 226 if (restoreElement.hasAttribute(ATTR_LINELE)) { 227 ht.put(LINELE_KEY, (Object)(restoreElement.getAttribute(ATTR_LINELE))); 228 } 229 if (restoreElement.hasAttribute(ATTR_MAG)) { 230 ht.put(MAG_KEY, (Object)(restoreElement.getAttribute(ATTR_MAG))); 231 } 232 if (restoreElement.hasAttribute(ATTR_PLACE)) { 233 ht.put(PLACE_KEY, (Object)(restoreElement.getAttribute(ATTR_PLACE))); 234 } 235 if (restoreElement.hasAttribute(ATTR_SIZE)) { 236 ht.put(SIZE_KEY, (Object)(restoreElement.getAttribute(ATTR_SIZE))); 237 } 238 if (restoreElement.hasAttribute(ATTR_UNIT)) { 239 ht.put(UNIT_KEY, (Object)(restoreElement.getAttribute(ATTR_UNIT))); 240 } 241 } else { 242 ht.put(NAVIGATION_KEY, (Object)getPropValue(PROP_NAV, null)); 243 } 244 ht.put(PREVIEW_KEY, (Object)previewBox.isSelected()); 245 } 246 247 /** 248 * Should we use the user supplied property 249 * 250 * @param propId 251 * The property 252 * 253 * @return Should use the value from the advanced widget 254 */ 255 protected boolean usePropFromUser(String propId) { 256 boolean fromSuper = super.usePropFromUser(propId); 257 if (propId.equals(PROP_UNIT)) fromSuper = false; 258 else if (propId.equals(PROP_BAND)) fromSuper = false; 259 return fromSuper; 260 } 261 262 /** 263 * Make the UI for this selector. 264 * 265 * @return The gui 266 */ 267 @Override 268 public JComponent doMakeContents() { 269 JPanel myPanel = new JPanel(); 270 271 JLabel timesLabel = McVGuiUtils.makeLabelRight("Times:"); 272 addDescComp(timesLabel); 273 274 JPanel timesPanel = makeTimesPanel(); 275 timesPanel.setBorder(javax.swing.BorderFactory.createEtchedBorder()); 276 addDescComp(timesPanel); 277 278 JLabel navigationLabel = McVGuiUtils.makeLabelRight("Navigation:"); 279 addDescComp(navigationLabel); 280 281 // Use processPropertyComponents to build combo boxes that we rely on 282 processPropertyComponents(); 283 addDescComp(navComboBox); 284 McVGuiUtils.setComponentWidth(navComboBox, McVGuiUtils.Width.DOUBLE); 285 286 // Preview checkbox 287 JLabel previewLabel = McVGuiUtils.makeLabelRight("Preview:"); 288 addDescComp(previewLabel); 289 XmlObjectStore store = getIdv().getStore(); 290 previewBox = new JCheckBox("Create preview image", store.get(Constants.PREF_IMAGE_PREVIEW, true)); 291 previewBox.setToolTipText("Creating preview images takes extra time and network bandwidth"); 292 previewBox.addItemListener(new ItemListener() { 293 public void itemStateChanged(ItemEvent e) { 294 XmlObjectStore store = getIdv().getStore(); 295 store.put(Constants.PREF_IMAGE_PREVIEW, e.getStateChange()); 296 store.save(); 297 } 298 }); 299 addDescComp(previewBox); 300 301 GroupLayout layout = new GroupLayout(myPanel); 302 myPanel.setLayout(layout); 303 layout.setHorizontalGroup( 304 layout.createParallelGroup(LEADING) 305 .addGroup(layout.createSequentialGroup() 306 .addGroup(layout.createParallelGroup(LEADING) 307 .addGroup(layout.createSequentialGroup() 308 .addComponent(descriptorLabel) 309 .addGap(GAP_RELATED) 310 .addComponent(descriptorComboBox)) 311 .addGroup(layout.createSequentialGroup() 312 .addComponent(timesLabel) 313 .addGap(GAP_RELATED) 314 .addComponent(timesPanel, PREFERRED_SIZE, DEFAULT_SIZE, Short.MAX_VALUE)) 315 .addGroup(layout.createSequentialGroup() 316 .addComponent(navigationLabel) 317 .addGap(GAP_RELATED) 318 .addComponent(navComboBox)) 319 .addGroup(layout.createSequentialGroup() 320 .addComponent(previewLabel) 321 .addGap(GAP_RELATED) 322 .addComponent(previewBox)))) 323 ); 324 layout.setVerticalGroup( 325 layout.createParallelGroup(LEADING) 326 .addGroup(layout.createSequentialGroup() 327 .addGroup(layout.createParallelGroup(BASELINE) 328 .addComponent(descriptorLabel) 329 .addComponent(descriptorComboBox)) 330 .addPreferredGap(RELATED) 331 .addGroup(layout.createParallelGroup(LEADING) 332 .addComponent(timesLabel) 333 .addComponent(timesPanel, PREFERRED_SIZE, DEFAULT_SIZE, Short.MAX_VALUE)) 334 .addPreferredGap(RELATED) 335 .addGroup(layout.createParallelGroup(LEADING) 336 .addComponent(navigationLabel) 337 .addComponent(navComboBox)) 338 .addGroup(layout.createParallelGroup(LEADING) 339 .addComponent(previewLabel) 340 .addComponent(previewBox))) 341 ); 342 343 setInnerPanel(myPanel); 344 return super.doMakeContents(true); 345 } 346 347 }