package org.mbari.seepsearch.ui;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import org.mbari.awt.layout.*;

import org.mbari.seepsearch.core.RovAltitudeFilter;

/**
 * <p>Panel for providing choices in filter paramters</p>
 *
 * <p>The Seep Search project is a sub-project of the Continental
 * Margin Fluids and Gases project (200010). It involves the analysis of
 * archived ROV data to obtain understanding of seep distritution in Monterey
 * Bay.</p>
 *
 * <p>The Purpose of this Java package is to intercompare ROV Navigation files,
 * VIMS data on seep community observations and the EM-300 bathymetry. We are
 * looking for locations where the ROV navigation files and the EM-300 data
 * have similar depths between the 2 data sets, which implies that the ROV is
 * observing the sea floor.</p><hr><br>
 *
 * <p>MBARI provides this documentation and code &quot;as is&quot;, with no
 * warranty, express or implied, of its quality or consistency. It is provided
 * without support and without obligation on the part of the Monterey Bay
 * Aquarium Research Institute to assist in its use, correction, modification,
 * or enhancement. This information should not be published or distributed to
 * third parties without specific written permission from MBARI.</p><br>
 *
 * Copyright 2002 MBARI.<br>
 * MBARI Proprietary Information. All rights reserved.<br><hr><br>
 *
 * $Log: RovAltitudeFilterPanel.java,v $
 * Revision 1.2  2002/03/05 00:41:40  brian
 * Final tweaks for creating UTM grids
 *
 * Revision 1.1  2002/01/30 00:23:56  brian
 * Added comments to all classes and methods. Tested the accuracy of AsciiRasterGridReader and AsciiRasterGridWriter. Also checked the the GridUtil was populating the spatial grids correctly and accurately. The data files generated matched up perfectly with the orginal text files. Also implemented an RovAltitudeFilter class to encapsulate different filtering methods.
 *<br><hr><br>
 *
 * @author  : $Author: brian $
 * @version : $Revision: 1.2 $
 */
public class RovAltitudeFilterPanel extends JPanel {
    JPanel rbPanel = new JPanel();
    JPanel paramPanel = new JPanel();
    ButtonGroup buttonGroup1 = new ButtonGroup();
    JRadioButton rb1 = new JRadioButton();
    JRadioButton rb2 = new JRadioButton();
    JRadioButton rb3 = new JRadioButton();
    VerticalFlowLayout verticalFlowLayout1 = new VerticalFlowLayout();
    VerticalFlowLayout verticalFlowLayout2 = new VerticalFlowLayout();
    JPanel p1 = new JPanel();
    JPanel p2 = new JPanel();
    JPanel p3 = new JPanel();
    JLabel lbl1 = new JLabel();
    JLabel lbl2a = new JLabel();
    JLabel lbl3a = new JLabel();
    JTextField tf2 = new JTextField();
    JLabel lbl2b = new JLabel();
    JTextField tf3 = new JTextField();
    JLabel lbl3b = new JLabel();
    private RovAltitudeFilter filter = new RovAltitudeFilter();

    public RovAltitudeFilterPanel() {
        try {
            jbInit();
        }
        catch(Exception ex) {
            ex.printStackTrace();
        }
    }
    void jbInit() throws Exception {
        rbPanel.setLayout(verticalFlowLayout1);
        paramPanel.setLayout(verticalFlowLayout2);
        paramPanel.setPreferredSize(new Dimension(351, 83));
        lbl1.setHorizontalAlignment(SwingConstants.LEFT);
        lbl1.setHorizontalTextPosition(SwingConstants.LEFT);
        lbl1.setText("No Filter");
        lbl2a.setText("Use ROV altitudes within +/- ");
        lbl3a.setText("Use ROV altitudes less than ");
        p1.setPreferredSize(new Dimension(341, 21));
        p2.setPreferredSize(new Dimension(21, 21));
        p3.setPreferredSize(new Dimension(51, 21));
        tf2.setPreferredSize(new Dimension(35, 21));
        tf2.setText("30");
        tf2.setHorizontalAlignment(SwingConstants.RIGHT);
        tf2.addKeyListener(new KeyAdapter() {
            public void keyTyped(KeyEvent e) {
                char c = e.getKeyChar();
                if (!((Character.isDigit(c)) ||
                        (c == KeyEvent.VK_BACK_SPACE) ||
                        (c == KeyEvent.VK_DELETE))) {
                    getToolkit().beep();
                    e.consume();
                }
            }
        });
        lbl2b.setToolTipText("");
        lbl2b.setText("meters of bottom.");
        tf3.setPreferredSize(new Dimension(35, 21));
        tf3.setText("30");
        tf3.setHorizontalAlignment(SwingConstants.RIGHT);
        tf3.addKeyListener(new KeyAdapter() {
            public void keyTyped(KeyEvent e) {
                char c = e.getKeyChar();
                if (!((Character.isDigit(c)) ||
                        (c == KeyEvent.VK_BACK_SPACE) ||
                        (c == KeyEvent.VK_DELETE))) {
                    getToolkit().beep();
                    e.consume();
                }
            }
        });
        lbl3b.setText("meters.");
        rb1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(ActionEvent e) {
                rb1_actionPerformed(e);
            }
        });
        rb2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(ActionEvent e) {
                rb2_actionPerformed(e);
            }
        });
        rb3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(ActionEvent e) {
                rb3_actionPerformed(e);
            }
        });
        this.add(rbPanel, null);
        rbPanel.add(rb1, null);
        rbPanel.add(rb2, null);
        rbPanel.add(rb3, null);
        this.add(paramPanel, null);
        paramPanel.add(p1, null);
        p1.add(lbl1, null);
        paramPanel.add(p2, null);
        p2.add(lbl2a, null);
        p2.add(tf2, null);
        p2.add(lbl2b, null);
        paramPanel.add(p3, null);
        p3.add(lbl3a, null);
        p3.add(tf3, null);
        p3.add(lbl3b, null);

        buttonGroup1.add(rb1);
        buttonGroup1.add(rb2);
        buttonGroup1.add(rb3);
        rb1.setSelected(true);
    }


    void rb1_actionPerformed(ActionEvent e) {
        filter.setMaxAltitude(Double.NaN);
        filter.setMinAltitude(Double.NaN);
    }

    void rb2_actionPerformed(ActionEvent e) {
        filter.setMaxAltitude(Double.parseDouble(tf2.getText()));
        filter.setMinAltitude(Double.parseDouble(tf2.getText()));
    }

    void rb3_actionPerformed(ActionEvent e) {
        filter.setMaxAltitude(Double.parseDouble(tf3.getText()));
        filter.setMinAltitude(Double.NaN);
    }

    /**
     *
     * @return The RovAltitudeFilter that is created by this panel
     */
    public RovAltitudeFilter getAltitudeFilter() {
        return filter;
    }
}