skip to main content
Diagrammer > Programmer's documentation > Rogue Wave JViews Framework Advanced Features > Printing framework for manager content > Printing the contents of a manager on multiple pages
 
Printing the contents of a manager on multiple pages
Describes the classes in the ilog.views.print package that allow you to print the contents of an IlvManager object on multiple pages.
*The IlvManagerPrintableDocument class
*Describes the printable document class for a manager.
*The IlvManagerDocumentSetupDialog class
*Describes the setup dialog class for a manager.
*The IlvManagerPrintingController class
*Describes the printing controller class for a manager.
*The IlvPrintAreaInteractor class
*Describes the area interactor class for a manager.
*A Swing application that prints the contents of a manager
*Shows an example Swing application that prints the contents of a manager on multiple pages.
The IlvManagerPrintableDocument class
JViews Framework provides a document class, IlvManagerPrintableDocument, which is a subclass of the generic IlvPrintableDocument class. The IlvManagerPrintableDocument class is dedicated to printing the contents of a manager on multiple pages.
When using the IlvManagerPrintableDocument class, you do not have to create pages and add them to the document. This class will create the pages for you, depending on the parameters you specify for the document.
In addition to the generic parameters defined in the superclass IlvPrintableDocument such as the name and author of the document, the page format, the header and footer, and the page order, the IlvManagerPrintableDocument class allows you to specify the following options:
*The number of pages
*The area of the manager to be printed
*The zoom level used for printing
The following code creates an instance of IlvManagerPrintableDocument to print the area (0,0,500,500) of a manager in five columns:
 
IlvManagerPrintableDocument document = new IlvPrintableManagerDocument
                                       ("My Document", view);
document.setColumnCount(5);
document.setPrintArea(new IlvRect(0,0,500,500));
Number of pages
The number of pages is determined by the number of rows and columns that you specify as follows:
*If you specify the number of rows, the document computes the number of columns necessary to cover the area to print.
*If you specify both the number of rows and the number of columns, then the document class will choose to use the number of rows or the number of columns to produce the minimum number of pages.
To print the manager on one page, set the number of rows and the number of columns to 1.
Area to print
The area of the manager to print is specified by the setPrintArea and getPrintArea methods. When no print area has been specified, then the printed area will be the full area of the manager. To reset the area to print to the full area of the manager, call:
 
document.setPrintArea(null);
Zoom Level for Printing
The contents of the manager may be graphically different when a different zoom level is used, in particular when the manager contains nonzoomable objects. Thus, when printing the manager, you may need to specify the zoom level used for printing. By default, the contents of the manager are printed using the identity affine transform (that is, zoom level 1).
The IlvManagerDocumentSetupDialog class
All properties of the IlvManagerPrintableDocument class can be specified by a dialog box (class IlvManagerDocumentSetupDialog). This dialog box, a subclass of the generic IlvDocumentSetupDialog, contains an additional page in the tabbed pane that allows you to specify the area to print, the number of columns and rows (that is, the number of pages), the zoom level at which to print, and the page order for the numbering of pages.
Page Setup dialog box
You may not want to allow the user to change the zoom level, or you may need to specify a range of zoom level that is allowed for this specific manager. To do this, use the following methods in the IlvManagerPrintableDocument class:
*Enable or disable the modification of the zoom level from the dialog box:
 
is/setZoomLevelModificationEnabled()
*Set the minimum or maximum zoom level that can be used for printing.
 
setMaximimumZoomLevel(double zl)
 
void setMinimumZoomLevel(double zl)
NOTE You do not have to create this dialog box yourself; the printing controller will manage an instance of this class for you.
The IlvManagerPrintingController class
The IlvManagerPrintingController is a subclass of the generic IlvPrintingController that controls the printing of an IlvManagerPrintableDocument object.
After creating your IlvManagerPrintableDocument object, you must create an instance of IlvManagerPrintingController for the document. Then you will be able to perform various actions on the document to be printed; for example, you can:
*Call the printDialog method to invoke a dialog box to select a printer or to specify other printer-related information.
*Call the setupDialog method to open the Page Setup dialog box.
*Call the printPreview method to preview your document.
*Call the print method of the print controller to print your document. You can also click the Print button while you preview the document.
The IlvPrintAreaInteractor class
The ilog.views.print package also contains a specific interactor (IlvPrintAreaInteractor) that allows you to specify the area to print on the manager by dragging a rectangle.
A Swing application that prints the contents of a manager
In this example, a full application using the IlvManagerPrintingController and IlvManagerPrintableDocument classes prints the contents of a manager on multiple pages.
This example has a Swing frame containing an instance of IlvManagerView that displays the contents of a manager. The application has also a menu bar with standard printing menu commands such as Print..., Print Preview, Page Setup..., and so on.
 
import java.awt.*;
import java.awt.print.*;
import java.awt.event.*;
import javax.swing.*;
import ilog.views.print.*;
import ilog.views.util.print.*;
import ilog.views.*;
import ilog.views.interactor.*;
import ilog.views.swing.*;
 
/**
 * This is a very simple example to show how to use
 * the IlvManagerPrintableDocument class.
 */
public class ExamplePrint extends JFrame
{
  /**
   * The manager to print.
   */
  IlvManager manager;
 
  /**
   * An IlvManagerView to display the content of a manager.
   */
  IlvManagerView mgrview;
 
  /**
   * The printing controller.
   */
  IlvManagerPrintingController controller;
 
  /**
   * The interactor that allows you to specify the area to print.
   */
  IlvPrintAreaInteractor printAreaInteractor;
 
  /**
   * Creates and initializes the example.
   */
  public ExamplePrint() {
 
    super("Printing Example");
    getContentPane().setLayout(new BorderLayout());
 
    // Creates the manager to print.
    manager = new IlvManager();
 
    // Fills the manager with some data.
    try {
       manager.read("data.ivl");
    } catch (Exception e) {
    }
 
 
    // Creates a view of the manager.
    mgrview = new IlvManagerView(manager);
    mgrview.setBackground(Color.white);
    mgrview.setKeepingAspectRatio(true);
 
    // Creates the printing controller
    controller = new IlvManagerPrintingController(mgrview);
 
    // Initializes the document with some parameters.
    IlvPrintableDocument document = controller.getDocument();
 
    document.setName("data.ivl");
    document.setAuthor("My name");
 
    // Creates the interactor.
    printAreaInteractor = new IlvPrintAreaInteractor(controller);
 
    // Adds a toolbar to edit/zoom/pan.
    IlvJManagerViewControlBar toolbar
          = new IlvJManagerViewControlBar();
    toolbar.setView(mgrview);
 
    // Creates a scroll manager view.
    IlvJScrollManagerView scrollview
             = new IlvJScrollManagerView(mgrview);
    getContentPane().add(scrollview, BorderLayout.CENTER);
    getContentPane().add(toolbar, BorderLayout.NORTH);
    scrollview.setPreferredSize(new Dimension(300,300));
    setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
 
    addWindowListener(new WindowAdapter () {
        public void windowClosed (WindowEvent e) {
          System.exit(0);
        }
    });
 
    // Creates the menu bar.
    setJMenuBar(createMenu());
 
  }
 
  private JMenuBar createMenu() {
 
    JMenuBar bar = new JMenuBar();
    JMenu file = new JMenu("File");
    JMenu parea = new JMenu("Print Area");
    JMenuItem preview = new JMenuItem("Print Preview...");
    JMenuItem setup = new JMenuItem("Page Setup...");
    JMenuItem setarea = new JMenuItem("Set Print Area");
    JMenuItem cleararea = new JMenuItem("Clear Print Area");
    JMenuItem print = new JMenuItem("Print...");
 
 
    // Action to open the print preview dialog.
    preview.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ev) {
          controller.printPreview(ExamplePrint.this);
        }
      });
 
    // Action to open the setup dialog box.
    setup.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ev) {
          controller.setupDialog(ExamplePrint.this, true, true);
 
        }
      });
 
    // Action to print the document.
    print.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ev) {
          try {
            controller.print(true);
          } catch (Exception e) { }
 
        }
      });
 
    // Action to install the print area interactor.
    setarea.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ev) {
          mgrview.setInteractor(printAreaInteractor);
        }
      });
 
 
    // Action to reset the print area to full manager size.
    cleararea.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ev) {
          ((IlvManagerPrintableDocument)controller.
                getDocument()).setPrintArea(null);
        }
      });
 
 
    file.add(setup);
    file.add(parea);
    parea.add(setarea);
    parea.add(cleararea);
    file.add(preview);
    file.add(print);
 
    bar.add(file);
 
    return bar;
 
  }
 
public static void main(String[] args)
{
  SwingUtilities.invokeLater(
    new Runnable() {
      public void run() {
        ExamplePrint example = new ExamplePrint();
        example.pack();
        example.setVisible(true);
      }
    });
}

Copyright © 2018, Rogue Wave Software, Inc. All Rights Reserved.