/* Research Project: Graphical Database for Category Theory J. Bradbury, Dr. R. Rosebrugh, I. Rutherford Mount Allison University 2001 File: MakeConfluentFrame.java Description: This file is displayed when the user selects the "Make Confluent " menu option in the main window. The user can select a category from a choice menu and then changes made to the category to make it confluent will be displayed in the text area. To save the changes to the current category press "ok". */ //import statements import java.awt.*; import java.awt.event.*; public class MakeConfluentFrame extends Frame { Category cat = new Category(); CategoryList l = new CategoryList(); int check_enter = 0; //Array to store relations that needed to be //added to current category in order to make it confluent. String newRelations = new String(); //Constants IniSettings ini = new IniSettings(); //Objects in the Graphical User Interface(GUI) Button exit = new Button(); Panel button_panel = new Panel(); BorderLayout borderLayout1 = new BorderLayout(); Button okButton = new Button(); Button cancelButton = new Button(); Label label2 = new Label(); TextArea textArea1 = new TextArea("", 10, 10, TextArea.SCROLLBARS_VERTICAL_ONLY); MainWindow edit; TextField categoryField = new TextField(); GridBagLayout gridBagLayout1 = new GridBagLayout(); GBConstraintsEditor g = new GBConstraintsEditor(); public MakeConfluentFrame(MainWindow ed) //Default Constructor with the list of categories and the ok //button as parameters { edit = ed; cat.copyCategory(ed.cat); edit.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); 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); hide(); //hide frame dispose(); //free resources return true; } return false; } private void jbInit() throws Exception //This function intializes the GUI { this.setTitle("GDCT: Make Category Confluent"); this.setBackground(new Color(192,192,192)); okButton.setLabel("OK"); okButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { okButton_actionPerformed(e); } }); cancelButton.setLabel("Cancel"); cancelButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { cancelButton_actionPerformed(e); } }); label2.setText("Current Category:"); this.setLayout(gridBagLayout1); categoryField.setBackground(Color.white); this.add(okButton, g.getConstraints(0, 2, 2, 1, 0.0, 0.0 ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(6, 17, 8, 0), 114, 8)); this.add(cancelButton, g.getConstraints(2, 2, 1, 1, 0.0, 0.0 ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(6, 7, 8, 15), 95, 8)); this.add(label2, g.getConstraints(0, 0, 1, 1, 0.0, 0.0 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(7, 17, 0, 0), 0, 0)); this.add(textArea1, g.getConstraints(0, 1, 3, 1, 1.0, 1.0 ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(7, 17, 0, 15), 205, -72)); this.add(categoryField, g.getConstraints(2, 0, 1, 1, 1.0, 0.0 ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(7, 0, 0, 16), 128, 2)); categoryField.setText(cat.name); categoryField.setEditable(false); textArea1.setBackground(Color.white); make_confluent(); //Call confluence } 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 { if (!newRelations.equals("")) { //textArea1.append("HERE"); //Indicate that relations have been added //to the category through the make confluent tool cat.mod.madeConfluent = true; //Save modified category in list edit.catList.replaceNode(cat); edit.cat.copyCategory(cat); //Edit graphical display of category GMLEditor gEdit = new GMLEditor(); gEdit.addRelation(cat, newRelations); //Display category graphically edit.displayCategoryGraph(cat.gml, edit.graph_); //edit.displayCategory(edit.cat); //edit.GraphCategory(edit.graph_, edit.graphCanvas_, edit.cat); } //Close frame edit.enableMenus(true); hide(); dispose(); } void cancelButton_actionPerformed(ActionEvent e) { edit.enableMenus(true); hide(); dispose(); } public int overlap(int path1[], int path2[]) /* Parameters: path1, path2: arrays of integers representing two paths of arrows. Purpose: To determine if there is an overlap between the two paths and to return its length; if there is no overlap, returns -1. Design: Compare the beginning of path1 to the end of path2. If they are the same, return the size of the overlap; otherwise return -1. */ { int i, k; //the length of the smaller of path1 and path2 int size =0; //temporary variables to store portions of path1 and path2 int temp1[] = new int [edit.ini.getMAXWORD()]; int temp2[] = new int [edit.ini.getMAXWORD()]; if(path_len(path1) > path_len(path2)) { size = path_len(path2); } else { size = path_len(path1); } for(i=0;i rhs is always true for (j=spot;j path_len(path2)) { return(true); } //Otherwise... else { //If the paths are equal in length if ((path_len(path1)) == (path_len(path2))) { //if ((path_len(path1) == 1) && (path1[0] == cons.id_code)) // return(false); j = 0; while (j < path_len(path1)) { //If index of current arrow in path2 is greater //then that in path1 return false since path2 //is greater than path1 if (path2[j] > path1[j]) { return(false); } //If index of current arrow in path2 is less than //that in path1 return true since path1 //is greater than path2 else { if (path2[j] < path1[j]) { return(true); } } j++; } } } //If path2 is greater in length than //path1 then return false return(false); } }