//Position Form
//by www.neiljohan.com

import java.io.*;
import javax.swing.JFrame; //Requires JDK 1.2
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.SwingConstants;
import java.awt.BorderLayout;
import java.awt.Container;
import javax.swing.JButton;
import javax.swing.JTextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class PositionForm
{
    private Box iForm;
    private JTextField iLongDegrees, iLongMinutes,iLongDirection,iLatDegrees,iLatMinutes,iLatDirection;
    private double tLongDegrees,tLongMinutes, tLatDegrees,tLatMinutes;
    private char tLongDirection,tLatDirection;
    
    
    
    public PositionForm()
        {
            iLongDegrees = new JTextField(15);
            final Box tNameBox = new Box(BoxLayout.X_AXIS);
            tNameBox.add(iLongDegrees);

            iLongMinutes = new JTextField(15);
            tNameBox.add(iLongMinutes);
            
            iLongDirection = new JTextField(15);
            tNameBox.add(iLongDirection);

            iLatDegrees = new JTextField(15);
            tNameBox.add(iLatDegrees);

            iLatMinutes = new JTextField(15);
            tNameBox.add(iLatMinutes);
            
            iLatDirection = new JTextField(15);
            tNameBox.add(iLatDirection);
            


                // now create the form
            iForm = new Box(BoxLayout.Y_AXIS);
            iForm.add(tNameBox);
            

        }


    public Position getPosition()
        {
            tLongDegrees = new Integer(iLongDegrees.getText()).intValue();
            tLongMinutes = new Integer(iLongMinutes.getText()).intValue();
            String tempDirection = iLongDirection.getText();
            tLongDirection = tempDirection.charAt(0);

            tLatDegrees = new Integer(iLatDegrees.getText()).intValue();
            tLatMinutes = new Integer(iLatMinutes.getText()).intValue();
            tempDirection = iLatDirection.getText();
            tLatDirection = tempDirection.charAt(0);

            Position tPosition = new PositionImpl(tLongDegrees +"-"+ tLongMinutes +"-" + tLongDirection +"-" + tLatDegrees +"-"+ tLatMinutes +"-" + tLatDirection);
            return tPosition;
        }

    public void setPosition(Position tPosition)
        {
            tLongDegrees = tPosition.getLatitude();
            tLongMinutes = tPosition.getLongMinutes();
            tLongDirection = tPosition.getLongDirection();

            iLongDegrees.setText(Double.toString(tPosition.getLongitude()));
            iLongMinutes.setText(Double.toString(tPosition.getLongMinutes()));
            String temp = "" + tLongDirection;
            iLongDirection.setText(temp);

            tLatDegrees = tPosition.getLatitude();
            tLatMinutes = tPosition.getLatMinutes();
            tLatDirection = tPosition.getLatDirection();

            iLatDegrees.setText(Double.toString(tLatDegrees));
            iLatMinutes.setText(Double.toString(tLatMinutes));
            temp = "" + tLatDirection;
            iLatDirection.setText(temp);


        }

    public Box getBox()
        {
            return iForm;
        }
    
}

            

