/* Research Project: Graphical Database for Category Theory J. Bradbury, Dr. R. Rosebrugh, I. Rutherford Mount Allison University 2001 File: InitialObjectFrame.java Description: This file is displayed when the user selects the "Initial Object" menu option in the main window. The user can select a category from a choice menu and then chose to check if one or all of the categories are intial. The information on each object tested will be displayed in the text area. */ //import statements import java.awt.*; import java.awt.event.*; import borland.jbcl.layout.*; public class InitialObjectFrame extends Frame { Category cat = new Category(); CategoryList l = new CategoryList(); int check_enter = 0; //Boolean to determine if max endomorphism was reached boolean endomorphism = false; //Constants IniSettings ini = new IniSettings(); //Objectsin the Graphical User Interface(GUI) Button exit = new Button(); Panel button_panel = new Panel(); BorderLayout borderLayout1 = new BorderLayout(); Button okButton = new Button(); Button checkButton = new Button(); Choice categoryChoice = new Choice(); Label label2 = new Label(); TextArea textArea1 = new TextArea("", 10, 10, TextArea.SCROLLBARS_VERTICAL_ONLY); MainWindow edit;//used for editing mainwindow... List objectList = new List(); Label label1 = new Label(); Button selectAllButton = new Button(); TextField currentCategory = new TextField(); GridBagLayout gridBagLayout1 = new GridBagLayout(); GBConstraintsEditor g = new GBConstraintsEditor(); public InitialObjectFrame(CategoryList ltemp, MainWindow ed) //Default Constructor with the list of categories and the ok //button as parameters { //l = ltemp; edit = ed; ed.enableMenus(false); try { jbInit(); } catch (Exception e) { e.printStackTrace(); } } public boolean handleEvent(Event e) { if ((e.id == Event.WINDOW_DESTROY) || (e.id == Event.ACTION_EVENT)) { edit.enableMenus(true); hide(); //hide frame dispose(); //free resources return true; } else if (e.key == Event.ENTER) { if (check_enter == 0) check_enter++; else { edit.enableMenus(true);//show the menus again hide(); //hide frame dispose(); //free resources } return true; } return super.handleEvent(e); } public boolean action(Event e, Object o) { if ((e.target == exit) || (e.key == Event.ENTER)) { edit.enableMenus(true);//enable menus again... hide(); //hide frame dispose(); //free resources return true; } return false; } private void jbInit() throws Exception //This function intializes the GUI { this.setTitle("GDCT: Check Category for Initial Object(s)"); this.setBackground(new Color(192,192,192)); okButton.setLabel("Close"); okButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { okButton_actionPerformed(e); } }); checkButton.setLabel("Check Object(s)"); /*categoryChoice.addItemListener(new java.awt.event.ItemListener() { public void itemStateChanged(ItemEvent e) { categoryChoice_itemStateChanged(e); } });*/ label2.setText("Current Category:"); this.setLayout(gridBagLayout1); currentCategory.setBackground(Color.white); objectList.setBackground(Color.white); this.add(okButton, g.getConstraints(5, 4, 1, 1, 0.0, 0.0 ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(9, 8, 10, 9), 43, 8)); this.add(checkButton, g.getConstraints(4, 4, 1, 1, 0.0, 0.0 ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(10, 8, 9, 0), -9, 8)); //this.add(categoryChoice, new XYConstraints(348, 251, 143, -1)); this.add(label2, g.getConstraints(0, 0, 1, 1, 0.0, 0.0 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 7, 0, 0), 0, 2)); this.add(textArea1, g.getConstraints(3, 1, 4, 3, 1.0, 1.0 ,GridBagConstraints.SOUTHEAST, GridBagConstraints.HORIZONTAL, new Insets(0, 7, 0, 21), 217, 138)); this.add(objectList, g.getConstraints(0, 3, 2, 2, 1.0, 1.0 ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(6, 7, 15, 5), 14, 95)); this.add(label1, g.getConstraints(0, 2, 3, 1, 0.0, 0.0 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 7, 0, 0), 0, 0)); this.add(selectAllButton, g.getConstraints(3, 4, 1, 1, 0.0, 0.0 ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(10, 0, 9, 0), 31, 8)); this.add(currentCategory, g.getConstraints(0, 1, 2, 1, 1.0, 0.0 ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 7, 0, 5), 117, 3)); // ListNode current = l.head; // while(current != null) // { // categoryChoice.addItem(current.cat.name); // current = current.next; //} textArea1.setEditable(false); textArea1.setBackground(Color.white); String name = categoryChoice.getSelectedItem(); //cat = l.getNode(name); cat = edit.cat; this.setSize(new Dimension(490, 329)); currentCategory.setEditable(false); currentCategory.setText(cat.name); selectAllButton.setLabel("Select All"); selectAllButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { selectAllButton_actionPerformed(e); } }); checkButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { checkButton_objectList_actionPerformed(e); } }); label1.setText("Select Object(s) to Check:"); //if (name.equals(cat.name)) //{ for (int i = 0; i < cat.numobj; i++) objectList.addItem("" + cat.obj[i]); if (objectList.countItems() == 0) { new MessageDialog(this, "Error", "Cannot test if initial object(s) exist, category has 0 objects", true); } //} objectList.setMultipleSelections(true); objectList.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { checkButton_objectList_actionPerformed(e); } }); } void okButton_actionPerformed(ActionEvent e) //Function called when OK button is pressed. This function //take the string in the nameField and makes it the name of //the current category { /*l.replaceNode(c); t.displayArea.setText(""); //Clear graphical display HERE t.displayCategory(c, t.displayArea); t.GraphCategory(t.graph_, t.graphCanvas_, c);*/ edit.enableMenus(true); hide(); dispose(); } /* void categoryChoice_itemStateChanged(ItemEvent e) //When an item in the categoryChoice pulldown menu is seleceted //this function is called { String name = categoryChoice.getSelectedItem(); cat = l.getNode(name); //Call confluence objectList.clear(); if (name.equals(cat.name)) { for (int i = 0; i < cat.numobj; i++) objectList.addItem("" + cat.obj[i]); if (objectList.countItems() == 0) { String e1 = "Error\nCan not Test if Initial Object(s) exist\nCategory has 0 Objects"; error_message(e1); } } else { String e1 = "Error\nInvalid\nCategory has been selected"; error_message(e1); hide(); dispose(); } edit.cat = cat; //Clear graphical display HERE edit.displayCategory(edit.cat); edit.GraphCategory(edit.graph_, edit.graphCanvas_, edit.cat); } */ void selectAllButton_actionPerformed(ActionEvent e) //This function selects all objects { for (int i=0; i < objectList.getItemCount(); i++) objectList.select(i); } void checkButton_objectList_actionPerformed(ActionEvent e) { textArea1.setText(""); if (objectList.getItemCount() == 0) return; for (int i = 0; i < objectList.getItemCount(); i++) { try { int editsub = 0; String temp = objectList.getSelectedItems()[i]; editsub = cat.object_number(temp); initial_object(editsub); } catch (ArrayIndexOutOfBoundsException aie) { } } for (int i=0; i < objectList.getItemCount(); i++) objectList.deselect(i); textArea1.setCaretPosition(0); } //INITIAL OBJECT FUNCTIONS public boolean check_initial(int path[], int domain, int objects[], int object_array[][], String orig) /* Parameters: path: array of integers containing the path of arrows followed so far domain: integer representing the domain of the current arrow in the path objects:array of integers containing the objects visited along the current path object_array: uses the integers representing the objects as subscripts and stores paths to each object as the elements of the array orig: string containing the name of the object being tested for an initial object Purpose: A recursive function to determine if object domain is initial. Design: Traces all paths from object domain. If a path is the first path with its codomain, the path is stored in object_array. Otherwise, the path is compared to the path stored for the object which is the codomain; if it is not equal to the stored path, the object is not initial, a message is displayed, and the function returns false. Otherwise, the function returns true. */ { int i, j, number, current_arrow, codomain; boolean done; int arrow_array[] = new int [edit.ini.getMAXARR()]; int first[] = new int [edit.ini.getMAXWORD()]; int second[] = new int [edit.ini.getMAXWORD()]; // check for a looped path done = false; // for every object in the current path for (i=0; i 1) done = true; } } if (!done) { // make sure the current path is ok if (object_array[domain][0] == -1) { // this object has not been reached yet first = cat.copy_path(path); first = cat.reduce(first); object_array[domain] = cat.copy_path(first); } else { // make sure the current path equals the already-stored path first = cat.copy_path(path); second = cat.copy_path(object_array[domain]); first = cat.reduce(first); second = cat.reduce(second); if (!cat.equals(first, second)) { textArea1.appendText("\n" + orig + " NOT INITIAL...\n" + cat.path_to_string(first)); textArea1.appendText(" and " + cat.path_to_string(second) + " are both paths to object " + cat.obj[domain] + "\n"); return false; } } // check all arrows from this object number = cat.all_arr(domain, arrow_array); for (i=0; i=0; j--) { path[j+1] = path[j]; } path[0] = current_arrow; objects[cat.path_len(objects)+1] = -1; objects[cat.path_len(objects)] = codomain; // now recurse by checking from the next object if (!check_initial(path, codomain, objects, object_array, orig)) return false; // presuming the last call returned true, then we remove the last object from the path // and the last arrow for (j=0; j