/* Research Project: Graphical Database for Category Theory J. Bradbury, Dr. R. Rosebrugh, I. Rutherford Mount Allison University 2001 File: printFunctor.java Description: This class is implemented to print a text version of the current functor along with the categories associated with it. */ //import statements import java.io.*; import java.awt.*; import java.awt.event.*; import java.util.*; public class printFunctor extends Frame { MainWindow ed; int x = 50; int y = 50; int inc = 15; public printFunctor(MainWindow e) //Default constructor { ed = e; } public void printTextFunctor() //Print text version of current functor { PrintJob pjob; Properties p = new Properties(); Graphics pgraphics; String name = new String("Print Functor(Text)"); pjob = getToolkit().getPrintJob(this, name, p); if(pjob != null) { pgraphics = pjob.getGraphics(); if(pgraphics != null) { pgraphics.setFont(new Font("Serif",Font.PLAIN,14)); printCat(pgraphics, ed.fnode.A); pgraphics.drawString("", x, y); y = y + inc; printCat(pgraphics, ed.fnode.B); pgraphics.drawString("", x, y); y = y + inc; printName(pgraphics); printObjects(pgraphics); printArrows(pgraphics); pgraphics.dispose(); } pjob.end(); } } public void printName(Graphics g) //Print Functor Name { g.drawString("functor", x, y); y = y + inc; g.drawString(" " + ed.fnode.f.name, x, y); y = y + inc; } public void printObjects(Graphics g) //Print Functor Objects { g.drawString("objects", x, y); String objects = " "; y = y + inc; for (int i = 0; i < ed.fnode.A.numobj; i++) { if (i < (ed.fnode.A.numobj - 1)) objects = objects.concat(ed.fnode.f.name + "(" + ed.fnode.A.obj[i] + ") = " + ed.fnode.B.obj[ed.fnode.f.obj[i]] + ", "); if (i == (ed.fnode.A.numobj - 1)) objects = objects.concat(ed.fnode.f.name + "(" + ed.fnode.A.obj[i] + ") = " + ed.fnode.B.obj[ed.fnode.f.obj[i]] + ".\n"); } g.drawString(objects, x, y); y = y + inc; } public void printArrows(Graphics g) //Print Functor Arrows { int j = 0; int i = 0; g.drawString("arrows", x, y); y = y + inc; String arrows = " "; for (i = 0; i < ed.fnode.A.numarr-1; i++) { arrows = arrows.concat(ed.fnode.f.name + "(" + ed.fnode.A.arrow[i] + ") = "); j = 0; if (ed.fnode.f.arr[i][j] == -2) arrows = arrows.concat("1\n"); else { while (ed.fnode.f.arr[i][j] != -1) { arrows = arrows.concat("" + ed.fnode.B.arrow[ed.fnode.f.arr[i][j]]); j++; } } arrows = arrows.concat(", "); } if (ed.fnode.A.numarr != 0) { arrows = arrows.concat(ed.fnode.f.name + "(" + ed.fnode.A.arrow[i] + ") = "); j = 0; if (ed.fnode.f.arr[i][j] == -2) arrows = arrows.concat("1\n"); else { while (ed.fnode.f.arr[i][j] != -1) { arrows = arrows.concat("" + ed.fnode.B.arrow[ed.fnode.f.arr[i][j]]); j++; } } arrows = arrows.concat("."); } else arrows = arrows.concat("."); g.drawString(arrows, x, y); y = y + inc; } public void printCat(Graphics g, Category c) //Prints text version of category { int counter = 0; //Print Category Name String cat = "category"; g.drawString(cat, x, y); y = y + inc; g.drawString(" " + c.name, x, y); y = y + inc; //Print Objects g.drawString("objects", x, y); String objects = " "; for (int i = 0; i < c.numobj; i++) { if (i < (c.numobj - 1)) objects = objects.concat(c.obj[i] + ", "); if (i == (c.numobj - 1)) objects = objects.concat(c.obj[i] + ".\n"); } y = y + inc; g.drawString(objects, x, y); y = y + inc; //Print Arrows g.drawString("arrows", x, y); String arrows = " "; for (int i = 0; i < c.numarr; i++) { if (i < (c.numarr - 1)) { arrows = arrows.concat(" " + c.arrow[i] + ":" + c.obj[c.arr[i][0]] + "->" + c.obj[c.arr[i][1]] + ", "); } if (i == (c.numarr - 1)) { arrows = arrows.concat(" " + c.arrow[i] + ":" + c.obj[c.arr[i][0]] + "->" + c.obj[c.arr[i][1]] + ". "); } counter++; if ((counter == 4) || (i == (c.numarr-1))) { counter = 0; y = y + inc; g.drawString(arrows, x, y); arrows = new String(); } } y = y + inc; //Print Relations g.drawString("relations", x, y); printRelations(g, c); } public void printRelations(Graphics g, Category c) //prints relations of current category to the printer { int i,j; int counter = 0; String relation = new String(); relation = " "; for (i=0;i