import java.awt.*;
import java.util.StringTokenizer;

/**
 * CSC 442F:    Software Engineering
 * Software:    Calendar Client
 * Component:   LocationPanel class
 * Description: The LocationPanel class produces an location panel from a 
 *              calendar server. This panel lists all possible locations to
 *              hold meetings, including their capacities. Included also are 
 *              the options "none" and "any".
 *
 * @author David Tam
 * @version 1.0
 */
public class LocationPanel extends Panel
{
  // Classes
  protected ClientSocket socket;

  // AWT classes
  protected Label location;
  public Choice locationChoice;

  // GridBagLayout constraints
  protected GridBagConstraints constraints;
  
 /**
  * Constructor
  * ===========
  *
  * @param socket_in     The socket which is used to talk to the server.
  */
  public LocationPanel(ClientSocket socket_in)
  {
    // Variable initialization
    socket = socket_in;

    // Constraints instantiation
    constraints = new GridBagConstraints();   

    // AWT class instantiation
    location = new Label("Location");
    locationChoice = new Choice();
    locationChoice.addItem("none");
    locationChoice.addItem("any");

    // locationPanel layout
    setLayout(new GridBagLayout());
    constraints.gridx=0;
    constraints.gridy=0;
    constraints.anchor=constraints.WEST;
    add(location, constraints);
    constraints.gridy=1;
    add(locationChoice, constraints);
  }
 
 
 /**
  * Method to fetch room list from server
  * =====================================
  */
  public void fetchData()
  {
    GetRooms getRooms = new GetRooms(socket, locationChoice);
  }
  
  
 /**
  * Method to send room choice to server
  * ====================================
  * 
  * @return Returns a String in the form of the protocol
  */
  public String buildResponse()
  {
    // Send only room location discard capacity information
    StringTokenizer token = new StringTokenizer(
                                locationChoice.getSelectedItem());
    String result = token.nextToken();
    result = result.concat(",");
   
    return result;
  }


 /**
  * Method to toggle input fields between editable and noneditable
  * ==============================================================
  *
  * @param value   A boolean value that set field to editable or noneditable
  */
  public void setEditable(boolean value)
  {    
    locationChoice.setEnabled(value);
  }
}
