JGoView.print()

Метод  printEnd(java.awt.Graphics2D g2, java.awt.print.PageFormat pf) <?:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
javadoc: «Called at the end of printing and before any new printing operation;
allows printBegin to reinitialize its precalculated values for the next printing operation.»

If we use JGoView.print(), printEnd will called only at the start of printing (i.e. before new printing operation).

Really? It ought to be called before and after, as the documentation says. You can tell if it’s before because the Graphics2D argument will be null.

The standard implementation of Printable.print call printEnd when it returns that there are no more pages.

Here is code that calls printEnd only before

import com.nwoods.jgo.JGoView;<?:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

import com.nwoods.jgo.examples.demo1.Demo1;

import java.awt.Dimension;

import java.awt.Graphics2D;

import java.awt.print.PageFormat;

import javax.swing.JFrame;

import javax.swing.UIManager;

/**

*

* @author alexey.zakharov

*/

public class TestPrinting extends JGoView {

/** Creates a new instance of TestPrinting */

public TestPrinting() {

}

static public void main(String args[]) {

try {

UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());

TestPrinting tp = new TestPrinting();

JFrame jFrame = new JFrame();

jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

jFrame.setTitle("Print Test Demo");

jFrame.setSize(640, 480);

jFrame.add(tp);

jFrame.setVisible(true);

tp.print();

} catch (Throwable t) {

System.err.println(t);

t.printStackTrace();

//Ensure the application exits with an error condition.

System.exit(1);

}

}

public void printBegin(Graphics2D g2, PageFormat pf){

System.out.println("printBegin");

super.printBegin(g2, pf);

}

public void printEnd(Graphics2D g2, PageFormat pf){

System.out.println("printEnd");

super.printEnd(g2, pf);

}

public Dimension getPrintDocumentSize(){

return new Dimension(800, 800);

}

}

Hmmm, apparently that functionality was broken when we reimplemented printing to use Books. We’ll have to investigate.