import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import com.sun.java.swing.*;

public class URLBar extends JPanel implements ActionListener {

  JLabel labelurl;
  //  JTextField tfurl;
  JComboBox tfurl;
  Explorer explorer;

  void buildConstraints(GridBagConstraints gbc, int gx, int gy, int gw, int gh, int wx, int wy) {
    gbc.gridx      = gx;
    gbc.gridy      = gy;
    gbc.gridwidth  = gw;
    gbc.gridheight = gh;
    gbc.weightx    = wx;
    gbc.weighty    = wy;
  }

  public URLBar(Explorer e) {
    GridBagLayout gridBag          = new GridBagLayout(); 
    GridBagConstraints constraints = new GridBagConstraints();
    setLayout(gridBag);
    explorer = e;

    /* le label */
    constraints.fill   = GridBagConstraints.BOTH;
    buildConstraints(constraints,0,0,1,1,0,0) ;
    labelurl = new JLabel ("Location : ");
    gridBag.setConstraints (labelurl, constraints);
    add(labelurl);

    /* la zone de saisie */
    constraints.fill = GridBagConstraints.HORIZONTAL;
    buildConstraints(constraints,1,0,1,1,90,100) ;
    //    tfurl  = new JTextField("http://");
    tfurl  = new JComboBox();
    tfurl.setBackground(Color.white);
    tfurl.setEditable(true);
    gridBag.setConstraints (tfurl, constraints);
    add(tfurl);
    tfurl.addActionListener( this );
  }

  public void actionPerformed(ActionEvent e) {
    boolean b = false;
    explorer.ChangeURL((String)tfurl.getSelectedItem());
    for (int i = 0; i<tfurl.getItemCount(); i++ )
      if (tfurl.getItemAt(i).equals((String)tfurl.getSelectedItem()))
	b = true;
    if (b == false) {
      tfurl.addItem(tfurl.getSelectedItem());
    }
  }
}
