|
Sample Programs and Sample Code
J2PrinterWorks includes 25 sample programs with complete source code. The source code for these applications may be freely used, modified, incorporated, and distributed without restriction as part of any software that uses J2PrinterWorks itself (see License and Terms of Use ).
| J2PrinterWorksTestApplication |
RUN ME FIRST! A comprehensive test of all the J2PrinterWorks printing components |
| StylepadPrinter |
Sun's Stylepad demo program (JTextPane-based word processor) with printing added |
| J2TextPrinterTestApplication |
J2TextPrinter program that reads and prints HTML, RTF, and StyledDocument files |
| J2TextPrinterHTMLFormTest |
Demonstrates use of "direct print" to print user entries in HTML <form> documents |
| J2TextPrinterSimplestTest |
Minimum J2TextPrinter program that prints a JTextPane (using HTML) |
| J2TablePrinterTestApplication |
J2TablePrinter program that reads a file directory and prints it as a JTable |
| J2TablePrinterSimplestTest |
Minimum J2TablePrinter program that prints a JTable |
| J2TreePrinterTestApplication |
J2TreePrinter program that reads a file directory and prints it as a JTree |
| J2TreePrinterSimplestTest |
Minimum J2TreePrinter program that prints a JTree |
| J2ListPrinterSimplestTest |
Minimum J2ListPrinter program that prints a JList |
| J2PanelPrinterImageApplication |
J2PanelPrinter program that reads and prints any .gif or .jpg image file |
| J2PanelPrinterGraphicsTest |
Minimum J2PanelPrinter program that prints a Graphics drawing and/or Image |
| J2PanelPrinterSimplestTest |
Minimum J2PanelPrinter program that prints a JLabel in a JPanel |
| J2ComponentPrinterSimplestTest |
Minimum J2ComponentPrinter program that prints a Component |
| J2ComponentPrinterTestApplication |
Reimplementation of J2PrinterWorksTestApplication using only J2ComponentPrinter |
| J2FlowPrinterSimplestTest |
Minimum J2FlowPrinter program that prints a JTextPane, JTable, JTree, JList, and JPanel back-to-back |
| J2FlowPrinterTestApplication |
J2FlowPrinter program that prints a typical report made up of JTextPane, JTable, JTree, JPanel, etc.
|
| J2Printer14PrinterSelectionTest |
J2Printer14 program that lets you find and choose printers (JDK 1.4.x or later required) |
| J2Printer14CrossPlatformTest |
J2Printer14 program that uses Java cross-platform printing dialogs (JDK 1.4.x or later required) |
| J2Printer14PSTest |
J2Printer14 program that prints to a Postscript file (JDK 1.4.x or later required)/td>
|
| J2PrinterPDFTest |
Program that prints to a PDF file + display & print any PDF file (iText.jar and Acrobat Reader required)
|
| J2PrintToImageTest |
Program that tests printing a page to an Image and saving Image as a .jpg file |
| J2PrinterWorksApplet |
Simple unsigned printing applet. |
| J2Printer14Applet |
Simple J2Printer14 unsigned printing applet (JDK 1.4.x or later required) |
| J2PrinterWebStartTest |
J2PrinterWebStart program that tests printing from a Java Web Start application |
Installing and running sample programs
J2PrinterWorks is a Java 2 program. You must have Java 2 (either JDK 1.2.x, 1.3.x, 1.4.x, 1.5.x, or 1.6.x) installed on your system. JDK 1.4 or later is highly recommended. You may encounter performance problems, feature limitations, and possible malfunctions when printing under JDK 1.2.x or JDK 1.3.x due to various problem present in earlier Java systems (see Known Problems section). Information is available at the Sun Java site for how to download (free) and install the latest release of Java.
All the sample programs are included in the J2PrinterWorks distribution (.zip) file. Unzip this file to create folders containing all the J2PrinterWorks sample programs.
In the top level J2PrinterWorks installation folder, you will find a folder called samplePrograms. Inside this folder, you will find multiple folders containing all the J2PrinterWorks sample programs and source code files. Most of the sample applications (all but the last three sample programs in the above list) are double-clickable .jar files.
To run the sample applets, double-click on the corresponding .html file.
To run the J2PrinterWebStartTest, you need to build (e.g. using Ant) and deploy to a Java-enabled web server (e.g. Tomcat). Instructions for doing this are included in the readme.txt file included in the J2PrinterWebStartTest folder and are the same as the standard Java Web Start sample programs from Sun.
In each folder other than J2PrinterWebStartTest there is a build.bat Windows batch file for building the sample program from the source code, and a run.bat Windows batch file for running the sample program. Alternatively, you can open a command window ("Terminal" on the Mac, the shell window in Unix, or MS-DOS window in Windows), and type the command lines such as the following:: java -cp .;..\..\J2PrinterWorks.jar J2PrinterWorksTestApplication
NOTE: On Unix and Mac, the class path file separator is colon instead of semi-colon and the path separator is forward slash instead of backward slash.
Page Setup Dialogs The standard Java page setup dialog is designed to let end users control the margins and orientation of printed pages. The Java cross-platform page setup dialog available in JDK 1.4.x and later adds several more printing feature controls to these. However, J2PrinterWorks contains a number of additional features beyond those in the Java page setup dialogs, including headers and footers, scale factors, centering, thread and dialog control, etc. Application developers may choose to control these features themselves or may wish to provide some or all of these choices to end users. To facilitate the latter case, the J2PrinterWorks sample programs provide the source code for a number of different "detailed" page setup dialogs which developers may wish to use or adapt for their own purposes to provide control over certain J2PrinterWorks features to end users. In particular, the following page setup dialogs are of interest:
J2PrinterWorksPageSetupDialog.java - contains the standard J2PrinterWorks controls including headers/footers contents, style, and gaps, margins, print and print preview scale factors, orientation, print thread, print dialog, number of copies, and print job name, which could replace the standard Java page setup dialog.
J2PrinterSettingsDialog.java - contains a minimum subset of the standard J2PrinterWorks controls without orientation or margins, which therefore avoids any overlap with and could be used in addition to the standard Java page setup dialog.
J2TextPrinterPageSetupDialog.java - contains the standard J2PrinterWorks controls plus controls specific to J2TextPrinter including centering and WYSIWYG control.
J2TablePrinterPageSetupDialog.java - contains the standard J2PrinterWorks controls plus controls specific to J2TablePrinter including centering, outside line control, column header replication and row/column ranges.
J2TreePrinterPageSetupDialog.java - contains the standard J2PrinterWorks controls plus controls specific to J2TreePrinter including centering and outside line control
Custom Flowables
The J2PrinterWorks Flowable interface is used to implement objects which are able to print incrementally, advancing by one rectangular area at a time. Flowables are used by J2PrinterWorks to implement printing components that can span multiple pages, but unlike Pageables, they can also begin and end in the middle of any page. The J2PrinterWorks abstract base class J2Pageable takes any such Flowable and provides an implementation of a full Java Pageable complete with headers, footers, margins, orientation, centering, scaling, etc. See sections Pageable and Flowable, Class Diagram, and FAQ.
The J2PrinterWorks classes J2TextPrinter, J2TablePrinter, J2TreePrinter, J2ListPrinter, J2PanelPrinter, and J2FlowPrinter all work by implementing Flowable and inheriting Pageable from J2Pageable in the above manner. J2PrinterWorks also provides a source code template FlowableExample.java which shows how you can do the same thing in order to create paginatable components of your own which can control how much they print on a page and thereby where pagination boundaries will occur. This is useful if you have custom multi-page content to be printed, such as your own tables, drawings, page layouts, etc.
|