/* Research Project: Graphical Database for Category Theory J. Bradbury, Dr. R. Rosebrugh, I. Rutherford Mount Allison University 2001 File: printCategory.java Description: This class is implemented to print a text version or a graphical version of the current category. */ //import statements import java.io.*; import java.awt.*; import java.awt.event.*; import java.util.*; public class printCategory extends Frame { MainWindow ed; Category c = new Category(); int x = 50; int y = 50; int inc = 15; private Matrix44 rotxMatrix_, rotzMatrix_; public printCategory(MainWindow e) //Default constructor { ed = e; c = ed.cat; } public void printTextCategory() //Print text version of current category { PrintJob pjob; Properties p = new Properties(); Graphics pgraphics; String name = new String("Print Category(Text)"); pjob = getToolkit().getPrintJob(this, name, p); if(pjob != null) { pgraphics = pjob.getGraphics(); if(pgraphics != null) { pgraphics.setFont(new Font("Serif",Font.PLAIN,14)); printOAR(pgraphics); pgraphics.dispose(); } pjob.end(); } } public void printGraphicalCategory() //Print graphical version of current category { PrintJob pjob; Properties p = new Properties(); Graphics pgraphics; String name = new String("Print Category(Graphical)"); pjob = getToolkit().getPrintJob(this, name, p); if(pjob != null) { pgraphics = pjob.getGraphics(); if(pgraphics != null) { pgraphics.setFont(new Font("Serif",Font.PLAIN,14)); printAxes(pgraphics); printObjects(false, pgraphics, 0); printArrows(pgraphics); pgraphics.dispose(); } pjob.end(); } } public void printOAR(Graphics g) //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); } public void printRelations(Graphics g) //prints relations of current category to the printer { int i,j; int counter = 0; String relation = new String(); relation = " "; for (i=0;i