logo
  Converting from 1.x
logo

Converting to J2PrinterWorks from J2TextPrinter 1.x or J2TablePrinter 1.x

The  J2PrinterWorks API has been redesigned to support its new multiple component printing capabilities.  The application code you write must therefore be changed from what you may have experienced with our earlier J2TextPrinter and J2TablePrinter products, but the changes are relatively straightforward.
 

Import statements

First, the import statements are different.  Previously, you needed the individual statements:
   import com.wildcrest.j2textprinter.*;
   import com.wildcrest.j2tableprinter.*;

Now you only need one import statement:
   import com.wildcrest.j2printerworks.*;
 

Instantiation and printing

Previously, the 1.x versions of J2TextPrinter and J2TablePrinter each consisted of one run-time class.  Typical printing code looked like:

    J2TextPrinter textPrinter = new J2TextPrinter();
    textPrinter.setPane(yourJTextPane);

    textPrinter.print();

J2PrinterWorks separates the printing mechanism and printing content into two classes.  The above code is now changed to:

    J2Printer printer = new J2Printer();              // (or J2Printer14)

    J2TextPrinter textPrinter = new J2TextPrinter();  // (same)
    textPrinter.setPane(yourJTextPane);               // (same)

    printer.setPageable(textPrinter);
    printer.print();

 

Method calls

The methods of J2TablePrinter or J2TextPrinter from version 1.x were all associated with the one run-time class.  Now in J2PrinterWorks, these methods have been refactored into being either methods of J2Printer, methods of J2TablePrinter/J2TextPrinter, or both.  For example, the methods that control the printable content remain J2TablePrinter methods in J2PrinterWorks:

   tableprinter.setColumnHeaderPrinting(J2TablePrinter.TOP_PAGES);
   tableprinter.setPrintArea(1,1,10,10);
   tableprinter.setHorizontalAlignment(J2TablePrinter.LEFT);

On the other hand, the methods the control the printing mechanism have been changed to J2Printer methods in J2PrinterWorks, for example:

   printer.setSeparatePrintThread(false);
   printer.setNumberOfCopies(3);
   printer.showPrintPreviewDialog(new JFrame());

Finally, the methods that control the page format (margins, headers/footers, orientation, scale) can be used with either J2Printer or the individual printing components such as J2TablePrinter or J2TextPrinter, for example:

     printer.setOrientation(J2Printer.LANDSCAPE);
     printer.setScale(.75);
     printer.setTopMargin(.5);
     printer.setLeftFooter("Page ###");
or:
     textPrinter.setOrientation(J2Printer.LANDSCAPE);
     textPrinter.setScale(.75);
     textPrinter.setTopMargin(.5);
     textPrinter.setLeftFooter("Page ###");

This is because under J2PrinterWorks it is now possible to print several Pageables (such as J2TextPrinter and J2TablePrinter instances) together in one document.  When you call the page formatting methods on the textPrinter or tablePrinter instances, you are setting the local values for the pages of just that Pageable  On the other hand, when you call these methods on the printer instance, you are setting the global (overall, default) values that will be used for all pages unless an individual Pageable has specified its own "local" values.


© Copyright 2009, Wildcrest Associates (http://www.wildcrest.com)