public void actionPerformed(ActionEvent event) {
        Object source = event.getSource();
        if (source == null)
            return;

        boolean cancelSetFocus = false;

        try {
            if (source == openFileMenuItem || source == openFileButton) {
                Runnable doSwingWork = new Runnable() {
                    public void run() {
                        openFile();
                    }
                };
                SwingUtilities.invokeLater(doSwingWork);
            } else if (source == openURLMenuItem) {
                Runnable doSwingWork = new Runnable() {
                    public void run() {
                        openURL();
                    }
                };
                SwingUtilities.invokeLater(doSwingWork);
            } else if (source == closeMenuItem) {
                closeDocument();
            } else if (source == saveAsFileMenuItem || source == saveAsFileButton) {
                Runnable doSwingWork = new Runnable() {
                    public void run() {
                        saveFile();
                    }
                };
                SwingUtilities.invokeLater(doSwingWork);
            } else if (source == exportTextMenuItem) {
                Runnable doSwingWork = new Runnable() {
                    public void run() {
                        exportText();
                    }
                };
                SwingUtilities.invokeLater(doSwingWork);
            } else if (source == exportSVGMenuItem) {
                Runnable doSwingWork = new Runnable() {
                    public void run() {
                        exportSVG();
                    }
                };
                SwingUtilities.invokeLater(doSwingWork);
            } else if (source == exitMenuItem) {
                exit();
            } else if (source == showHideToolBarMenuItem) {
                toggleToolBarVisibility();
            } else if (source == minimiseAllMenuItem) {
                Runnable doSwingWork = new Runnable() {
                    public void run() {
                        SwingController sc = SwingController.this;
                        if (sc.getWindowManagementCallback() != null)
                            sc.getWindowManagementCallback().minimiseAllWindows();
                    }
                };
                SwingUtilities.invokeLater(doSwingWork);
            } else if (source == bringAllToFrontMenuItem) {
                Runnable doSwingWork = new Runnable() {
                    public void run() {
                        SwingController sc = SwingController.this;
                        if (sc.getWindowManagementCallback() != null)
                            sc.getWindowManagementCallback().bringAllWindowsToFront(sc);
                    }
                };
                SwingUtilities.invokeLater(doSwingWork);
            } else if (windowListMenuItems != null && windowListMenuItems.contains(source)) {
                final int index = windowListMenuItems.indexOf(source);
                Runnable doSwingWork = new Runnable() {
                    public void run() {
                        SwingController sc = SwingController.this;
                        if (sc.getWindowManagementCallback() != null) {
                            sc.getWindowManagementCallback().bringWindowToFront(index);
                        }
                    }
                };
                SwingUtilities.invokeLater(doSwingWork);
            } else if (source == aboutMenuItem) {
                showAboutDialog();
            } else if (document != null) {
                // get document previous icon
                int documentIcon = getDocumentViewToolMode();
                try {
                    // set cursor for document view
                    setDisplayTool(DocumentViewModelImpl.DISPLAY_TOOL_WAIT);

                    if (source == permissionsMenuItem) {
                        Runnable doSwingWork = new Runnable() {
                            public void run() {
                                showDocumentPermissionsDialog();
                            }
                        };
                        SwingUtilities.invokeLater(doSwingWork);
                    } else if (source == informationMenuItem) {
                        Runnable doSwingWork = new Runnable() {
                            public void run() {
                                showDocumentInformationDialog();
                            }
                        };
                        SwingUtilities.invokeLater(doSwingWork);
                    } else if (source == printSetupMenuItem) {
                        Runnable doSwingWork = new Runnable() {
                            public void run() {
                                showPrintSetupDialog();
                            }
                        };
                        SwingUtilities.invokeLater(doSwingWork);
                    } else if (source == printMenuItem) {
                        print(true);
                    } else if (source == printButton) {
                        print(true); // Used to be 'false' PDF-86
                    } else if (source == undoMenuItem) {
                        documentViewController.undo();
                        // refresh undo buttons.
                        reflectUndoCommands();
                    } else if (source == redoMenuItem) {
                        documentViewController.redo();
                        reflectUndoCommands();
                    } else if (source == deleteMenuItem) {
                        documentViewController.deleteCurrentAnnotation();
                        reflectUndoCommands();
                    } else if (source == copyMenuItem) {
                        if (document != null &&
                                havePermissionToExtractContent() &&
                                !(documentViewController.getDocumentViewModel().isSelectAll() &&
                                        document.getNumberOfPages() > MAX_SELECT_ALL_PAGE_COUNT)) {
                            // get the text.
                            StringSelection stringSelection = new StringSelection(
                                    documentViewController.getSelectedText());
                            Toolkit.getDefaultToolkit().getSystemClipboard().
                                    setContents(stringSelection, null);
                        } else {
                            Runnable doSwingWork = new Runnable() {
                                public void run() {
                                    org.icepdf.ri.util.Resources.showMessageDialog(
                                            viewer,
                                            JOptionPane.INFORMATION_MESSAGE,
                                            messageBundle,
                                            "viewer.dialog.information.copyAll.title",
                                            "viewer.dialog.information.copyAll.msg",
                                            MAX_SELECT_ALL_PAGE_COUNT);
                                }
                            };
                            SwingUtilities.invokeLater(doSwingWork);
                        }
                    } else if (source == selectAllMenuItem) {
                        // check to see how many page are in the document
                        documentViewController.selectAllText();
                    } else if (source == deselectAllMenuItem) {
                        documentViewController.clearSelectedText();
                    } else if (source == fitActualSizeMenuItem) {
                        // Clicking only seems to invoke an itemStateChanged() event,
                        //  so this is probably redundant
                        setPageFitMode(org.icepdf.core.views.DocumentViewController.PAGE_FIT_ACTUAL_SIZE, false);
                    } else if (source == fitPageMenuItem) {
                        // Clicking only seems to invoke an itemStateChanged() event
                        //  so this is probably redundant
                        setPageFitMode(org.icepdf.core.views.DocumentViewController.PAGE_FIT_WINDOW_HEIGHT, false);
                    } else if (source == fitWidthMenuItem) {
                        // Clicking only seems to invoke an itemStateChanged() event
                        //  so this is probably redundant
                        setPageFitMode(org.icepdf.core.views.DocumentViewController.PAGE_FIT_WINDOW_WIDTH, false);
                    } else if (source == zoomInMenuItem || source == zoomInButton) {
                        zoomIn();
                    } else if (source == zoomOutMenuItem || source == zoomOutButton) {
                        zoomOut();
                    } else if (source == rotateLeftMenuItem || source == rotateLeftButton) {
                        rotateLeft();
                    } else if (source == rotateRightMenuItem || source == rotateRightButton) {
                        rotateRight();
                    } else if (source == showHideUtilityPaneMenuItem || source == showHideUtilityPaneButton) {
                        toggleUtilityPaneVisibility();
                    } else if (source == firstPageMenuItem || source == firstPageButton) {
                        showPage(0);
                    } else if (source == previousPageMenuItem || source == previousPageButton) {
                        DocumentView documentView = documentViewController.getDocumentView();
                        goToDeltaPage(-documentView.getPreviousPageIncrement());
                    } else if (source == nextPageMenuItem || source == nextPageButton) {
                        DocumentView documentView = documentViewController.getDocumentView();
                        goToDeltaPage(documentView.getNextPageIncrement());
                    } else if (source == lastPageMenuItem || source == lastPageButton) {
                        showPage(getPageTree().getNumberOfPages() - 1);
                    } else if (source == searchMenuItem || source == searchButton) {
                        cancelSetFocus = true;
                        showSearchPanel();
                    } else if (source == goToPageMenuItem) {
                        showPageSelectionDialog();
                    } else if (source == currentPageNumberTextField) {
                        showPageFromTextField();
                    } else {
                        logger.log(Level.FINE, "Unknown action event: " + source.toString());
                    }
                } finally {
                    // set view pane back to previous icon
                    setDisplayTool(documentIcon);
                }
            }
        } catch (Exception e) {
            final Exception f = e;
            Runnable doSwingWork = new Runnable() {
                public void run() {
                    org.icepdf.ri.util.Resources.showMessageDialog(
                            viewer,
                            JOptionPane.INFORMATION_MESSAGE,
                            messageBundle,
                            "viewer.dialog.error.exception.title",
                            "viewer.dialog.error.exception.msg",
                            f.getMessage());
                }
            };
            SwingUtilities.invokeLater(doSwingWork);
            logger.log(Level.FINE, "Error processing action event.", e);
        }

        if (!cancelSetFocus) {
            // setup focus to ensure page up and page down keys work
            documentViewController.requestViewFocusInWindow();
        }
    }