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    package edu.wisc.ssec.mcidasv.chooser.adde;
029    
030    import static javax.swing.GroupLayout.DEFAULT_SIZE;
031    import static javax.swing.GroupLayout.PREFERRED_SIZE;
032    import static javax.swing.GroupLayout.Alignment.BASELINE;
033    import static javax.swing.GroupLayout.Alignment.LEADING;
034    import static javax.swing.LayoutStyle.ComponentPlacement.RELATED;
035    
036    import java.util.Hashtable;
037    import java.util.List;
038    
039    import javax.swing.GroupLayout;
040    import javax.swing.JComponent;
041    import javax.swing.JLabel;
042    import javax.swing.JPanel;
043    
044    import org.w3c.dom.Element;
045    
046    import ucar.unidata.data.imagery.ImageDataset;
047    import ucar.unidata.idv.chooser.IdvChooserManager;
048    
049    import edu.wisc.ssec.mcidas.AreaDirectory;
050    import edu.wisc.ssec.mcidasv.util.McVGuiUtils;
051    
052    
053    /**
054     * Widget to select images from a remote ADDE server
055     * Displays a list of the descriptors (names) of the image datasets
056     * available for a particular ADDE group on the remote server.
057     *
058     * @author Don Murray
059     */
060    public class AddeBasicImageChooser extends AddeImageChooser {
061    
062        /**
063         * Construct an Adde image selection widget
064         *
065         *
066         * @param mgr The chooser manager
067         * @param root The chooser.xml node
068         */
069        public AddeBasicImageChooser(IdvChooserManager mgr, Element root) {
070            super(mgr, root);
071        }
072            
073        /**
074         *  Get the default value for a key
075         *
076         *  @param property      property (key type)
077         *  @param dflt        default value
078         *  @return value for key or dflt if not found
079         */
080        protected String getDefault(String property, String dflt) {
081            if (property.equals(PROP_UNIT)) return "";
082            if (property.equals(PROP_BAND)) return "ALL";
083            return super.getDefault(property, dflt);
084        }
085        
086        /**
087         * Set the available units in the  unit selector
088         *
089         * @param ad   AreaDirectory for the image
090         * @param band band to use for units
091         */
092        protected void setAvailableUnits(AreaDirectory ad, int band) {
093            super.setAvailableUnits(ad, band);
094            unitComboBox.setSelectedItem(ALLUNITS);
095        }
096        
097        /**
098         * User said go, we go. Simply get the list of images
099         * from the imageChooser and create the ADDE.IMAGE.V
100         * DataSource
101         *
102         */
103        public void doLoadInThread() {
104            if ( !getGoodToGo()) {
105                updateStatus();
106                return;
107            }
108    
109            List imageList = getImageList();
110            if(imageList==null || imageList.size()==0) return;
111            ImageDataset ids = new ImageDataset(getDatasetName(), imageList);
112    
113            Hashtable ht = new Hashtable();
114            getDataSourceProperties(ht);
115            ht.put("preview", true);
116            makeDataSource(ids, "ADDE.IMAGE.V", ht);
117            saveServerState();
118        }
119    
120        /**
121         * Make the UI for this selector.
122         * 
123         * @return The gui
124         */   
125        public JComponent doMakeContents() {
126            JPanel myPanel = new JPanel();
127    
128            JLabel timesLabel = McVGuiUtils.makeLabelRight("Times:");
129            addDescComp(timesLabel);
130    
131            JPanel timesPanel = makeTimesPanel();
132            timesPanel.setBorder(javax.swing.BorderFactory.createEtchedBorder());
133            addDescComp(timesPanel);
134    
135            JLabel navigationLabel = McVGuiUtils.makeLabelRight("Navigation:");
136            addDescComp(navigationLabel);
137            
138            // Use processPropertyComponents to build combo boxes that we rely on
139            processPropertyComponents();
140            addDescComp(navComboBox);
141            McVGuiUtils.setComponentWidth(navComboBox, McVGuiUtils.Width.DOUBLE);
142                            
143            GroupLayout layout = new GroupLayout(myPanel);
144            myPanel.setLayout(layout);
145            layout.setHorizontalGroup(
146                    layout.createParallelGroup(LEADING)
147                    .addGroup(layout.createSequentialGroup()
148                            .addGroup(layout.createParallelGroup(LEADING)
149                                    .addGroup(layout.createSequentialGroup()
150                                            .addComponent(descriptorLabel)
151                                            .addGap(GAP_RELATED)
152                                            .addComponent(descriptorComboBox))
153                                            .addGroup(layout.createSequentialGroup()
154                                                    .addComponent(timesLabel)
155                                                    .addGap(GAP_RELATED)
156                                                    .addComponent(timesPanel, PREFERRED_SIZE, DEFAULT_SIZE, Short.MAX_VALUE))
157                                                    .addGroup(layout.createSequentialGroup()
158                                                            .addComponent(navigationLabel)
159                                                            .addGap(GAP_RELATED)
160                                                            .addComponent(navComboBox))))
161            );
162            layout.setVerticalGroup(
163                    layout.createParallelGroup(LEADING)
164                    .addGroup(layout.createSequentialGroup()
165                            .addGroup(layout.createParallelGroup(BASELINE)
166                                    .addComponent(descriptorLabel)
167                                    .addComponent(descriptorComboBox))
168                                    .addPreferredGap(RELATED)
169                                    .addGroup(layout.createParallelGroup(LEADING)
170                                            .addComponent(timesLabel)
171                                            .addComponent(timesPanel, PREFERRED_SIZE, DEFAULT_SIZE, Short.MAX_VALUE))
172                                            .addPreferredGap(RELATED)
173                                            .addGroup(layout.createParallelGroup(LEADING)
174                                                    .addComponent(navigationLabel)
175                                                    .addComponent(navComboBox)))
176            );
177            
178            setInnerPanel(myPanel);
179            return super.doMakeContents(true);
180        }
181    
182    }