/code/MainPane.java
Java | 1192 lines | 1014 code | 35 blank | 143 comment | 190 complexity | c64a0fc2ad48ff173ec190db6287d020 MD5 | raw file
Large files files are truncated, but you can click here to view the full file
- import java.io.*;
- import java.util.*;
- import java.awt.*;
- import java.awt.event.*;
- import javax.swing.*;
- import javax.swing.text.*;
- import javax.swing.filechooser.*;
- import java.beans.*;
- /**
- The MainPane class is the top-level window for this application, holding all other windows in its contentPane
- (which is a JDesktopPane). There should be only one instance of MainPane. The static fields <code>activity</code> and
- <code>openBrowsers</code> hold, respectively, the system-wide Error Log and a list of all open LibBrowser windows
- (for good housekeeping purposes).
- <p>
- This class creates the MenuBar and is the ActionListener which implements menu choices. Menu choices which lead to
- exceptions trigger the instantiation of the Error Log and posting to it. The Error Log is intended to record all
- problems encountered and recommended solutions. Therefore, all methods that post to it must provide enough information
- about the problem for the User to know what specific action to take much later when the log is reviewed.
- @author Gary Morris, Northern Virginia Community College garymorris2245@verizon.net
- */
- public class MainPane extends JFrame implements ActionListener {
- public static KSJInternalFrame activity; // single activity log for all windows
- static ArrayList<Object> openBrowsers = new ArrayList<Object>(), openPersonEditors = new ArrayList<Object>(),
- openFamilyEditors = new ArrayList<Object>();
- public static ContextEditor curr_CUC_Editor;
- static JMenu menuView;
- public JMenu menuFileAdd2Library;
- public JMenuItem miFileOpenSILK, miFileDelete, miFileDeleteContext, miFileSaveContext;
- public static JDesktopPane desktop;
- public static MainPane topPane;
- public static int testSerialNmbr;
- public static int buildNmbr = 11;
- public static int NUMBER_OF_EGOS = 4;
- public static boolean fill_In_Flag = false;
- private JMenuBar menuBar = new JMenuBar();
- JMenu menuAdmin;
- KSJInternalFrame currentFrame;
- Runtime topDog = Runtime.getRuntime();
- JFileChooser fc = null;
- File currDomTheoryDir = null, currGEDCOMDir = null;
- int numWindows = 0;
- public static TreeMap treeMapDeepCopy(TreeMap model) {
- // this utility method returns a "deep copy" with new elements replacing any
- // subordinate TreeMaps or ALists as VALUES in the model.
- // KEYS are not deep-copied.
- TreeMap newTM = new TreeMap();
- Iterator topIter = model.entrySet().iterator();
- while (topIter.hasNext()) {
- Map.Entry entry = (Map.Entry) topIter.next();
- Object key = entry.getKey(),
- value = entry.getValue(),
- newValue;
- if (value instanceof TreeMap) {
- newValue = treeMapDeepCopy((TreeMap) value);
- } else if (value instanceof ArrayList) {
- newValue = new ArrayList<Object>((ArrayList<Object>) value);
- } else {
- newValue = value;
- }
- newTM.put(key, newValue);
- } // end of loop thru top level of model TMap
- return newTM;
- } // end of method treeMapDeepCopy
- public MainPane(String title) {
- super(title);
- createMenu();
- setDefaultCloseOperation(DISPOSE_ON_CLOSE);
- desktop = new JDesktopPane();
- topPane = this;
- setContentPane(desktop);
- Toolkit tKit = getToolkit();
- createActivityLog(desktop, menuView);
- Dimension wndSize = tKit.getScreenSize();
- int maxHi = 768, maxWide = 1024;
- setBounds(40, 0,
- Math.min(maxWide, (int) (wndSize.width / 1.1)),
- Math.min(maxHi, (int) (wndSize.height / 1.1)));
- setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
- // Listen for window closing, so Library.stubs file can be saved before exit.
- topDog.addShutdownHook(new CleanUpThread());
- setVisible(false);
- } // end of constructor
- public static void displayError(String msg, String title, int typ) {
- if (activity == null) {
- createActivityLog(desktop, menuView);
- }
- JFrame topWindow = topPane;
- if (topWindow == null || !topWindow.isVisible()) {
- topWindow = SIL_Edit.editWindow;
- }
- JOptionPane.showMessageDialog(topWindow, msg, title, typ);
- MainPane.activity.log.append(msg + "\n\n");
- }
- /** Add a window to the desktop, and make it the current focus.
- @param wind A window to be added to the system's desktop & displayed. */
- public void addWindow(KSJInternalFrame wind) {
- currentFrame = wind;
- numWindows++;
- wind.desktop = desktop;
- wind.miViewMe = menuView.add(wind.windowNum);
- wind.miViewMe.addActionListener(wind);
- wind.menuView = menuView;
- desktop.add(wind);
- wind.show();
- }
- public void createMenu() {
- // menu bar
- setJMenuBar(menuBar);
- JMenu menuFile = new JMenu("File");
- menuFile.setMnemonic(KeyEvent.VK_F);
- JMenu menuEdit = new JMenu("Edit");
- menuEdit.setMnemonic(KeyEvent.VK_E);
- menuView = new JMenu("View");
- menuView.setMnemonic(KeyEvent.VK_V);
- menuAdmin = new JMenu("Admin");
- JMenu menuHelp = new HelpFrame.HMenu();
- menuHelp.setText("Help");
- menuHelp.setMnemonic(KeyEvent.VK_H);
- HelpFrame.help = new HelpFrame();
- // JMenu menuFileNew = new JMenu("New");
- JMenuItem miFileNewBrowser = menuFile.add("New Library Browser");
- miFileNewBrowser.setActionCommand("new browser");
- miFileNewBrowser.addActionListener(this);
- // JMenuItem miFileNewContext = menuFileNew.add("Context (Language)");
- // miFileNewContext.setActionCommand("new context");
- // miFileNewContext.addActionListener(this);
- // miFileNewSuggest = menuFileNew.add("Suggestions");
- // miFileNewSuggest.setEnabled(false);
- // menuFile.add(menuFileNew);
- JMenuItem miFileClose = menuFile.add("Close Window");
- miFileClose.setActionCommand("close window");
- miFileClose.addActionListener(this);
- miFileOpenSILK = menuFile.add("Open SILK File");
- miFileOpenSILK.setActionCommand("open silk");
- miFileOpenSILK.addActionListener(this);
- JMenuItem miFileOpenContext = menuFile.add("Open Context");
- miFileOpenContext.setActionCommand("open context");
- miFileOpenContext.addActionListener(this);
- menuFileAdd2Library = new JMenu("Add to Library...");
- JMenuItem miFileAdd2LibraryDT = menuFileAdd2Library.add("Domain Theory");
- miFileAdd2LibraryDT.setActionCommand("add domain theory");
- miFileAdd2LibraryDT.addActionListener(this);
- JMenuItem miFileAdd2LibraryBatch = menuFileAdd2Library.add("Batch Add Dom Thys");
- miFileAdd2LibraryBatch.setActionCommand("add batch of domain theories");
- miFileAdd2LibraryBatch.addActionListener(this);
- JMenuItem miFileAdd2LibraryCen = menuFileAdd2Library.add("People Data (.cen)");
- miFileAdd2LibraryCen.setEnabled(false);
- JMenuItem miFileAdd2LibraryGEDCOM = menuFileAdd2Library.add("GEDCOM File (.ged)");
- miFileAdd2LibraryGEDCOM.setEnabled(false);
- menuFile.add(menuFileAdd2Library);
- miFileDelete = menuFile.add("Delete From Library...");
- miFileDelete.setActionCommand("delete from library");
- miFileDelete.addActionListener(this);
- miFileDeleteContext = menuFile.add("Delete Context");
- miFileDeleteContext.setActionCommand("delete context");
- miFileDeleteContext.addActionListener(this);
- menuFile.addSeparator();
- miFileSaveContext = menuFile.add("Save Context");
- miFileSaveContext.setActionCommand("save context");
- miFileSaveContext.addActionListener(this);
- JMenuItem miFileSaveContextAs = menuFile.add("Save Context As...");
- miFileSaveContextAs.setActionCommand("save context as");
- miFileSaveContextAs.addActionListener(this);
- JMenu menuFileExport = new JMenu("Export File ...");
- JMenuItem miFileExportDT = menuFileExport.add("Domain Theory (.thy)");
- miFileExportDT.setActionCommand("export domain theory");
- miFileExportDT.addActionListener(this);
- JMenuItem miFileExportCen = menuFileExport.add("People Data (.cen)");
- miFileExportCen.setEnabled(false);
- JMenuItem miFileExportGEDCOM = menuFileExport.add("GEDCOM File (.ged)");
- miFileExportGEDCOM.setActionCommand("export GEDCOM");
- miFileExportGEDCOM.addActionListener(this);
- menuFile.add(menuFileExport);
- menuFile.addSeparator();
- JMenuItem miFileExit = menuFile.add("Exit SILKin");
- miFileExit.setActionCommand("exit");
- miFileExit.addActionListener(this);
- JMenuItem miEditUnDo = menuEdit.add("Un-Do");
- miEditUnDo.setEnabled(false);
- JMenuItem miEditReDo = menuEdit.add("Re-Do");
- miEditReDo.setEnabled(false);
- menuEdit.addSeparator();
- JMenuItem miEditCut = new JMenuItem(new DefaultEditorKit.CutAction());
- miEditCut.setText("Cut");
- miEditCut.setMnemonic(KeyEvent.VK_T);
- menuEdit.add(miEditCut);
- JMenuItem miEditCopy = new JMenuItem(new DefaultEditorKit.CopyAction());
- miEditCopy.setText("Copy");
- miEditCopy.setMnemonic(KeyEvent.VK_C);
- menuEdit.add(miEditCopy);
- JMenuItem miEditPaste = new JMenuItem(new DefaultEditorKit.PasteAction());
- miEditPaste.setText("Paste");
- miEditPaste.setMnemonic(KeyEvent.VK_P);
- menuEdit.add(miEditPaste);
- // JMenuItem miEditDelete = menuEdit.add("Delete");
- // JMenuItem miEditSelectAll= menuEdit.add("Select All");
- menuEdit.addSeparator();
- JMenuItem miEditPrefs = menuEdit.add("Edit Prefs");
- miEditPrefs.setActionCommand("edit prefs");
- miEditPrefs.addActionListener(this);
- JMenuItem miEditUserContext = menuEdit.add("Edit User Context");
- miEditUserContext.setActionCommand("edit user context");
- miEditUserContext.addActionListener(this);
- JMenuItem miTest1 = menuAdmin.add("Compute Similarity Matrix");
- miTest1.setActionCommand("Compute Similarity Matrix");
- miTest1.addActionListener(this);
- JMenuItem miTest2 = menuAdmin.add("Make Curr Lang dyadsUndefined");
- miTest2.setActionCommand("Make Curr Lang dyadsUndefined");
- miTest2.addActionListener(this);
- JMenuItem miTest3 = menuAdmin.add("Match dyadsUndefined");
- miTest3.setActionCommand("Match dyadsUndefined");
- miTest3.addActionListener(this);
- JMenuItem miTest4 = menuAdmin.add("Cluster the Feature Vectors");
- miTest4.setActionCommand("Cluster the Feature Vectors");
- miTest4.addActionListener(this);
- JMenuItem miTest5 = menuAdmin.add("Gen CUC Population");
- miTest5.setActionCommand("Gen CUC Population");
- miTest5.addActionListener(this);
- JMenuItem miTest6 = menuAdmin.add("Gen Indexes");
- miTest6.setActionCommand("Gen Indexes");
- miTest6.addActionListener(this);
- JMenuItem miTest7 = menuAdmin.add("Merge Indexes");
- miTest7.setActionCommand("Merge Indexes");
- miTest7.addActionListener(this);
- JMenuItem miTest10 = menuAdmin.add("Simulate User Data");
- miTest10.setActionCommand("Simulate User Data");
- miTest10.addActionListener(this);
- JMenuItem miTest11 = menuAdmin.add("Leave One Out");
- miTest11.setActionCommand("Leave One Out");
- miTest11.addActionListener(this);
- JMenuItem miTest12 = menuAdmin.add("Leave 1 Instant Replay");
- miTest12.setActionCommand("Leave 1 Instant Replay");
- miTest12.addActionListener(this);
- menuBar.add(menuFile);
- menuBar.add(menuEdit);
- menuBar.add(menuView);
- menuBar.add(menuAdmin);
- menuBar.add(menuHelp);
- if (Library.currentActivity != Library.ADMIN) {
- menuAdmin.setEnabled(false);
- }
- menuBar.validate();
- } // end of method createMenu
-
- public void enableAdvancedMenuItems(boolean bool) {
- menuFileAdd2Library.setEnabled(bool);
- miFileDelete.setEnabled(bool);
- miFileDeleteContext.setEnabled(bool);
- }
-
-
- // Method required to implement ActionListener interface
- public void actionPerformed(ActionEvent e) {
- if (e.getActionCommand().equals("new browser")) {
- browseLibrary();
- } // end of action-is-new-browser
- else if (e.getActionCommand().equals("new context")) {
- // FIX ME !!! open a DG window, and pass sit instead. Activity -> DG
- try {
- Library.createUserContext(currentFrame);
- } catch (Exception ex) {
- activity.log.append("While creating a new context, " + ex + "\n\n");
- }
- changeActivity(Library.DATA_GATHERING);
- } // end of action-is-new-context
- else if (e.getActionCommand().equals("Match dyadsUndefined")) {
- try {
- DomainTheory.current.matchDyads();
- } catch (Exception ex) {
- activity.log.append("While matching dyadsUndefined, " + ex + "\n\n");
- }
- } // end of action-is-Match-dyadsUndefined
- else if (e.getActionCommand().equals("open context")) {
- // FIX ME !!! open a DG window, and pass it instead. Activity -> DG
- try {
- Library.chooseUserContext(currentFrame);
- } catch (Exception ex) {
- activity.log.append("While opening a new context, " + ex + "\n\n");
- }
- changeActivity(Library.DATA_GATHERING);
- } // end of action-is-new-context
- else if (e.getActionCommand().equals("open silk")) {
- if (fc == null) {
- fc = new JFileChooser();
- }
- fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
- fc.setDialogTitle("File from KinshipEditor (.silk)");
- // Display File-Open dialog and get User's selection
- int returnVal = fc.showOpenDialog(desktop);
- if (returnVal == JFileChooser.APPROVE_OPTION) { // User Finds File
- changeActivity(Library.DATA_GATHERING);
- File file = fc.getSelectedFile();
- try {
- Library.loadSILKFile(file);
- } catch (Exception ex) {
- activity.log.append("While opening a KinshipEditor (.silk) file:\n" + ex + "\n\n");
- }
- } // end of User Finds File
- } // end of action-is-open-kinedit
- else if (e.getActionCommand().equals("close window")) {
- KSJInternalFrame frame = (KSJInternalFrame) desktop.getSelectedFrame();
- // IF INSTANCE_OF DATA_GATHERING, SAVE THE CONTEXT TO DISK
- frame.doDefaultCloseAction();
- } // end of action-is-close-window
- else if (e.getActionCommand().equals("exit")) {
- if (SIL_Edit.editWindow != null
- && SIL_Edit.editWindow.chart.dirty) {
- SIL_Edit.editWindow.chart.doWantToSave();
- }
- System.exit(0);
- } else if (e.getActionCommand().equals("delete from library")) {
- // First, let User choose what to language to delete.
- String[] langs = Library.genCtxtMenu("All");
- String victim = (String) JOptionPane.showInputDialog(desktop,
- "1) For what language would you like to make a deletion?",
- "What To Delete",
- JOptionPane.PLAIN_MESSAGE,
- null,
- langs,
- langs[0]);
- //Check for cancellation.
- if (victim == null) {
- return;
- }
- if (victim.equals("All")) {
- String vict;
- Library.ContextStub cs1;
- File aboutToDi;
- try {
- for (int k = 1; k < langs.length; k++) {
- vict = langs[k];
- cs1 = Library.retrieveOrCreateStub(vict);
- Library.removeContextStub(cs1);
- aboutToDi = new File(Library.libraryCtxtDirectory + vict + ".ctxt");
- aboutToDi.delete();
- }
- Library.cbIndex = null;
- Library.writeStubFile();
- } catch (Exception exc) {
- activity.log.append("While deleting Library files:\n" + exc + "\n\n");
- } // end of catch block
- } // end of delete-All
- else {
- Library.ContextStub cs = Library.retrieveOrCreateStub(victim);
- Context actxt = (Context) Library.activeContexts.get(victim);
- String[] choices;
- if (cs.adrThyExists && cs.refThyExists) { // a context with 2 domain theories
- choices = new String[4];
- choices[3] = "Both domain theories";
- choices[1] = victim + " domain theory";
- choices[2] = victim + " (Adr) domain theory";
- choices[0] = "The entire " + victim + " context & its 2 domain theories";
- } else if (cs.refThyExists) {
- choices = new String[2];
- choices[1] = victim + " domain theory";
- choices[0] = "The entire " + victim + " context and its domain theory";
- } else if (cs.adrThyExists) {
- choices = new String[2];
- choices[1] = victim + " (Adr) domain theory";
- choices[0] = "The entire " + victim + " context and its domain theory";
- } else {
- choices = new String[1];
- choices[0] = "The entire " + victim + " context. (It has no domain theory.)";
- }
- String choice = (String) JOptionPane.showInputDialog(desktop,
- "2) Which elements of the context for that language \nwould you like to delete?",
- "What To Delete",
- JOptionPane.PLAIN_MESSAGE,
- null,
- choices,
- choices[0]);
- if (choice == null) {
- return;
- }
- String[] onlyAlso = {"Card File ONLY", "Disk ALSO"};
- String eraser = (String) JOptionPane.showInputDialog(desktop,
- "3) Delete from the Library's 'card file' only?\n Or delete the file from your computer also?",
- "What To Delete",
- JOptionPane.PLAIN_MESSAGE,
- null,
- onlyAlso,
- "Disk ALSO");
- if (eraser == null) {
- return;
- }
- String filePath = Library.libraryCtxtDirectory + victim;
- File aboutToDie;
- try {
- if (choice.substring(0, 10).equals("The entire")) { // kill the whole context
- Library.removeContextStub(cs);
- Library.writeStubFile();
- if (eraser.substring(0, 4).equals("Disk")) {
- aboutToDie = new File(filePath + ".ctxt");
- aboutToDie.delete();
- filePath = Library.thyDirectory + victim;
- aboutToDie = new File(filePath + ".thy");
- if (aboutToDie.exists()) {
- aboutToDie.delete();
- }
- aboutToDie = new File(filePath + "(Adr).thy");
- if (aboutToDie.exists()) {
- aboutToDie.delete();
- }
- } // end of erase-disk-also
- } else if (choice.substring(0, 4).equals("Both")) { // choice-equals-both-theories
- cs.refThyExists = false;
- cs.adrThyExists = false;
- if (actxt == null) {
- actxt = Library.readContextFromDisk(filePath + ".ctxt");
- } // end of this-context-was-not-active
- actxt.domTheoryAdrNullify();
- actxt.domTheoryRefNullify();
- if (eraser.substring(0, 4).equals("Disk")) { // erase disk = over-write .ctxt file
- Library.saveContextToDisk(actxt);
- filePath = Library.thyDirectory + victim;
- aboutToDie = new File(filePath + ".thy");
- if (aboutToDie.exists()) {
- aboutToDie.delete();
- }
- aboutToDie = new File(filePath + "(Adr).thy");
- if (aboutToDie.exists()) {
- aboutToDie.delete();
- }
- }
- } else if (choice.indexOf("(Adr)") >= 0) {
- cs.adrThyExists = false;
- if (actxt == null) {
- actxt = Library.readContextFromDisk(filePath + ".ctxt");
- } // end of this-context-was-not-active
- actxt.domTheoryAdrNullify();
- if (eraser.substring(0, 4).equals("Disk")) { // erase disk = over-write .ctxt file
- Library.saveContextToDisk(actxt);
- filePath = Library.thyDirectory + victim;
- aboutToDie = new File(filePath + "(Adr).thy");
- if (aboutToDie.exists()) {
- aboutToDie.delete();
- }
- }
- } else {
- cs.refThyExists = false;
- if (actxt == null) {
- actxt = Library.readContextFromDisk(filePath + ".ctxt");
- } // end of this-context-was-not-active
- actxt.domTheoryRefNullify();
- if (eraser.substring(0, 4).equals("Disk")) { // erase disk = over-write .ctxt file
- Library.saveContextToDisk(actxt);
- filePath = Library.thyDirectory + victim;
- aboutToDie = new File(filePath + ".thy");
- if (aboutToDie.exists()) {
- aboutToDie.delete();
- }
- }
- }
- } catch (Exception exc) {
- activity.log.append("While deleting Library files:\n" + exc + "\n\n");
- }
- } // end of don't-delete-all
- for (int i = 0; i < MainPane.openBrowsers.size(); i++) {
- LibBrowser lb = (LibBrowser) MainPane.openBrowsers.get(i);
- lb.picker.refreshLangMenu();
- } // end of loop thru MainPane.openBrowsers
- JOptionPane.showMessageDialog(desktop,
- "Requested deletions are completed.",
- "Task Completed",
- JOptionPane.PLAIN_MESSAGE);
- } // end of action-command-is-delete
- else if (e.getActionCommand().equals("add domain theory")) {
- if (fc == null) {
- fc = new JFileChooser();
- }
- fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
- fc.setDialogTitle("File holding Domain Theory (Horn Clauses)");
- if (currDomTheoryDir != null) {
- fc.setCurrentDirectory(currDomTheoryDir);
- }
- // Display File-Open dialog and get User's selection
- int returnVal = fc.showOpenDialog(desktop);
- if (returnVal == JFileChooser.APPROVE_OPTION) {
- File file = fc.getSelectedFile();
- try {
- Library.loadNewDomTh(file);
- DomainTheory dt = DomainTheory.current;
- Context.simulation = false;
- dt.ctxt.simDataGen = false;
- String lang = dt.languageName, filePath;
- for (int i = 0; i < MainPane.openBrowsers.size(); i++) {
- LibBrowser lb = (LibBrowser) MainPane.openBrowsers.get(i);
- lb.picker.refreshLangMenu();
- } // end of loop thru MainPane.openBrowsers
- // Create a FeatureVector, postDistributions & write to disk
- ArrayList<Object> egoList = new ArrayList<Object>();
- if (FeatureVectorObj.el_1_distn == null) {
- Library.readDistributionsFromFile();
- }
- FeatureVectorObj fv1 = dt.computeFeatureVector(egoList);
- Library.postDistributions(fv1);
- filePath = Library.libraryDirectory + "Feature Vectors/" + fv1.languageName + ".fvect";
- PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(filePath)));
- fv1.toDisk(out);
- dt.findOverlappingTerms(egoList);
- dt.findHiddenNeuterEgos();
- currDomTheoryDir = fc.getCurrentDirectory();
- filePath = Library.libraryDirectory + "Domain Theory Files/" + lang + ".thy";
- out = new PrintWriter(new BufferedWriter(new FileWriter(filePath)));
- dt.toThyFile(out);
- Library.saveContextToDisk(dt.ctxt);
- JOptionPane.showMessageDialog(desktop,
- lang + " Successfully Added to Library.",
- "Task Completed",
- JOptionPane.PLAIN_MESSAGE);
- } catch (KSConstraintInconsistency exc) {
- int where = exc.toString().indexOf(":");
- String msg = "PROBLEM: " + exc.toString().substring(where + 1)
- + "\nRECOMMENDATION: Correct or remove this clause from domain theory.\n "
- + "Then delete this theory from the Library & re-add it.";
- displayError(msg, "Horn Clause Error - Constraints", JOptionPane.ERROR_MESSAGE);
- } catch (KSBadHornClauseException exc) {
- int where = exc.toString().indexOf(":");
- String msg = "PROBLEM: " + exc.toString().substring(where + 1)
- + "\nRECOMMENDATION: Correct or remove this clause from domain theory.\n "
- + "Then delete this theory from the Library & re-add it.";
- displayError(msg, "Horn Clause Error", JOptionPane.ERROR_MESSAGE);
- } catch (KSParsingErrorException exc) {
- int where = exc.toString().indexOf(":");
- String msg = "PROBLEM: " + exc.toString().substring(where + 1)
- + "\nRECOMMENDATION: Correct this line number & try again.";
- JOptionPane.showMessageDialog(desktop, msg, "Parsing Error",
- JOptionPane.ERROR_MESSAGE);
- activity.log.append(msg + "\n\n");
- } catch (ClassNotFoundException exc) {
- int where = exc.toString().indexOf(":");
- String msg = "PROBLEM: " + exc.toString().substring(where + 1)
- + "\nRECOMMENDATION: Submit Bug Report.";
- JOptionPane.showMessageDialog(desktop, msg, "Missing Class encountered",
- JOptionPane.ERROR_MESSAGE);
- activity.log.append(msg + "\n\n");
- } catch (KSInternalErrorException exc) {
- int where = exc.toString().indexOf(":");
- String msg = "PROBLEM: " + exc.toString().substring(where + 1)
- + "\nRECOMMENDATION: To replace an existing theory, delete the old"
- + " version, then add the new version.";
- JOptionPane.showMessageDialog(desktop, msg, "Duplicate Domain Theory",
- JOptionPane.ERROR_MESSAGE);
- activity.log.append(msg + "\n\n");
- } catch (NotSerializableException exc) {
- int where = exc.toString().indexOf(":");
- String msg = "PROBLEM: Internal Error: " + exc
- + "\nRECOMMENDATION: Submit Bug Report.";
- JOptionPane.showMessageDialog(desktop, msg, "Internal Error",
- JOptionPane.ERROR_MESSAGE);
- activity.log.append(msg + "\n\n");
- } catch (IOException exc) {
- int where = exc.toString().indexOf(":");
- String msg = "PROBLEM: Writing out to Library, " + exc.toString().substring(where + 1)
- + "\nRECOMMENDATION: Check for disk, directory, or permissions problems.";
- JOptionPane.showMessageDialog(desktop, msg, "File System Error",
- JOptionPane.ERROR_MESSAGE);
- activity.log.append(msg + "\n\n");
- } catch (JavaSystemException exc) {
- int where = exc.toString().indexOf(":");
- String msg = "PROBLEM: Writing out to Library, " + exc.toString().substring(where + 1)
- + "\nRECOMMENDATION: Check for disk, directory, or permissions problems.";
- JOptionPane.showMessageDialog(desktop, msg, "File System Error",
- JOptionPane.ERROR_MESSAGE);
- activity.log.append(msg + "\n\n");
- } // end of catch blocks
- } // end of if-returnVal=Approve
- } // end of action-is-add-dom-thy
- else if (e.getActionCommand().equals("add batch of domain theories")) {
- if (fc == null) {
- fc = new JFileChooser();
- }
- fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
- fc.setDialogTitle("Directory holding Domain Theories");
- if (currDomTheoryDir != null) {
- fc.setCurrentDirectory(currDomTheoryDir.getParentFile());
- }
- // Display File-Open dialog and get User's selection
- String lang = "";
- DomainTheory dt = null;
- int returnVal = fc.showOpenDialog(desktop);
- if (returnVal == JFileChooser.APPROVE_OPTION) {
- try {
- File dir = fc.getSelectedFile();
- if (!dir.isDirectory()) {
- throw new JavaSystemException("Selected file is not a directory.");
- }
- int doFVs = JOptionPane.showConfirmDialog(this, "Compute Feature Vectors?");
- int keep = JOptionPane.showConfirmDialog(this, "Keep Contexts Active?");
- int overWrite = JOptionPane.showConfirmDialog(this, "Allow Over-Write of Existing DTs?");
- Library.allowOverWrites = (overWrite == JOptionPane.YES_OPTION);
- currDomTheoryDir = dir;
- if (doFVs == JOptionPane.YES_OPTION && FeatureVectorObj.el_1_distn == null) {
- Library.resetDistributions();
- }
- File[] batch = dir.listFiles();
- for (int i = 0; i < batch.length; i++) {
- File file = batch[i];
- String fName = file.getName(), filePath, mod;
- if (fName.indexOf(".") != 0) {
- Library.loadNewDomTh(file);
- dt = DomainTheory.current;
- Context.current = dt.ctxt;
- Context.simulation = false;
- dt.ctxt.simDataGen = false;
- if (keep == JOptionPane.NO_OPTION) {
- lang = dt.languageName;
- int end = lang.indexOf("(");
- if (end > -1) {
- lang = lang.substring(0, end);
- }
- Library.activeContexts.remove(lang);
- }
- PrintWriter out;
- ArrayList<Object> egoList = new ArrayList<Object>();
- if (doFVs == JOptionPane.YES_OPTION) {
- // Create a FeatureVector & write to disk
- FeatureVectorObj fv1 = dt.computeFeatureVector(egoList);
- filePath = Library.libraryDirectory + "Feature Vectors/" + dt.languageName + ".fvect";
- out = new PrintWriter(new BufferedWriter(new FileWriter(filePath)));
- fv1.toDisk(out);
- } else {
- // Just asssure examples generated
- ClauseBody.priorPred = ""; // Needed for Clause Counts
- ClauseBody.seqTotal = 0;
- ClauseBody.dupTotal = 0;
- Iterator ktdIter = dt.theory.values().iterator();
- egoList = dt.maleAndFemaleCreatedHeThem();
- while (ktdIter.hasNext()) {
- KinTermDef ktd = (KinTermDef) ktdIter.next();
- if (dt.printableTerm(ktd)) {
- ktd.assureExamplesGenerated(egoList);
- if (ktd.eqcSigExact == null) {
- ktd.makeSigStrings();
- }
- }
- }
- // Print out the Clause Counts, etc.
- String pad = "";
- if (++ClauseBody.seq < 10) {
- pad = " ";
- } else if (ClauseBody.seq < 100) {
- pad = " ";
- }
- System.out.println(ClauseBody.priorPred + ": " + pad + ClauseBody.seq + " - " + ClauseBody.dups
- + " = " + (ClauseBody.seq - ClauseBody.dups));
- ClauseBody.seqTotal += ClauseBody.seq;
- System.out.println("\nTotal clauses for " + dt.languageName + " is " + ClauseBody.seqTotal
- + " - " + ClauseBody.dupTotal + " = " + (ClauseBody.seqTotal - ClauseBody.dupTotal) + "\n\n");
- }
- dt.findOverlappingTerms(egoList);
- dt.findHiddenNeuterEgos();
- filePath = Library.libraryDirectory + "Domain Theory Files/" + dt.languageName + ".thy";
- out = new PrintWriter(new BufferedWriter(new FileWriter(filePath)));
- dt.toThyFile(out);
- System.out.println("Wrote: " + filePath);
- Library.saveContextToDisk(Context.current);
- } // end of it's not an invisible file (e.g. .DSxxxx)
- } // end of loop thru DT files
- for (int i = 0; i < MainPane.openBrowsers.size(); i++) {
- LibBrowser lb = (LibBrowser) MainPane.openBrowsers.get(i);
- lb.picker.refreshLangMenu();
- } // end of loop thru MainPane.openBrowsers
- int num = batch.length - 1;
- JOptionPane.showMessageDialog(desktop,
- num + " DomTheories Added to Library.",
- "Task Completed",
- JOptionPane.PLAIN_MESSAGE);
- } catch (KSConstraintInconsistency exc) {
- int where = exc.toString().indexOf(":");
- String msg = "PROBLEM with " + dt.languageName + ": " + exc.toString().substring(where + 1)
- + "\nRECOMMENDATION: Correct or remove this clause from domain theory.\n "
- + "Then delete this theory from the Library & re-add it.";
- JOptionPane.showMessageDialog(desktop, msg, "Horn Clause Error - Constraints",
- JOptionPane.ERROR_MESSAGE);
- activity.log.append(msg + "\n\n");
- } catch (KSBadHornClauseException exc) {
- int where = exc.toString().indexOf(":");
- String msg = "PROBLEM with " + dt.languageName + ": " + exc.toString().substring(where + 1)
- + "\nRECOMMENDATION: Correct or remove this clause from domain theory.\n "
- + "Then delete this theory from the Library & re-add it.";
- JOptionPane.showMessageDialog(desktop, msg, "Horn Clause Error",
- JOptionPane.ERROR_MESSAGE);
- activity.log.append(msg + "\n\n");
- } catch (KSParsingErrorException exc) {
- int where = exc.toString().indexOf(":");
- String msg = "PROBLEM in Parsing: " + exc.toString().substring(where + 1)
- + "\nRECOMMENDATION: Correct this line number & try again.";
- JOptionPane.showMessageDialog(desktop, msg, "Parsing Error",
- JOptionPane.ERROR_MESSAGE);
- activity.log.append(msg + "\n\n");
- } catch (ClassNotFoundException exc) {
- int where = exc.toString().indexOf(":");
- String msg = "PROBLEM with " + dt.languageName + ": " + exc.toString().substring(where + 1)
- + "\nRECOMMENDATION: Submit Bug Report.";
- JOptionPane.showMessageDialog(desktop, msg, "Missing Class encountered",
- JOptionPane.ERROR_MESSAGE);
- activity.log.append(msg + "\n\n");
- } catch (KSInternalErrorException exc) {
- int where = exc.toString().indexOf(":");
- String msg = "PROBLEM with " + DomainTheory.current.languageName + ": " + exc.toString().substring(where + 1)
- + "\nRECOMMENDATION: To replace an existing theory, delete the old"
- + " version, then add the new version.";
- JOptionPane.showMessageDialog(desktop, msg, "Duplicate Domain Theory",
- JOptionPane.ERROR_MESSAGE);
- activity.log.append(msg + "\n\n");
- } catch (NotSerializableException exc) {
- int where = exc.toString().indexOf(":");
- String msg = "PROBLEM: Internal Error: " + exc.toString().substring(where + 1)
- + "\nRECOMMENDATION: Submit Bug Report.";
- JOptionPane.showMessageDialog(desktop, msg, "Internal Error",
- JOptionPane.ERROR_MESSAGE);
- activity.log.append(msg + "\n\n");
- } catch (IOException exc) {
- int where = exc.toString().indexOf(":");
- String msg = "PROBLEM: Writing out to Library, " + exc.toString().substring(where + 1)
- + "\nRECOMMENDATION: Check for disk, directory, or permissions problems.";
- JOptionPane.showMessageDialog(desktop, msg, "File System Error",
- JOptionPane.ERROR_MESSAGE);
- activity.log.append(msg + "\n\n");
- } catch (JavaSystemException exc) {
- int where = exc.toString().indexOf(":");
- String msg = "PROBLEM: Writing out to Library, " + exc.toString().substring(where + 1)
- + "\nRECOMMENDATION: Check for disk, directory, or permissions problems.";
- JOptionPane.showMessageDialog(desktop, msg, "File System Error",
- JOptionPane.ERROR_MESSAGE);
- activity.log.append(msg + "\n\n");
- } // end of catch blocks
- } // end of if-returnVal=Approve
- } // end of action-is-add-batch-of-dom-thys
- else if (e.getActionCommand().equals("delete context")) {
- // FINISH ME !!!
- try {
- Library.deleteContext(currentFrame);
- } catch (Exception ex) {
- activity.log.append("While deleting a context, " + ex + "\n\n");
- }
- changeActivity(Library.DATA_GATHERING);
- } // end of action-is-delete-context
- else if (e.getActionCommand().equals("save context")) {
- if (SIL_Edit.editWindow != null) {
- SIL_Edit.editWindow.chart.saveSILKinFile();
- }else try {
- Library.saveUserContext(currentFrame, false);
- } catch (Exception ex) {
- activity.log.append("While saving a context, " + ex + "\n\n");
- }
- changeActivity(Library.DATA_GATHERING);
- } // end of action-is-save-context
- else if (e.getActionCommand().equals("save context as")) {
- if (SIL_Edit.editWindow != null) {
- SIL_Edit.editWindow.chart.saveAsFile();
- }else try {
- Library.saveUserContext(currentFrame, true);
- } catch (Exception ex) {
- activity.log.append("While saving a context, " + ex + "\n\n");
- }
- changeActivity(Library.DATA_GATHERING);
- } // end of action-is-save-context-as
- else if (e.getActionCommand().equals("export GEDCOM")) {
- int population = Context.current.indSerNumGen + Context.current.famSerNumGen;
- if (population < 2) {
- JOptionPane.showMessageDialog(desktop,
- "You are requesting export of a total of " + population + " people and families.\n"
- + "That makes no sense. Make sure you have chosen the correct\n"
- + "context and generated a population before exporting.",
- "Nothing To Export",
- JOptionPane.ERROR_MESSAGE);
- } // end of too-small-population
- else { // normal-population-numberOfKinTerms
- if (fc == null) {
- fc = new JFileChooser();
- }
- fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
- fc.setDialogTitle("Location for GEDCOM file -- .ged extension recommended");
- if (currGEDCOMDir != null) {
- fc.setCurrentDirectory(currGEDCOMDir);
- }
- // Display File-Open dialog and get User's selection
- int returnVal = fc.showSaveDialog(desktop);
- if (returnVal == JFileChooser.APPROVE_OPTION) {
- File file = fc.getSelectedFile();
- currGEDCOMDir = fc.getCurrentDirectory();
- String fName = file.getName(), fPath = file.getPath();
- Object[] options2 = {"Include", "Don't Include"};
- int choice1 = 1;
- choice1 = JOptionPane.showOptionDialog(desktop,
- "Some names have 'flags' like <aux> embedded in them. Include those?",
- "Include Names With Tags?",
- JOptionPane.YES_NO_OPTION,
- JOptionPane.QUESTION_MESSAGE,
- null, //don't use a custom Icon
- options2, //the titles of buttons
- options2[1]); //default is "Don't Include"
- try {
- PrintWriter outFile = new PrintWriter(new BufferedWriter(new FileWriter(fPath)));
- Context.current.exportGEDCOM(outFile, fName, (String) options2[choice1]);
- outFile.flush();
- outFile.close();
- } catch (IOException exc) {
- String msg = "PROBLEM: While exporting a GEDCOM file, " + prettify(exc.toString())
- + "\nRECOMMENDATION: Check for disk, directory, or permissions problems.";
- JOptionPane.showMessageDialog(desktop, msg, "File System Error",
- JOptionPane.ERROR_MESSAGE);
- activity.log.append(msg + "\n\n");
- } catch (Exception exc) {
- String msg = "PROBLEM: While exporting a GEDCOM file, " + prettify(exc.toString())
- + "\nRECOMMENDATION: Submit a Bug Report!";
- JOptionPane.showMessageDialog(desktop, msg, "General Error",
- JOptionPane.ERROR_MESSAGE);
- activity.log.append(msg + "\n\n");
- } // end of catch bodies
- } // end of if-APPROVE_OPTION
- } // end of normal-population-numberOfKinTerms
- } // end of action-is-export-GEDCOM
- else if (e.getActionCommand().equals("export domain theory")) {
- // Add Here the code to write out a .thy file to location of User's choice (EXCEPT LIBRARY).
- // REMEMBER TO RE-USE FILE CHOOSER
- // DomTh.writeThyFile() is all set to go.
- } // end of action-is-export-domain-theory
- else if (e.getActionCommand().equals("edit prefs")) {
- if (SIL_Edit.editWindow != null) {
- SIL_Edit.editWindow.editPrefsItemActionPerformed(null);
- }else {
- String msg = "You may only edit Prefs for a Context Under Construction."
- + "\nThere currently is none.";
- JOptionPane.showMessageDialog(desktop, msg, "Invalid Command",
- JOptionPane.ERROR_MESSAGE);
- activity.log.append(msg + "\n\n");
- }
- } // end of action-is-edit-prefs
- else if (e.getActionCommand().equals("edit user context")) {
- editCUC();
- } // end of action-is-edit-context
- else if (e.getActionCommand().equals("Compute Similarity Matrix")) {
- try {
- Library.generateSimMatrix();
- } catch (Exception exc) {
- String msg = "PROBLEM: During FV generation, " + prettify(exc.toString())
- + "\nRECOMMENDATION: DeBug!";
- JOptionPane.showMessageDialog(desktop, msg, "Testing Error",
- JOptionPane.ERROR_MESSAGE);
- activity.log.append(msg + "\n\n");
- }
- } // end of action-is-Compute-Similarity-Matrix
- else if (e.getActionCommand().equals("Cluster the Feature Vectors")) {
- int minK, maxK;
- float penalty;
- try {
- String minKStr = JOptionPane.showInputDialog(this, "Enter Smallest Number of Clusters"),
- maxKStr = JOptionPane.showInputDialog(this, "Enter Largest Number of Clusters"),
- penaltyStr = JOptionPane.showInputDialog(this, "Enter Penalty Percentage (a whole number)");
- minK = Integer.parseInt(minKStr);
- maxK = Integer.parseInt(maxKStr);
- penalty = Float.parseFloat(penaltyStr) / 100f;
- Library.clusterFVs(minK, maxK, penalty);
- } catch (Exception exc) {
- String msg = "PROBLEM: During FV clustering, " + prettify(exc.toString())
- + "\nRECOMMENDATION: DeBug!";
- JOptionPane.showMessageDialog(desktop, msg, "Testing Error",
- JOptionPane.ERROR_MESSAGE);
- activity.log.append(msg + "\n\n");
- }
- } // end of action-is-Cluster-the-Feature-Vectors
- else if (e.getActionCommand().equals("Make Curr Lang dyadsUndefined")) {
- try {
- if (Context.current != null) {
- System.out.println("Generating dyadsUndefined for " + Context.current.languageName);
- DomainTheory.current.dyadsUndefined = new DyadTMap();
- // currentContext.cleanNodeFields();
- Context.current.addDyads((Individual) Context.current.individualCensus.get(0));
- }
- // ((JTextArea)diagramArea).setText(censusString() + dtm.summaryString());
- } catch (Exception exc) {
- String msg = "PROBLEM: During Dyad generation, " + prettify(exc.toString())
- + "\nRECOMMENDATION: DeBug!";
- JOptionPane.showMessageDialog(desktop, msg, "Testing Error",
- JOptionPane.ERROR_MESSAGE);
- activity.log.append(msg + "\n\n");
- }
- } // end of action-is-Make-dyadsUndefined
- else …
Large files files are truncated, but you can click here to view the full file