/* Research Project: Graphical Database for Category Theory J. Bradbury, Dr. R. Rosebrugh, I. Rutherford Mount Allison University 2001 File: SumFrame.java Description: This class implements a frame which allows the user to run the category tool "Sum" on the current category. */ //import statements import java.awt.*; import java.awt.event.*; public class SumFrame extends Frame { CategoryList l = new CategoryList(); int check_enter = 0; int editoption = 0; boolean supress_output = false; boolean endopassed = false; 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(); MainWindow ed; Category cat = new Category(); Label objectLabel = new Label(); Label alphaLabel = new Label(); Label betaLabel = new Label(); Choice objectChoice = new Choice(); public SumFrame(MainWindow edit) //Default Constructor with the parent frame as a parameter { ed = edit; cat.copyCategory(ed.cat); ed.enableMenus(false); try { jbInit(); } catch (Exception e) { e.printStackTrace(); } } public boolean handleEvent(Event e) { if ((e.id == Event.WINDOW_DESTROY)) { ed.enableMenus(true); hide(); //hide frame dispose(); //free resources return true; } else if (e.key == Event.ENTER) { if (check_enter == 0) check_enter++; else { ed.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)) { ed.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: Sum Category"); this.setBackground(new Color(192,192,192)); okButton.setLabel("Close"); objectLabel.setText("Object of Sum:"); alphaLabel.setText("First injection:"); betaLabel.setText("Second injection:"); objectChoice.setBackground(Color.white); categoryLabel.setText("Current Category:"); viewbox.setEditable(false); viewbox.setBackground(Color.white); sumButton.setLabel("Sum?"); alphaField.setBackground(Color.white); betaField.setBackground(Color.white); sumButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { sumButton_actionPerformed(e); } }); objectChoice.addItemListener(new java.awt.event.ItemListener() { public void itemStateChanged(ItemEvent e) { objectChoice_itemStateChanged(e); } }); okButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { okButton_actionPerformed(e); } }); this.setLayout(gridBagLayout1); categoryField.setBackground(Color.white); this.add(okButton, g.getConstraints(2, 4, 1, 1, 0.0, 0.0 ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(7, 10, 8, 0), 70, 8)); this.add(betaLabel, g.getConstraints(0, 3, 2, 1, 0.0, 0.0 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 2, 0, 0), -14, 2)); this.add(alphaLabel, g.getConstraints(0, 2, 1, 1, 0.0, 0.0 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 2, 0, 0), -5, 8)); this.add(objectLabel, g.getConstraints(0, 1, 1, 1, 0.0, 0.0 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(9, 2, 0, 0), -5, 4)); this.add(objectChoice, g.getConstraints(2, 1, 1, 1, 1.0, 0.0 ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(7, 8, 0, 0), 77, 0)); this.add(categoryField, g.getConstraints(2, 0, 1, 1, 1.0, 0.0 ,GridBagConstraints.SOUTHWEST, GridBagConstraints.HORIZONTAL, new Insets(9, 8, 0, 1), 79, 2)); this.add(categoryLabel, g.getConstraints(0, 0, 2, 1, 0.0, 0.0 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(15, 2, 0, 0), -10, 0)); this.add(viewbox, g.getConstraints(3, 0, 1, 5, 1.0, 1.0 ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(9, 17, 8, 6), 177, -9)); this.add(sumButton, g.getConstraints(0, 4, 2, 1, 0.0, 0.0 ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(7, 2, 8, 0), 48, 8)); this.add(alphaField, g.getConstraints(2, 2, 1, 1, 1.0, 0.0 ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 7, 0, 0), 82, 3)); this.add(betaField, g.getConstraints(2, 3, 1, 1, 1.0, 0.0 ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 7, 0, 0), 83, 3)); categoryField.setEditable(false); categoryField.setText(cat.name); objectChoice.addItem("Check all objects"); for (int i = 0; i < cat.numobj; i++) objectChoice.addItem(cat.obj[i]); objectChoice.select(1); if (objectChoice.getItemCount() == 0) { new MessageDialog(this, "Error", "Can not perform sum, category has 0 Objects", true); } } void sumButton_actionPerformed(ActionEvent e) //Determine the sum of the current object given //an alpha and beta value { endopassed = false; int numsums = 0; objchr = objectChoice.getSelectedItem(); if (objchr.equals("Check all objects")) { if (cat.check_obj(alphaField.getText())) { viewbox.append("\n********ERROR********\n"); viewbox.append(alphaField.getText() + " is not an object of " + cat.name + ".\n"); viewbox.append("***********************\n\n"); } else if (cat.check_obj(betaField.getText())) { viewbox.append("\n********ERROR********\n"); viewbox.append(betaField.getText() + " is not an object of " + cat.name + ".\n"); viewbox.append("***********************\n\n"); } else { for (int i=0; i=0; j--) path[j+1] = path[j]; path[0] = arrow_array[i]; if (!check_oneone(path, domain, codomain, gamalbet, alpha, beta, gammatree, maxloop, pathtree)) return false; len = cat.path_len(path); for (j=0; j=0; i--) { // add the new arrow to the path, and the new object to the object list for (j=cat.path_len(path); j>=0; j--) path[j+1] = path[j]; path[0] = arrows[i]; numpaths += makeHomTree(path, homtree, cat.arr[arrows[i]][1], obj2, maxloop, pathtree); // now remove the arrow and object from the path and object list for (j=0; j<=pathlen; j++) path[j] = path[j+1]; } // if we're at the second object, then add the path to the tree if (obj1 == obj2 && pathlen != 0) { numpaths++; homtree.addPath(newpath); } } } else { endopassed = true; } return numpaths; } public boolean check_onto(int path[], int domain, int codomain, HomTree gamalbet, HomTree rhotree, int maxloop, HomTree pathtree) /* Parameters: path: the current path domain: the current object of the path codomain: the object we are trying to find all arrows to objects: an array of integers which keeps the function from exceeding the maximum number of loops gamalbet: the tree of gamma alphas with gamma betas rho_tree: a tree of all the rhos Local Variables: number: stores the number of arrows from an object current_arrow: stores the number of the current arrow in the path codom: stores the codomain of the current arrow arrow_array: contains all of the arrows from an object Purpose: To check that a sum is onto Design: Generates all of the lambdas from one object to another and uses the rho tree it is passed to check that all of the pairs are in our tree. */ { int i, j, len, number, codom, endo = 0; int arrow_array[] = new int[cat.numarr]; path = cat.reduce(path); if (path[0] == -2) path[0] = -1; // check to see if we've passed the endomorphism limit len = cat.path_len(path); for (i=0; i 0) for (i=0; i=0; j--) path[j+1] = path[j]; path[0] = arrow_array[i]; if (!check_onto(path, domain, codomain, gamalbet, rhotree, maxloop, pathtree)) return false; for (j=0; j<=len; j++) path[j] = path[j+1]; } } } else { endopassed = true; return false; } return true; } public boolean is_sum(int sumobj, int alpha[], int beta[], int maxloop) /* Parameters: A: pointer to the category being tested sumobj: the object of the sum being tested alpha: first injection of the sum beta: second injection of the sum Local Variables: testobj: is currently being tested for sum property path: keeps track of the current path to testobj from sumobj objects: array of integers storing the number of times each object has been visited in current path id: a path that has a value of -2 and represents the identity arrow gammatree: tree of all arrows from sumobj to testobj gamalbet: tree of gamma alphas with gamma beta subtrees rhotree: tree of all arrows from domain of beta to testobj p, tp: temporary pointers reduced_alpha, reduced_beta : normalized versions of the injections Purpose: To check each object in the category for 1-1 and onto. Design: Returns true if object is a sum, and false if not. */ { int path[] = new int[ini.getMAXWORD()]; int id[] = new int[2]; int reducedAlpha[] = new int[ini.getMAXWORD()]; int reducedBeta[] = new int[ini.getMAXWORD()]; HomTree gamalbet; // all paths from all Paths A to C composed with gamma(C->D) HomTree gammatree;//all paths from C -> D HomTree rhotree;//all paths from B to D (will be bigger than gammalbet) HomTree pathtree; int obj, i, dom; // check each object in the category for (obj=0; obj= 0 && cat.arr[alpha[0]][1] != obj) { viewbox.append("\nFirst path must have codomain of " + cat.obj[obj] + "\n\n"); } else { editoption = 2; } } else { viewbox.append("Invalid first path\n"); } } else { viewbox.append("Invalid first path\n"); } } if (editoption == 2) { if ((cat.check_string(betapath))) { beta = cat.copy_path(cat.string_to_path(betapath)); if (cat.check_path(beta)) { if (beta[0] >= 0 && cat.arr[beta[0]][1] != obj) { viewbox.append("\nSecond path must have codomain of " + cat.obj[obj] + "\n"); } else { if (is_sum(obj,alpha,beta,ini.getMaxLoop())) { viewbox.append(cat.obj[obj] + " is a sum.\n"); } else { viewbox.append(cat.obj[obj] + " is not a sum.\n"); } } } else { viewbox.append("Invalid second path\n"); } } else { viewbox.append("Invalid second path\n"); } } } return numsums; } public void objectChoice_itemStateChanged (ItemEvent e) { if (objectChoice.getSelectedItem().equals("Check all objects")) { alphaLabel.setText("First object:"); betaLabel.setText("Second object:"); } else { alphaLabel.setText("First injection:"); betaLabel.setText("Second injection:"); } } }