/*
 * ThresholdRun.java
 *
 * Created on March 16, 2006, 11:07 AM
 */

package usda.weru.erosion.gui;

import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.awt.event.WindowEvent;
import si.uom.SI;
import tec.uom.se.unit.MetricPrefix;
import org.jdesktop.beansbinding.AutoBinding.UpdateStrategy;
import org.jdesktop.beansbinding.BeanProperty;
import org.jdesktop.beansbinding.BindingGroup;
import org.jdesktop.beansbinding.Bindings;
import usda.weru.util.ConfigData;
import usda.weru.weps.RunFileBean;
import usda.weru.weps.location.Site;
import usda.weru.weps.location.StationMode;
import usda.weru.weps.location.chooser.StationChooser;

/**
 *
 * @author  wjr
 */
public class ThresholdRun_n extends javax.swing.JFrame {
    private static final long serialVersionUID = 1L;

	/**
	 *
	 */
	protected RunFileBean c_rfb;
    /** Creates new form ThresholdRun */
    public ThresholdRun_n() {
        c_rfb = new RunFileBean();
        initComponents();
        siteChooser.addComponentListener(new ComponentAdapter() {

            @Override
            public void componentResized(ComponentEvent e) {
                pack();
            }

        });
        siteChooser.setSelectedSite(Site.UNITED_STATES);




        c_rfb.setWindgenStationMode(StationMode.Choice);


        windgenStationChooser.setStationModes(
                StationMode.parseStationModes(ConfigData.getDefault().getData(ConfigData.CligenAllowedModes)));
        windgenStationChooser.setRunFileBean(c_rfb);
        windgenStationChooser.setStationType(RunFileBean.StationType.Windgen);
        windgenStationChooser.setDistanceUnits(MetricPrefix.KILO(SI.METRE));
        

        

         //add the bean bindings
        BindingGroup bindings = new BindingGroup();
        //windgen mode
        bindings.addBinding(Bindings.createAutoBinding(UpdateStrategy.READ_WRITE, c_rfb, BeanProperty.create(RunFileBean.PROP_WINDGEN_STATION_MODE), windgenStationChooser, BeanProperty.create(StationChooser.PROP_STATION_MODE)));
        //windgen station
        bindings.addBinding(Bindings.createAutoBinding(UpdateStrategy.READ_WRITE, c_rfb, BeanProperty.create(RunFileBean.PROP_WINDGEN_STATION), windgenStationChooser, BeanProperty.create(StationChooser.PROP_SELECTED_STATION)));
        //latlong
        bindings.addBinding(Bindings.createAutoBinding(UpdateStrategy.READ, c_rfb, BeanProperty.create(RunFileBean.PROP_LATLONG), windgenStationChooser, BeanProperty.create(StationChooser.PROP_LATLONG)));

        bindings.bind();

        c_rfb.setSite(Site.UNITED_STATES);
    ;

    }

//    @Override
//    public void windowClosing(WindowEvent e) {
//        
//    }
	/**
	 *
	 * @return
	 */
    public RunFileBean getBean(){
        return c_rfb;
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("rawtypes")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        bindingGroup = new org.jdesktop.beansbinding.BindingGroup();

        JB_run = new javax.swing.JButton();
        JB_cancel = new javax.swing.JButton();
        siteChooser = new usda.weru.weps.location.chooser.SiteChooser();
        siteLabel = siteChooser.getLabelPanel();
        jPanel1 = new javax.swing.JPanel();
        windgenStationChooser = new usda.weru.weps.location.chooser.StationChooser();
        stationLabel = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setResizable(false);

        JB_run.setText("Run");
        JB_run.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                JB_runActionPerformed(evt);
            }
        });

        JB_cancel.setText("Cancel");
        JB_cancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                JB_cancelActionPerformed(evt);
            }
        });

        org.jdesktop.beansbinding.Binding binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, this, org.jdesktop.beansbinding.ELProperty.create("${bean.site}"), siteChooser, org.jdesktop.beansbinding.BeanProperty.create("selectedSite"));
        bindingGroup.addBinding(binding);

        siteLabel.setLayout(new java.awt.GridLayout(0, 1));

        stationLabel.setText("Windgen:");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(stationLabel)
                .addContainerGap(203, Short.MAX_VALUE))
            .addComponent(windgenStationChooser, javax.swing.GroupLayout.DEFAULT_SIZE, 249, Short.MAX_VALUE)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(stationLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(windgenStationChooser, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(siteLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(207, 207, 207))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(55, 55, 55)
                                .addComponent(siteChooser, javax.swing.GroupLayout.DEFAULT_SIZE, 194, Short.MAX_VALUE))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addComponent(JB_run, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(JB_cancel, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addContainerGap())))
        );

        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {JB_cancel, JB_run});

        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(siteLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 22, Short.MAX_VALUE)
                    .addComponent(siteChooser, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(50, 50, 50)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(JB_cancel)
                    .addComponent(JB_run))
                .addContainerGap())
        );

        layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {siteChooser, siteLabel});

        bindingGroup.bind();

        pack();
    }// </editor-fold>//GEN-END:initComponents

    protected void JB_cancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_JB_cancelActionPerformed
	}//GEN-LAST:event_JB_cancelActionPerformed

    protected void JB_runActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_JB_runActionPerformed
    }//GEN-LAST:event_JB_runActionPerformed
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                new ThresholdRun_n().setVisible(true);
            }
        });
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    public javax.swing.JButton JB_cancel;
    public javax.swing.JButton JB_run;
    public javax.swing.JPanel jPanel1;
    public usda.weru.weps.location.chooser.SiteChooser siteChooser;
    public javax.swing.JPanel siteLabel;
    public javax.swing.JLabel stationLabel;
    public usda.weru.weps.location.chooser.StationChooser windgenStationChooser;
    private org.jdesktop.beansbinding.BindingGroup bindingGroup;
    // End of variables declaration//GEN-END:variables
    
}
