Creating a standalone viewer application

You can build a document viewer that is a standalone application.

About this task

As you complete the following steps, see the Application Programming Reference in the information center. Also see the samples for the standalone viewer application, TGenericDocViewer.java, that are in the samples directory.

To begin, instantiate the CMBGenericDocViewer object. When instantiating the CMBGenericDocViewer object, you must create an instance of each of the CMBStreamingDocServices and CMBAnnotationServices class objects by implementing the following callback classes:
  • CMBStreamingDocServicesCallbacks abstract class
  • CMBAnnotationServicesCallbacks abstract class
To create a standalone viewer application, complete the following steps:

Procedure

  1. Create a class that extends CMBStreamingDocServicesCallbacks.
    This class is used by CMBGenericDocViewer to retrieve and update document parts and resources. This includes methods to retrieve a background form for a document and the print privilege of a document. In the code sample, this class is called StreamingDocServicesCallbacks.
  2. Create an instance of CMBStreamingDocServices by using the callbacks implemented in step 1.
    In the code sample, this is the docServices object.
  3. Create a class that extends CMBAnnotationServicesCallbacks.
    This class is used by CMBGenericDocViewer to retrieve and update annotations. You must provide the implementation for the required methods, like retrieve and update. You can ignore the methods that are not relevant for the type of documents being viewed. In the code sample, this is the AnnotationServicesCallbacks class.
  4. Create an instance of CMBAnnotationServices by using the callbacks implemented in step 3.
    In the code sample this is the annoServices object.
  5. Create an instance of CMBGenericDocViewer.
    1. Initialize it with the CMBStreamingDocServices, CMBAnnotationServices, and the configuration properties object.
    2. Pass null for the properties object if you want to use the default configuration object.
      The default configuration is constructed from the default configuration file cmbviewerconfiguration.properties, contained in cmbview81.jar.
    The message string for this default configuration, like action labels and tool tips, is read from the language-specific cmbViewerMessages.properities file in cmbview81.jar.
  6. Add the viewer to the application's main frame.
  7. Prepare a menu bar by retrieving the actions from the generic document viewer and add the menu to the application as shown in the section about customizing.
  8. Implement the viewer listener interfaces, such as CMBGenericDocSaveListener and CMBGenericDocClosedListener.
    Remember to use the genericDocSave method of CMBGenericDocSaveListener to save a document and annotation set.
  9. Add the viewer listeners by using the add listener methods of CMBGenericDocViewer, such as addDocSaveListener.
  10. Specify the engines and their order by using the engine property file, called cmbviewerengine.properties.
    The CMBStreamingDocServices object relies on document engine classes to handle the manipulation of images. The cmbviewerengine.properties is contained in cmbview81.jar. You can also do this programmatically as demonstrated in the following code snippet:
    // Create engine properties
    engineProperties = new Properties();
    engineProperties.put("ENGINES","2");
    engineProperties.put("ENGINE1_CLASSNAME",
    "com.ibm.mm.viewer.CMBSnowboundEngine");
    engineProperties.put("ENGINE2_CLASSNAME",
    "com.ibm.mm.viewer.CMBOutsideInExportEngine");
    // Create a streaming doc services object and associate
    // the document engine classes
    docServices = new CMBStreamingDocServices(
    new StreamingDocServicesCallbacks(), engineProperties);

Example

The following code shows how to create the CMBGenericDocViewer object:
// Create streaming doc services object
docServices = new CMBStreamingDocServices(
             new StreamingDocServicesCallbacks(), null);

// Create annotation services object
annoServices = new CMBAnnotationServices(
     new AnnotationServicesCallbacks());

// Create generic doc viewer object
genericDocViewer = new CMBGenericDocViewer(
     docServices, annoServices, configProps);

// Add generic doc viewer GUI to content pane
getContentPane().add(genericDocViewer, BorderLayout.CENTER);