org.icepdf.ri.common.SwingViewBuilder Maven / Gradle / Ivy
Show all versions of icepdf-viewer Show documentation
/*
* Copyright 2006-2016 ICEsoft Technologies Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an "AS
* IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/
package org.icepdf.ri.common;
import apple.dts.samplecode.osxadapter.OSXAdapter;
import org.icepdf.core.util.Defs;
import org.icepdf.ri.common.utility.annotation.AnnotationPanel;
import org.icepdf.ri.common.utility.layers.LayersPanel;
import org.icepdf.ri.common.utility.outline.OutlinesTree;
import org.icepdf.ri.common.utility.search.SearchPanel;
import org.icepdf.ri.common.utility.signatures.SignaturesPanel;
import org.icepdf.ri.common.utility.thumbs.ThumbnailsPanel;
import org.icepdf.ri.common.views.DocumentViewController;
import org.icepdf.ri.common.views.DocumentViewControllerImpl;
import org.icepdf.ri.images.Images;
import org.icepdf.ri.util.PropertiesManager;
import javax.swing.*;
import java.awt.*;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.ResourceBundle;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* The purpose of this class is to facilitate in the building of user interface components
* that are used to view and interact with PDF Documents.
*
* As such, there are three main scenarios that are covered.
*
* - Building a standalone Viewer JFrame that will behave much as a full-featured PDF viewing application.
*
- Building an embeddable PDF Viewer JPanel, which can easily be added into any existing client application,
* augmenting its cababilities to include the capacity for viewing PDF Documents.
*
- Building a subset of the above, using the various building block methods in this class to construct GUI
* components that provide certain aspects of the overall functionality, and adding those into
* your application as desired.
*
*
* Building a standalone window
* This is the main entry point for building a JFrame containing all of the graphical user interface
* elements necessary for viewing PDF files.
* The hierarchy of the methods that are invoked to construct the complete GUI
* is provided below for your reference.
* You may choose to use any of the individual methods to construct a sub-set of the complete
* GUI that meets your specific requirements. This also provides you flexibility in the containers
* that you add the components into and the overall layout of the application, etc.
*
* public JFrame buildViewerFrame()
*
* - public JMenuBar buildCompleteMenuBar()
*
* - public JMenu buildFileMenu()
*
* - public JMenuItem buildOpenFileMenuItem()
* - public JMenuItem buildOpenURLMenuItem()
* - public JMenuItem buildCloseMenuItem()
* - public JMenuItem buildSaveAsFileMenuItem()
* - public JMenuItem buildExportTextMenuItem()
* - public JMenuItem buildExportSVGMenuItem()
* - public JMenuItem buildPermissionsMenuItem()
* - public JMenuItem buildInformationMenuItem()
* - public JMenuItem buildPrintSetupMenuItem()
* - public JMenuItem buildPrintMenuItem()
* - public JMenuItem buildExitMenuItem()
*
*
*
* - public JMenu buildViewMenu()
*
* - public JMenuItem buildFitActualSizeMenuItem()
* - public JMenuItem buildFitPageMenuItem()
* - public JMenuItem buildFitWidthMenuItem()
* - public JMenuItem buildZoomInMenuItem()
* - public JMenuItem buildZoomOutMenuItem()
* - public JMenuItem buildRotateLeftMenuItem()
* - public JMenuItem buildRotateRightMenuItem()
* - public JMenuItem buildShowHideToolBarMenuItem()
* - public JMenuItem buildShowHideUtilityPaneMenuItem()
*
*
*
* - public JMenu buildDocumentMenu()
*
* - public JMenuItem buildFirstPageMenuItem()
* - public JMenuItem buildPreviousPageMenuItem()
* - public JMenuItem buildNextPageMenuItem()
* - public JMenuItem buildLastPageMenuItem()
* - public JMenuItem buildSearchMenuItem()
* - public JMenuItem buildGoToPageMenuItem()
*
*
*
* - public JMenu buildWindowMenu()
*
* - public JMenuItem buildMinimiseAllMenuItem()
* - public JMenuItem buildBringAllToFrontMenuItem()
* - public void buildWindowListMenuItems(JMenu menu)
*
*
*
* - public JMenu buildHelpMenu()
*
* - public JMenuItem buildAboutMenuItem()
*
*
*
*
*
*
* - public void buildContents(Container cp, boolean embeddableComponent)
*
*
* - public JToolBar buildCompleteToolBar(boolean embeddableComponent)
*
* - public JToolBar buildUtilityToolBar(boolean embeddableComponent)
*
* - public JButton buildOpenFileButton()
* - public JButton buildSaveAsFileButton()
* - public JButton buildPrintButton()
* - public JButton buildSearchButton()
* - public JButton buildShowHideUtilityPaneButton()
*
*
*
* - public JToolBar buildPageNavigationToolBar()
*
* - public JButton buildFirstPageButton()
* - public JButton buildPreviousPageButton()
* - public JButton buildNextPageButton()
* - public JButton buildLastPageButton()
* - public JTextField buildCurrentPageNumberTextField()
* - public JLabel buildNumberOfPagesLabel()
*
*
*
* - public JToolBar buildZoomToolBar()
*
* - public JButton buildZoomOutButton()
* - public JComboBox buildZoomCombBox()
* - public JButton buildZoomInButton()
*
*
*
* - public JToolBar buildFitToolBar()
*
* - public JToggleButton buildFitActualSizeButton()
* - public JToggleButton buildFitPageButton()
* - public JToggleButton buildFitWidthButton()
*
*
*
* - public JToolBar buildRotateToolBar()
*
* - public JButton buildRotateLeftButton()
* - public JButton buildRotateRightButton()
*
*
*
* - public JToolBar buildToolToolBar()
*
* - public JToggleButton buildPanToolButton()
* - public JToggleButton buildZoomInToolButton()
* - public JToggleButton buildZoomOutToolButton()
*
*
*
*
*
*
* - public JSplitPane buildUtilityAndDocumentSplitPane(boolean embeddableComponent)
*
* - public JTabbedPane buildUtilityTabbedPane()
*
* - public JComponent buildOutlineComponents()
* - public SearchPanel buildSearchPanel()
*
*
*
* - public JScrollPane buildDocumentComponents(boolean embeddableComponent)
*
*
*
* - public JLabel buildStatusPanel()
*
*
*
*
*
*
*
* Building an embeddable component
* This is the main entry point for building a JPanel containing all of the GUI elements
* necessary for viewing PDF files. The main differences between this and buildViewerFrame() are:
*
* - The buildViewerPanel method returns a JPanel which you may then embed anywhere into your GUI
*
- The JPanel will not contain a menu bar.
*
- The JPanel uses the sub-set of the GUI components available in buildViewerFrame that are
* suited to an embedded component scenario.
*
*
*
* The following hierarchy of methods that are invoked to construct the complete Component GUI
* is provided for your reference.
* You may choose to use any of the individual methods below to construct a sub-set of the complete
* GUI that meets your specific requirements. This also provides you flexibility in the containers
* that you add the components into and the overall layout of the application, etc.
*
* public JPanel buildViewerPanel()
*
*
* - public void buildContents(Container cp, boolean embeddableComponent)
*
*
* - public JToolBar buildCompleteToolBar(boolean embeddableComponent)
*
* - public JToolBar buildUtilityToolBar(boolean embeddableComponent)
*
* - public JButton buildSaveAsFileButton()
* - public JButton buildPrintButton()
* - public JButton buildSearchButton()
* - public JButton buildShowHideUtilityPaneButton()
*
*
*
* - public JToolBar buildPageNavigationToolBar()
*
* - public JButton buildFirstPageButton()
* - public JButton buildPreviousPageButton()
* - public JButton buildNextPageButton()
* - public JButton buildLastPageButton()
* - public JTextField buildCurrentPageNumberTextField()
* - public JLabel buildNumberOfPagesLabel()
*
*
*
* - public JToolBar buildZoomToolBar()
*
* - public JButton buildZoomOutButton()
* - public JComboBox buildZoomCombBox()
* - public JButton buildZoomInButton()
*
*
*
* - public JToolBar buildFitToolBar()
*
* - public JToggleButton buildFitActualSizeButton()
* - public JToggleButton buildFitPageButton()
* - public JToggleButton buildFitWidthButton()
*
*
*
* - public JToolBar buildRotateToolBar()
*
* - public JButton buildRotateLeftButton()
* - public JButton buildRotateRightButton()
*
*
*
* - public JToolBar buildToolToolBar()
*
* - public JToggleButton buildPanToolButton()
* - public JToggleButton buildZoomInToolButton()
* - public JToggleButton buildZoomOutToolButton()
*
*
*
*
*
*
* - public JSplitPane buildUtilityAndDocumentSplitPane(boolean embeddableComponent)
*
* - public JTabbedPane buildUtilityTabbedPane()
*
* - public JComponent buildOutlineComponents()
* - public SearchPanel buildSearchPanel()
*
*
*
* - public JScrollPane buildDocumentComponents(boolean embeddableComponent)
*
*
*
*
* - public JLabel buildStatusPanel()
*
*
*
*
*
*
*
*
*
* @author Mark Collette
* @since 2.0
*/
public class SwingViewBuilder {
private static final Logger logger =
Logger.getLogger(SwingViewBuilder.class.toString());
public static final int TOOL_BAR_STYLE_FLOATING = 1;
public static final int TOOL_BAR_STYLE_FIXED = 2;
protected static final float[] DEFAULT_ZOOM_LEVELS = {
0.05f, 0.10f, 0.25f, 0.50f, 0.75f,
1.0f, 1.5f, 2.0f, 3.0f,
4.0f, 8.0f, 16.0f, 24.0f, 32.0f, 64.0f};
protected SwingController viewerController;
protected Font buttonFont;
protected boolean showButtonText;
protected int toolbarStyle;
protected float[] zoomLevels;
protected boolean haveMadeAToolBar;
protected int documentViewType;
protected int documentPageFitMode;
protected ResourceBundle messageBundle;
protected PropertiesManager propertiesManager;
public static boolean isMacOs;
private static boolean isDemo;
static {
isMacOs = (Defs.sysProperty("mrj.version") != null);
// check for demo system property
isDemo = Defs.sysPropertyBoolean("org.icepdf.ri.viewer.demo", false);
}
/**
* Construct a SwingVewBuilder with all of the default settings
*
* @param c SwingController that will interact with the GUI
*/
public SwingViewBuilder(SwingController c) {
// Use all the defaults
this(c, null, null, false, SwingViewBuilder.TOOL_BAR_STYLE_FIXED, null,
DocumentViewControllerImpl.ONE_PAGE_VIEW,
DocumentViewController.PAGE_FIT_WINDOW_HEIGHT);
}
/**
* Constructor that accepts a different PropertiesManager and otherwise
* defaults the remaining settings
*
* @param c SwingController that will interact with the GUI
* @param properties PropertiesManager that can customize the UI
*/
public SwingViewBuilder(SwingController c, PropertiesManager properties) {
this(c, properties, null, false, SwingViewBuilder.TOOL_BAR_STYLE_FIXED, null,
DocumentViewControllerImpl.ONE_PAGE_VIEW,
DocumentViewController.PAGE_FIT_WINDOW_HEIGHT);
}
/**
* Construct a SwingVewBuilder with all of the default settings
*
* @param c SwingController that will interact with the GUI
* @param documentViewType view type to build , single page, single column etc.
* @param documentPageFitMode fit mode to initially load document with.
*/
public SwingViewBuilder(SwingController c, int documentViewType,
int documentPageFitMode) {
// Use all the defaults
this(c, null, null, false, SwingViewBuilder.TOOL_BAR_STYLE_FIXED,
null, documentViewType, documentPageFitMode);
}
/**
* Construct a SwingVewBuilder with whichever settings you desire
*
* @param c SwingController that will interact with the GUI
*/
public SwingViewBuilder(SwingController c, Font bf, boolean bt, int ts,
float[] zl, final int documentViewType,
final int documentPageFitMode) {
this(c, null, bf, bt, ts, zl, documentViewType, documentPageFitMode);
}
/**
* Construct a SwingVewBuilder with whichever settings you desire
*
* @param c SwingController that will interact with the GUI
*/
public SwingViewBuilder(SwingController c, PropertiesManager properties,
Font bf, boolean bt, int ts,
float[] zl, final int documentViewType,
final int documentPageFitMode) {
viewerController = c;
messageBundle = viewerController.getMessageBundle();
if (properties != null) {
viewerController.setPropertiesManager(properties);
this.propertiesManager = properties;
}
// Attempt to override the highlight color from the properties file
overrideHighlightColor();
// update View Controller with previewer document page fit and view type info
DocumentViewControllerImpl documentViewController = (DocumentViewControllerImpl) viewerController.getDocumentViewController();
documentViewController.setDocumentViewType(documentViewType, documentPageFitMode);
buttonFont = bf;
if (buttonFont == null)
buttonFont = buildButtonFont();
showButtonText = bt;
toolbarStyle = ts;
zoomLevels = zl;
if (zoomLevels == null)
zoomLevels = DEFAULT_ZOOM_LEVELS;
// set default doc view type, single page, facing page, etc.
this.documentViewType = documentViewType;
// set default view mode type, fit page, fit width, no-fit.
this.documentPageFitMode = documentPageFitMode;
}
/**
* This is a standard method for creating a standalone JFrame, that would
* behave as a fully functional PDF Viewer application.
*
* @return a JFrame containing the PDF document's current page visualization,
* menu bar, accelerator buttons, and document outline if available.
* @see #buildViewerPanel
*/
public JFrame buildViewerFrame() {
JFrame viewer = new JFrame();
viewer.setIconImage(new ImageIcon(Images.get("icepdf-app-icon-64x64.png")).getImage());
viewer.setTitle(messageBundle.getString("viewer.window.title.default"));
viewer.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
JMenuBar menuBar = buildCompleteMenuBar();
if (menuBar != null)
viewer.setJMenuBar(menuBar);
Container contentPane = viewer.getContentPane();
buildContents(contentPane, false);
if (viewerController != null)
viewerController.setViewerFrame(viewer);
return viewer;
}
/**
* Used by the Applet and Pilot RI code to create an embeddable panel
* for viewing PDF files, as opposed to buildViewerFrame(), which makes a
* standalone JFrame
*
* @return JPanel containing the PDF document's current page visualization,
* menu bar, accelerator buttons, and document outline if available.
* @see #buildViewerFrame
*/
public JPanel buildViewerPanel() {
JPanel panel = new JPanel();
buildContents(panel, true);
return panel;
}
/**
* The Container will contain the PDF document's current page visualization
* and document outline if available.
*
* @param cp Container in which to put components for viewing PDF documents
*/
public void buildContents(Container cp, boolean embeddableComponent) {
cp.setLayout(new BorderLayout());
JToolBar toolBar = buildCompleteToolBar(embeddableComponent);
if (toolBar != null)
cp.add(toolBar, BorderLayout.NORTH);
// Builds the utility pane as well as the main document View, important
// code entry point.
JSplitPane utilAndDocSplit =
buildUtilityAndDocumentSplitPane(embeddableComponent);
if (utilAndDocSplit != null)
cp.add(utilAndDocSplit, BorderLayout.CENTER);
JPanel statusPanel = buildStatusPanel();
if (statusPanel != null)
cp.add(statusPanel, BorderLayout.SOUTH);
}
public JMenuBar buildCompleteMenuBar() {
JMenuBar menuBar = new JMenuBar();
addToMenuBar(menuBar, buildFileMenu());
addToMenuBar(menuBar, buildEditMenu());
addToMenuBar(menuBar, buildViewMenu());
addToMenuBar(menuBar, buildDocumentMenu());
addToMenuBar(menuBar, buildWindowMenu());
addToMenuBar(menuBar, buildHelpMenu());
// If running on MacOS, setup the native app. menu item handlers
if (isMacOs) {
try {
// Generate and register the OSXAdapter, passing it a hash of all the methods we wish to
// use as delegates for various com.apple.eawt.ApplicationListener methods
OSXAdapter.setQuitHandler(viewerController, viewerController.getClass().getDeclaredMethod("exit", (Class[]) null));
OSXAdapter.setAboutHandler(viewerController, viewerController.getClass().getDeclaredMethod("showAboutDialog", (Class[]) null));
} catch (Exception e) {
logger.log(Level.FINE, "Error occurred while loading the OSXAdapter:", e);
}
}
return menuBar;
}
protected KeyStroke buildKeyStroke(int keyCode, int modifiers) {
return buildKeyStroke(keyCode, modifiers, false);
}
/**
* Create and return a KeyStroke with the specified code and modifier
* Note this will automatically return null if the PROPERTY_SHOW_KEYBOARD_SHORTCUTS
* property is 'false'
*
* @param keyCode to build
* @param modifiers to build
* @param onRelease to build
* @return built KeyStroke
*/
protected KeyStroke buildKeyStroke(int keyCode, int modifiers, boolean onRelease) {
doubleCheckPropertiesManager();
if (PropertiesManager.checkAndStoreBooleanProperty(propertiesManager,
PropertiesManager.PROPERTY_SHOW_KEYBOARD_SHORTCUTS,
true)) {
return KeyStroke.getKeyStroke(keyCode, modifiers, onRelease);
}
return null;
}
/**
* Return a valid mnemonic for the passed character, unless the
* PropertiesManager.PROPERTY_SHOW_KEYBOARD_SHORTCUTS property is 'false',
* in which case we'll return -1
*
* @param mnemonic to build
* @return built mnemonic
*/
protected int buildMnemonic(char mnemonic) {
doubleCheckPropertiesManager();
if (PropertiesManager.checkAndStoreBooleanProperty(propertiesManager,
PropertiesManager.PROPERTY_SHOW_KEYBOARD_SHORTCUTS,
true)) {
return mnemonic;
}
return -1;
}
public JMenu buildFileMenu() {
JMenu fileMenu = new JMenu(messageBundle.getString("viewer.menu.file.label"));
fileMenu.setMnemonic(buildMnemonic(messageBundle.getString("viewer.menu.file.mnemonic").charAt(0)));
JMenuItem openFileMenuItem = buildOpenFileMenuItem();
JMenuItem openURLMenuItem = buildOpenURLMenuItem();
if (openFileMenuItem != null && openURLMenuItem != null) {
JMenu openSubMenu = new JMenu(messageBundle.getString("viewer.menu.open.label"));
openSubMenu.setIcon(new ImageIcon(Images.get("open_a_24.png")));
openSubMenu.setDisabledIcon(new ImageIcon(Images.get("open_i_24.png")));
openSubMenu.setRolloverIcon(new ImageIcon(Images.get("open_r_24.png")));
addToMenu(openSubMenu, openFileMenuItem);
addToMenu(openSubMenu, openURLMenuItem);
addToMenu(fileMenu, openSubMenu);
} else if (openFileMenuItem != null || openURLMenuItem != null) {
addToMenu(fileMenu, openFileMenuItem);
addToMenu(fileMenu, openURLMenuItem);
}
fileMenu.addSeparator();
addToMenu(fileMenu, buildCloseMenuItem());
addToMenu(fileMenu, buildSaveAsFileMenuItem());
addToMenu(fileMenu, buildExportTextMenuItem());
addToMenu(fileMenu, buildExportSVGMenuItem());
fileMenu.addSeparator();
addToMenu(fileMenu, buildPermissionsMenuItem());
addToMenu(fileMenu, buildInformationMenuItem());
addToMenu(fileMenu, buildFontInformationMenuItem());
fileMenu.addSeparator();
addToMenu(fileMenu, buildPrintSetupMenuItem());
addToMenu(fileMenu, buildPrintMenuItem());
if (!isMacOs) {
// Not on a Mac, so create the Exit menu item.
fileMenu.addSeparator();
addToMenu(fileMenu, buildExitMenuItem());
}
return fileMenu;
}
public JMenuItem buildOpenFileMenuItem() {
JMenuItem mi = makeMenuItem(
messageBundle.getString("viewer.menu.open.file.label"),
buildKeyStroke(KeyEventConstants.KEY_CODE_OPEN_FILE, KeyEventConstants.MODIFIER_OPEN_FILE));
if (viewerController != null && mi != null)
viewerController.setOpenFileMenuItem(mi);
return mi;
}
public JMenuItem buildOpenURLMenuItem() {
JMenuItem mi = makeMenuItem(
messageBundle.getString("viewer.menu.open.URL.label"),
buildKeyStroke(KeyEventConstants.KEY_CODE_OPEN_URL, KeyEventConstants.MODIFIER_OPEN_URL));
if (viewerController != null && mi != null)
viewerController.setOpenURLMenuItem(mi);
return mi;
}
public JMenuItem buildCloseMenuItem() {
JMenuItem mi = makeMenuItem(
messageBundle.getString("viewer.menu.close.label"), null, null,
buildKeyStroke(KeyEventConstants.KEY_CODE_CLOSE, KeyEventConstants.MODIFIER_CLOSE));
if (viewerController != null && mi != null)
viewerController.setCloseMenuItem(mi);
return mi;
}
public JMenuItem buildSaveAsFileMenuItem() {
JMenuItem mi = makeMenuItem(
messageBundle.getString("viewer.menu.saveAs.label"), "save",
Images.SIZE_MEDIUM,
buildKeyStroke(KeyEventConstants.KEY_CODE_SAVE_AS, KeyEventConstants.MODIFIER_SAVE_AS, false));
if (viewerController != null && mi != null)
viewerController.setSaveAsFileMenuItem(mi);
return mi;
}
public JMenuItem buildExportTextMenuItem() {
JMenuItem mi = makeMenuItem(
messageBundle.getString("viewer.menu.exportText.label"), null, null, null);
if (viewerController != null && mi != null)
viewerController.setExportTextMenuItem(mi);
return mi;
}
public JMenuItem buildExportSVGMenuItem() {
JMenuItem mi = null;
// Check to make sure SVG libraries are available
try {
Class.forName("org.apache.batik.dom.GenericDOMImplementation");
mi = makeMenuItem(
messageBundle.getString("viewer.menu.exportSVG.label"), null, null, null);
if (viewerController != null && mi != null)
viewerController.setExportSVGMenuItem(mi);
} catch (ClassNotFoundException e) {
logger.warning("SVG Support Not Found");
}
return mi;
}
public JMenuItem buildPermissionsMenuItem() {
JMenuItem mi = makeMenuItem(
messageBundle.getString("viewer.menu.documentPermission.label"), null, null, null);
if (viewerController != null && mi != null)
viewerController.setPermissionsMenuItem(mi);
return mi;
}
public JMenuItem buildInformationMenuItem() {
JMenuItem mi = makeMenuItem(
messageBundle.getString("viewer.menu.documentInformation.label"), null, null, null);
if (viewerController != null && mi != null)
viewerController.setInformationMenuItem(mi);
return mi;
}
public JMenuItem buildFontInformationMenuItem() {
JMenuItem mi = makeMenuItem(
messageBundle.getString("viewer.menu.documentFonts.label"), null, null, null);
if (viewerController != null && mi != null)
viewerController.setFontInformationMenuItem(mi);
return mi;
}
public JMenuItem buildPrintSetupMenuItem() {
JMenuItem mi = makeMenuItem(
messageBundle.getString("viewer.menu.printSetup.label"), null, null,
buildKeyStroke(KeyEventConstants.KEY_CODE_PRINT_SETUP, KeyEventConstants.MODIFIER_PRINT_SETUP, false));
if (viewerController != null && mi != null)
viewerController.setPrintSetupMenuItem(mi);
return mi;
}
public JMenuItem buildPrintMenuItem() {
JMenuItem mi = makeMenuItem(
messageBundle.getString("viewer.menu.print.label"), "print",
Images.SIZE_MEDIUM,
buildKeyStroke(KeyEventConstants.KEY_CODE_PRINT, KeyEventConstants.MODIFIER_PRINT));
if (viewerController != null && mi != null)
viewerController.setPrintMenuItem(mi);
return mi;
}
public JMenuItem buildExitMenuItem() {
JMenuItem mi = makeMenuItem(
messageBundle.getString("viewer.menu.exit.label"), null, null,
buildKeyStroke(KeyEventConstants.KEY_CODE_EXIT, KeyEventConstants.MODIFIER_EXIT));
if (viewerController != null && mi != null)
viewerController.setExitMenuItem(mi);
return mi;
}
public JMenu buildEditMenu() {
JMenu viewMenu = new JMenu(messageBundle.getString("viewer.menu.edit.label"));
viewMenu.setMnemonic(buildMnemonic(messageBundle.getString("viewer.menu.edit.mnemonic").charAt(0)));
addToMenu(viewMenu, buildUndoMenuItem());
addToMenu(viewMenu, buildRedoMenuItem());
viewMenu.addSeparator();
addToMenu(viewMenu, buildCopyMenuItem());
addToMenu(viewMenu, buildDeleteMenuItem());
viewMenu.addSeparator();
addToMenu(viewMenu, buildSelectAllMenuItem());
addToMenu(viewMenu, buildDeselectAllMenuItem());
return viewMenu;
}
public JMenuItem buildUndoMenuItem() {
JMenuItem mi = makeMenuItem(
messageBundle.getString("viewer.menu.edit.undo.label"),
null, null, buildKeyStroke(KeyEventConstants.KEY_CODE_UNDO,
KeyEventConstants.MODIFIER_UNDO));
if (viewerController != null && mi != null)
viewerController.setUndoMenuItem(mi);
return mi;
}
public JMenuItem buildRedoMenuItem() {
JMenuItem mi = makeMenuItem(
messageBundle.getString("viewer.menu.edit.redo.label"),
null, null, buildKeyStroke(KeyEventConstants.KEY_CODE_REDO,
KeyEventConstants.MODIFIER_REDO));
if (viewerController != null && mi != null)
viewerController.setReduMenuItem(mi);
return mi;
}
public JMenuItem buildCopyMenuItem() {
JMenuItem mi = makeMenuItem(
messageBundle.getString("viewer.menu.edit.copy.label"),
null, null, buildKeyStroke(KeyEventConstants.KEY_CODE_COPY,
KeyEventConstants.MODIFIER_COPY));
if (viewerController != null && mi != null)
viewerController.setCopyMenuItem(mi);
return mi;
}
public JMenuItem buildDeleteMenuItem() {
JMenuItem mi = makeMenuItem(
messageBundle.getString("viewer.menu.edit.delete.label"),
null, null, buildKeyStroke(KeyEventConstants.KEY_CODE_DELETE,
KeyEventConstants.MODIFIER_DELETE));
if (viewerController != null && mi != null)
viewerController.setDeleteMenuItem(mi);
return mi;
}
public JMenuItem buildSelectAllMenuItem() {
JMenuItem mi = makeMenuItem(
messageBundle.getString("viewer.menu.edit.selectAll.label"),
null, null, buildKeyStroke(KeyEventConstants.KEY_CODE_SELECT_ALL,
KeyEventConstants.MODIFIER_SELECT_ALL));
if (viewerController != null && mi != null)
viewerController.setSelectAllMenuItem(mi);
return mi;
}
public JMenuItem buildDeselectAllMenuItem() {
JMenuItem mi = makeMenuItem(
messageBundle.getString("viewer.menu.edit.deselectAll.label"),
null, null, buildKeyStroke(KeyEventConstants.KEY_CODE_DESELECT_ALL,
KeyEventConstants.MODIFIER_DESELECT_ALL));
if (viewerController != null && mi != null)
viewerController.setDselectAllMenuItem(mi);
return mi;
}
public JMenu buildViewMenu() {
JMenu viewMenu = new JMenu(messageBundle.getString("viewer.menu.view.label"));
viewMenu.setMnemonic(buildMnemonic(messageBundle.getString("viewer.menu.view.mnemonic").charAt(0)));
addToMenu(viewMenu, buildFitActualSizeMenuItem());
addToMenu(viewMenu, buildFitPageMenuItem());
addToMenu(viewMenu, buildFitWidthMenuItem());
viewMenu.addSeparator();
addToMenu(viewMenu, buildZoomInMenuItem());
addToMenu(viewMenu, buildZoomOutMenuItem());
viewMenu.addSeparator();
addToMenu(viewMenu, buildRotateLeftMenuItem());
addToMenu(viewMenu, buildRotateRightMenuItem());
viewMenu.addSeparator();
addToMenu(viewMenu, buildShowHideToolBarMenuItem());
addToMenu(viewMenu, buildShowHideUtilityPaneMenuItem());
return viewMenu;
}
public JMenuItem buildFitActualSizeMenuItem() {
JMenuItem mi = makeMenuItem(
messageBundle.getString("viewer.menu.view.actualSize.label"),
"actual_size", Images.SIZE_MEDIUM,
buildKeyStroke(KeyEventConstants.KEY_CODE_FIT_ACTUAL, KeyEventConstants.MODIFIER_FIT_ACTUAL));
if (viewerController != null && mi != null)
viewerController.setFitActualSizeMenuItem(mi);
return mi;
}
public JMenuItem buildFitPageMenuItem() {
JMenuItem mi = makeMenuItem(
messageBundle.getString("viewer.menu.view.fitInWindow.label"),
"fit_window", Images.SIZE_MEDIUM,
buildKeyStroke(KeyEventConstants.KEY_CODE_FIT_PAGE, KeyEventConstants.MODIFIER_FIT_PAGE));
if (viewerController != null && mi != null)
viewerController.setFitPageMenuItem(mi);
return mi;
}
public JMenuItem buildFitWidthMenuItem() {
JMenuItem mi = makeMenuItem(
messageBundle.getString("viewer.menu.view.fitWidth.label"),
null, null,
buildKeyStroke(KeyEventConstants.KEY_CODE_FIT_WIDTH, KeyEventConstants.MODIFIER_FIT_WIDTH));
if (viewerController != null && mi != null)
viewerController.setFitWidthMenuItem(mi);
return mi;
}
public JMenuItem buildZoomInMenuItem() {
JMenuItem mi = makeMenuItem(
messageBundle.getString("viewer.menu.view.zoomIn.label"),
"zoom_in", Images.SIZE_MEDIUM,
buildKeyStroke(KeyEventConstants.KEY_CODE_ZOOM_IN, KeyEventConstants.MODIFIER_ZOOM_IN, false));
if (viewerController != null && mi != null)
viewerController.setZoomInMenuItem(mi);
return mi;
}
public JMenuItem buildZoomOutMenuItem() {
JMenuItem mi = makeMenuItem(
messageBundle.getString("viewer.menu.view.zoomOut.label"),
"zoom_out", Images.SIZE_MEDIUM,
buildKeyStroke(KeyEventConstants.KEY_CODE_ZOOM_OUT, KeyEventConstants.MODIFIER_ZOOM_OUT, false));
if (viewerController != null && mi != null)
viewerController.setZoomOutMenuItem(mi);
return mi;
}
public JMenuItem buildRotateLeftMenuItem() {
JMenuItem mi = makeMenuItem(
messageBundle.getString("viewer.menu.view.rotateLeft.label"),
"rotate_left", Images.SIZE_MEDIUM,
buildKeyStroke(KeyEventConstants.KEY_CODE_ROTATE_LEFT, KeyEventConstants.MODIFIER_ROTATE_LEFT));
if (viewerController != null && mi != null)
viewerController.setRotateLeftMenuItem(mi);
return mi;
}
public JMenuItem buildRotateRightMenuItem() {
JMenuItem mi = makeMenuItem(
messageBundle.getString("viewer.menu.view.rotateRight.label"),
"rotate_right", Images.SIZE_MEDIUM,
buildKeyStroke(KeyEventConstants.KEY_CODE_ROTATE_RIGHT, KeyEventConstants.MODIFIER_ROTATE_RIGHT));
if (viewerController != null && mi != null)
viewerController.setRotateRightMenuItem(mi);
return mi;
}
public JMenuItem buildShowHideToolBarMenuItem() {
JMenuItem mi = makeMenuItem("", null);
if (viewerController != null && mi != null)
viewerController.setShowHideToolBarMenuItem(mi);
return mi;
}
public JMenuItem buildShowHideUtilityPaneMenuItem() {
JMenuItem mi = makeMenuItem("", null);
if (viewerController != null && mi != null)
viewerController.setShowHideUtilityPaneMenuItem(mi);
return mi;
}
public JMenu buildDocumentMenu() {
JMenu documentMenu = new JMenu(messageBundle.getString("viewer.menu.document.label"));
documentMenu.setMnemonic(buildMnemonic(messageBundle.getString("viewer.menu.document.mnemonic").charAt(0)));
addToMenu(documentMenu, buildFirstPageMenuItem());
addToMenu(documentMenu, buildPreviousPageMenuItem());
addToMenu(documentMenu, buildNextPageMenuItem());
addToMenu(documentMenu, buildLastPageMenuItem());
documentMenu.addSeparator();
addToMenu(documentMenu, buildSearchMenuItem());
addToMenu(documentMenu, buildGoToPageMenuItem());
return documentMenu;
}
public JMenuItem buildFirstPageMenuItem() {
JMenuItem mi = makeMenuItem(
messageBundle.getString("viewer.menu.document.firstPage.label"),
"page_first", Images.SIZE_MEDIUM,
buildKeyStroke(KeyEventConstants.KEY_CODE_FIRST_PAGE, KeyEventConstants.MODIFIER_FIRST_PAGE));
if (viewerController != null && mi != null)
viewerController.setFirstPageMenuItem(mi);
return mi;
}
public JMenuItem buildPreviousPageMenuItem() {
JMenuItem mi = makeMenuItem(
messageBundle.getString("viewer.menu.document.previousPage.label"),
"page_up", Images.SIZE_MEDIUM,
buildKeyStroke(KeyEventConstants.KEY_CODE_PREVIOUS_PAGE, KeyEventConstants.MODIFIER_PREVIOUS_PAGE));
if (viewerController != null && mi != null)
viewerController.setPreviousPageMenuItem(mi);
return mi;
}
public JMenuItem buildNextPageMenuItem() {
JMenuItem mi = makeMenuItem(
messageBundle.getString("viewer.menu.document.nextPage.label"),
"page_down", Images.SIZE_MEDIUM,
buildKeyStroke(KeyEventConstants.KEY_CODE_NEXT_PAGE, KeyEventConstants.MODIFIER_NEXT_PAGE));
if (viewerController != null && mi != null)
viewerController.setNextPageMenuItem(mi);
return mi;
}
public JMenuItem buildLastPageMenuItem() {
JMenuItem mi = makeMenuItem(
messageBundle.getString("viewer.menu.document.lastPage.label"),
"page_last", Images.SIZE_MEDIUM,
buildKeyStroke(KeyEventConstants.KEY_CODE_LAST_PAGE, KeyEventConstants.MODIFIER_LAST_PAGE));
if (viewerController != null && mi != null)
viewerController.setLastPageMenuItem(mi);
return mi;
}
public JMenuItem buildSearchMenuItem() {
JMenuItem mi = makeMenuItem(
messageBundle.getString("viewer.menu.document.search.label"),
buildKeyStroke(KeyEventConstants.KEY_CODE_SEARCH, KeyEventConstants.MODIFIER_SEARCH));
if (viewerController != null && mi != null)
viewerController.setSearchMenuItem(mi);
return mi;
}
public JMenuItem buildGoToPageMenuItem() {
JMenuItem mi = makeMenuItem(
messageBundle.getString("viewer.menu.document.gotToPage.label"),
buildKeyStroke(KeyEventConstants.KEY_CODE_GOTO, KeyEventConstants.MODIFIER_GOTO));
if (viewerController != null && mi != null)
viewerController.setGoToPageMenuItem(mi);
return mi;
}
public JMenu buildWindowMenu() {
final JMenu windowMenu = new JMenu(messageBundle.getString("viewer.menu.window.label"));
windowMenu.setMnemonic(buildMnemonic(messageBundle.getString("viewer.menu.window.mnemonic").charAt(0)));
addToMenu(windowMenu, buildMinimiseAllMenuItem());
addToMenu(windowMenu, buildBringAllToFrontMenuItem());
windowMenu.addSeparator();
final int allowedCount = windowMenu.getItemCount();
windowMenu.addMenuListener(new javax.swing.event.MenuListener() {
public void menuCanceled(javax.swing.event.MenuEvent e) {
}
public void menuDeselected(javax.swing.event.MenuEvent e) {
}
public void menuSelected(javax.swing.event.MenuEvent e) {
int count = windowMenu.getItemCount();
while (count > allowedCount) {
windowMenu.remove(count - 1);
count--;
}
buildWindowListMenuItems(windowMenu);
}
});
return windowMenu;
}
public JMenuItem buildMinimiseAllMenuItem() {
JMenuItem mi = makeMenuItem(messageBundle.getString("viewer.menu.window.minAll.label"), null);
mi.setMnemonic(buildMnemonic(messageBundle.getString("viewer.menu.window.minAll.mnemonic").charAt(0)));
if (viewerController != null)
viewerController.setMinimiseAllMenuItem(mi);
return mi;
}
public JMenuItem buildBringAllToFrontMenuItem() {
JMenuItem mi = makeMenuItem(messageBundle.getString("viewer.menu.window.frontAll.label"), null);
mi.setMnemonic(buildMnemonic(messageBundle.getString("viewer.menu.window.frontAll.mnemonic").charAt(0)));
if (viewerController != null)
viewerController.setBringAllToFrontMenuItem(mi);
return mi;
}
@SuppressWarnings("unchecked")
public void buildWindowListMenuItems(JMenu menu) {
if (viewerController != null &&
viewerController.getWindowManagementCallback() != null) {
WindowManagementCallback winMgr = viewerController.getWindowManagementCallback();
List