import java.awt.datatransfer.*;
import java.util.*;

/**
 * An encapsulation of an Appointment.
 * 
 * Note that this class implements the Transferable interface so there
 * is no reason to also create a wrapper.
 * 
 * @author  Prof. David Bernstein, James Madison University
 * @version 1.0
 */
public class Appointment implements Transferable
{
  public static DataFlavor APPOINTMENT_FLAVOR = new DataFlavor(Appointment.class, "Appointment");
  private static DataFlavor[] flavors = {APPOINTMENT_FLAVOR};
  
  private Date    date;
  private String  description;

  /**
   * Construct an Appointment with no description and the 
   * current date/time.
   */
  public Appointment()
  {
    this(new Date(), "");
  }
  
  /**
   * Construct an Appointment with the given description and the 
   * current date/time.
   * 
   * @param description  The description
   */
  public Appointment(String description)
  {
    this(new Date(), description);
  }
  
  /**
   * Construct an Appointment with the given date and description.
   * 
   * @param date         The date
   * @param description  The description
   */
  public Appointment(Date date, String description)
  {
    this.date = date;
    this.description = description;
  }
  
  /**
   * Get the date.
   * 
   * @return The date.
   */
  public Date getDate()
  {
    return date;
  }
  
  /**
   * Get the description.
   * 
   * @return The description.
   */
  public String getDescription()
  {
    return description;
  }
  
  // Methods required by Transferable
  
  /**
   * Get the Object to transfer based on the given DataFlavor.
   * 
   * @return  The Object
   * @throws UnsupportedFlavorException if the DataFlavor isn't supported
   */
  public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException
  {
    if (flavor.equals(Appointment.APPOINTMENT_FLAVOR))
    {
      return this;
    }
    throw new UnsupportedFlavorException(flavor);
  }
  
  /**
   * Get an array of all of the DataFlavor objects that are supported.
   * 
   * @return  The DataFlavor objects
   */
  public DataFlavor[] getTransferDataFlavors()
  {
    return flavors;
  }
  
  /**
   * Is the given DataFlavor supported?
   * 
   * @param flavor  The DataFlavor of interest
   * @return true if supported; false otherwise
   */
  public boolean isDataFlavorSupported(DataFlavor flavor)
  {
    for (int i=0; i<flavors.length; i++)
    {
      if (flavor.equals(flavors[0])) return true;
    }
    return false;
  }
}
