/*
 * SoilChooser_n.java
 *
 * Created on April 23, 2007, 4:50 PM
 */

package usda.weru.soil.gui;

import de.schlichtherle.truezip.file.TFile;
import java.awt.Frame;
import java.awt.event.ActionEvent;
import usda.weru.util.Util;
import usda.weru.util.WepsFileChooser;

/**
 *
 * @author  Joseph Levin
 */
public class MassSoilChooser_n extends javax.swing.JDialog {
    private static final long serialVersionUID = 1L;

	/**
	 *
	 * @param parent
	 */
	public MassSoilChooser_n(Frame parent) {
        super(parent);
         initComponents(); 
        g_tree.setShowsRootHandles(true);
    }
    
    /** Creates new form SoilChooser_n */
    public MassSoilChooser_n() {
        initComponents();       
        g_tree.setShowsRootHandles(true);
    }
    
    /** 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.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        g_scrollPane = new javax.swing.JScrollPane();
        g_tree = new javax.swing.JTree();
        downloadButton = new javax.swing.JButton();
        g_cancelButton = new javax.swing.JButton();
        componentsTot = new javax.swing.JLabel();
        componentsNum = new javax.swing.JLabel();
        componentsLab = new javax.swing.JLabel();
        mapUnitsLab = new javax.swing.JLabel();
        mapUnitsNum = new javax.swing.JLabel();
        mapUnitsTot = new javax.swing.JLabel();
        legendsLab = new javax.swing.JLabel();
        legendsNum = new javax.swing.JLabel();
        legendsTot = new javax.swing.JLabel();
        destinationDirectoryButton = new javax.swing.JButton();
        destinationDirectoryField = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosed(java.awt.event.WindowEvent evt) {
                formWindowClosed(evt);
            }
        });

        g_tree.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                g_treeMouseClicked(evt);
            }
        });
        g_tree.addTreeSelectionListener(new javax.swing.event.TreeSelectionListener() {
            public void valueChanged(javax.swing.event.TreeSelectionEvent evt) {
                g_treeValueChanged(evt);
            }
        });
        g_scrollPane.setViewportView(g_tree);

        downloadButton.setText("Download");
        downloadButton.setEnabled(false);
        downloadButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                downloadButtonActionPerformed(evt);
            }
        });

        g_cancelButton.setText("Cancel");
        g_cancelButton.setEnabled(false);
        g_cancelButton.setMaximumSize(new java.awt.Dimension(101, 31));
        g_cancelButton.setMinimumSize(new java.awt.Dimension(101, 31));
        g_cancelButton.setPreferredSize(new java.awt.Dimension(101, 31));
        g_cancelButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                g_cancelButtonActionPerformed(evt);
            }
        });

        componentsTot.setText("/50");

        componentsNum.setText("50");

        componentsLab.setText("Components:");

        mapUnitsLab.setText("Map Units:");

        mapUnitsNum.setText("10");

        mapUnitsTot.setText("/10");

        legendsLab.setText("Legends:");

        legendsNum.setText("1");

        legendsTot.setText("/1");

        destinationDirectoryButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/usda/weru/resources/folder.gif"))); // NOI18N
        destinationDirectoryButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                destinationDirectoryButtonActionPerformed(evt);
            }
        });

        destinationDirectoryField.setText("jTextField1");
        destinationDirectoryField.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                destinationDirectoryFieldFocusLost(evt);
            }
        });
        destinationDirectoryField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                destinationDirectoryFieldActionPerformed(evt);
            }
        });

        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)
                    .addComponent(g_scrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 429, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGap(0, 86, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(mapUnitsLab)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(mapUnitsNum)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(mapUnitsTot))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(legendsLab)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(legendsNum)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(legendsTot)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(componentsLab)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(componentsNum)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(componentsTot)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(downloadButton, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(g_cancelButton, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(destinationDirectoryField)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(destinationDirectoryButton, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(destinationDirectoryField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(destinationDirectoryButton, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(g_scrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 381, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(downloadButton, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(mapUnitsTot)
                    .addComponent(mapUnitsNum)
                    .addComponent(mapUnitsLab))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(legendsNum)
                        .addComponent(legendsLab)
                        .addComponent(legendsTot))
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(g_cancelButton, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(componentsTot)
                        .addComponent(componentsNum)
                        .addComponent(componentsLab)))
                .addGap(14, 14, 14))
        );

        setSize(new java.awt.Dimension(451, 514));
        setLocationRelativeTo(null);
    }// </editor-fold>//GEN-END:initComponents

	/**
	 *
	 * @param evt
	 */
	protected void indexActionPerformed(java.awt.event.ActionEvent evt) {
        
    }
    
    private void g_treeMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_g_treeMouseClicked
        treeMouseClicked(evt);
    }//GEN-LAST:event_g_treeMouseClicked

	/**
	 *
	 * @param evt
	 */
	protected void treeMouseClicked(java.awt.event.MouseEvent evt) {                                    

    } 
    
    private void g_treeValueChanged(javax.swing.event.TreeSelectionEvent evt) {//GEN-FIRST:event_g_treeValueChanged
        treeValueChanged(evt);
    }//GEN-LAST:event_g_treeValueChanged

	/**
	 *
	 * @param evt
	 */
	protected void treeValueChanged(javax.swing.event.TreeSelectionEvent evt) {

    }
    
    private void g_cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_g_cancelButtonActionPerformed
        cancelButtonActionPerformed(evt);
    }//GEN-LAST:event_g_cancelButtonActionPerformed

    private void downloadButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_downloadButtonActionPerformed
        downloadButtonAction(evt);
    }//GEN-LAST:event_downloadButtonActionPerformed

private void formWindowClosed(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosed
    formWindow_closed(evt);
}//GEN-LAST:event_formWindowClosed

    private void destinationDirectoryFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_destinationDirectoryFieldActionPerformed
        destinationDirectoryFieldUpdate();
    }//GEN-LAST:event_destinationDirectoryFieldActionPerformed

    private void destinationDirectoryFieldFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_destinationDirectoryFieldFocusLost
        destinationDirectoryFieldUpdate();
    }//GEN-LAST:event_destinationDirectoryFieldFocusLost

    private void destinationDirectoryButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_destinationDirectoryButtonActionPerformed
        destinationDirectoryChooser();
    }//GEN-LAST:event_destinationDirectoryButtonActionPerformed

	/**
	 *
	 * @param evt
	 */
	protected void formWindow_closed(java.awt.event.WindowEvent evt) {

    }

	/**
	 *
	 * @param evt
	 */
	protected void cancelButtonActionPerformed(ActionEvent evt) {                                               

    }                                              

	/**
	 *
	 * @param evt
	 */
	protected void downloadButtonAction(ActionEvent evt) {                                               

    }   
        protected void destinationDirectoryFieldUpdate()
        {

        }
        private void destinationDirectoryChooser()
        {
            WepsFileChooser wfc = new WepsFileChooser(WepsFileChooser.Filetype.DIR, 
                    destinationDirectoryField.getText(), WepsFileChooser.SELECT);
            wfc.setCurrentDirectory(new TFile(destinationDirectoryField.getText()));
            if (wfc.showDialog(this) == WepsFileChooser.APPROVE_OPTION) 
            {
                TFile install = new TFile(".").getCanOrAbsFile();
                TFile selected = new TFile(wfc.getSelectedFile());
                selected = Util.resolveFileAsRelativeChildOrAbsolute(install, selected);

                String path = selected.getPath();
                destinationDirectoryField.setText(path + TFile.separator);
                destinationDirectoryFieldUpdate();
            }
            
        }
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                new MassSoilChooser_n().setVisible(true);
            }
        });
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    protected javax.swing.JLabel componentsLab;
    protected javax.swing.JLabel componentsNum;
    protected javax.swing.JLabel componentsTot;
    protected javax.swing.JButton destinationDirectoryButton;
    protected javax.swing.JTextField destinationDirectoryField;
    protected javax.swing.JButton downloadButton;
    protected javax.swing.JButton g_cancelButton;
    protected javax.swing.JScrollPane g_scrollPane;
    protected javax.swing.JTree g_tree;
    protected javax.swing.JLabel legendsLab;
    protected javax.swing.JLabel legendsNum;
    protected javax.swing.JLabel legendsTot;
    protected javax.swing.JLabel mapUnitsLab;
    protected javax.swing.JLabel mapUnitsNum;
    protected javax.swing.JLabel mapUnitsTot;
    // End of variables declaration//GEN-END:variables
    
}
