Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright 2006-2019 ICEsoft Technologies Canada Corp.
*
* 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 org.icepdf.core.pobjects.Page;
import org.icepdf.core.pobjects.graphics.images.references.ImageReference;
import org.icepdf.core.pobjects.graphics.images.references.ImageReferenceFactory;
import org.icepdf.core.util.Library;
import org.icepdf.core.util.SystemProperties;
import org.icepdf.ri.common.utility.annotation.AnnotationPanel;
import org.icepdf.ri.common.utility.annotation.destinations.DestinationsPanel;
import org.icepdf.ri.common.utility.annotation.markup.MarkupAnnotationPanel;
import org.icepdf.ri.common.utility.attachment.AttachmentPanel;
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.search.SearchToolBar;
import org.icepdf.ri.common.utility.signatures.SignaturesHandlerPanel;
import org.icepdf.ri.common.utility.thumbs.ThumbnailsPanel;
import org.icepdf.ri.common.views.AbstractDocumentView;
import org.icepdf.ri.common.views.DocumentViewController;
import org.icepdf.ri.common.views.DocumentViewControllerImpl;
import org.icepdf.ri.common.views.PageViewDecorator;
import org.icepdf.ri.common.widgets.annotations.AnnotationColorToggleButton;
import org.icepdf.ri.common.widgets.annotations.IconAnnotationColorToggleButton;
import org.icepdf.ri.images.Images;
import org.icepdf.ri.util.MacOSAdapter;
import org.icepdf.ri.util.ViewerPropertiesManager;
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;
import java.util.prefs.Preferences;
/**
*
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 capabilities 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 buildSaveFileMenuItem()
*
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 buildSaveFileButton()
*
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 buildSaveFileButton()
*
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 implements ViewBuilder {
private static final Logger logger =
Logger.getLogger(SwingViewBuilder.class.toString());
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 String iconSize;
protected ResourceBundle messageBundle;
protected static ViewerPropertiesManager propertiesManager;
protected static boolean isMacOs;
static {
isMacOs = SystemProperties.OS_NAME.contains("OS X");
}
/**
* Construct a SwingVewBuilder with all of the default settings
*
* @param c Controller 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, 0);
}
/**
* Constructor that accepts a different PropertiesManager and otherwise
* defaults the remaining settings
*
* @param c Controller that will interact with the GUI
* @param properties PropertiesManager that can customize the UI
*/
public SwingViewBuilder(SwingController c, ViewerPropertiesManager properties) {
this(c, properties, null, false, SwingViewBuilder.TOOL_BAR_STYLE_FIXED, null,
DocumentViewControllerImpl.ONE_PAGE_VIEW,
DocumentViewController.PAGE_FIT_WINDOW_HEIGHT, 0);
}
/**
* Construct a SwingVewBuilder with all of the default settings
*
* @param c Controller 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, 0);
}
/**
* Construct a SwingVewBuilder with all of the default settings
*
* @param c Controller 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.
* @param rotation default page rotation.
*/
public SwingViewBuilder(SwingController c, int documentViewType,
int documentPageFitMode, float rotation) {
// Use all the defaults
this(c, null, null, false, SwingViewBuilder.TOOL_BAR_STYLE_FIXED,
null, documentViewType, documentPageFitMode, rotation);
}
/**
* Construct a SwingVewBuilder with whichever settings you desire
*
* @param c Controller that will interact with the GUI
* @param bf button font.
* @param bt show button text.
* @param ts text size
* @param zl zoom levels
* @param documentViewType default document view.
* @param documentPageFitMode page fit mode
*/
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, 0);
}
/**
* Construct a SwingVewBuilder with whichever settings you desire
*
* @param c Controller that will interact with the GUI
* @param properties properties manager
* @param bf button font.
* @param bt show button text.
* @param ts text size
* @param zl zoom levels
* @param documentViewType default document view.
* @param documentPageFitMode page fit mode
* @param rotation rotation factor
*/
public SwingViewBuilder(SwingController c, ViewerPropertiesManager properties,
Font bf, boolean bt, int ts,
float[] zl, final int documentViewType,
final int documentPageFitMode, final float rotation) {
viewerController = c;
messageBundle = viewerController.getMessageBundle();
propertiesManager = properties;
if (propertiesManager == null) {
propertiesManager = ViewerPropertiesManager.getInstance();
}
viewerController.setPropertiesManager(propertiesManager);
// Apply viewer preferences settings to various core system properties.
overrideHighlightColor(propertiesManager);
// 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;
// apply default button size
iconSize = propertiesManager.getPreferences().get(ViewerPropertiesManager.PROPERTY_ICON_DEFAULT_SIZE, Images.SIZE_LARGE);
}
/**
* 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 embeddableComponent true if the component is to be used as an embedded component.
* @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 MacOSAdapter, passing it a hash of all the methods we wish to
// use as delegates for various com.apple.eawt.ApplicationListener methods
// for legacy OS X, no longer works on macOS
MacOSAdapter.setQuitHandler(viewerController, viewerController.getClass().getDeclaredMethod("exit", (Class[]) null));
MacOSAdapter.setAboutHandler(viewerController, viewerController.getClass().getDeclaredMethod("showAboutDialog", (Class[]) null));
} catch (Exception e) {
logger.log(Level.FINE, "Error occurred while loading the MacOSAdapter:", e);
}
}
return menuBar;
}
protected static 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 static KeyStroke buildKeyStroke(int keyCode, int modifiers, boolean onRelease) {
doubleCheckPropertiesManager();
if (propertiesManager.checkAndStoreBooleanProperty(
ViewerPropertiesManager.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(
ViewerPropertiesManager.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);
}
addToMenu(fileMenu, buildRecentFileMenuItem());
fileMenu.addSeparator();
addToMenu(fileMenu, buildCloseMenuItem());
addToMenu(fileMenu, buildSaveFileMenuItem());
addToMenu(fileMenu, buildSaveAsFileMenuItem());
addToMenu(fileMenu, buildExportTextMenuItem());
addToMenu(fileMenu, buildSendByMailMenuItem());
fileMenu.addSeparator();
addToMenu(fileMenu, buildPropertiesMenuItem());
// 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 JMenu buildRecentFileMenuItem() {
if (propertiesManager.checkAndStoreBooleanProperty(ViewerPropertiesManager.PROPERTY_SHOW_MENU_RECENT_FILES)) {
JMenu recentFilesSubMenu = new JMenu(messageBundle.getString("viewer.menu.open.recentFiles.label"));
viewerController.setRecentFilesSubMenu(recentFilesSubMenu);
viewerController.refreshRecentFileMenuItem();
return recentFilesSubMenu;
} else {
return null;
}
}
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 buildSendByMailMenuItem() {
final JMenuItem mi = makeMenuItem(messageBundle.getString("viewer.menu.sendMail.label"), null, iconSize,
buildKeyStroke(KeyEventConstants.KEY_CODE_SEND_MAIL, KeyEventConstants.MODIFIER_SEND_MAIL));
if (viewerController!=null && mi!=null){
viewerController.setSendMailMenuItem(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 buildSaveFileMenuItem() {
JMenuItem mi = makeMenuItem(
messageBundle.getString("viewer.menu.save.label"), "save",
Images.SIZE_SMALL,
buildKeyStroke(KeyEventConstants.KEY_CODE_SAVE, KeyEventConstants.MODIFIER_SAVE, false));
if (viewerController != null && mi != null)
viewerController.setSaveFileMenuItem(mi);
return mi;
}
public JMenuItem buildSaveAsFileMenuItem() {
JMenuItem mi = makeMenuItem(
messageBundle.getString("viewer.menu.saveAs.label"), "save",
Images.SIZE_SMALL,
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,
buildKeyStroke(KeyEventConstants.KEY_CODE_EXPORT_TEXT, KeyEventConstants.MODIFIER_EXPORT_TEXT, false));
if (viewerController != null && mi != null)
viewerController.setExportTextMenuItem(mi);
return mi;
}
public JMenuItem buildPropertiesMenuItem() {
JMenuItem mi = makeMenuItem(
messageBundle.getString("viewer.menu.documentProperties.label"), null, null,
buildKeyStroke(KeyEventConstants.KEY_CODE_DOCUMENT_PROPERTIES,
KeyEventConstants.MODIFIER_DOCUMENT_PROPERTIES));
if (viewerController != null && mi != null)
viewerController.setPropertiesMenuItem(mi);
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_SMALL,
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());
viewMenu.addSeparator();
addToMenu(viewMenu, buildPreferencesMenuItem());
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.setDeselectAllMenuItem(mi);
return mi;
}
public JMenuItem buildPreferencesMenuItem() {
JMenuItem mi = makeMenuItem(
messageBundle.getString("viewer.menu.edit.preferences.label"),
null, null, buildKeyStroke(KeyEventConstants.KEY_CODE_PREFERENCES,
KeyEventConstants.MODIFIER_PREFERENCES));
if (viewerController != null && mi != null)
viewerController.setPreferencesMenuItem(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, buildFullScreenMenuItem());
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_SMALL,
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_SMALL,
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"),
"fit_width", Images.SIZE_SMALL,
buildKeyStroke(KeyEventConstants.KEY_CODE_FIT_WIDTH, KeyEventConstants.MODIFIER_FIT_WIDTH));
if (viewerController != null && mi != null)
viewerController.setFitWidthMenuItem(mi);
return mi;
}
public JMenuItem buildFullScreenMenuItem() {
JMenuItem mi = makeMenuItem(
messageBundle.getString("viewer.menu.view.fullScreen.label"),
"fullscreen", Images.SIZE_SMALL,
buildKeyStroke(KeyEventConstants.KEY_CODE_FULL_SCREEN, KeyEventConstants.MODIFIER_FULL_SCREEN));
if (viewerController != null && mi != null)
viewerController.setFullScreenMenuItem(mi);
return mi;
}
public JMenuItem buildZoomInMenuItem() {
JMenuItem mi = makeMenuItem(
messageBundle.getString("viewer.menu.view.zoomIn.label"),
"zoom_in", Images.SIZE_SMALL,
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_SMALL,
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_SMALL,
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_SMALL,
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, buildAdvancedSearchMenuItem());
addToMenu(documentMenu, buildSearchNextMenuItem());
addToMenu(documentMenu, buildSearchPreviousMenuItem());
documentMenu.addSeparator();
addToMenu(documentMenu, buildGoToPageMenuItem());
return documentMenu;
}
public JMenuItem buildFirstPageMenuItem() {
JMenuItem mi = makeMenuItem(
messageBundle.getString("viewer.menu.document.firstPage.label"),
"first", Images.SIZE_SMALL,
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"),
"back", Images.SIZE_SMALL,
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"),
"forward", Images.SIZE_SMALL,
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"),
"last", Images.SIZE_SMALL,
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 buildAdvancedSearchMenuItem() {
final JMenuItem mi = makeMenuItem(messageBundle.getString("viewer.toolbar.search.advanced.label"), buildKeyStroke(KeyEventConstants.KEY_CODE_SEARCH, KeyEventConstants.MODIFIER_ADVANCED_SEARCH));
if (viewerController != null && mi != null) {
viewerController.setAdvancedSearchMenuItem(mi);
}
return mi;
}
public JMenuItem buildSearchNextMenuItem() {
JMenuItem mi = makeMenuItem(
messageBundle.getString("viewer.menu.document.search.next.label"),
buildKeyStroke(KeyEventConstants.KEY_CODE_SEARCH_NEXT, KeyEventConstants.MODIFIER_SEARCH_NEXT));
if (viewerController != null && mi != null)
viewerController.setSearchNextMenuItem(mi);
return mi;
}
public JMenuItem buildSearchPreviousMenuItem() {
JMenuItem mi = makeMenuItem(
messageBundle.getString("viewer.menu.document.search.previous.label"),
buildKeyStroke(KeyEventConstants.KEY_CODE_SEARCH_PREVIOUS, KeyEventConstants.MODIFIER_SEARCH_PREVIOUS));
if (viewerController != null && mi != null)
viewerController.setSearchPreviousMenuItem(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();
addToMenu(windowMenu, buildShowAnnotationPreviewMenuItem());
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;
}
public JMenuItem buildShowAnnotationPreviewMenuItem() {
JMenuItem mi = makeMenuItem(messageBundle.getString("viewer.menu.window.annotationPreview.label"), null);
mi.setMnemonic(buildMnemonic(messageBundle.getString("viewer.menu.window.annotationPreview.mnemonic").charAt(0)));
if (viewerController != null)
viewerController.setAnnotationPreviewMenuItem(mi);
return mi;
}
@SuppressWarnings("unchecked")
public void buildWindowListMenuItems(JMenu menu) {
if (viewerController != null &&
viewerController.getWindowManagementCallback() != null) {
WindowManagementCallback winMgr = viewerController.getWindowManagementCallback();
List