FileDocCategorySizeDatePackage
InEntry.javaAPI DocExample13146Tue Dec 08 01:21:00 GMT 1998HumanInterface

InEntry

public class InEntry extends Dialog implements ActionListener, TextListener
note
Dialog for creating individuals and families
version
0.3
author
Tim Shelley

Fields Summary
ListDialog
listDlg
ErrorDialog
errorDlg
Hashtable
list
Hashtable
people
Family
childReturned
Family
parentReturned
Individual
person
boolean
newFamily
boolean
newIndividual
boolean
cancel
private GridLayout
gridLayout1
private Panel
panel1
private Label
label1
private Label
label2
private Label
label3
private Label
label4
private Label
label5
private Label
label6
private Label
label7
private Label
label8
private TextField
textField1
private TextField
textField2
private TextField
textField3
private TextField
textField4
private TextField
textField5
private TextField
textField6
private TextField
textField7
private Button
button1
private Button
button2
private Button
button3
private Button
button4
private Button
button5
Constructors Summary
public InEntry(Frame frame, String title, boolean modal)


         
    super(frame, title, modal);
    try {
      setup();
      add(panel1);
      pack();
    }
    catch (Exception e) {
      e.printStackTrace();
    }
    this.setSize(410,291);
    Dimension frmSize = Toolkit.getDefaultToolkit().getScreenSize();
    setLocation((frmSize.width - getSize().width)/2, (frmSize.height - getSize().height)/2);
//    validate();
  
public InEntry(Frame frame)

    this(frame, "", false);
  
public InEntry(Frame frame, boolean modal)

    this(frame, "", modal);
  
public InEntry(Frame frame, String title)

    this(frame, title, false);
  
Methods Summary
public voidactionPerformed(java.awt.event.ActionEvent e)

note
Implemented method to handle action events, in this class only handles the button events.

    String command = e.getActionCommand();
    if(command.equals("OK")) createIndividual();
    if(command.equals("Update")) updateIndividual();
    if(command.equals("Cancel"))
    {
      cancel = true;
      dispose();
    }
    if(command.equals("Child Of >>")) setChildOfField();
    if(command.equals("Married To >>")) setParentOfField();       
    if(command.equals("Individual >>")) setIndividualFields();
  
voidcreateIndividual()

note
When the OK button is pressed a new individual is created

    Family family;
    String testSex = new String();
    int notComplete = 0;
    String error = new String();
                     
    testSex = textField3.getText().toUpperCase();
    if(textField1.getText().length() == 0) {
      notComplete = 1;
      error = new String("Need to input first name");
    }
    else {
      if(parentReturned != null) {
        if(testSex.equals("M")) {
          if(parentReturned.getHusband() != null) {
            notComplete = 1;
            error = error + "\nHusband for family already exists";
          }
        }
        else {
          if(testSex.equals("F")) {
            if(parentReturned.getWife() != null) {
              notComplete = 1;
              error = error + "\nWife for family already exists";
            }
          }
        }
      }
    }

    if(textField7.getText().length() == 0) {
      if(textField2.getText().length() == 0) {
        notComplete = 1;
        error = error + "\nNeed childOf or parentOf";
      }
    }
    if(textField3.getText().length() == 0) {
      error = error + "\nNeed to enter sex";
      notComplete = 1;
    }
    else {
      if(!testSex.equals("M") && !testSex.equals("F")) {
        notComplete = 1;
        error = error + "\nSex must be m or f";
      }
    }
    if(newFamily == true && testSex.equals("F")) {
      notComplete = 1;
      error = error + "\nCreation of new family must start with \nhusband";
    }
    if(notComplete == 0) {
      if(newIndividual) {
        person = new Individual();
        if(textField7.getText().length() == 0) {
          if(testSex.equals("F") && textField6.getText().length() != 0)
            person.setFamilyName(textField6.getText());
          else
            person.setFamilyName(textField2.getText());
        }
        else person.setFamilyName(textField7.getText());
        person.setGivenNames(textField1.getText());
        person.setSex(testSex);
      }
      dispose();
    }
    else {
      errorDlg = new ErrorDialog((Frame)getParent(),true);
      errorDlg.setMessage(error);
      Dimension frmSize = getParent().getSize();
      Point loc = getParent().getLocation();
      errorDlg.setLocation((frmSize.width - 253)/ 2 + loc.x, (frmSize.height - 192) / 2 + loc.y);
      errorDlg.setVisible(true);
    }
  
voidcreateListDialog()

note
Create and setup a list dialog

    listDlg = new ListDialog((Frame)getParent());
    Dimension frmSize = getSize();
    Point loc = getLocation();
    listDlg.setLocation((frmSize.width - 180)/ 2 + loc.x, (frmSize.height - 300) / 2 + loc.y);
    listDlg.setModal(true);
    listDlg.setMenu(false);
  
booleangetCancel()

note
Small method to check to see if the cancel button has been pressed
return
boolean

    return cancel;
  
FamilygetChild()

    return childReturned;
  
IndividualgetIndividual()

note
Method to return the individual if one has been newly created.
return
ProblemDomain.Individual

    return person;
  
booleangetNewFamily()

return
Returns true if it is a new Family.

    return newFamily;
  
FamilygetParentOf()

    return parentReturned;
  
booleanisChild()

note
A simple method to check to see if the Individual is a child of any family

    if(childReturned != null) {
      if(newIndividual) return true;
      else return false;
    }
    else return false;
  
booleanisNewIndividual()

return
Returns true if Individual is a new Individual.

    return newIndividual;
  
booleanisParent()

    if(parentReturned != null) return true;
    else return false;
  
voidkeyPressed()

    newFamily = true;
    parentReturned = null;
  
voidsetChildOfField()

note
This method is called when the 'Child Of' button is pressed. It displays a list of families for the list dialog to display. When a family is chosen it will appear in the Child Of field.

    createListDialog();
    listDlg.setTitle("Child of...");
    listDlg.createFamilyList(list);
    listDlg.setVisible(true);
    childReturned = listDlg.getFamily();
    if(childReturned != null) textField7.setText(childReturned.getHusband().getFamilyName());
    if(textField2.getText().length() > 0) {
      textField3.setText("F");
      textField6.setText(textField7.getText());
    }
    else
      textField6.setText("");
  
voidsetInList(java.util.Hashtable list)

note
Method to set up temporary individual list
param
Hashtable list

    people = list;
  
voidsetIndividualFields()

note
This method is called when the 'Individual' button is pressed. It allows the user to pick an individual to be display in this dialog.

    Family family;
    String test;

    createListDialog();
    listDlg.setTitle("Individuals...");
    listDlg.createIndividualList(people);
    listDlg.setVisible(true);
    person = listDlg.getIndividual();
    if(person != null) {
      newFamily = true;    
      parentReturned = null;
      newIndividual = false;
      textField1.setText(person.getGivenNames()); 
      family = person.getChildOf();
      if(family != null) textField7.setText(family.getHusband().getFamilyName());
      textField3.setText(person.getSex());
      test = person.getSex();
      if(test.equals("M")) textField2.setText(person.getFamilyName());
      button1.setLabel("Update");
    }
  
voidsetList(java.util.Hashtable list)

note
Method to set up the list for the dialog
param
Hashtable list

    this.list = list;  
  
voidsetParentOfField()

note
This method is called when the 'Parent Of' button is pressed and allows the user to choose which individual the current individual is married to. When chosen it will display the name in the Parent Of field.

    createListDialog();
    listDlg.setTitle("Married To...");
    listDlg.createSinglesList(list);
    listDlg.setVisible(true);
    parentReturned = listDlg.getFamily();
    if(parentReturned != null)
    {
      textField2.setText(parentReturned.getHusband().getFamilyName());
      newFamily = false;
	}
    if(textField7.getText().length() > 0) {
       textField3.setText("F");
       textField6.setText(textField7.getText());
    }       
    if(textField3.getText().toUpperCase().equals("F"))
      textField6.setEditable(true);

  
public voidsetup()

note
Setup labels for the dialog
exception
Exception


    this.setTitle("Individual Detail Entry...");

    label1.setText("First Names");
    label2.setText("Child Of");
    label3.setText("Sex");
    label4.setText("Date of Birth");
    label6.setText("Date of Death");
    label7.setText("Parent Of");
    label8.setText("Maiden Name");

    textField2.addKeyListener(new textEventHandler(this));
    textField3.addTextListener(this);
    textField6.setEditable(false);
    textField7.setEditable(false);

    button1.setLabel("OK");
    button1.addActionListener(this);
    button2.setLabel("Cancel");
    button2.addActionListener(this);
    button3.setLabel("Child Of >>");
    button3.addActionListener(this);
    button4.setLabel("Married To >>");
    button4.addActionListener(this);
    button5.setLabel("Individual >>");
    button5.addActionListener(this);

    gridLayout1.setRows(10);
    gridLayout1.setHgap(5);
    gridLayout1.setColumns(2);
    gridLayout1.setVgap(5);

    panel1.setLayout(gridLayout1);
    panel1.add(label1, null);
    panel1.add(textField1, null);
    panel1.add(label2, null);
    panel1.add(textField7, null);
    panel1.add(label7, null);
    panel1.add(textField2, null);
    panel1.add(button5, null);
    panel1.add(button3, null);
    panel1.add(button4, null);
    panel1.add(label5, null);
    panel1.add(label3, null);
    panel1.add(textField3, null);
    panel1.add(label8, null);
    panel1.add(textField6, null);
    panel1.add(label4, null);
    panel1.add(textField4, null);
    panel1.add(label6, null);
    panel1.add(textField5, null);
    panel1.add(button1, null);
    panel1.add(button2, null);
    this.addWindowListener(new InEntry_windowEvent(this));
  
public voidtextValueChanged(java.awt.event.TextEvent e)

    String testSex = textField3.getText().toUpperCase();
    if(testSex.equals("F") && textField2.getText().length() != 0)
      textField6.setEditable(true);
    else textField6.setEditable(false);
    validate();
  
voidthis_windowClosing(java.awt.event.WindowEvent ee)

note
Captures the windowClosing event and calls dispose() so that the dialog closes.

    dispose();
  
voidupdateIndividual()

note
If the Individual already exists then this method is called to update the Individuals' record.

    if(textField1.getText().length() > 0) person.setGivenNames(textField1.getText());
    dispose();