package Layout;

import java.awt.Component;
import java.awt.Container;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;

public class AgExManagerGui extends JFrame implements ActionListener {
	private boolean started=false;
	private JButton startStop ;
	private JTextField current;
	private JTextField opTime ;
    private JTextField numberClocks;
    private JTextField listAgent;

	public void actionPerformed(ActionEvent ag0) {
		started=!started;
		if(started)
			startStop.setText("Stop");
		else
			startStop.setText("Start");
		
	}
	
	public void setInfo(final int clock,final int numberOfClocks,final String time,final String list) {
		SwingUtilities.invokeLater( 
                new Runnable() {
                   
                   // pick random character and display it
                   public void run() 
                   {
                	   	current.setText(""+ clock);
                	   	opTime.setText(time) ;
                	   	numberClocks.setText(""+numberOfClocks);
                	   	listAgent.setText("List of agents: " +list);
                   }
 
                } // end inner class
 
             ); // end call to SwingUtilities.invokeLater
	}

	private Container container;
	   private GridBagLayout layout;
	   private GridBagConstraints constraints; 
	    
	   // set up GUI
	   public AgExManagerGui()
	   {
	      super( "AgEx Manager GUI " );

	      container = getContentPane();
	      layout = new GridBagLayout();
	      container.setLayout( layout );   

	      // instantiate gridbag constraints
	      constraints = new GridBagConstraints();

	     
	      current = new JTextField( "Current Clock: 0",100);
	     
	       opTime = new JTextField( "Operation Time: " ,100);
	       numberClocks = new JTextField( "Number of Clocks: 0" ,100);
	      
	       startStop = new JButton( "Start  " );
	       startStop.addActionListener(this);
	    
          listAgent=new JTextField("List of Agents: ",200);
	      
          current.setEditable(false);
          opTime.setEditable(false);
          numberClocks.setEditable(false);
          listAgent.setEditable(false);
          
          // button2
          constraints.weightx = 1;  // can grow wider
          constraints.weighty = 0;     // can grow taller
          // weightx and weighty for textArea1 are both 0: the default
	      // anchor for all components is CENTER: the default
	      constraints.fill = GridBagConstraints.BOTH;
	      addComponent( startStop, 0, 0, 2, 1 );    
	       

	      constraints.fill = GridBagConstraints.HORIZONTAL;
	      addComponent( current, 1, 0, 1, 1 );
	      addComponent( numberClocks, 2,0, 1, 1 );
	      
	      addComponent( opTime, 3,0, 1, 1 );             

	   
	      
	       
	  
	      addComponent( listAgent, 4,0, 1, 1 );
	       
	      setBounds( 500,200,400, 150 );
	      
	     
	      setVisible( true );

	   } // end constructor GridBagDemo

	   // method to set constraints on 
	   private void addComponent( Component component,
	      int row, int column, int width, int height )
	   {
	      // set gridx and gridy 
	      constraints.gridx = column;
	      constraints.gridy = row;

	      // set gridwidth and gridheight
	      constraints.gridwidth = width;   
	      constraints.gridheight = height;

	      // set constraints and add component
	      layout.setConstraints( component, constraints );  
	      container.add( component );      
	   }

	   public static void main( String args[] )
	   {
		   AgExManagerGui application = new AgExManagerGui();
	      application.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
	   }
}
