package chapter01;

import javax.swing.*;
import java.io.*;

public class MitsuPDTest {
  /**
   * @param args
   */
  public static void main(String[] args) {
    /* fc is a Java File Chooser that allows file selection */
    final JFileChooser fc = new JFileChooser();
    /* Set the mode of fc to Files and Directories */
    fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
    /* Invoke the file chooser and obtain its return value */
    int retval = fc.showOpenDialog(null);
    /* If the file chooser returns "APPROVE_OPTION" then */
    if (retval == JFileChooser.APPROVE_OPTION) {
      /* Obtain the File type object from fc and */
      /* turn it into a file name (of type String) */
      File file = fc.getSelectedFile();
      String sourceName = file.toString();

      /* Now lab01 the PD methods using the file name */
      /* create an ArrayBasedPD object */
      PhoneDirectory myPD = new ArrayBasedPD();
      /* load data into that object from the source file */
      myPD.loadData(sourceName);
      /* create a new PDGUI object */
      PDUserInterface myGUI = new PDGUI();
      /* assign the role of processing commands w.r.t. myPD */
      myGUI.processCommands(myPD);
      
      PDUserInterface myGUI2 = new PDConsoleUI();
      myGUI2.processCommands(myPD);
    }
  }
}

