Analysis
Overview
This task should define the functionality for book print support in Sophie2. It should allow choosing of a printer, different printing formats (A4, A3, B4 ...) and printing orientation.
Task requirements
- Create a new module for print support
- Make a print action for the book
- Make a HUD (or a Dialog) for supported print featrues:
- Choosing printer
- Choosing paper format
- Choosing orientation - portrait, landscape
Task result
The result should be source code
Implementation idea
We can use Java Printing Service API, in which case printing is done through the graphic context and can be used (in some form and case) the painting, that we already have, of the visual elements.
Related
http://java.sun.com/javase/6/docs/technotes/guides/jps/spec/JPSTOC.fm.html
http://java.sun.com/docs/books/tutorial/2d/printing/
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6633656
How to demo
Print a book from Sophie2
Design
Printing support should be easy to maintain and easy to extend and something extra to the functionality of Sophie2. That's why a new module will be created. This module will define a new extension point. This extension point will define the relations between the Book model and its printing presentation. Also it will add a new menu item - Print..., which will be in the File menu.
The extenstion point will have two properties - id and a model for which it will print. The id is important because you can have many presentations of one and the same model. Also the printing support will use JPS (Java Printing Service). This API gives us functionality for querying printers, dialogs for print preferences, print to file (in postscript format of course) and so on. There are two major interfaces that are used for printing.
The first one is java.awt.printPrintable which has one print method with graphic context and page format as arguments. This interface is very powerfull because you can make pagination (separating graphics in pages) by hand.
The other one is java.awt.print.Pageable which is a little more complicated but working with it is more straightforward.
However there's a class which implements and extends java.awt.print.Pageable, and its name is java.awt.print.Book. It adds append methods, which add a new (logical) page to the book, with its presentation (java.awt.print.Printable instance). This is the most convenient class for our purposes because it lets us to add a presentation for every Resource we have in a Book, and this presentation to be independent. By independent I mean that one page can be A4 with landscape orientation and the next - B4 with portraint orientation.
When print is invoked it should:
- Collect all the Resources of the Book
- Find print presentation of each Resource (if more than one to choose the most appropriate)
- Create a java.awt.print.Book instance with pages and presentations
- Create a PrintJob with the java.awt.print.Book instance (PrintJob#setPageable)
- Open the dialog for the PrintJob and print
The current desing allows to make only one presentation for the whole Book itself and to handle pagination in it, but I think it's a better way to create separate presentations for each Resource. However the choise is up to the implementor.
It's important to know that when using JRE that is lower than Java 6 update 10, NullPointerException will be thrown. That's why a try/catch should be used to alert the user if this happens and to ask to use at least JRE 6 update 10.
See the Related section for tutorials and more information about the bug.
Implementation
Implementation is according to the analysis and design...in some form...
Changesets : [1963], [1964], [1997], [1999], [2000], [2001], [2012], [2013], [2016], [2017], [2035], [2045], [2164], [2096]
Testing
(Place the testing results here.)
Comments
(Write comments for this or later revisions here.)