private void reflectStateInComponents() {
        boolean opened = document != null;
        int nPages = (getPageTree() != null) ? getPageTree().getNumberOfPages() : 0;

        // get security information for printing and text extraction
        boolean canPrint = havePermissionToPrint();
        boolean canExtract = havePermissionToExtractContent();
        boolean canModify = havePermissionToModifyDocument();

        reflectPageChangeInComponents();

        // menu items.
        setEnabled(closeMenuItem, opened);
        setEnabled(saveAsFileMenuItem, opened);
        setEnabled(exportTextMenuItem, opened && canExtract);
        // Exporting to SVG creates output as if we printed,
        //   which is not the same as extracting text
        setEnabled(exportSVGMenuItem, opened && canPrint);
        setEnabled(permissionsMenuItem, opened);
        setEnabled(informationMenuItem, opened);
        // Printer setup is global to all PDFs, so don't limit it by this one PDF
        setEnabled(printSetupMenuItem, opened && canPrint);
        setEnabled(printMenuItem, opened && canPrint);

        // set initial sate for undo/redo edit, afterwards state is set by
        // valueChange events depending on tool selection.
        setEnabled(undoMenuItem, false);
        setEnabled(redoMenuItem, false);
        setEnabled(copyMenuItem, false);
        setEnabled(deleteMenuItem, false);

        setEnabled(selectAllMenuItem, opened && canExtract);
        setEnabled(deselectAllMenuItem, false);


        setEnabled(fitActualSizeMenuItem, opened);
        setEnabled(fitPageMenuItem, opened);
        setEnabled(fitWidthMenuItem, opened);

        setEnabled(zoomInMenuItem, opened);
        setEnabled(zoomOutMenuItem, opened);

        setEnabled(rotateLeftMenuItem, opened);
        setEnabled(rotateRightMenuItem, opened);

//        setEnabled(facingPageViewContinuousMenuItem , opened );
//        setEnabled(singlePageViewContinuousMenuItem , opened );
//        setEnabled(facingPageViewNonContinuousMenuItem , opened );
//        setEnabled(singlePageViewNonContinuousMenuItem , opened );

        setEnabled(fitPageMenuItem, opened);
        setEnabled(fitWidthMenuItem, opened);
        if (showHideToolBarMenuItem != null) {
            boolean vis = (completeToolBar != null) && completeToolBar.isVisible();
            showHideToolBarMenuItem.setText(
                    vis ? messageBundle.getString("viewer.toolbar.hideToolBar.label") :
                            messageBundle.getString("viewer.toolbar.showToolBar.label"));
        }
        setEnabled(showHideToolBarMenuItem, completeToolBar != null);
        if (showHideUtilityPaneMenuItem != null) {
            boolean vis = isUtilityPaneVisible();
            showHideUtilityPaneMenuItem.setText(
                    (opened && vis) ?
                            messageBundle.getString("viewer.toolbar.hideUtilityPane.label") :
                            messageBundle.getString("viewer.toolbar.showUtilityPane.label"));
        }
        setEnabled(showHideUtilityPaneMenuItem, opened && utilityTabbedPane != null);
        setEnabled(searchMenuItem, opened && searchPanel != null);
        setEnabled(goToPageMenuItem, opened && nPages > 1);

        setEnabled(saveAsFileButton, opened);
        setEnabled(printButton, opened && canPrint);
        setEnabled(searchButton, opened && searchPanel != null);
        setEnabled(showHideUtilityPaneButton, opened && utilityTabbedPane != null);
        setEnabled(currentPageNumberTextField, opened && nPages > 1);
        if (numberOfPagesLabel != null) {

            Object[] messageArguments = new Object[]{String.valueOf(nPages)};
            MessageFormat formatter =
                    new MessageFormat(
                            messageBundle.getString("viewer.toolbar.pageIndicator"));
            String numberOfPages = formatter.format(messageArguments);

            numberOfPagesLabel.setText(
                    opened ? numberOfPages : "");
        }
        setEnabled(zoomInButton, opened);
        setEnabled(zoomOutButton, opened);
        setEnabled(zoomComboBox, opened);
        setEnabled(fitActualSizeButton, opened);
        setEnabled(fitHeightButton, opened);
        setEnabled(fitWidthButton, opened);
        setEnabled(rotateLeftButton, opened);
        setEnabled(rotateRightButton, opened);
        setEnabled(panToolButton, opened);
        setEnabled(zoomInToolButton, opened);
        setEnabled(zoomOutToolButton, opened);
        setEnabled(textSelectToolButton, opened && canExtract);
        setEnabled(selectToolButton, opened && canModify);
        setEnabled(linkAnnotationToolButton, opened && canModify);
        setEnabled(fontEngineButton, opened);
        setEnabled(facingPageViewContinuousButton, opened);
        setEnabled(singlePageViewContinuousButton, opened);
        setEnabled(facingPageViewNonContinuousButton, opened);
        setEnabled(singlePageViewNonContinuousButton, opened);

        if (opened) {
            reflectZoomInZoomComboBox();
            reflectFitInFitButtons();
            reflectDocumentViewModeInButtons();
            reflectToolInToolButtons();
        }
    }