FileDocCategorySizeDatePackage
TD.javaAPI DocExample3553Mon May 01 10:39:04 BST 2000None

TD

public class TD extends Observable
TestEdit application model

Fields Summary
public static final String
PROGRAM
The name of this program for printing purposes
String
curFileName
The current datafile
TV
viewctl
The main view/control
XamDataAccessor
ls
The current XamDataAccessor object
Exam
curX
Constructors Summary
public TD()
Construct the data model

		super();

		doNew();
	
Methods Summary
protected voiddoNew()

		curX = new Exam();
	
public voiddoPrint()
Print the current exam

		new PrintDraft(curX).print();
	
public voiddoStats()

		TStat t = new TStat();
		t.nq = curX.getqvs().size();
		t.n = new int[4];
		for (int i=0; i<t.nq; i++) {
			Q tq = curX.getQuestion(i);
			if (tq.question == null || tq.question.length() == 0) {
				++t.incomplete;
				continue;
			}
			t.complete++;
			if (tq.correct == 0) {
				++t.noAnswer;
				continue;
			}
			int ans = tq.correct;
			if (ans >= 0)
				t.n[ans]++;
			if (tq.objective < 0) {
				++t.noObjective;
				continue;
			}
		}
		// System.out.println("TStats t = " + t);
		viewctl.showStats(t);
	
public synchronized voidexit(int n)
Exit method, just calls System.exit(). Synchronized to prevent calling System.exit() during a saveFile(), which would be very bad :-)

		System.exit(n);
	
public voidloadFile(java.lang.String fn)

		if (ls == null)
			ls = new XamDataAccessor(viewctl);
		String newFN;
		if (fn == null) {
			viewctl.fc.setVisible(true);	// blocking dialog
			if ((newFN = ((FileDialog)viewctl.fc).getFile()) == null)
				return;
			fn = newFN;
		}
		try {
			ls.load(new BufferedReader(new FileReader(curFileName=fn)), curX);
		} catch (FileNotFoundException e) {
			System.err.println("Can't find file " + curFileName);
		} catch (IOException e) {
			System.err.println("IO Error in processing " + curFileName + ": " + e);
		} catch (Exception e) {
			System.err.println("Error in data file " + curFileName + "\n");
			e.printStackTrace();
		}
    
public static voidmain(java.lang.String[] av)
"main program" method - just for testing.


	        
	     
		// create a TD object
		TD td = new TD();
		td.loadFile("toy.xam");
	
protected voidmkTitle()

		String newt = curX.crsNum + " Exam" +
			curX.examName + " " + curX.examVers + " " + curX.crsName;
		viewctl.setTitle(newt);
	
public synchronized voidsaveFile()
Save the current file

		saveFile(curFileName);
	
public synchronized voidsaveFile(java.lang.String fName)
Save the current exam into a file

		// System.out.println("Saving file...");
		try {
			ls.save(new PrintWriter(new FileWriter(fName), true), curX);
		} catch (IOException e) {
			System.err.println("I/O error " + e);
		}
		// System.out.println("Save done");
	
public synchronized voidsaveHTML(java.lang.String fName)
Save the current file AS HTML. This is just an interface to the XamDataAccessorHTML object, and should be done away with, once we hava a Properties listing all the different XamDataAccessor subclasses!

		// System.out.println("Saving...");
		XamDataAccessorHTML hs = new XamDataAccessorHTML(viewctl);
		try {
			hs.save(new PrintWriter(new FileWriter(fName), true), curX);
		} catch (IOException e) {
			System.err.println("I/O error " + e);
		}
		// System.out.println("Save done");
	
protected voidsetViewCtl(TV tv)

		viewctl = tv;