PageRenderTime 79ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/code/PersonEditor.java

http://silkin.googlecode.com/
Java | 1378 lines | 1291 code | 47 blank | 40 comment | 334 complexity | b449ca186b2abe6b92684dfed87f621d MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1. import java.util.*;
  2. import java.text.*;
  3. import java.awt.*;
  4. import java.awt.event.*;
  5. import javax.swing.*;
  6. import javax.swing.event.*;
  7. import java.beans.*;
  8. /**
  9. The PersonEditor is a window that displays an {@link Individual}'s fields for editing.
  10. It is an extension of KSJInternalFrame so it will appear in the View menu.
  11. @author Gary Morris, Northern Virginia Community College garymorris2245@verizon.net
  12. */
  13. public class PersonEditor extends KSJInternalFrame implements ListSelectionListener {
  14. public Context ctxt;
  15. public KSJInternalFrame genericEd;
  16. public PEdListener listener;
  17. public Individual ind;
  18. private int resetInd, resetFam, selectedUDP = 0;
  19. public JTextField dataAuth, firstNames, lastName, birthDay, birthMnth, birthYr, deathDay, deathMnth, deathYr, udpValText;
  20. public JTextArea notes, udpTextArea;
  21. public ArrayList<Object> newValList;
  22. public UserDefinedProperty udCopy; // always the currently-selected UDP for this person
  23. public boolean childBirth = false, rebuilding, dupEditor = false;
  24. public JComboBox udPick, spousePicker;
  25. public JPanel editor, udpArea = new JPanel(), udBtns, marriageBox = new JPanel(), bFam = new JPanel();
  26. public JLabel typLabel, restrictLabel, udEdInstr, wName, hName;
  27. public JList udpValList;
  28. public Object[] udpValArray;
  29. public JRadioButton male, female;
  30. public JButton doneBtn, addPerson, deletePerson;
  31. public String newBirthDate, newDeathDate, edTitle, fieldFlag;
  32. public Rectangle bnds = new Rectangle();
  33. public PersonEditor(Context cntxt, KSJInternalFrame ctEd, String title,
  34. Individual person, Family bthFam, String fieldFlg, int selUDP) {
  35. super(title);
  36. ctxt = cntxt;
  37. genericEd = ctEd;
  38. edTitle = title;
  39. ind = person;
  40. ind.birthFamily = bthFam;
  41. fieldFlag = fieldFlg;
  42. selectedUDP = selUDP;
  43. buildEditor();
  44. }
  45. public PersonEditor(Context cntxt, KSJInternalFrame ctEd, String title,
  46. Individual person, String fieldFlg, int selUDP) {
  47. super(title);
  48. ctxt = cntxt;
  49. genericEd = ctEd;
  50. edTitle = title;
  51. ind = person;
  52. fieldFlag = fieldFlg;
  53. selectedUDP = selUDP;
  54. buildEditor();
  55. }
  56. public void buildEditor() {
  57. windowNum = "Person Editor: " + ind.name + " (" + ind.serialNmbr + ")";
  58. setDefaultCloseOperation(DISPOSE_ON_CLOSE);
  59. addInternalFrameListener(this); // allows View Menu to work
  60. Iterator edIter = MainPane.openPersonEditors.iterator(); // Check for duplicates
  61. PersonEditor fe;
  62. while (edIter.hasNext()) {
  63. fe = (PersonEditor) edIter.next();
  64. if (fe.ind == ind) { // found open editor for same person
  65. JOptionPane.showMessageDialog(genericEd,
  66. "There is already an editor open for this person.\n"
  67. + "Choose it from the 'View' menu.",
  68. "Duplicate Editors Not Allowed", JOptionPane.WARNING_MESSAGE);
  69. dupEditor = true;
  70. try {
  71. setClosed(true);
  72. } catch (PropertyVetoException pve) {
  73. if (MainPane.activity == null) {
  74. MainPane.createActivityLog(desktop, menuView);
  75. }
  76. MainPane.activity.log.append("Closing Duplicate PersonEditor:\n" + pve);
  77. }
  78. return;
  79. } // end of found open editor for same person
  80. } // end of loop thru openPersonEditors
  81. MainPane.openPersonEditors.add(this);
  82. listener = new PEdListener(this);
  83. resetInd = ctxt.indSerNumGen;
  84. resetFam = ctxt.famSerNumGen;
  85. rebuilding = true;
  86. Dimension oneLine = new Dimension(250, 30),
  87. halfLine = new Dimension(120, 30),
  88. digs4 = new Dimension(50, 30),
  89. digs2 = new Dimension(35, 30);
  90. // HEADER AREA
  91. editor = new JPanel();
  92. editor.setLayout(new BoxLayout(editor, BoxLayout.PAGE_AXIS));
  93. JLabel instr = new JLabel("After editing any field, hit 'Enter' to record changes.");
  94. instr.setAlignmentX(0.5f);
  95. editor.add(instr);
  96. if (ind.deleted) {
  97. JPanel deleteBox = new JPanel();
  98. deleteBox.setLayout(new BoxLayout(deleteBox, BoxLayout.LINE_AXIS));
  99. JLabel deLabel = new JLabel("This is a DELETED record.");
  100. deleteBox.add(deLabel);
  101. JButton unDelBtn = new JButton("Un-Delete");
  102. unDelBtn.setActionCommand("un-delete");
  103. unDelBtn.addActionListener(listener);
  104. deleteBox.add(unDelBtn);
  105. editor.add(deleteBox);
  106. }
  107. editor.add(Box.createRigidArea(new Dimension(0, 8)));
  108. // NAME ROW
  109. JPanel nameBox = new JPanel();
  110. nameBox.setLayout(new BoxLayout(nameBox, BoxLayout.LINE_AXIS));
  111. JLabel serialNum = new JLabel("Serial # " + ind.serialNmbr);
  112. JLabel nameLabel = new JLabel("Name: ");
  113. firstNames = new JTextField(ind.firstNames);
  114. firstNames.setMaximumSize(halfLine);
  115. lastName = new JTextField(ind.surname);
  116. lastName.setMaximumSize(halfLine);
  117. nameBox.add(serialNum);
  118. nameBox.add(Box.createRigidArea(new Dimension(75, 0)));
  119. nameBox.add(nameLabel);
  120. nameBox.add(firstNames);
  121. nameBox.add(lastName);
  122. editor.add(nameBox);
  123. // BORN ROW
  124. JPanel bornRow = new JPanel();
  125. bornRow.setLayout(new BoxLayout(bornRow, BoxLayout.LINE_AXIS));
  126. bornRow.setAlignmentX(0.0f);
  127. JLabel bornLabel = new JLabel("Born: Yr");
  128. JLabel birthMMLabel = new JLabel("MM");
  129. JLabel birthDDLabel = new JLabel("DD");
  130. birthDay = new JTextField();
  131. birthDay.setActionCommand("new birthdate");
  132. birthDay.addActionListener(listener);
  133. birthDay.setMaximumSize(digs2);
  134. birthMnth = new JTextField();
  135. birthMnth.setActionCommand("new birthdate");
  136. birthMnth.addActionListener(listener);
  137. birthMnth.setMaximumSize(digs2);
  138. birthYr = new JTextField();
  139. birthYr.setActionCommand("new birthdate");
  140. birthYr.addActionListener(listener);
  141. birthYr.setMaximumSize(digs4);
  142. birthDay.setText(ind.getBirthDD());
  143. birthMnth.setText(ind.getBirthMM());
  144. birthYr.setText(ind.getBirthYr());
  145. male = new JRadioButton("Male");
  146. male.setActionCommand("male");
  147. male.addActionListener(listener);
  148. bornRow.add(bornLabel);
  149. bornRow.add(birthYr);
  150. bornRow.add(birthMMLabel);
  151. bornRow.add(birthMnth);
  152. bornRow.add(birthDDLabel);
  153. bornRow.add(birthDay);
  154. bornRow.add(Box.createRigidArea(new Dimension(4, 0)));
  155. bornRow.add(male);
  156. // DIED ROW
  157. JPanel diedRow = new JPanel();
  158. diedRow.setLayout(new BoxLayout(diedRow, BoxLayout.LINE_AXIS));
  159. diedRow.setAlignmentX(0.0f);
  160. JLabel diedLabel = new JLabel("Died: Yr");
  161. JLabel deathMMLabel = new JLabel("MM");
  162. JLabel deathDDLabel = new JLabel("DD");
  163. deathDay = new JTextField();
  164. deathDay.setActionCommand("new deathdate");
  165. deathDay.addActionListener(listener);
  166. deathDay.setMaximumSize(digs2);
  167. deathMnth = new JTextField();
  168. deathMnth.setActionCommand("new deathdate");
  169. deathMnth.addActionListener(listener);
  170. deathMnth.setMaximumSize(digs2);
  171. deathYr = new JTextField();
  172. deathYr.setActionCommand("new deathdate");
  173. deathYr.addActionListener(listener);
  174. deathYr.setMaximumSize(digs4);
  175. deathDay.setText(ind.getDeathDD());
  176. deathMnth.setText(ind.getDeathMM());
  177. deathYr.setText(ind.getDeathYr());
  178. female = new JRadioButton("Female");
  179. female.setActionCommand("female");
  180. female.addActionListener(listener);
  181. ButtonGroup genderBtns = new ButtonGroup();
  182. genderBtns.add(male);
  183. genderBtns.add(female);
  184. if (ind.gender.equals("M")) {
  185. male.setSelected(true);
  186. } else {
  187. female.setSelected(true);
  188. ind.gender = "F"; // if ind was neuter, this makes it a default female
  189. }
  190. diedRow.add(diedLabel);
  191. diedRow.add(deathYr);
  192. diedRow.add(deathMMLabel);
  193. diedRow.add(deathMnth);
  194. diedRow.add(deathDDLabel);
  195. diedRow.add(deathDay);
  196. diedRow.add(Box.createRigidArea(new Dimension(4, 0)));
  197. diedRow.add(female);
  198. // COMBINE 2 DATE ROWS
  199. JPanel datesRow = new JPanel();
  200. datesRow.setLayout(new BoxLayout(datesRow, BoxLayout.PAGE_AXIS));
  201. datesRow.setAlignmentX(0.5f);
  202. datesRow.add(bornRow);
  203. datesRow.add(diedRow);
  204. editor.add(Box.createRigidArea(new Dimension(0, 8)));
  205. editor.add(datesRow);
  206. editor.add(Box.createRigidArea(new Dimension(0, 8)));
  207. // UDP ROW
  208. // The layout and content of udpArea is variable, depending on the UDPs for this person
  209. if (ind.userDefinedProperties == null) {
  210. udpArea = new JPanel();
  211. udpArea.setLayout(new BoxLayout(udpArea, BoxLayout.PAGE_AXIS));
  212. udpArea.setBorder(BorderFactory.createTitledBorder(
  213. BorderFactory.createLineBorder(Color.red),
  214. "UDPs"));
  215. JLabel line1 = new JLabel("No User-Defined Properties are defined in this context.");
  216. line1.setAlignmentX(0.5f);
  217. udpArea.add(line1);
  218. udpArea.setMinimumSize(new Dimension(250, 80));
  219. udpArea.setMaximumSize(new Dimension(450, 150));
  220. } else {
  221. buildUDPArea(selectedUDP);
  222. }
  223. editor.add(Box.createRigidArea(new Dimension(0, 6)));
  224. editor.add(udpArea);
  225. editor.add(Box.createRigidArea(new Dimension(0, 16)));
  226. // BIRTHFAMILY ROW
  227. bFam.setLayout(new BoxLayout(bFam, BoxLayout.LINE_AXIS));
  228. buildBFamRow();
  229. editor.add(bFam);
  230. // MARRIAGES
  231. marriageBox.setMaximumSize(new Dimension(450, 150));
  232. buildMarriageBox();
  233. editor.add(Box.createRigidArea(new Dimension(0, 8)));
  234. editor.add(marriageBox);
  235. editor.add(Box.createRigidArea(new Dimension(0, 6)));
  236. // NOTES
  237. notes = new JTextArea(ind.comment);
  238. notes.setWrapStyleWord(true);
  239. JScrollPane noteScroll = new JScrollPane(notes);
  240. noteScroll.setMinimumSize(new Dimension(400, 50));
  241. noteScroll.setMaximumSize(new Dimension(400, 100));
  242. editor.add(noteScroll);
  243. editor.add(Box.createRigidArea(new Dimension(0, 6)));
  244. // DATA AUTHOR LINE
  245. JPanel dataRow = new JPanel();
  246. dataRow.setLayout(new BoxLayout(dataRow, BoxLayout.LINE_AXIS));
  247. JLabel dataAuthLabel = new JLabel("Data Author ");
  248. dataAuth = new JTextField(ind.dataAuthor);
  249. dataAuth.setMaximumSize(oneLine);
  250. JLabel lastMod = new JLabel("Last Modified: " + ind.dataChangeDate);
  251. dataRow.add(Box.createRigidArea(new Dimension(10, 0)));
  252. dataRow.add(dataAuthLabel);
  253. dataRow.add(dataAuth);
  254. dataRow.add(Box.createRigidArea(new Dimension(10, 0)));
  255. dataRow.add(lastMod);
  256. editor.add(dataRow);
  257. // BUTTONS AT THE BOTTOM
  258. JPanel bottomBtns = new JPanel();
  259. bottomBtns.setLayout(new BoxLayout(bottomBtns, BoxLayout.LINE_AXIS));
  260. JButton indDelete = new JButton("Delete Person");
  261. indDelete.setActionCommand("delete person");
  262. indDelete.addActionListener(listener);
  263. bottomBtns.add(indDelete);
  264. doneBtn = new JButton("Done");
  265. doneBtn.setActionCommand("done");
  266. doneBtn.addActionListener(listener);
  267. bottomBtns.add(Box.createRigidArea(new Dimension(100, 0)));
  268. bottomBtns.add(doneBtn);
  269. editor.add(Box.createRigidArea(new Dimension(0, 6)));
  270. editor.add(bottomBtns);
  271. JPanel sideFrame = new JPanel();
  272. sideFrame.setLayout(new BoxLayout(sideFrame, BoxLayout.LINE_AXIS));
  273. sideFrame.add(Box.createRigidArea(new Dimension(10, 0)));
  274. sideFrame.add(editor);
  275. sideFrame.add(Box.createRigidArea(new Dimension(10, 0)));
  276. getContentPane().add(sideFrame);
  277. addInternalFrameListener(this);
  278. setSize(550, 650);
  279. setVisible(true);
  280. rebuilding = false;
  281. } // end of method buildEditor
  282. public void setTypeAndValue(UserDefinedProperty theUDP, JLabel typLabel, JTextField valText) {
  283. // This is the single-valued version of this method -- 0 or 1 value goes in valText
  284. String valString = "";
  285. if (theUDP.value.size() > 0) {
  286. if (theUDP.typ.equals("individual")) {
  287. valString += ((Individual) theUDP.value.get(0)).name;
  288. } else {
  289. valString += theUDP.value.get(0).toString();
  290. }
  291. }
  292. valText.setText(valString);
  293. if (theUDP.typ.equals("integer")) {
  294. typLabel.setText("Integer");
  295. } else if (theUDP.typ.equals("float")) {
  296. typLabel.setText("Real Number");
  297. } else if (theUDP.typ.equals("string")) {
  298. typLabel.setText("String");
  299. } else if (theUDP.typ.equals("boolean")) {
  300. typLabel.setText("Boolean");
  301. } else {
  302. typLabel.setText("Person");
  303. }
  304. } // end of method setTypeAndValue - for single value
  305. public void setTypeAndValue(UserDefinedProperty theUDP, JLabel typLabel) {
  306. // This is the multi-valued version of this method -- 0+ values go in udpValList
  307. // First set the Type Label
  308. if (theUDP.typ.equals("integer")) {
  309. typLabel.setText("Integer");
  310. } else if (theUDP.typ.equals("float")) {
  311. typLabel.setText("Real Number");
  312. } else if (theUDP.typ.equals("string")) {
  313. typLabel.setText("String");
  314. } else if (theUDP.typ.equals("boolean")) {
  315. typLabel.setText("ERROR -- Multi-Valued Boolean!!");
  316. } else {
  317. typLabel.setText("Person");
  318. }
  319. // Then select and initialize the list
  320. if (theUDP.typ.equals("individual")) {
  321. String valTextString = "";
  322. Individual valor;
  323. for (int i = 0; i < theUDP.value.size(); i++) {
  324. if (i > 0) {
  325. valTextString += "\n";
  326. }
  327. valor = (Individual) theUDP.value.get(i);
  328. if ((valor.name != null) && (valor.name.length() > 0)) {
  329. valTextString += valor.name + " (" + valor.serialNmbr + ")";
  330. } else {
  331. valTextString += "Person #" + valor.serialNmbr;
  332. }
  333. } // end of loop through the values
  334. udpTextArea = new JTextArea(valTextString);
  335. udpTextArea.setEditable(false);
  336. } else { // non-person selectable list of values
  337. udpValArray = new Object[theUDP.value.size() + 1];
  338. udpValArray[0] = "Add-a-Value";
  339. for (int i = 0; i < theUDP.value.size(); i++) {
  340. udpValArray[i + 1] = theUDP.value.get(i).toString();
  341. }
  342. udpValList = new JList(udpValArray);
  343. udpValList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
  344. udpValList.setLayoutOrientation(JList.VERTICAL);
  345. udpValList.setVisibleRowCount(-1);
  346. udpValList.addListSelectionListener(this);
  347. }
  348. } // end of method setTypeAndValue - multi-valued
  349. public void buildUDPArea(int ndx) {
  350. rebuilding = true;
  351. udpArea.removeAll();
  352. udpArea.setLayout(new BoxLayout(udpArea, BoxLayout.PAGE_AXIS));
  353. udpArea.setBorder(BorderFactory.createTitledBorder(
  354. BorderFactory.createLineBorder(Color.red),
  355. "View/Edit UDPs"));
  356. JPanel udpLine = new JPanel();
  357. udpLine.setLayout(new BoxLayout(udpLine, BoxLayout.LINE_AXIS));
  358. Dimension sizer = new Dimension(250, 50);
  359. String[] udpMenu = genUDPMenu();
  360. udPick = new JComboBox(udpMenu);
  361. udPick.setSelectedIndex(ndx);
  362. udCopy = (UserDefinedProperty) ind.userDefinedProperties.get(udpMenu[ndx]);
  363. udPick.addActionListener(listener);
  364. udPick.setActionCommand("pick UDP");
  365. udPick.setMinimumSize(sizer);
  366. udPick.setMaximumSize(sizer);
  367. udpLine.add(udPick);
  368. JLabel typTitle = new JLabel("Type: ");
  369. typLabel = new JLabel();
  370. JLabel valTitle = new JLabel("Value: ");
  371. JPanel valueLine = new JPanel();
  372. valueLine.setLayout(new BoxLayout(valueLine, BoxLayout.LINE_AXIS));
  373. valueLine.add(valTitle);
  374. JScrollPane valScroll;
  375. if (udCopy.singleValue) { // only need a single TextField to hold the value
  376. udpValText = new JTextField();
  377. setTypeAndValue(udCopy, typLabel, udpValText);
  378. udpValText.addActionListener(listener);
  379. udpValText.setActionCommand("edit single UDP value");
  380. udpValText.setMinimumSize(new Dimension(250, 40));
  381. udpValText.setMaximumSize(new Dimension(250, 40));
  382. valueLine.add(udpValText);
  383. } else { // need a list of the (potentially) multiple values
  384. setTypeAndValue(udCopy, typLabel); // builds udpValList or udpTextArea by side-effect
  385. if (udCopy.typ.equals("individual")) {
  386. valScroll = new JScrollPane(udpTextArea);
  387. udpTextArea.setMinimumSize(new Dimension(400, 150));
  388. udpTextArea.setMaximumSize(new Dimension(400, 150));
  389. } else { // non-person type of values
  390. valScroll = new JScrollPane(udpValList);
  391. udpValList.setMinimumSize(new Dimension(400, 150));
  392. udpValList.setMaximumSize(new Dimension(400, 150));
  393. }
  394. valScroll.setMinimumSize(new Dimension(410, 160));
  395. valScroll.setMaximumSize(new Dimension(410, 160));
  396. valueLine.add(valScroll);
  397. } // end of multiple values case
  398. udpLine.add(Box.createRigidArea(new Dimension(10, 0)));
  399. udpLine.add(typTitle);
  400. udpLine.add(typLabel);
  401. udpArea.add(udpLine);
  402. udpArea.add(valueLine);
  403. if (typLabel.getText().equals("Person")) {
  404. buildPersonBtnBox(); // finishes udpArea with "Add Person" etc. btns
  405. } else {
  406. buildRestrictionBox(); // finishes udpArea with restriction lines
  407. }
  408. rebuilding = false;
  409. } // end of method buildUDPArea
  410. public String[] genUDPMenu() {
  411. String[] menu = new String[ind.userDefinedProperties.size()];
  412. Iterator udpIter = ind.userDefinedProperties.keySet().iterator();
  413. String item;
  414. int ndex = 0;
  415. while (udpIter.hasNext()) {
  416. item = (String) udpIter.next();
  417. menu[ndex++] = item;
  418. }
  419. return menu;
  420. } // end of method genUDPMenu()
  421. public void buildBFamRow() {
  422. bFam.removeAll();
  423. rebuilding = true;
  424. JPanel famL1 = new JPanel();
  425. famL1.setLayout(new BoxLayout(famL1, BoxLayout.PAGE_AXIS));
  426. JLabel bFamLabel = new JLabel("Birth Family: ");
  427. JButton chooseBFam = null, viewBFam = new JButton("View/Edit");
  428. viewBFam.setActionCommand("view birth family");
  429. viewBFam.addActionListener(listener);
  430. famL1.add(bFamLabel);
  431. famL1.add(viewBFam);
  432. bFam.add(famL1);
  433. JPanel famL2 = new JPanel();
  434. famL2.setLayout(new BoxLayout(famL2, BoxLayout.PAGE_AXIS));
  435. String husbName = " Birth Family", wifeName = "Not Recorded";
  436. JButton delBFam = new JButton("Delete");
  437. if (ind.birthFamily == null) {
  438. viewBFam.setText("Create");
  439. viewBFam.setActionCommand("create birth family");
  440. chooseBFam = new JButton("Choose");
  441. chooseBFam.setActionCommand("choose birth family");
  442. chooseBFam.addActionListener(listener);
  443. delBFam.setEnabled(false);
  444. } else {
  445. if (ind.birthFamily.husband != null) {
  446. husbName = ind.birthFamily.husband.name;
  447. } else {
  448. husbName = "Father's Name Not Recorded";
  449. }
  450. if (ind.birthFamily.wife != null) {
  451. wifeName = ind.birthFamily.wife.name;
  452. } else {
  453. wifeName = "Mother's Name Not Recorded";
  454. }
  455. }
  456. hName = new JLabel("H: " + husbName);
  457. wName = new JLabel("W: " + wifeName);
  458. Font font1 = hName.getFont();
  459. famL2.add(hName);
  460. famL2.add(wName);
  461. bFam.add(famL2);
  462. delBFam.setActionCommand("delete birth family");
  463. delBFam.addActionListener(listener);
  464. if (chooseBFam != null) {
  465. bFam.add(chooseBFam);
  466. }
  467. bFam.add(delBFam);
  468. rebuilding = false;
  469. }
  470. public void buildMarriageBox() {
  471. rebuilding = true;
  472. String plur = "s";
  473. if (ind.marriages.size() == 1) {
  474. plur = "";
  475. }
  476. marriageBox.removeAll();
  477. marriageBox.setLayout(new BoxLayout(marriageBox, BoxLayout.PAGE_AXIS));
  478. marriageBox.setBorder(BorderFactory.createTitledBorder(
  479. BorderFactory.createLineBorder(Color.red),
  480. ind.marriages.size() + " Marriage" + plur));
  481. JButton chooseSpouse = new JButton("Choose New Spouse");
  482. chooseSpouse.setActionCommand("choose spouse");
  483. chooseSpouse.addActionListener(listener);
  484. JButton createSpouse = new JButton("Create New Spouse");
  485. createSpouse.setActionCommand("create spouse");
  486. createSpouse.addActionListener(listener);
  487. JPanel spBtnBox = new JPanel();
  488. spBtnBox.setLayout(new BoxLayout(spBtnBox, BoxLayout.LINE_AXIS));
  489. spBtnBox.add(chooseSpouse);
  490. spBtnBox.add(createSpouse);
  491. if (ind.marriages.isEmpty()) {
  492. JLabel lonely = new JLabel("No marriages or fertile unions.");
  493. lonely.setAlignmentX(0.5f);
  494. marriageBox.add(lonely);
  495. marriageBox.add(spBtnBox);
  496. } // end of no-mariages
  497. else {
  498. String[] spice = genSpouseMenu(ind, ind.marriages);
  499. spousePicker = new JComboBox(spice);
  500. spousePicker.setActionCommand("edit family");
  501. spousePicker.addActionListener(listener);
  502. JLabel marriageLabel = new JLabel("Select a marriage to view, edit, or delete that family.");
  503. marriageLabel.setAlignmentX(0.5f);
  504. marriageBox.add(marriageLabel);
  505. marriageBox.add(spousePicker);
  506. marriageBox.add(spBtnBox);
  507. } // end of marriages-exist
  508. rebuilding = false;
  509. }
  510. public static String[] genSpouseMenu(Individual ind, ArrayList<Object> unions) {
  511. // Marriage may have no opp sex spouse, 'cuz it was just created.
  512. int num = unions.size();
  513. String[] menu = new String[num];
  514. Family fam;
  515. for (int i = 0; i < num; i++) {
  516. fam = (Family) unions.get(i);
  517. if (ind.gender.equals("M")) {
  518. if (fam.wife == null) {
  519. menu[i] = "No wife shown for marriage # " + fam.serialNmbr;
  520. } else {
  521. menu[i] = fam.wife.name + " (" + fam.wife.serialNmbr + ")";
  522. }
  523. } else {
  524. if (fam.husband == null) {
  525. menu[i] = "No husband shown for marriage # " + fam.serialNmbr;
  526. } else {
  527. menu[i] = fam.husband.name + " (" + fam.husband.serialNmbr + ")";
  528. }
  529. }
  530. } // end of loop thru marriages
  531. return menu;
  532. } // end of method genSpouseMenu
  533. public void buildRestrictionBox() {
  534. restrictLabel = new JLabel("No Restrictions on the Value.");
  535. restrictLabel.setAlignmentX(0.5f);
  536. String newRestriction = "";
  537. boolean restrictns = false;
  538. if ((udCopy.validEntries != null) && (udCopy.validEntries.size() > 0)) {
  539. newRestriction = "Restricted to: ";
  540. for (int i = 0; i < udCopy.validEntries.size(); i++) {
  541. if (i > 0) {
  542. newRestriction += ", ";
  543. }
  544. newRestriction += udCopy.validEntries.get(i).toString();
  545. }
  546. restrictns = true;
  547. }
  548. if (udCopy.minVal != null) {
  549. newRestriction += (restrictns ? "\nMin: " : "Min: ");
  550. newRestriction += udCopy.minVal;
  551. restrictns = true;
  552. }
  553. if (udCopy.maxVal != null) {
  554. newRestriction += (restrictns ? "\nMax: " : "Max: ");
  555. newRestriction += udCopy.maxVal;
  556. restrictns = true;
  557. }
  558. if (restrictns) {
  559. restrictLabel.setText(newRestriction);
  560. }
  561. if (udpValText != null) {
  562. udpValText.setEditable(true);
  563. }
  564. udpArea.add(restrictLabel);
  565. udEdInstr = new JLabel();
  566. udEdInstr.setAlignmentX(0.5f);
  567. if (udCopy.singleValue) {
  568. udEdInstr.setText("Edit value, then hit 'enter' to record change.");
  569. } else {
  570. udEdInstr.setText("Click on the value to edit or delete.");
  571. }
  572. udpArea.add(udEdInstr);
  573. } // end of method buildRestrictionBox
  574. public void buildPersonBtnBox() {
  575. udBtns = new JPanel();
  576. udBtns.setLayout(new BoxLayout(udBtns, BoxLayout.LINE_AXIS));
  577. addPerson = new JButton("Add Person");
  578. addPerson.setActionCommand("udp add person");
  579. addPerson.addActionListener(listener);
  580. if ((udCopy.value.size() > 0) && udCopy.singleValue) {
  581. addPerson.setEnabled(false);
  582. }
  583. deletePerson = new JButton("Delete Person");
  584. deletePerson.setActionCommand("udp delete person");
  585. deletePerson.addActionListener(listener);
  586. if (udCopy.value.isEmpty()) {
  587. deletePerson.setEnabled(false);
  588. }
  589. udBtns.add(addPerson);
  590. udBtns.add(deletePerson);
  591. if (udpValText != null) {
  592. udpValText.setEditable(false);
  593. }
  594. udpArea.add(udBtns);
  595. } // end of method buildPersonBtnBox
  596. public void valueChanged(ListSelectionEvent e) { // required method for ListSelectionListener
  597. if (e.getValueIsAdjusting() == false) {
  598. if (udpValList.getSelectedIndex() > -1) {
  599. // We have a final selection.
  600. int edee = udpValList.getSelectedIndex();
  601. String titl = "Enter New Value", msg, str, typ = udCopy.typ;
  602. msg = "Enter a new value for this UDP.\nMust be a " + typLabel.getText()
  603. + ".\nTo delete this value, erase it.";
  604. if (edee == 0) // always the Add-a-Value spot
  605. {
  606. titl = "Enter Value to Add";
  607. }
  608. boolean goofFlag = true;
  609. while (goofFlag) {
  610. goofFlag = false;
  611. str = (String) JOptionPane.showInputDialog(this, msg, titl,
  612. JOptionPane.PLAIN_MESSAGE, null, null,
  613. udpValList.getSelectedValue());
  614. if (str == null) {
  615. udpValList.clearSelection();
  616. return; // user cancelled
  617. }
  618. if (str.equals("")) { // user erased this value = deletion.
  619. if (edee == 0) {
  620. udpValList.clearSelection();
  621. return; // cancelling the addition = no change
  622. }
  623. udCopy.value.remove(edee - 1);
  624. udpValArray = new Object[udCopy.value.size() + 1];
  625. udpValArray[0] = "Add-a-Value";
  626. for (int i = 0; i < udCopy.value.size(); i++) {
  627. udpValArray[i + 1] = udCopy.value.get(i).toString();
  628. }
  629. udpValList.setListData(udpValArray);
  630. return;
  631. }
  632. try { // an exception will be thrown if type or validity is violated
  633. if (typ.equals("integer")) {
  634. Integer newInt = new Integer(str);
  635. if (udCopy.validEntries != null && !udCopy.validEntries.isEmpty()
  636. && udCopy.validEntries.indexOf(newInt) == -1) {
  637. throw new KSConstraintInconsistency("Not a permitted value.");
  638. }
  639. if (edee > 0) {
  640. udCopy.value.set(edee - 1, newInt);
  641. } else {
  642. udCopy.value.add(newInt); // new value goes on end of list
  643. }
  644. } else if (typ.equals("string")) {
  645. if (udCopy.validEntries != null && !udCopy.validEntries.isEmpty()
  646. && udCopy.validEntries.indexOf(str) == -1) {
  647. throw new KSConstraintInconsistency("Not a permitted value.");
  648. }
  649. if (edee > 0) {
  650. udCopy.value.set(edee - 1, str);
  651. } else {
  652. udCopy.value.add(str);
  653. }
  654. } else if (typ.equals("float")) {
  655. Float newFlt = new Float(str);
  656. if (udCopy.validEntries != null && !udCopy.validEntries.isEmpty()
  657. && udCopy.validEntries.indexOf(newFlt) == -1) {
  658. throw new KSConstraintInconsistency("Not a permitted value.");
  659. }
  660. if (edee > 0) {
  661. udCopy.value.set(edee - 1, newFlt);
  662. } else {
  663. udCopy.value.add(newFlt);
  664. }
  665. } else if (typ.equals("boolean")) { // no restricted values for booleans
  666. if ((str.equals("true")) || (str.equals("false"))) {
  667. if (edee > 0) {
  668. udCopy.value.set(edee - 1, new Boolean(str));
  669. } else {
  670. udCopy.value.add(new Boolean(str));
  671. }
  672. } else {
  673. throw new KinshipSystemException("Bad boolean value: must be 'true' or 'false'.");
  674. }
  675. }
  676. } catch (KSConstraintInconsistency ksci) {
  677. String msg2 = ksci.getMessage() + ".\n Please try again.";
  678. JOptionPane.showMessageDialog(genericEd, msg2, "Error Parsing UDP Value", JOptionPane.WARNING_MESSAGE);
  679. goofFlag = true;
  680. } catch (KinshipSystemException kse) {
  681. String msg2 = kse.getMessage() + "\n Please try again.";
  682. JOptionPane.showMessageDialog(genericEd, msg2, "Error Parsing UDP Value", JOptionPane.WARNING_MESSAGE);
  683. } catch (Exception exc) {
  684. String msg2 = "UDP Value field should contain a " + typLabel + ".\n"
  685. + "Please try again.";
  686. JOptionPane.showMessageDialog(genericEd, msg2, "Error Parsing UDP Value", JOptionPane.WARNING_MESSAGE);
  687. goofFlag = true;
  688. } // end of catch block
  689. } // end of while-goofFlag loop
  690. // If we get here, a valid new value has been parsed. Refresh the udpValList
  691. udpValArray = new Object[udCopy.value.size() + 1];
  692. udpValArray[0] = "Add-a-Value";
  693. for (int i = 0; i < udCopy.value.size(); i++) {
  694. udpValArray[i + 1] = udCopy.value.get(i).toString();
  695. }
  696. udpValList.setListData(udpValArray);
  697. udpValList.clearSelection();
  698. } // end of valid selection
  699. } // end of stable choice
  700. } // end of method valueChanged
  701. public class PEdListener implements ActionListener {
  702. KSJInternalFrame ed;
  703. public PEdListener(KSJInternalFrame ped) {
  704. ed = ped;
  705. } // end of constructor
  706. public void actionPerformed(ActionEvent e) {
  707. if (rebuilding) {
  708. return;
  709. }
  710. String a, b, c = "";
  711. if (e.getActionCommand().equals("un-delete")) {
  712. // Can only fire when a deleted record is being edited.
  713. ind.deleted = false;
  714. } else if (e.getActionCommand().equals("new birthdate")) {
  715. a = birthDay.getText();
  716. b = birthYr.getText();
  717. c = birthMnth.getText();
  718. int nmbr = a.length() + b.length() + c.length();
  719. if (nmbr > 0) {
  720. try {
  721. UDate.valiDate(b,c,a, ind, false);
  722. }catch(KSDateParseException exc) {
  723. JOptionPane.showMessageDialog(ed, exc,
  724. "Unrecognized Date Input",
  725. JOptionPane.WARNING_MESSAGE);
  726. }
  727. }
  728. } // end of "new birthdate"
  729. else if (e.getActionCommand().equals("new deathdate")) {
  730. a = deathDay.getText();
  731. b = deathYr.getText();
  732. c = deathMnth.getText();
  733. int nmbr = a.length() + b.length() + c.length();
  734. if (nmbr > 0) {
  735. try {
  736. UDate.valiDate(b,c,a, ind, true);
  737. }catch(KSDateParseException exc) {
  738. JOptionPane.showMessageDialog(ed, exc,
  739. "Unrecognized Date Input",
  740. JOptionPane.WARNING_MESSAGE);
  741. }
  742. }
  743. } // end of "new deathdate"
  744. else if (e.getActionCommand().equals("male")) {
  745. // Must have just been changed from female.
  746. if (ind.marriages.size() > 0) {
  747. int troubles = 0, flips = 0;
  748. Family fam;
  749. Individual spouse;
  750. for (int i = 0; i < ind.marriages.size(); i++) {
  751. fam = (Family) ind.marriages.get(i);
  752. if (fam.husband == ind) {
  753. spouse = fam.wife;
  754. } else {
  755. spouse = fam.husband;
  756. }
  757. if ((spouse.gender.equals("M")) && (spouse.name != null)
  758. && (spouse.name.indexOf("Presumed") == -1)) {
  759. troubles++;
  760. } else if ((spouse.gender.equals("M")) && (spouse.name != null)
  761. && (spouse.name.indexOf("Presumed") > -1)) {
  762. flips++; // found a presumed spouse with wrong presumed gender
  763. }
  764. } // end of loop thru marriages
  765. if (troubles > 0) {
  766. String msg, plural = "s", article = "those";
  767. if (troubles == 1) {
  768. plural = "";
  769. article = "that";
  770. }
  771. msg = "CAUTION: You have changed gender to 'male' but this Person has\n"
  772. + troubles + " male marriage partner" + plural + ". You can only change gender after\n"
  773. + "deleting " + article + " marriage" + plural + ".";
  774. JOptionPane.showMessageDialog(ed, msg, "Illegal Gender Change", JOptionPane.WARNING_MESSAGE);
  775. female.setSelected(true);
  776. return;
  777. }
  778. ind.gender = "M"; // if we get here, he's unmarried or no troubles
  779. if (flips > 0) { // we got here because troubles = 0
  780. // Must flip Presumed Spouse genders, too.
  781. String oppSex = "F";
  782. if (ind.gender.equals(oppSex)) {
  783. oppSex = "M";
  784. }
  785. for (int i = 0; i < ind.marriages.size(); i++) {
  786. fam = (Family) ind.marriages.get(i);
  787. if (fam.husband == ind) {
  788. spouse = fam.wife;
  789. } else {
  790. spouse = fam.husband;
  791. }
  792. if ((spouse.gender.equals(ind.gender)) && (spouse.name != null)
  793. && (spouse.name.indexOf("Presumed") > -1)) {
  794. spouse.gender = oppSex;
  795. }
  796. } // end of loop thru marriages
  797. } // end of flips > 0
  798. } // end of person-is-married!!
  799. else {
  800. ind.gender = "M"; // if we get here, he's unmarried
  801. } // end of sex-change-was-made
  802. } else if (e.getActionCommand().equals("female")) {
  803. // Must have just been changed from male.
  804. if (ind.marriages.size() > 0) {
  805. int troubles = 0, flips = 0;
  806. Family fam;
  807. Individual spouse;
  808. for (int i = 0; i < ind.marriages.size(); i++) {
  809. fam = (Family) ind.marriages.get(i);
  810. if (fam.husband == ind) {
  811. spouse = fam.wife;
  812. } else {
  813. spouse = fam.husband;
  814. }
  815. if ((spouse.gender.equals("F")) && (spouse.name != null)
  816. && (spouse.name.indexOf("Presumed") == -1)) {
  817. troubles++;
  818. } else if ((spouse.gender.equals("F")) && (spouse.name != null)
  819. && (spouse.name.indexOf("Presumed") > -1)) {
  820. flips++; // found a presumed spouse with wrong presumed gender
  821. }
  822. } // end of loop thru marriages
  823. if (troubles > 0) {
  824. String msg, plural = "s", article = "those";
  825. if (troubles == 1) {
  826. plural = "";
  827. article = "that";
  828. }
  829. msg = "CAUTION: You have changed gender to 'female' but this Person has\n"
  830. + troubles + " female marriage partner" + plural + ". You can only change gender after\n"
  831. + "deleting " + article + " marriage" + plural + ".";
  832. JOptionPane.showMessageDialog(ed, msg, "Illegal Gender Change", JOptionPane.INFORMATION_MESSAGE);
  833. male.setSelected(true);
  834. return;
  835. }
  836. ind.gender = "F";
  837. if (flips > 0) { // we got here because troubles = 0
  838. // Must flip Presumed Spouse genders, too.
  839. String oppSex = "F";
  840. if (ind.gender.equals(oppSex)) {
  841. oppSex = "M";
  842. }
  843. for (int i = 0; i < ind.marriages.size(); i++) {
  844. fam = (Family) ind.marriages.get(i);
  845. if (fam.husband == ind) {
  846. spouse = fam.wife;
  847. } else {
  848. spouse = fam.husband;
  849. }
  850. if ((spouse.gender.equals(ind.gender)) && (spouse.name != null)
  851. && (spouse.name.indexOf("Presumed") > -1)) {
  852. spouse.gender = oppSex;
  853. }
  854. } // end of loop thru marriages
  855. } // end of flips > 0
  856. } // end of person-is-married!!
  857. else {
  858. ind.gender = "F"; // if we get here, she's unmarried
  859. }
  860. } else if (e.getActionCommand().equals("view birth family")) {
  861. FamilyEditor fEd = new FamilyEditor(ctxt, ed, "View/Edit a Family", ind.birthFamily, "view birth fam");
  862. if (!fEd.dupEditor) {
  863. fEd.desktop = desktop;
  864. fEd.setLocation(350, 100);
  865. desktop.add(fEd);
  866. fEd.miViewMe = menuView.add(fEd.windowNum);
  867. fEd.miViewMe.addActionListener(fEd);
  868. fEd.menuView = menuView;
  869. fEd.show();
  870. fEd.moveToFront();
  871. try {
  872. fEd.setSelected(true);
  873. } catch (PropertyVetoException pv) {
  874. }
  875. } else {
  876. try {
  877. fEd.setClosed(true);
  878. } catch (PropertyVetoException pv) {
  879. }
  880. }
  881. } // end of view-birth-family
  882. else if (e.getActionCommand().equals("create birth family")) {
  883. Family bFam = new Family(ctxt, true);
  884. FamilyEditor fEd = new FamilyEditor(ctxt, ed, "Create Birth Family", bFam, ind, "create birth fam");
  885. if (!fEd.dupEditor) {
  886. fEd.desktop = desktop;
  887. fEd.setLocation(350, 100);
  888. desktop.add(fEd);
  889. fEd.miViewMe = menuView.add(fEd.windowNum);
  890. fEd.miViewMe.addActionListener(fEd);
  891. fEd.menuView = menuView;
  892. fEd.show();
  893. fEd.moveToFront();
  894. try {
  895. fEd.setSelected(true);
  896. } catch (PropertyVetoException pv) {
  897. }
  898. } else {
  899. try {
  900. fEd.setClosed(true);
  901. } catch (PropertyVetoException pv) {
  902. }
  903. }
  904. } // end of create-a-new-birthFamily
  905. else if (e.getActionCommand().equals("choose birth family")) {
  906. ArrayList<Family> famList = new ArrayList<Family>();
  907. for (int i = 0; i < ctxt.familyCensus.size(); i++) // filter deleted records
  908. {
  909. if (!(ctxt.familyCensus.get(i)).deleted) {
  910. famList.add(ctxt.familyCensus.get(i));
  911. }
  912. }
  913. FamilyPicker fPick = new FamilyPicker(famList, "Choose Birth Family of " + ind.name,
  914. "choose birth", ed);
  915. fPick.desktop = desktop;
  916. fPick.setLocation(350, 100);
  917. desktop.add(fPick);
  918. fPick.miViewMe = menuView.add(fPick.windowNum);
  919. fPick.miViewMe.addActionListener(fPick);
  920. fPick.menuView = menuView;
  921. fPick.show();
  922. fPick.moveToFront();
  923. try {
  924. fPick.setSelected(true);
  925. } catch (PropertyVetoException pv) {
  926. }
  927. } else if (e.getActionCommand().equals("delete birth family")) {
  928. int choice = JOptionPane.showConfirmDialog(ed,
  929. "Are you sure you want to delete the birth family?");
  930. if (choice != JOptionPane.YES_OPTION) {
  931. return;
  932. }
  933. JOptionPane.showMessageDialog(ed,
  934. "This family will be removed as the birth family of\n"
  935. + firstNames.getText() + " " + lastName.getText() +
  936. ". Siblings' birth families are not affected.\n"
  937. + "The family will not be erased. Use Family Editor to do that.",
  938. "Scope of Deletion", JOptionPane.WARNING_MESSAGE);
  939. // OK. User is well warned what they're doing.
  940. ind.birthFamily = null;
  941. bFam.removeAll();
  942. buildBFamRow();
  943. editor.getBounds(bnds);
  944. editor.repaint(bnds);
  945. } // end of delete-birthFamily
  946. else if (e.getActionCommand().equals("pick UDP")) {
  947. // post the new UDP selection, and repaint
  948. selectedUDP = udPick.getSelectedIndex();
  949. buildUDPArea(selectedUDP);
  950. editor.getBounds(bnds);
  951. editor.repaint(bnds);
  952. try {
  953. ed.setSelected(false); // to force the repaint
  954. ed.setSelected(true);
  955. } catch (PropertyVetoException pve) {
  956. }
  957. } else if (e.getActionCommand().equals("udp add person")) {
  958. ArrayList<Object> folks = new ArrayList<Object>();
  959. Individual sumbody;
  960. for (int i = 0; i < ctxt.individualCensus.size(); i++) {
  961. sumbody = (Individual) ctxt.individualCensus.get(i);
  962. if (!sumbody.deleted) {
  963. folks.add(sumbody);
  964. }
  965. }
  966. String title, plural = "s";
  967. if (udCopy.singleValue) {
  968. plural = "";
  969. }
  970. title = "Choose Person" + plural + " to Add.";
  971. PersonPicker pp = new PersonPicker(folks, title, "Add UDP", selectedUDP, udCopy.singleValue, ed);
  972. pp.desktop = desktop;
  973. desktop.add(pp);
  974. pp.miViewMe = menuView.add(pp.windowNum);
  975. pp.miViewMe.addActionListener(pp);
  976. pp.menuView = menuView;
  977. pp.show();
  978. pp.moveToFront();
  979. try {
  980. pp.setSelected(true);
  981. } catch (PropertyVetoException pv) {
  982. }
  983. } // end of add-udp-person
  984. else if (e.getActionCommand().equals("udp delete person")) {
  985. if (udCopy.singleValue) { // only 1 person we can delete. Easy!
  986. udCopy.value.clear();
  987. udpValText.setText("");
  988. addPerson.setEnabled(true);
  989. deletePerson.setEnabled(false);
  990. udpArea.getBounds(bnds);
  991. udpArea.repaint(bnds);
  992. return;
  993. } // end of single-Valued
  994. if (udCopy.value.size() < 2) { // multi-valued, but only 1 item
  995. udCopy.value.clear();
  996. buildUDPArea(selectedUDP);
  997. udpArea.getBounds(bnds);
  998. udpArea.repaint(bnds);
  999. try {
  1000. ed.setSelected(false); // to force the repaint
  1001. ed.setSelected(true);
  1002. } catch (PropertyVetoException pve) {
  1003. }
  1004. return;
  1005. } // end of only 1 item
  1006. Individual psn;
  1007. ArrayList<Object> source = new ArrayList<Object>();
  1008. for (int j = 0; j < udCopy.value.size(); j++) {
  1009. psn = (Individual) udCopy.value.get(j);
  1010. if (!psn.deleted) {
  1011. source.add(psn);
  1012. }
  1013. } // end of filtering out deleted records
  1014. String title = "Choose Person to Delete.";
  1015. PersonPicker pp = new PersonPicker(source, title, "Delete UDP", selectedUDP, false, ed);
  1016. pp.desktop = desktop;
  1017. desktop.add(pp);
  1018. pp.miViewMe = menuView.add(pp.windowNum);
  1019. pp.miViewMe.addActionListener(pp);
  1020. pp.menuView = menuView;
  1021. pp.show();
  1022. pp.moveToFront();
  1023. try {
  1024. pp.setSelected(true);
  1025. } catch (PropertyVetoException pv) {
  1026. }
  1027. } // end of udp-delete-person
  1028. else if (e.getActionCommand().equals("edit single UDP value")) {
  1029. // Can't get here if typ = indiv.
  1030. String newVal = udpValText.getText().trim(), valType = typLabel.getText();
  1031. try { // an exception will be thrown if type is violated
  1032. if (udCopy.typ.equals("integer")) {
  1033. Integer newInt = new Integer(newVal);
  1034. if (udCopy.validEntries != null && !udCopy.validEntries.isEmpty()
  1035. && udCopy.validEntries.indexOf(newInt) == -1) {
  1036. throw new KSConstraintInconsistency("Not a permitted value.");
  1037. }
  1038. if (udCopy.value.isEmpty()) {
  1039. udCopy.value.add(newInt);
  1040. } else {
  1041. udCopy.value.set(0, newInt);
  1042. }
  1043. } else if (udCopy.typ.equals("float")) {
  1044. Float newFlt = new Float(newVal);

Large files files are truncated, but you can click here to view the full file