FileDocCategorySizeDatePackage
FamilyFrame.javaAPI DocExample17623Tue Dec 08 01:21:00 GMT 1998HumanInterface

FamilyFrame

public class FamilyFrame extends Frame implements ActionListener
note
This is the main frame which is shown when the application is run. It consists of a frame, main menu and text area for displaying details.

Fields Summary
ListDialog
listDlg
AboutBox
aboutBox
InEntry
entryDlg
Search
searchDlg
Hashtable
people
Hashtable
families
DataManagement.DMControl
dmControl
int
listType
FlatFile
fileType
public TextArea
textArea
private BorderLayout
borderLayout
private MenuBar
menuBar
Menu class instantations: Main menu bar
private Menu
menuFile
Menu class instantations: Main menu options: File
private Menu
menuEdit
Menu class instantations: Main menu options: Edit
private Menu
menuView
Menu class instantations: Main menu options: View
private Menu
menuHelp
Menu class instantations: Main menu options: Help
private MenuItem
menuOpen
Menu class instantations: Menu items: Open
private MenuItem
menuSave
Menu class instantations: Menu items: Open
private MenuItem
menuClose
Menu class instantations: Menu items: Close
private MenuItem
menuExit
Menu class instantations: Menu items: Exit
private MenuItem
menuNewIndividual
Menu class instantations: Menu items: New Individual
private MenuItem
menuSearch
Menu class instantations: Menu items: Search
private MenuItem
menuDescendents
Menu class instantations: Menu items: Descendents
private MenuItem
menuAncestors
Menu class instantations: Menu items: Ancestors
private MenuItem
menuAbout
Menu class instantations: Menu items: About
private CheckboxMenuItem
checkShowSpouse
Constructors Summary
public FamilyFrame(DataManagement.DMControl dmControl)
Construct the frame


       
     
    this.dmControl = dmControl;
    dmControl.setTarget(this);
    try {
      setup();
    }
    catch (Exception e) {
      e.printStackTrace();
    }
  
Methods Summary
public voidactionPerformed(java.awt.event.ActionEvent e)

note
Method to handle the action events for the menu options.

    String command = e.getActionCommand();
//    System.out.println(command);
    if(command.equals("Open")) openFile();
    if(command.equals("Save as")) saveFile();
    if(command.equals("Close")) close();
    if(command.equals("Exit")) exit();
    if(command.equals("About")) showAboutBox();
    if(command.equals("New Individual")) newIndividual();
    if(command.equals("Find")) find();
    if(command.equals("Descendants")) getDescendants();
    if(command.equals("Ancestors")) getAncestors();
  
voidclose()

note
Close and empty the Family and Individual lists, as well as resetting the reference numbers.

    people = new Hashtable();
    families = new Hashtable();
    Individual temp1 = new Individual();
    temp1.reset();
    Family temp2 = new Family();
    temp2.reset();
//    baseFamily = new Family();
  
public voidexit()

note
Exit action performed

    System.exit(0);
  
voidfind()

note
Creates the Search dialog and displays on the screen.

    
    searchDlg = new Search();
    searchDlg.setTarget(this);
    searchDlg.setVisible(true);
  
voidgetAncestors()

note
Create a list of individuals and pass them to the ListDialog to be displayed.

    Vector buffer = null;
    Enumeration pers;
    Individual temp;
    String name;
    int count = 0;

    listType = 2;
    if(people != null) {
      listDlg = new ListDialog(this);
      listDlg.setTitle("List of Individuals...");
      pers = people.keys();
      while (pers.hasMoreElements()) {
        temp = (Individual)people.get((Integer)pers.nextElement());
        name = temp.getGivenNames() + " " + temp.getFamilyName();
        if(buffer == null) buffer = new Vector();
        buffer.addElement(temp);
        count++;
      }
      listDlg.setData(buffer);
      listDlg.setTarget(this);
      Dimension frmSize = getSize();
      Point loc = getLocation();
      listDlg.setLocation((frmSize.width - 180)/ 2 + loc.x, (frmSize.height - 300) / 2 + loc.y);
      listDlg.setVisible(true);
    }
  
voidgetDescendants()

note
Create a list of individuals and pass them to the ListDialog to be displayed.

    Vector buffer = null;
    Family t;
    Individual temp;
    Enumeration pers;
    String name;
    int count = 0;

    listType = 1;
    if(people != null) {
      listDlg = new ListDialog(this);
      listDlg.setTitle("List of Individuals...");
      pers = people.keys();
      while (pers.hasMoreElements()) {
        temp = (Individual)people.get((Integer)pers.nextElement());
        name = temp.getGivenNames() + " " + temp.getFamilyName();
        if(buffer == null) buffer = new Vector();
        buffer.addElement(temp);
        count++;
      }
      listDlg.setData(buffer);
      listDlg.setTarget(this);
      Dimension frmSize = getSize();
      Point loc = getLocation();
      listDlg.setLocation((frmSize.width - 180)/ 2 + loc.x, (frmSize.height - 300) / 2 + loc.y);
      listDlg.setVisible(true);
    }
  
voidlistClick()

note
This method is called from ListDialog when an element in the list has been selected and clicked on.

    Enumeration list;
    String name;
    Individual found;
    Enumeration descendants;
    Vector alist;
    if(listType == 2) showAncestors();
    else {
      Individual person = listDlg.getIndividual();
      if(person.isParent()) {
        list = person.getSpouseInList();
        while(list.hasMoreElements()) {
          alist = ((Family)list.nextElement()).getDescendants(person.getName(),0,checkShowSpouse.getState());
          if(alist != null) {
            textArea.setText(" ");
            descendants = alist.elements();
            while(descendants.hasMoreElements()) {
              name = (String)descendants.nextElement();
              textArea.setText(textArea.getText() + name + "\n");
            }
            name = person.getGivenNames() + " " + person.getFamilyName().toLowerCase();
            textArea.setText("The Descendants of: " + name + "\n\n" + textArea.getText());
          }
        }
      }
      else textArea.setText("No Descendants found.");
    }
  
voidnewIndividual()

note
When Edit | New Individual is chosen from the main menu, display the InEntry dialog for the user to create an individual.

    Individual tempPerson;
    Family tempFamily;
    Hashtable test;

    test = families;
    entryDlg = new InEntry(this,true);
    entryDlg.setList(families);
    entryDlg.setInList(people);
    entryDlg.setVisible(true);
    tempPerson = entryDlg.getIndividual();
    if(tempPerson != null && entryDlg.getCancel() != true) {
      if(entryDlg.isNewIndividual()) {
        people.put(new Integer(tempPerson.getReference()),tempPerson);
        if(entryDlg.isParent()) {
          entryDlg.getParentOf().setWife(tempPerson);
          if(entryDlg.isChild()) {
            entryDlg.getChild().addChild(tempPerson);
          }  
        }    
        else {
          if(entryDlg.isChild()) {
            entryDlg.getChild().addChild(tempPerson);
          }  
          else {
            tempFamily = new Family();
            tempFamily.setHusband(tempPerson);
            int next = families.size() + 1;
            families.put(new Integer(next),tempFamily);     
          }
        }
      }
      else {
        tempFamily = new Family();
        tempFamily.setHusband(tempPerson);
        int next = families.size() + 1;
        families.put(new Integer(next),tempFamily);     
      }
    }
  
voidopenFile()

note
The method to handle opening the data file, the actual reading in of the data is left to the FlatFile object created within this method.

    FileDialog fDialog = new FileDialog(this,"Open...",FileDialog.LOAD);
    fDialog.setFile("*.ged");
    fDialog.show();
    if(fDialog.getFile() != null) {
      close();
      dmControl.readData(fDialog.getFile());
      families = dmControl.getFamilies();
      people = dmControl.getIndividuals();
    }
  
public voidsaveFile()

note
Using the string representation from ther Inidivudal and Family objects, this method can write out records and fields to a data file.

    FileDialog fDialog = new FileDialog(this,"Save as...",FileDialog.SAVE);
    fDialog.show();
    if(fDialog.getFile() != null) {
/*      try {
        BufferedWriter out = new BufferedWriter(new FileWriter(fDialog.getFile()));
        textArea.setText("Saving as " + fDialog.getFile());
        Enumeration list = people.keys();
        while(list.hasMoreElements()) {
          out.write(((Individual)people.get(list.nextElement())).toString("0"));
        }
        list = families.keys();
        while(list.hasMoreElements()) {
          out.write(((Family)families.get(list.nextElement())).toString("0"));
        }
        out.write("0 TRLR");
        out.close();
        textArea.appendText("\nFinished saving file....");
      }
      catch(FileNotFoundException ex) {}
      catch(IOException exe) {}*/
      dmControl.saveData(fDialog.getFile());
    }
  
public voidsearch()

note
The Search Dialog directly calls this method once you have entered a search string

 
    Vector found = new Vector();
    boolean flag;
    Individual person;
    if(searchDlg.getSearchName().length() > 0) {
      String name = searchDlg.getSearchName().toLowerCase();
      Enumeration list = people.keys();
      while(list.hasMoreElements()) {
        person = (Individual)people.get(list.nextElement());
        if(person.getFamilyName().toLowerCase().equals(name) || person.getGivenNames().toLowerCase().equals(name))
          found.addElement(person);
      }
      listDlg = new ListDialog(this);
      listDlg.setTitle("List of Individuals...");
      listDlg.setData(found);
      listDlg.setTarget(this);
      Dimension frmSize = getSize();
      Point loc = getLocation();
      listDlg.setLocation((frmSize.width - 180)/ 2 + loc.x, (frmSize.height - 300) / 2 + loc.y);
      listDlg.setVisible(true);
    }
  
public voidsetup()

note
Component initialization.

    this.setLayout(borderLayout);
    this.setSize(new Dimension(529, 327));
    this.setTitle("Family Tree");
    menuFile.setLabel("File");
    menuOpen.setLabel("Open");
    menuSave.setLabel("Save as");
    menuClose.setLabel("Close");
    menuExit.setLabel("Exit");
    menuEdit.setLabel("Edit");
    menuNewIndividual.setLabel("New Individual");
    menuView.setLabel("View");
    menuSearch.setLabel("Find");
    menuDescendents.setLabel("Descendants");
    menuAncestors.setLabel("Ancestors");
    checkShowSpouse.setLabel("Show Spouse");
    menuHelp.setLabel("Help");
    menuAbout.setLabel("About");

    menuAbout.addActionListener(this);
    menuOpen.addActionListener(this);
    menuSave.addActionListener(this);
    menuClose.addActionListener(this);
    menuExit.addActionListener(this);
    menuNewIndividual.addActionListener(this);
    menuSearch.addActionListener(this);
    menuDescendents.addActionListener(this);
    menuAncestors.addActionListener(this);

    menuBar.add(menuFile);
    menuBar.add(menuEdit);
    menuBar.add(menuView);
    menuBar.add(menuHelp);

    menuFile.add(menuOpen);
    menuFile.add(menuSave);
    menuFile.add(menuClose);
    menuFile.add(menuExit);
    menuEdit.add(menuNewIndividual);
    menuView.add(menuSearch);
    menuView.add(menuDescendents);
    menuView.add(menuAncestors);
    menuView.add(checkShowSpouse);
    menuHelp.add(menuAbout);

    this.setMenuBar(menuBar);
    this.addWindowListener(new windowEventHandler(this));
    textArea.setEditable(false);
    this.add(textArea, BorderLayout.CENTER);
    testData();
  
public voidshowAboutBox()

note
Help | About action performed

    aboutBox = new AboutBox(this);
    Dimension frmSize = getSize();
    Point loc = getLocation();
    aboutBox.setLocation((frmSize.width - 216)/ 2 + loc.x, (frmSize.height - 100) / 2 + loc.y);
    aboutBox.setModal(true);
    aboutBox.show();
  
voidshowAncestors()

note
This method creates a list of ancestors to be displayed in the Text area.

    Vector list = null;
    String name;
    String test;

    textArea.setText(" ");
    Individual person = listDlg.getCurrent();
    try {
      list = person.getChildOf().getAncestors(0);
    }catch(NullPointerException ex) {
      textArea.setText(person.getName() + " has no Ancestors");
    }
    if(list != null) {
      Enumeration loop = list.elements();
      textArea.setText("The Ancestors of " + person.getName() + "\n");
      while(loop.hasMoreElements()) {
        name = (String)loop.nextElement();
        textArea.setText(textArea.getText() + "\n" + name);
      }
    }
  
voidtestData()

note
This method sets up test data by creating Individuals and placing them into Families.

    Family f;

    people = new Hashtable();
    families = new Hashtable();
    people.put(new Integer(1),Individual.testObject());
    people.put(new Integer(2),Individual.testObject2());
    people.put(new Integer(3),Individual.testObject3());
    people.put(new Integer(4),Individual.testObject4());
    people.put(new Integer(5),Individual.testObject5());
    people.put(new Integer(6),Individual.testObject6());

    f = new Family(1,
    (Individual)people.get(new Integer(1)), (Individual)people.get(new Integer(2)),
      Marriage.testObject(), Divorce.testObject());
    f.addChild((Individual)people.get(new Integer(3)));
    f.addChild((Individual)people.get(new Integer(4)));

    families.put(new Integer(1),f);

    f = new Family(2,
    (Individual)people.get(new Integer(3)), (Individual)people.get(new Integer(5)),
      Marriage.testObject(), Divorce.testObject());
    f.addChild((Individual)people.get(new Integer(6)));

    families.put(new Integer(2),f);
    dmControl.setUpRecords(families,people);
  
voidthis_windowClosing(java.awt.event.WindowEvent e)

note
Handle the window closing event by shutting down the entire application.

    System.exit(0);
  
voidviewFamily()

note
This method is called from ListDialog, and displays in the Text area the Individuals family details.

    Individual person;
    Enumeration list;
    Family family;
    person = listDlg.getCurrent();  
    if(person != null) {
      textArea.setText(" ");
      family = person.getChildOf();
      if(family != null) textArea.setText(family.getDetails());
      if(person.isParent() == true) {
        list = person.getSpouseInList();
        if(list != null) {
          while(list.hasMoreElements()) {
            textArea.setText(textArea.getText() + "\n" + ((Family)list.nextElement()).getDetails());
          }   
        }
      }
    }
  
voidviewIndividual()

note
This method is called from ListDialog, and displays in the Text area the Individuals details.

    Individual person;

    person = listDlg.getCurrent();
    if(person != null)
    {
      textArea.setText(person.getDetails());
    }
    else
      textArea.setText("Please select an individual before choosing to view their details or family...");