// file: PzmapTracer.java
//

// include the necessary system files
//
//import java.awt.*;
import javax.swing.*;
import java.awt.GridBagConstraints;
import java.awt.Font;
import java.awt.GridBagLayout;
import java.awt.event.*;
import java.awt.Container;
import java.awt.Insets;
import java.awt.Dimension;

// include the necessary local files
//
//import Constants;
//import SubPanel;

// class: PzmapTracer
//
// this class implements a popup frame which displays the coordinates of the
// current position on the pz_map
//
public class PzmapTracer extends JFrame implements ActionListener, Constants {
    //public class PzmapTracer extends Frame {
    
    private JLabel freq_value = new JLabel("0.00000000");
    private JLabel band_value = new JLabel("0.00000000");
    private JLabel freq_label = new JLabel ("freq");
    private JLabel band_label = new JLabel ("BW");
    private JButton close = new JButton("Close");
    
    // method: PzmapTracer
    //
    // parameters: 
    //     String title: title of frame
    // 
    // this method instantiates the class
    //
    // returns: none
    //
    public PzmapTracer(String title) {
	
	// set the layout manager of the frame
	//
	close.addActionListener(this);
	
	GridBagLayout gridbag = new GridBagLayout();
	GridBagConstraints c = new GridBagConstraints();
	Container contentpane = getContentPane();
	contentpane.setLayout(gridbag);
	
	// set the preferred size for components
	//
	Dimension label_dim = new Dimension(50, 50);
	Dimension value_dim = new Dimension(100, 30);
	
	
	freq_value.setPreferredSize(value_dim);
	freq_label.setPreferredSize(label_dim);
	band_value.setPreferredSize(value_dim);
	band_label.setPreferredSize(label_dim);
	close.setPreferredSize(label_dim);
	
	// align the labels
	//
	c.gridx = 0;
	c.gridy = 0;
	c.fill = GridBagConstraints.NORTH;
	c.insets = new Insets(0, 0, Constants.INSET_SIZE, Constants.INSET_SIZE);
	gridbag.setConstraints(freq_label,c);
	contentpane.add(freq_label);
	
	c.gridx = 1;
	c.gridy = 0;
	c.fill = GridBagConstraints.NORTH;
	c.insets = new Insets(0, 0, Constants.INSET_SIZE, Constants.INSET_SIZE);
	gridbag.setConstraints(freq_value,c);
	contentpane.add(freq_value);
	
	c.gridx = 0;
	c.gridy = 1;
	c.fill = GridBagConstraints.NORTH;
	c.insets = new Insets(0, 0, Constants.INSET_SIZE, Constants.INSET_SIZE);
	gridbag.setConstraints(band_label,c);
	contentpane.add(band_label);
	
	c.gridx = 1;
	c.gridy = 1;
	c.fill = GridBagConstraints.NORTH;
	c.insets = new Insets(Constants.INSET_SIZE, Constants.INSET_SIZE, Constants.INSET_SIZE, Constants.INSET_SIZE);
	gridbag.setConstraints(band_value,c);
	contentpane.add(band_value);
	
	c.gridx = 1;
	c.gridy = 2;
	c.fill = GridBagConstraints.NORTH;
	c.insets = new Insets(Constants.INSET_SIZE, Constants.INSET_SIZE, Constants.INSET_SIZE, Constants.INSET_SIZE);
	gridbag.setConstraints(close,c);
	contentpane.add(close);
	
	// set font of frame
	//
	this.setFont(new Font("Helvetica", Font.PLAIN, 9));
	
	// set the title
	//
	super.setTitle(title);
	
	// resize the window
	//
	this.setSize(220, 150);
    }
    
    
    // method: set_frequency
    //
    // parameters:
    //     double freq_a: new frequency
    //
    // this method sets the frequency value to be displayed
    //
    // returns boolean
    //
    public boolean set_frequency (double freq_a) {
	freq_value.setText( String.valueOf(freq_a) );
	
	// exit gracefully
	//
	return true;
    }
    
    
    // method: set_bandwidth
    //
    // parameters:
    //     double band_a: new frequency
    //
    // this method sets the bandwidth value to be displayed
    //
    // returns boolean
    //
    public boolean set_bandwidth (double band_a) {
	band_value.setText( String.valueOf(band_a) );
	
	// exit gracefully
	//
	return true;
    }
    
    
    // method: set_both
    //
    // parameters:
    //     double freq_a: new frequency
    //     double band_a: new frequency
    //
    // this method sets the frequency and bandwidth values to be displayed
    //
    // returns boolean
    //
    public boolean set_both(double freq_a, double band_a) {
	freq_value.setText( String.valueOf(freq_a) );
	band_value.setText( String.valueOf(band_a) );
	
	// exit gracefully
	//
	return true;
    }
    
    public void actionPerformed(ActionEvent e) {
	if (e.getActionCommand().equals("Close")) {
	    this.setVisible(false);
	}
    }
    
} // end of class PzmapTracer
