001/*
002 * $Id: AddeBasicImageChooser.java,v 1.8 2011/03/24 16:06:32 davep Exp $
003 *
004 * This file is part of McIDAS-V
005 *
006 * Copyright 2007-2011
007 * Space Science and Engineering Center (SSEC)
008 * University of Wisconsin - Madison
009 * 1225 W. Dayton Street, Madison, WI 53706, USA
010 * https://www.ssec.wisc.edu/mcidas
011 * 
012 * All Rights Reserved
013 * 
014 * McIDAS-V is built on Unidata's IDV and SSEC's VisAD libraries, and
015 * some McIDAS-V source code is based on IDV and VisAD source code.  
016 * 
017 * McIDAS-V is free software; you can redistribute it and/or modify
018 * it under the terms of the GNU Lesser Public License as published by
019 * the Free Software Foundation; either version 3 of the License, or
020 * (at your option) any later version.
021 * 
022 * McIDAS-V is distributed in the hope that it will be useful,
023 * but WITHOUT ANY WARRANTY; without even the implied warranty of
024 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
025 * GNU Lesser Public License for more details.
026 * 
027 * You should have received a copy of the GNU Lesser Public License
028 * along with this program.  If not, see http://www.gnu.org/licenses.
029 */
030package edu.wisc.ssec.mcidasv.chooser.adde;
031
032import static javax.swing.GroupLayout.DEFAULT_SIZE;
033import static javax.swing.GroupLayout.PREFERRED_SIZE;
034import static javax.swing.GroupLayout.Alignment.BASELINE;
035import static javax.swing.GroupLayout.Alignment.LEADING;
036import static javax.swing.LayoutStyle.ComponentPlacement.RELATED;
037
038import java.util.Hashtable;
039import java.util.List;
040
041import javax.swing.GroupLayout;
042import javax.swing.JComponent;
043import javax.swing.JLabel;
044import javax.swing.JPanel;
045
046import org.w3c.dom.Element;
047
048import ucar.unidata.data.imagery.ImageDataset;
049import ucar.unidata.idv.chooser.IdvChooserManager;
050
051import edu.wisc.ssec.mcidas.AreaDirectory;
052import edu.wisc.ssec.mcidasv.util.McVGuiUtils;
053
054
055/**
056 * Widget to select images from a remote ADDE server
057 * Displays a list of the descriptors (names) of the image datasets
058 * available for a particular ADDE group on the remote server.
059 *
060 * @author Don Murray
061 */
062public class AddeBasicImageChooser extends AddeImageChooser {
063
064    /**
065     * Construct an Adde image selection widget
066     *
067     *
068     * @param mgr The chooser manager
069     * @param root The chooser.xml node
070     */
071    public AddeBasicImageChooser(IdvChooserManager mgr, Element root) {
072        super(mgr, root);
073    }
074        
075    /**
076     *  Get the default value for a key
077     *
078     *  @param property      property (key type)
079     *  @param dflt        default value
080     *  @return value for key or dflt if not found
081     */
082    protected String getDefault(String property, String dflt) {
083        if (property.equals(PROP_UNIT)) return "";
084        if (property.equals(PROP_BAND)) return "ALL";
085        return super.getDefault(property, dflt);
086    }
087    
088    /**
089     * Set the available units in the  unit selector
090     *
091     * @param ad   AreaDirectory for the image
092     * @param band band to use for units
093     */
094    protected void setAvailableUnits(AreaDirectory ad, int band) {
095        super.setAvailableUnits(ad, band);
096        unitComboBox.setSelectedItem(ALLUNITS);
097    }
098    
099    /**
100     * User said go, we go. Simply get the list of images
101     * from the imageChooser and create the ADDE.IMAGE.V
102     * DataSource
103     *
104     */
105    public void doLoadInThread() {
106        if ( !getGoodToGo()) {
107            updateStatus();
108            return;
109        }
110
111        List imageList = getImageList();
112        if(imageList==null || imageList.size()==0) return;
113        ImageDataset ids = new ImageDataset(getDatasetName(), imageList);
114
115        Hashtable ht = new Hashtable();
116        getDataSourceProperties(ht);
117        ht.put("preview", true);
118        makeDataSource(ids, "ADDE.IMAGE.V", ht);
119        saveServerState();
120    }
121
122    /**
123     * Make the UI for this selector.
124     * 
125     * @return The gui
126     */   
127    public JComponent doMakeContents() {
128        JPanel myPanel = new JPanel();
129
130        JLabel timesLabel = McVGuiUtils.makeLabelRight("Times:");
131        addDescComp(timesLabel);
132
133        JPanel timesPanel = makeTimesPanel();
134        timesPanel.setBorder(javax.swing.BorderFactory.createEtchedBorder());
135        addDescComp(timesPanel);
136
137        JLabel navigationLabel = McVGuiUtils.makeLabelRight("Navigation:");
138        addDescComp(navigationLabel);
139        
140        // Use processPropertyComponents to build combo boxes that we rely on
141        processPropertyComponents();
142        addDescComp(navComboBox);
143        McVGuiUtils.setComponentWidth(navComboBox, McVGuiUtils.Width.DOUBLE);
144                        
145        GroupLayout layout = new GroupLayout(myPanel);
146        myPanel.setLayout(layout);
147        layout.setHorizontalGroup(
148                layout.createParallelGroup(LEADING)
149                .addGroup(layout.createSequentialGroup()
150                        .addGroup(layout.createParallelGroup(LEADING)
151                                .addGroup(layout.createSequentialGroup()
152                                        .addComponent(descriptorLabel)
153                                        .addGap(GAP_RELATED)
154                                        .addComponent(descriptorComboBox))
155                                        .addGroup(layout.createSequentialGroup()
156                                                .addComponent(timesLabel)
157                                                .addGap(GAP_RELATED)
158                                                .addComponent(timesPanel, PREFERRED_SIZE, DEFAULT_SIZE, Short.MAX_VALUE))
159                                                .addGroup(layout.createSequentialGroup()
160                                                        .addComponent(navigationLabel)
161                                                        .addGap(GAP_RELATED)
162                                                        .addComponent(navComboBox))))
163        );
164        layout.setVerticalGroup(
165                layout.createParallelGroup(LEADING)
166                .addGroup(layout.createSequentialGroup()
167                        .addGroup(layout.createParallelGroup(BASELINE)
168                                .addComponent(descriptorLabel)
169                                .addComponent(descriptorComboBox))
170                                .addPreferredGap(RELATED)
171                                .addGroup(layout.createParallelGroup(LEADING)
172                                        .addComponent(timesLabel)
173                                        .addComponent(timesPanel, PREFERRED_SIZE, DEFAULT_SIZE, Short.MAX_VALUE))
174                                        .addPreferredGap(RELATED)
175                                        .addGroup(layout.createParallelGroup(LEADING)
176                                                .addComponent(navigationLabel)
177                                                .addComponent(navComboBox)))
178        );
179        
180        setInnerPanel(myPanel);
181        return super.doMakeContents(true);
182    }
183
184}