Customizing the viewer
A document viewer, provided by CMBGenericDocViewer, is included with the product. You can customize the functionality provided by the document viewer through the configuration properties file.
The configuration properties file contains a series of parameters that control what toolbars display, where they display, and the tool buttons that are available. You can also customize such features as popup menus and the default display resolution.
You can customize the document viewer by providing a custom configProperties object while constructing the viewer. To view an example of a customized document viewer, see the TGenericDocViewer viewer application sample. The sample document viewer source code, TGenericdocviewer.java, and the custom property file it uses, TViewerDefaultConfiguration.properties are located in the samples directory. When reading through this section, reference the TViewerDefaultConfiguration.properties.
The document viewer configuration contains default toolbars, such as Operation, Annotation, and Page, a number of default tools, and a few properties that control certain viewer behaviors such as page manipulation, multiple selection, and so on. By using a custom document viewer configuration file, you can control which toolbars are visible, customize existing toolbars, create new toolbars and actions, and enable or disable configurable viewer behaviors.
You can customize the default configuration object, CMBViewerConfiguration.properties, located in the cmbview81.jar file, or you can create a new configuration object.
Providing configProperties object to the viewer
The following code snippet demonstrates how to provide a custom configProperties object to the viewer:
//Load the custom configuration file.
Properties customProperties = null;
try {
URL url =
this.getClass().getClassLoader().getResource(
“TViewerDefaultConfiguration.properties”);
InputStream configFile = null;
Properties defaultProperties = null;
if (url != null) {
configFile = url.openStream();
defaultProperties = new Properties();
defaultProperties.load(configFile);
customProperties = defaultProperties;
}
}
catch (Exception e) {System.out.println(e);
e.printStackTrace();
}
// Create the generic doc viewer and
// add it to the window
genericDocViewer =
new CMBGenericDocViewer
(docServices, annoServices,customProperties);Customizing the toolbar
The following code
snippet is the section of the TViewerDefaultConfiguration.properties file that customizes the toolbar. By using the various properties,
you can customize which toolbars appear, their position, the tools
that appear, the order in which they appear, and their groupings.
The toolbarname.position property specifies the
position of the toolbar with respect to the document. The thumbnail
bar position is also specified in the same way. The toolbarname.tools property specifies the list of tools, separated by commas, that
appear on the toolbar. The tools appear on the toolbar in the same
order that you specify them. To group tools together, use the keyword separator:
//The Toolbar defines all the toolbars listed
Toolbars=OperationToolbar,PageToolbar,AnnoToolbar
//You can customize the position and the
// tools of each toolbar
OperationToolbar.position=NORTH
OperationToolbar.tools=new_doc,open_doc,save_doc,
save_as,separator,
export_doc,print,separator,cut,copy,paste,separator,
undo,redo,separator,
rotate_90,rotate_180,rotate_270,rotate_pages,separator
,zoom_in,zoom_out,
zoom_custom,separator, \
fit_height,fit_width,fit_window,fit_actualsize,separator,
enhance,invert,
separator,hide_show,showhidethumb,separator,close_doc,
close_all_doc,separator,help
AnnoToolbar.position=WEST
AnnoToolbar.tools=selectArea,pointer,separator,Arrow,Circle,
Highlight,
Line,Note,Pen,Rect,Stamp,Text,eraser,separator, \
move_front,send_back,properties
PageToolbar.position=SOUTH
PageToolbar.tools=page_first,page_prev,goto_page,
page_next,page_last,
separator, \
doc_first,doc_prev,doc_next,doc_last
Thumbnailbar.position=EASTAll the tools listed in the
Customizing the toolbar code snippet, except open_doc, are default actions, which the viewer implements. The open_doc tool is a custom tool that you can add. You can also specify where
the tool appears by adding the open_doc tool to the OperationToolbar after the new_doc tool.
Adding a custom tool
The following code snippet demonstrates how to add a custom tool:open_doc.label=Open
open_doc.tooltip=Open
Document open_doc.icon=OpenDocument_normal.gif
open_doc.key=control O
open_doc.className=TGenericDocViewer$OpenActionThe viewer creates the tool as a CMBViewerAction. You must provide the class that provides the action of your custom tool.
Defining an action class for a custom tool
The following code snippet demonstrates how to define the class that provides the action for your custom tool:
// This class handles the Open action. This is a custom action
// added to the operations toolbar. It must be static since it is
// instantiated from within CMBGenericDocViewer.
public static class OpenAction extends CMBViewerAction {
public OpenAction(CMBGenericDocViewer viewer) {
super(viewer);
}
public OpenAction(CMBGenericDocViewer viewer, String name) {
super(viewer, name);
}
public OpenAction(CMBGenericDocViewer viewer, String name, Icon icon) {
super(viewer, name, icon);
}
// @see java.awt.event.ActionListener#actionPerformed(ActionEvent)
public void actionPerformed(ActionEvent e) {
// Find the TGenericDocViewer instance(it is a parent of CMBGenericDocViewer)
TGenericDocViewer gdvFrame = (TGenericDocViewer) getViewer()
.getParent()
.getParent()
.getParent()
.getParent();
JFileChooser chooser = new JFileChooser(System.getProperty("user.dir"));
chooser.setMultiSelectionEnabled(true);
int ret = chooser.showOpenDialog(gdvFrame);
if (ret == JFileChooser.APPROVE_OPTION) {
File [] files = chooser.getSelectedFiles();
for (int i = 0; i *!ENTITY!* files.length; i++) {
gdvFrame.openDocument(files[i].getAbsolutePath(),i == 0);
}
}
}
}Using viewer actions in your application
The following code snippet demonstrates how to add a viewer action to the menu bar of an application://create a menubar and menu
JMenuBar mainMenuBar = new JMenuBar();
JMenu viewerMenu = new JMenu("Viewer");
mainMenuBar.add(viewerMenu);
//get an action object that has been loaded into the viewer
Action zoomInAction = genericDocViewer.getAction("zoom_in");
// add the viewer action to the menu
viewerMenu.add(zoomInAction);
// add the menu bar
getRootPane().setJMenuBar(mainMenuBar);Customizing popup menus
The viewer also provides popup menus that you can customize. The popup menus include Page, Thumbnail, Annotation, Document Tab, and Select Area. The names of the popup menus are fixed and signify where the menu appears. The tools available for each popup menu are listed in the value of the popupmenuName.items property, which you can customize.
The following code snippet is the popup menu section from TViewerDefaultConfiguration.properties file://Popup Menus
//annotation popup
annotationpopup.items=cut,copy,paste,delete,separator,
move_front,send_back,separator,properties
//thumbnail popup
thumbpopup.items=cut,copy,paste,delete,separator,deselectAll,
selectAll,separator,rotate
//page popup
pagepopup.items=cut,copy,paste,delete,separator,rotate,zoom,
fit,navigate,separator,paste
//doc tab popup (appears when right-click on document tabs)
doctabpopup.items=close_doc,close_all_doc,separator,
save_doc,print
//select area popup
selectareapopup.items=copyAdding submenus
You can add submenus to
the popup menus by creating label and item entries for the values in popupmenuname.item. The
following code snippet shows how to add submenus for rotate, zoom,
fit, and navigate:
//submenus (appear on some of the popup menus)
rotate.label=Rotate Pages
zoom.label=Zoom
fit.label=Fit
navigate.label=Navigate
rotate.items=rotate_90,rotate_180,rotate_270
zoom.items=zoom_in,zoom_out,zoom_custom
fit.items=fit_height,fit_width,fit_window,fit_actualsize
navigate.items=page_first,page_prev,goto_page,page_next,
page_last,showhidethumbThe following sections describe other viewer options that you can customize. Each of the options are explained in the comments that accompany each property.
Inverting documents
To automatically invert a document the first time it is opened, set the Document.invert property to true. Otherwise, to open a document normally, set the Document.invert property to false. By default, documents are not inverted. For example:Document.invert=falseEnhancing documents
To automatically enhance documents upon opening, set the Document.enhance property to true. The default is to enhance documents. Enhancing certain image documents can increase memory usage. For example:Document.enhance=trueRotating documents
Documents can be set to rotate when you open them. The default behavior is to not rotate a document when it is opened. To automatically rotate a document when it is opened, set the Document.rotate property accordingly:- Do not rotate: rotate_0
- Rotate 90 degrees: rotate_90
- Rotate 180: rotate_180
- Rotate 270: rotate_270
Document.rotate=rotate_0Document scroll locking
When you view two document views in a side-by-side layout, you have the option of locking the scroll bars so that both document views can be simultaneously scrolled, therefore allowing you to visually compare them more easily. By default, document scroll locking is set to off when side-to-side document viewing is initiated.Showing annotations
To automatically show all annotations associated with a document when it is opened, set the Annotations.show property to true. Set the property to false if you want the annotations hidden when the document is opened. The default setting is true. For example:Annotations.show=trueZooming
To zoom in and out on a document, set the Zoom.factor property to a numeric value greater than 0 and less than 100. This value represents a percentage. The default zoom value is 10 percent. For example:Zoom.factor=10 Fit-to-window
To fit the document page to a window, set the Page.fit property according to following options:- fit_width: Fit pages to view width
- fit_height: Fit pages to the height of the view
- fit_in_window: Fit the entire page within the view
- fit_none: Display the page by using the initial zoom (the default)
Page.fit=fit_width Resizing Thumbnails
The ThumbnailSize properties define the width and height of each thumbnail view. The values in the following example are appropriate for an 8.5 x 11-inch page. For example:ThumbnailSize.width=60
ThumbnailSize.height=77The thumbnail size might also be
a factor of this width and height by using ThumbnailSize. For example: small - actual thumbnail size would be ThumbnailSize.width/2,
ThumbnailSize.height/2
medium - actual thumbnail size would be ThumbnailSize.width,
ThumbnailSize.height
large - actual thumbnail size would be ThumbnailSize.widht * 2,
ThumbnailSize.height * 2
By default ThumbnailSize is medium
ThumbnailSize=mediumThumbnail docking
Thumbnails can be configured either to be docked or to float in a separate window. Configuring thumbnails to appear in a floating window allows you to view a document and the thumbnails simultaneously in separate windows. By default, thumbnails are docked. To configure thumbnails to dock, set the Thumbnail.dock property to true. To configure thumbnails to float in a separate window, set the Thumbnail.dock property to false. For example:Thumbnail.dock=falseManipulating pages
You can copy, cut, paste, delete, and rotate a page of a document and have all of these changes automatically saved. To save all changes made to a page, set the PageManipulation property to true. For example:PageManipulation=trueCustomizing viewer behavior
The following code snippet shows how to customize other viewer behavior options:# MultiplePageSelection enables multi-select of pages
# within the thumbnails.
MultiplePageSelection=true
# Set NewDocument.mimetype property to the MIME type
# to be used when creating new empty document.
# Examples include, image/gif, image/jpeg,
# image/tiff, application/pdf, text/plain,
# text/richtext, application/vnd.lotus_wordpro
NewDocument.mimetype=image/tiff
# Set NewDocument.annotationtype property to a string
# constant for the
# type of annotations when creating a new empty document.
# For example, 'application/vnd.ibm.modcap'
# for Content Manager annotations
# or a two letter representation of the server type such
# as 'DL','OD','V4'
NewDocument.annotationtype=application/vnd.ibm.modcap
#PrintMargins
#Specify the print margins for a mimetype.
#Default is 0,0,0,0 (top, left, bottom, right)
#printmargins.image/tiff=1,1,1,1