/*This class implements the weekly view.*/

import java.awt.*;
import java.awt.event.*;
import java.applet.*;

public class WeekPanel extends Panel  {

  public WeekPanel(ClientSocket cs,Label wklabel,String user)
  {
    super();
    username = user;
    clientsocket = cs;
    setLayout(new GridLayout(7,1));
   
    label = wklabel;
    
    TodaysDate today = new TodaysDate();
    year = today.getCurrentYear();
    month = today.getCurrentMonth();
    nDaysInMonth = today.getnDaysInMonth();

    label.setText(today.intToMonth(month));
    validate();

    textBox1 = new DayTextArea("Sunday",this,clientsocket,username);
    textBox2 = new DayTextArea("Monday",this,clientsocket,username);
    textBox3 = new DayTextArea("Tuesday",this,clientsocket,username);
    textBox4 = new DayTextArea("Wednesday",this,clientsocket,username);
    textBox5 = new DayTextArea("Thursday",this,clientsocket,username);
    textBox6 = new DayTextArea("Friday",this,clientsocket,username);
    textBox7 = new DayTextArea("Saturday",this,clientsocket,username);
    
    add(textBox1);
    add(textBox2);
    add(textBox3);
    add(textBox4);
    add(textBox5);
    add(textBox6);
    add(textBox7);
   

  }
 


  
  public void nextWeek()
  {
    Year yearobject = new Year();
    startDate = startDate + 7;
    if (startDate > nDaysInMonth)
      {
	startDate = startDate - nDaysInMonth;
	month++;
	if (month > 11)
	  {
	    year++;
	    month = 0;
	  }
	nDaysInMonth = yearobject.getNumDaysInMonth(month);
      }
    updateWeekPanel();
  }

  public void previousWeek()
  {
    Year yearobject = new Year();
    startDate = startDate - 7;
    if (startDate < 1)
      {
	month--;
	if (month < 0)
	  {
	    year--;
	    month = 11;
	  }
	nDaysInMonth = yearobject.getNumDaysInMonth(month);
	startDate = nDaysInMonth + startDate;
      }

    updateWeekPanel();
  }
  
  public void updateWeekPanel()
  {
    TodaysDate today = new TodaysDate();
    label.setText(today.intToMonth(month));

    this.removeAll();
    
    textBox1 = new DayTextArea("Sunday",this,clientsocket,username,startDate);
    textBox2 = new DayTextArea("Monday",this,clientsocket,username,startDate);
    textBox3 = new DayTextArea("Tuesday",this,clientsocket,username,startDate);
    textBox4 = new DayTextArea("Wednesday",this,clientsocket,username,startDate);
    textBox5 = new DayTextArea("Thursday",this,clientsocket,username,startDate);
    textBox6 = new DayTextArea("Friday",this,clientsocket,username,startDate);
    textBox7 = new DayTextArea("Saturday",this,clientsocket,username,startDate);
    
    add(textBox1);
    add(textBox2);
    add(textBox3);
    add(textBox4);
    add(textBox5);
    add(textBox6);
    add(textBox7);

    validate();

  }

  public void setnDaysInMonth(int nDays)
  {
    nDaysInMonth = nDays;
  }
  public void setStartDate(int date)
  {
    startDate = date;
  }
  public int getnDaysInMonth()
  {
    return nDaysInMonth;

  }
	
  public int getMonth()
  {
    return month;
  }

  public int getYear()
  {

    return year;
  }
		
  private String username;
  private ClientSocket clientsocket;
  private int startDate;
  private int nDaysInMonth;
  private int month;
  private int year;
  private DayTextArea textBox1;
  private DayTextArea textBox2; 
  private DayTextArea textBox3; 
  private DayTextArea textBox4;
  private DayTextArea textBox5;
  private DayTextArea textBox6;
  private DayTextArea textBox7;
  private Label label;
}





