/* Research Project: Graphical Database for Category Theory J. Bradbury, Dr. R. Rosebrugh, I. Rutherford Mount Allison University 2001 File: FileProcessing.java Description: This class handles the opening and saving of CAT, CGL, FUN, and FGL files. */ //import statements import java.io.*; import java.awt.*; import java.awt.event.*; import java.util.*; import java.lang.System; import java.io.StringBufferInputStream; import java.net.*; public class FileProcessing extends Frame { BufferedReader input; BufferedWriter output; boolean moreRecords = true; boolean badfile = false; MainWindow edit; String fname = new String(); public FileProcessing(String filename, MainWindow ed, boolean save, boolean localfile) //Constructor { edit = ed; fname = filename; //If file is on server... if (localfile == false) { URL fileURL; try { fileURL = new URL(filename); try { InputStream i = fileURL.openStream(); input = new BufferedReader(new InputStreamReader(i)); } catch (Exception e) { new MessageDialog(this, "Error", "Unable to load file " + filename, true); badfile = true; } } catch (MalformedURLException except) { new MessageDialog(this, "Error", "Unable to open file File unable to Load", true); badfile = true; } //cat.filename = cons.server + cons.catdir + fname; //this.setTitle("Graphical Database for Category Theory [" + cat.filename + "]"); //validate(); //try //{ // input = fileURL.openStream(); // dataInput = new DataInputStream(input); } //If file is on local machine.... else { try { if (!save) input = new BufferedReader(new InputStreamReader(new FileInputStream(filename))); } catch(IOException e) { new MessageDialog(this, "Error", "Unable to open file " + filename, true); badfile = true; } try { if (save) { output = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(filename))); edit.cat.filename = filename; edit.setTitle("Category Theory Database Tools [" + edit.cat.filename + "]"); edit.validate(); } } catch(IOException e) { new MessageDialog(this, "Error", "Unable to save file " + filename, true); badfile = true; } } } boolean readCATFile(Category c) //Method reads a category file (*.CAT from a drive on the local computer { if (!fname.toLowerCase().endsWith(".cat")) { new MessageDialog(this, "Error", "Invalid file - please choose a *.CAT file", true); return false; } //Update graphCanvas info from ini file edit.graphCanvas_.setFont(edit.ini.getCatFont()); edit.graphCanvas_.setScale(edit.ini.getCatScale()); int filelength = 20; boolean morelines = true; try { try { for(int i=0; i < filelength; i++) { try { String currLine = input.readLine(); if (currLine.charAt(0) == '#') { String com = currLine.substring(1, currLine.length()); c.comment = c.comment + com; //edit.commentArea.appendText(currLine); } else { if(currLine.equals("category")) { currLine = input.readLine(); for (int j=0; j < currLine.length(); j++) { if ((currLine.charAt(j) == ' ') || (currLine.charAt(j) == '\t')) { if (j == 0) currLine = currLine.substring(j+1, currLine.length()); else currLine = currLine.substring(0, j) + currLine.substring(j+1, currLine.length()); } } CategoryNode current = edit.catList.head; boolean name = false; while(current != null) { if (current.cat.name.equals(currLine)) name = true; current = current.next; } if (name == false) c.name = currLine; else { new NameDialog(this, "Error", true, edit, c); } } else if (currLine.equals("objects")) { String objects = new String(); while (!currLine.equals("arrows")) { currLine = input.readLine(); if (currLine.charAt(0) == '#') { String com = currLine.substring(1, currLine.length()); c.comment = c.comment + com; } else if (!currLine.equals("arrows")) objects = objects.concat(currLine); } parseObjects(objects, c); if (badfile) return false; //edit.objectArea.appendText("\nOBJECTS = " + objects); } if (currLine.equals("arrows")) { String arrows = new String(); while (!currLine.equals("relations")) { currLine = input.readLine(); if (currLine.charAt(0) == '#') { String com = currLine.substring(1, currLine.length()); c.comment = c.comment + com; } else if (!currLine.equals("relations")) arrows = arrows.concat(currLine); } parseArrows(arrows, c); if (badfile) return false; //edit.objectArea.appendText("\nARROWS = " + arrows); } if (currLine.equals("relations")) { String relations = new String(); boolean relend = false; while (relend == false) { currLine = input.readLine(); //edit.objectArea.appendText("HERE"); for (int r = 0; r < currLine.length(); r++) { if (currLine.charAt(r) == '.') { relend = true; } } relations = relations.concat(currLine); } //edit.error_message("\nRELATIONS = " + relations); parseRelations(relations, c); if (badfile) return false; } } //edit.objectArea.appendText("\nLINE = " + currLine); //edit.displayArea.appendText(input.readLine() + "\n"); } catch(EOFException eof) { morelines = false; } } input.close(); } catch (IOException e1) { // edit.objectArea.setText("Error: Data File not found!"); } } catch (NullPointerException aie) { } if (!c.name.equals("")) edit.catList.insertNode(c); return true; } void parseObjects (String obj, Category c) //This method parse a string of objects { int i =0; int prev = 0; for (i=0; i < obj.length(); i++) { if (obj.charAt(i) == ' ') { prev++; } else { if ((obj.charAt(i) == ',') || (obj.charAt(i) == '.')) { if (prev == 0) c.obj[c.numobj] = obj.substring(prev, i); else c.obj[c.numobj] = obj.substring(prev+1, i); c.numobj++; prev = i; } } } } void parseArrows(String arr, Category c) //This method parses a string of arrows { int i =0; int prev = 0; int colon = 0; int tail = 0; int head = 0; if (arr.charAt(0) != '.') for (i=0; i < arr.length(); i++) { if (arr.charAt(i) == ' ') { prev++; } else { if (arr.charAt(i) == ':') colon = i; if (arr.charAt(i) == '>') { head = i-1; tail = i; } if ((arr.charAt(i) == ',') || (arr.charAt(i) == '.')) { if (prev == 0) c.arrow[c.numarr] = arr.substring(prev, colon); else c.arrow[c.numarr] = arr.substring(prev+1, colon); String domain = arr.substring(colon+1, head); for (int j = 0; j < c.numobj; j++) { if (c.obj[j].equals(domain)) c.arr[c.numarr][0] = j; } String codomain = arr.substring(tail+1, i); for (int j = 0; j < c.numobj; j++) { if (c.obj[j].equals(codomain)) c.arr[c.numarr][1] = j; } c.numarr++; prev = i; } } } } void parseRelations(String rel, Category c) //This method parses a string of relations { int i =0; int prev = 0; int equals = 0; String right = new String(); String left = new String(); for (i=0; i < rel.length(); i++) { if ((rel.charAt(i) == ' ') || (rel.charAt(i) == '\t')) { rel = rel.substring(0, i) + rel.substring(i+1, rel.length()); } } if (rel.charAt(0) != '.') { for (i=0; i < rel.length(); i++) { //if ((rel.charAt(i) == ' ') || (rel.charAt(i) == '\t')) //{ // prev++; //} //else //{ if (rel.charAt(i) == '=') equals = i; if ((rel.charAt(i) == ',') || (rel.charAt(i) == '.')) { //if (c.num_rel == 0) //{ left = rel.substring(prev, equals); right = rel.substring(equals+1, i); //} //else //{ // left = rel.substring(prev+1, equals); // right = rel.substring(equals+1, i); //} prev = i+1; //edit.relationArea.append("left = " + left); //edit.relationArea.append("right = " + right + "\n"); edit.get_rel(left, right, c); } //} } } } boolean readCGLFile(Category c) //Method reads a category file (*.CGL) from a drive on the local computer { if (!fname.toLowerCase().endsWith(".cgl")) { new MessageDialog(this, "Error", "Invalid file - please choose a *.CGL file", true); return false; } //Update graphCanvas info from ini file edit.graphCanvas_.setFont(edit.ini.getCatFont()); edit.graphCanvas_.setScale(edit.ini.getCatScale()); int filelength = 20; boolean morelines = true; try { try { for(int i=0; i < filelength; i++) { try { String currLine = input.readLine(); if (currLine.charAt(0) == '#') { String com = currLine.substring(1, currLine.length()); c.comment = c.comment + com; //edit.commentArea.appendText(currLine); } else if (currLine.length() != 0) { if(currLine.equals("category")) { currLine = input.readLine(); for (int j=0; j < currLine.length(); j++) { if ((currLine.charAt(j) == ' ') || (currLine.charAt(j) == '\t')) { if (j == 0) currLine = currLine.substring(j+1, currLine.length()); else currLine = currLine.substring(0, j) + currLine.substring(j+1, currLine.length()); } } CategoryNode current = edit.catList.head; boolean name = false; while(current != null) { if (current.cat.name.equals(currLine)) name = true; current = current.next; } if (name == false) c.name = currLine; else { new NameDialog(this, "Error", true, edit, c); } } else if (currLine.equals("objects")) { String objects = new String(); while (!currLine.equals("arrows")) { currLine = input.readLine(); if (currLine.length() != 0 && currLine.charAt(0) == '#') { String com = currLine.substring(1, currLine.length()); c.comment = c.comment + com; } else if (!currLine.equals("arrows") && currLine.length() != 0) objects = objects.concat(currLine); } parseObjects(objects, c); if (badfile) return false; //edit.objectArea.appendText("\nOBJECTS = " + objects); } if (currLine.equals("arrows")) { String arrows = new String(); while (!currLine.equals("relations")) { currLine = input.readLine(); if (currLine.length() != 0 && currLine.charAt(0) == '#') { String com = currLine.substring(1, currLine.length()); c.comment = c.comment + com; } else if (!currLine.equals("relations")) arrows = arrows.concat(currLine); } parseArrows(arrows, c); if (badfile) return false; //edit.objectArea.appendText("\nARROWS = " + arrows); } if (currLine.equals("relations")) { String relations = new String(); while (!currLine.equals("gml")) { currLine = input.readLine(); if (currLine.length() != 0 && currLine.charAt(0) == '#') { String com = currLine.substring(1, currLine.length()); c.comment = c.comment + com; } else if (!currLine.equals("gml") && currLine.length() != 0) relations = relations.concat(currLine); } parseRelations(relations, c); if (badfile) return false; } if (currLine.equals("gml")) { int left = 0; int right = 0; String gml = new String(); boolean gmlend = false; while (gmlend == false) { currLine = input.readLine(); //edit.objectArea.appendText("HERE"); for (int r = 0; r < currLine.length(); r++) { if (currLine.charAt(r) == '[') left++; if (currLine.charAt(r) == ']') right++; if ((left == right) && (left != 0) && (right != 0)) gmlend = true; } gml = gml.concat(currLine); } //Strore gml in category c.gml = gml; c.originalGml = gml; //Store orginal gml in category if (c.gml.equals("")) edit.GraphCategory(edit.graph_, edit.graphCanvas_, c); else { //Category temp = new Category(); //edit.GraphCategory(edit.graph_, edit.graphCanvas_, temp); boolean test = edit.displayCategoryGraph(c.gml); edit.graphCanvas_.update(true); GraphEdit ge = new GraphEdit(edit.graph_, edit.graphCanvas_); c.originalGml = ge.getGMLText(); c.gml = c.originalGml; } } } //edit.objectArea.appendText("\nLINE = " + currLine); //edit.displayArea.appendText(input.readLine() + "\n"); } catch(EOFException eof) { morelines = false; } } input.close(); } catch (IOException e1) { // edit.objectArea.setText("Error: Data File not found!"); } } catch (NullPointerException aie) { } if (!c.name.equals("")) edit.catList.insertNode(c); return true; } void saveCATFile() //This method saves the text version of a category file (*.CAT) { try { try { String comments = edit.commentArea.getText(); /*String comments = "This is a test\nIt should work"; for (int i=0; i < comments.length(); i++) { if (comments.charAt(i) == '\n') { comments = comments.substring(0, i) + "#" + comments.substring(i, comments.length()); } } */ if (!comments.equals("")) output.write("#" + comments + "\n"); output.write("category\n"); output.write(edit.categoryChoice.getSelectedItem() + "\n"); output.write("objects\n"); output.write(edit.objectArea.getText()); if (edit.objectArea.getText().length() == 0) output.write(".\n"); output.write("arrows\n"); output.write(edit.arrowArea.getText()); if (edit.arrowArea.getText().length() == 0) output.write(".\n"); output.write("relations\n"); output.write(edit.relationArea.getText()); if (edit.relationArea.getText().length() == 0) output.write(".\n"); } catch(EOFException eof) { } output.close(); } catch (IOException e1) { //edit.displayArea.setText("Error: Data File not found!"); } } void saveCGLFile() //This method saves the text and graphical versions of a category file (*.CGL) { try { try { String comments = edit.commentArea.getText(); /*String comments = "This is a test\nIt should work"; for (int i=0; i < comments.length(); i++) { if (comments.charAt(i) == '\n') { comments = comments.substring(0, i) + "#" + comments.substring(i, comments.length()); } } */ if (!comments.equals("")) output.write("#" + comments + "\n"); output.write("category\n"); output.write(edit.categoryChoice.getSelectedItem() + "\n"); output.write("objects\n"); output.write(edit.objectArea.getText() + "\n"); if (edit.objectArea.getText().length() == 0) output.write(".\n"); output.write("arrows\n"); output.write(edit.arrowArea.getText() + "\n"); if (edit.arrowArea.getText().length() == 0) output.write(".\n"); output.write("relations\n"); output.write(edit.relationArea.getText() + "\n"); if (edit.relationArea.getText().length() == 0) output.write(".\n"); output.write("gml\n"); output.write(edit.cat.gml); } catch(EOFException eof) { } output.close(); } catch (IOException e1) { //edit.displayArea.setText("Error: Data File not found!"); } } boolean readFUNFile(CatFunctor func, Category A, Category B) { /* //Update graphCanvas info from ini file edit.functorFromCanvas.setFont(edit.ini.getCatAFont()); edit.functorFromCanvas.setScale(edit.ini.getCatAScale()); edit.functorToCanvas.setFont(edit.ini.getCatBFont()); edit.functorToCanvas.setScale(edit.ini.getCatBScale()); */ if (!fname.toLowerCase().endsWith(".fun")) { new MessageDialog(this, "Error", "Invalid file - please choose a *.FUN file", true); return false; } //func = new cat_functor(); //A = new Category(); //B = new Category(); readFuncCATFile(A, false); if (badfile) return false; readFuncCATFile(B, false); if (badfile) return false; readFunctorFile(func, A, B); if (badfile) return false; edit.funcDisplayControls.setVisible(true); validate(); //create functor node edit.fnode = new FunctorNode(edit); edit.fnode.functor_type = 0; edit.fnode.A = A; edit.fnode.B = B; func.filename = fname; edit.fnode.f = func; edit.f_list.insertNode(edit.fnode, edit.functorArrowArea); edit.functorChoice.add(func.name); edit.functorChoice.select(func.name); try { input.close(); } catch (IOException e1) { //edit.objectArea.setText("Error: Data File not found!"); } return true; } boolean readFGLFile(CatFunctor func, Category A, Category B) { //Update graphCanvas info from ini file /* edit.functorFromCanvas.setFont(edit.ini.getCatAFont()); edit.functorFromCanvas.setScale(edit.ini.getCatAScale()); edit.functorToCanvas.setFont(edit.ini.getCatBFont()); edit.functorToCanvas.setScale(edit.ini.getCatBScale()); */ if (!fname.toLowerCase().endsWith(".fgl")) { new MessageDialog(this, "Error", "Invalid file - please choose a *.FGL file", true); return false; } readFuncCATFile(A, true); if (badfile) return false; readFuncCATFile(B, true); if (badfile) return false; readFunctorFile(func, A, B); if (badfile) return false; edit.funcDisplayControls.setVisible(true); validate(); edit.textCardLayout.show(edit.textPanel, "Functor Display"); //create functor node edit.fnode = new FunctorNode(edit); edit.fnode.functor_type = 0; edit.fnode.A = A; edit.fnode.B = B; func.filename = fname; edit.fnode.f = func; edit.f_list.insertNode(edit.fnode, edit.functorArrowArea); edit.functorChoice.add(func.name); edit.functorChoice.select(func.name); try { input.close(); } catch (IOException e1) { //edit.objectArea.setText("Error: Data File not found!"); } return true; } void readFuncCATFile(Category c, boolean graphical) //Method reads a category file (*.CAT) from a drive on the local computer { int filelength = 20; boolean morelines = true; boolean relend = false; String gml = new String(); boolean gmlend = false; try { try { while (gmlend == false) { try { String currLine = input.readLine(); if (currLine.length() == 0) { //edit.functorObjectArea.append("EMPTY LINE\n"); } else if (currLine.charAt(0) == '#') { String com = currLine.substring(1, currLine.length()); c.comment = c.comment + com; //edit.functorObjectArea.append(currLine); } else { if(currLine.equals("category")) { currLine = input.readLine(); for (int j=0; j < currLine.length(); j++) { if ((currLine.charAt(j) == ' ') || (currLine.charAt(j) == '\t')) { if (j == 0) currLine = currLine.substring(1, currLine.length()); else currLine = currLine.substring(0, j) + currLine.substring(j+1, currLine.length()); } } CategoryNode current = edit.catList.head; boolean name = false; while(current != null) { if (current.cat.name.equals(currLine)) name = true; current = current.next; } if (name == false) { c.name = new String(currLine); //edit.functorObjectArea.append("CAT NAME = " + c.name + "\n"); } //Error message if category name is already in use else { name = false; c.name = new String(currLine + "diagram"); } } else if (currLine.equals("objects")) { String objects = new String(); while (!currLine.equals("arrows")) { currLine = input.readLine(); if (currLine.charAt(0) == '#') { String com = currLine.substring(1, currLine.length()); c.comment = c.comment + com; } else if (!currLine.equals("arrows")) objects = objects.concat(currLine); } //edit.functorObjectArea.append("OBJECTS = " + objects + "\n"); parseObjects(objects, c); if (badfile) return; } if (currLine.equals("arrows")) { String arrows = new String(); while (!currLine.equals("relations")) { currLine = input.readLine(); if (currLine.charAt(0) == '#') { String com = currLine.substring(1, currLine.length()); c.comment = c.comment + com; } else if (!currLine.equals("relations")) arrows = arrows.concat(currLine); } parseArrows(arrows, c); if (badfile) return; //edit.functorObjectArea.append("ARROWS = " + arrows); } if (currLine.equals("relations")) { String relations = new String(); while (relend == false) { currLine = input.readLine(); //edit.objectArea.appendText("HERE"); for (int r = 0; r < currLine.length(); r++) { if (currLine.charAt(r) == '.') { relend = true; } } relations = relations.concat(currLine); } if (!graphical) gmlend = true; //edit.functorObjectArea.append("\nRELATIONS = " + relations); parseRelations(relations, c); if (badfile) return; } if (graphical == true) { if (currLine.equals("gml") && gmlend == false) { int left = 0; int right = 0; while (gmlend == false) { currLine = input.readLine(); if (currLine == null || currLine.length() == 0) gmlend = true; else { for (int r = 0; r < currLine.length(); r++) { if (currLine.charAt(r) == '[') left++; if (currLine.charAt(r) == ']') right++; if ((left == right) && (left != 0) && (right != 0)) gmlend = true; } gml = gml.concat(currLine); } } c.gml = new String(gml); gmlend = true; //if (c.gml.equals("")) // edit.GraphCategory(edit.graph_, edit.graphCanvas_, c); //else //{ // boolean test = edit.displayCategory(c.gml); // edit.graphCanvas_.update(true); //} } } } //edit.objectArea.appendText("\nLINE = " + currLine); //edit.displayArea.appendText(input.readLine() + "\n"); } catch(EOFException eof) { morelines = false; } } } catch (IOException e1) { // edit.objectArea.setText("Error: Data File not found!"); } } catch (NullPointerException aie) { } // Add the current category to the list, even tho it was opened from a functor file // option removed // if (!c.name.equals("")) // { // edit.catList.insertNode(c); // edit.categoryChoice.add(c.name); // } } void readFunctorFile(CatFunctor f, Category A, Category B) //This method reads and parses the functor part of a *.FUN file { boolean arrowend = false; String comment = new String(); try { try { //Repeat until end of arrows is found while (arrowend == false) { try { //Read Current Line String currLine = input.readLine(); //If current line is blank do nothing if (currLine.length() == 0) { // edit.functorObjectArea.append("EMPTY LINE\n"); } //If current line has # it is a comment else if (currLine.charAt(0) == '#') { String com = currLine.substring(1, currLine.length()); comment = comment + com; edit.functorObjectArea.append(currLine); } //Otherwise current line is part of the functor else { if(currLine.equals("functor")) { currLine = input.readLine(); for (int j=0; j < currLine.length(); j++) { if ((currLine.charAt(j) == ' ') || (currLine.charAt(j) == '\t')) { if (j == 0) currLine = currLine.substring(j+1, currLine.length()); else currLine = currLine.substring(0, j) + currLine.substring(j+1, currLine.length()); } } FunctorNode current = edit.f_list.head; boolean name = false; while(current != null) { if (current.f.name.equals(currLine)) name = true; current = current.next; } if (name == false) f.name = currLine; else { new FuncNameDialog(this, "Error", true, edit, f); } } else if (currLine.equals("objects")) { String objects = new String(); while (!currLine.equals("arrows")) { currLine = input.readLine(); //If current line has # it is a comment if (currLine.charAt(0) == '#') { String com = currLine.substring(1, currLine.length()); comment = comment + com; } else if (!currLine.equals("arrows")) objects = objects.concat(currLine); } //edit.functorObjectArea.append("OBJECTS = " + objects + "\n"); //Parse object string into individual objects parseFunctorObjects(objects, f, A, B); if (badfile) return; } if (currLine.equals("arrows")) { String arrows = new String(); while (arrowend == false) { currLine = input.readLine(); //If current line has # it is a comment if (currLine.charAt(0) == '#') { String com = currLine.substring(1, currLine.length()); comment = comment + com; } for (int r = 0; r < currLine.length(); r++) { if (currLine.charAt(r) == '.') { arrowend = true; } } arrows = arrows.concat(currLine); } //edit.functorObjectArea.append("ARROWS = " + arrows); //Parse arrow string into individual arrows parseFunctorArrows(arrows, f, A, B); if (badfile) return; } } } catch(EOFException eof) { } } } catch (IOException e1) { } } catch (NullPointerException aie) { } } void parseFunctorObjects(String objs, CatFunctor func, Category A, Category B) //This method parses a string of functor objects { int i =0; //Positions of "(", ")", "=", and "," for parsing purposes int prevcomma = -1; int bar = 0; int arrow = 0; int comma = 0; //Strings to store current object from and object to String objectfrom = new String(); String objectto = new String(); //Read until end of string is reached //and remove all tabs and spaces for (i=0; i < objs.length(); i++) { if ((objs.charAt(i) == ' ') || (objs.charAt(i) == '\t')) { objs = objs.substring(0, i) + objs.substring(i+1, objs.length()); } } if (objs.charAt(0) != '.') { //Parse string into objects for (i=0; i < objs.length(); i++) { if (objs.charAt(i) == '|') bar = i; if (objs.charAt(i) == '>') arrow = i; if ((objs.charAt(i) == ',') || (objs.charAt(i) == '.')) { comma = i; if (bar < prevcomma || comma < arrow) { new MessageDialog(this, "Error", fname + " is not a valid functor file", true); badfile = true; return; } objectfrom = objs.substring(prevcomma+1, bar); objectto = objs.substring(arrow+1, comma); //check to see that objectfrom and objectto are valid in categories A and B if(A.check_obj(objectfrom)) { new MessageDialog(this, "Error", objectfrom + " is not an object of Category " + A.name, true); } else if (B.check_obj(objectto)) { new MessageDialog(this, "Error", objectto + " is not an object of Category " + B.name, true); } else { func.obj[A.object_number(objectfrom)] = B.object_number(objectto); } prevcomma = comma; } } } } void parseFunctorArrows(String arrs, CatFunctor func, Category A, Category B) //This method parses a string of functor objects { int i =0; int arrnum = 0; int pathfrom[] = new int[edit.ini.getMAXWORD()]; int pathto[] = new int[edit.ini.getMAXWORD()]; int reduced_path[] = new int[edit.ini.getMAXWORD()]; //Positions of "(", ")", "=", and "," for parsing purposes int prevcomma = -1; int closebracket = 0; int equals = 0; int comma = 0; //Strings to store current object from and object to String objectfrom = new String(); String objectto = new String(); //Read until end of string is reached //and remove all tabs and spaces for (i=0; i < arrs.length(); i++) { if ((arrs.charAt(i) == ' ') || (arrs.charAt(i) == '\t')) { arrs = arrs.substring(0, i) + arrs.substring(i+1, arrs.length()); } } if (arrs.charAt(0) != '.') { //Parse string into objects for (i=0; i < arrs.length(); i++) { if (arrs.charAt(i) == '|') closebracket = i; if (arrs.charAt(i) == '>') equals = i; if ((arrs.charAt(i) == ',') || (arrs.charAt(i) == '.')) { comma = i; objectfrom = arrs.substring(prevcomma+1, closebracket); objectto = arrs.substring(equals+1, comma); //edit.functorObjectArea.append("FROM = " + objectfrom + " TO = " + objectto + "\n"); //checks to see that the string the user enters //contains only arrows that exist in category A if ((objectfrom.equals("1")) || (objectto.equals("1"))) { //path = copy_path(path,string_to_path(path_string, cat)); //func.arr[editsub] = copy_path(func.arr[editsub],path); } else { if(!(A.check_string(objectfrom))) { new MessageDialog(this, "Error", "One or more of the arrows specified do not exist in Category" + A.name, true); } //checks to see that the string the user enters //contains only arrows that exist in category B else if(!(B.check_string(objectto))) { new MessageDialog(this, "Error", "One or more of the arrows specified do not exist in Category" + B.name, true); } else { pathto = B.copy_path(B.string_to_path(objectto)); //checks to see that domains and codomains of each arrow in path match up if(!(B.check_path(pathto))) { new MessageDialog(this, "Error", "Domains and codomains of each arrow in path do not match", true); } else { //Checks to see that domain and codomain of path //match up with domain and codomain of arrow under the functor if((!(edit.check_domain(pathto,arrnum,func,A,B))) || (!(edit.check_codomain(pathto,arrnum,func,A,B)))) { //viewbox.append("if((!(check_domain(path,editsub,func,A,B))) || (!(check_codomain(path,editsub,func,A,B))))"); } else { reduced_path = B.reduce(pathto); //reduced_path = pathto; func.arr[arrnum] = B.copy_path(reduced_path); arrnum++; } } } } prevcomma = comma; } //} } } } void saveFUNFile(Category A, Category B, CatFunctor f) //This method saves the text version of a functor file (*.FUN) { //Save Category A savefuncCATFile(A, false); //edit.functorObjectArea.append("Category A " + A.name + " DONE!"); //Save Category B savefuncCATFile(B, false); //edit.functorObjectArea.append("Category B " + B.name + " DONE!"); //Save cat_functor f saveFunctorFile(A, B, f); //Close *.FUN File try { output.close(); } catch (IOException e1) { //edit.objectArea.setText("Error: Data File not found!"); } } void saveFGLFile(Category A, Category B, CatFunctor f) //This method saves the text version of a functor file (*.FUN) { //Save Category A savefuncCATFile(A, true); //edit.functorObjectArea.append("Category A " + A.name + " DONE!"); //Save Category B savefuncCATFile(B, true); //edit.functorObjectArea.append("Category B " + B.name + " DONE!"); //Save cat_functor f saveFunctorFile(A, B, f); //Close *.FGL File try { output.close(); } catch (IOException e1) { //edit.objectArea.setText("Error: Data File not found!"); } } void saveFunctorFile(Category A, Category B,CatFunctor f) //This method saves the cat_functor assoicated with the //current functor { int i =0,j; try { try { //Display functor name output.write("\nfunctor\n " + f.name + "\n"); //Display functor objects output.write("objects\n"); for (i=0;i " + B.obj[f.obj[i]]); //output.write(f.name + "(" + A.obj[i] + ") = " + B.obj[f.obj[i]]); output.write(", "); } output.write(A.obj[i] + " |--> " + B.obj[f.obj[i]] + ".\n"); //output.write(f.name + "(" + A.obj[i] + ") = " + B.obj[f.obj[i]] + ".\n"); //Display functor arrows output.write("arrows\n"); for (i=0;i "); //output.write(f.name + "(" + A.arrow[i] + ") = "); j = 0; while (f.arr[i][j] != -1) { output.write("" + B.arrow[f.arr[i][j]]); j++; } if (j==0) output.write("1"); output.write(", "); } if (A.numarr != 0) { output.write(A.arrow[i] + " |--> "); //output.write(f.name + "(" + A.arrow[i] + ") = "); j = 0; while (f.arr[i][j] != -1) { output.write("" + B.arrow[f.arr[i][j]]); j++; } if (j==0) output.write("1"); output.write(".\n"); } else output.write(".\n"); } catch(EOFException eof) { } } catch (IOException e1) { //edit.displayArea.setText("Error: Data File not found!"); } } void savefuncCATFile(Category c, boolean graphical) //This method saves the text version of a category assoicated with the //current functor { int counter = 0; int i,j; try { try { String comments = edit.commentArea.getText(); /*for (int i=0; i < comments.length(); i++) { if (comments.charAt(i) == '\n') { comments = comments.substring(0, i) + "#" + comments.substring(i+1, comments.length()); } } */ if (!comments.equals("")) output.write("#" + comments + "\n"); output.write("category\n"); output.write(c.name + "\n"); output.write("objects\n"); for (i = 0; i < c.numobj; i++) { if (i < (c.numobj - 1)) output.write(c.obj[i] + ", "); if (i == (c.numobj - 1)) output.write(c.obj[i] + ".\n"); } output.write("arrows\n"); for (i = 0; i < c.numarr; i++) { if (i < (c.numarr - 1)) { output.write(c.arrow[i] + ":"); output.write(c.obj[c.arr[i][0]] + "->"); output.write(c.obj[c.arr[i][1]] + ", "); } if (i == (c.numarr - 1)) { output.write(c.arrow[i] + ":"); output.write(c.obj[c.arr[i][0]] + "->"); output.write(c.obj[c.arr[i][1]] +". " ); } counter++; if ((counter == 4) || (i == (c.numarr-1))) { counter = 0; output.write("\n"); } } output.write("relations\n"); for (i=0;i