Class AbstractDocumentViewModel

  • All Implemented Interfaces:
    DocumentViewModel
    Direct Known Subclasses:
    DocumentViewModelImpl

    public abstract class AbstractDocumentViewModel
    extends Object
    implements DocumentViewModel

    The AbstractDocumentViewModel is responsible for keeping the state of the document view. The AbstractDocumentViewModel also stores an list of PageViewComponents who's state is update as the model changes. The AbstractDocumentViewModel can be swapped into different page views quickly and efficiently.

    Since:
    2.5
    See Also:
    DocumentViewModelImpl
    • Field Detail

      • currentDocument

        protected final Document currentDocument
      • documentViewScrollPane

        protected JScrollPane documentViewScrollPane
      • userZoom

        protected float userZoom
      • oldUserZoom

        protected float oldUserZoom
      • userRotation

        protected float userRotation
      • oldUserRotation

        protected float oldUserRotation
      • currentPageIndex

        protected int currentPageIndex
      • oldPageIndex

        protected int oldPageIndex
      • pageBoundary

        protected int pageBoundary
      • userToolModeFlag

        protected int userToolModeFlag
      • oldUserToolModeFlag

        protected int oldUserToolModeFlag
      • MAX_PAGE_SIZE_READ_AHEAD

        protected static final int MAX_PAGE_SIZE_READ_AHEAD
        See Also:
        Constant Field Values
    • Constructor Detail

      • AbstractDocumentViewModel

        public AbstractDocumentViewModel​(Document currentDocument)
    • Method Detail

      • getDocument

        public Document getDocument()
        Description copied from interface: DocumentViewModel
        Gets the PDF document object associated with this views.
        Specified by:
        getDocument in interface DocumentViewModel
        Returns:
        PDF document which is associated with this view.
      • removeFloatingAnnotationComponent

        public void removeFloatingAnnotationComponent​(AbstractAnnotationComponent annotationComponent)
      • setViewCurrentPageIndex

        public boolean setViewCurrentPageIndex​(int pageIndex)
        Description copied from interface: DocumentViewModel
        Sets the view model current page index.
        Specified by:
        setViewCurrentPageIndex in interface DocumentViewModel
        Parameters:
        pageIndex - zero based current pages page index of the document.
        Returns:
        true if the page index could be set, false otherwise.
      • getSelectedPageText

        public ArrayList<AbstractPageViewComponent> getSelectedPageText()
        Gets the list of components that have a selected state. The WeakReference must be checked to make sure the page was not disposed of for some reason by the memory manager.
        Specified by:
        getSelectedPageText in interface DocumentViewModel
        Returns:
        list of pages that are in a selected state.
      • isSelectAll

        public boolean isSelectAll()
        Gets the selected all state of the document pages view.
        Specified by:
        isSelectAll in interface DocumentViewModel
        Returns:
        true if all pages are ina selected state, false otherwise.
      • setSelectAll

        public void setSelectAll​(boolean selectAll)
        Sets the select all state of the text in the document. If true the document text is all selected; otherwise, false. This is only a flag and must be interpreted by the pages and page view components.
        Specified by:
        setSelectAll in interface DocumentViewModel
        Parameters:
        selectAll - to specify all text is selected, false to specify no text is selected
      • addSelectedPageText

        public void addSelectedPageText​(AbstractPageViewComponent pageComponent)
        Adds the specified page to selected page cache. No checking is done to make sure of selected text. The caches are used as an optimization to make sure selected text can be cleared quickly.
        Specified by:
        addSelectedPageText in interface DocumentViewModel
        Parameters:
        pageComponent - pageView component to add to list.
      • removeSelectedPageText

        public void removeSelectedPageText​(AbstractPageViewComponent pageComponent)
        Removes the specified page to selected page cache. No checking is done to make sure of selected text. The caches are used as an optimization to make sure selected text can be cleared quickly.
        Specified by:
        removeSelectedPageText in interface DocumentViewModel
        Parameters:
        pageComponent - pageView component to add to list.
      • clearSelectedPageText

        public void clearSelectedPageText()
        Clears cache used to store which pages have selected state.
        Specified by:
        clearSelectedPageText in interface DocumentViewModel
      • setViewZoom

        public boolean setViewZoom​(float viewZoom)
        Sets the zoom factor of the page visualization. A zoom factor of 1.0f is equal to 100% or actual size. A zoom factor of 0.5f is equal to 50% of the original size.
        Specified by:
        setViewZoom in interface DocumentViewModel
        Parameters:
        viewZoom - zoom factor
        Returns:
        if zoom actually changed
      • getViewZoom

        public float getViewZoom()
        Description copied from interface: DocumentViewModel
        Gets the view model zoom level.
        Specified by:
        getViewZoom in interface DocumentViewModel
        Returns:
        zoom level of this view model
      • setViewRotation

        public boolean setViewRotation​(float viewRotation)
        Description copied from interface: DocumentViewModel
        Sets the view rotation of this model.
        Specified by:
        setViewRotation in interface DocumentViewModel
        Parameters:
        viewRotation - rotation in degrees
        Returns:
        true if the view rotation was set correctly, otherwise false.
      • getViewRotation

        public float getViewRotation()
        Returns the zoom factor of the page visualization. A zoom factor of 1.0f is equal to 100% or actual size. A zoom factor of 0.5f is equal to 50% of the original size.
        Specified by:
        getViewRotation in interface DocumentViewModel
        Returns:
        zoom factor
      • setViewToolMode

        public boolean setViewToolMode​(int viewToolMode)
        Description copied from interface: DocumentViewModel
        Sets the view tool mode.
        Specified by:
        setViewToolMode in interface DocumentViewModel
        Parameters:
        viewToolMode - selected tool mode, pan, zoom and et.
        Returns:
        true if the view tool was set correctly, false otherwise.
      • isViewToolModeSelected

        public boolean isViewToolModeSelected​(int viewToolMode)
        Description copied from interface: DocumentViewModel
        Checks if the specified tool mode is set in the view model.
        Specified by:
        isViewToolModeSelected in interface DocumentViewModel
        Parameters:
        viewToolMode - tool model to check if selected.
        Returns:
        true if specified tool mode is selected, otherwise false.
      • setPageBoundary

        public void setPageBoundary​(int pageBoundary)
        Sets the page boundary used to paint a page.
        Specified by:
        setPageBoundary in interface DocumentViewModel
        Parameters:
        pageBoundary - page bounds
      • getPageBoundary

        public int getPageBoundary()
        Description copied from interface: DocumentViewModel
        Gets the page boundary used to paint document pages.
        Specified by:
        getPageBoundary in interface DocumentViewModel
        Returns:
        page boundary type as defined in the class Page.
      • getPageBounds

        public Rectangle getPageBounds​(int pageIndex)
        Description copied from interface: DocumentViewModel
        Gets the page bound of the specified page Index.
        Specified by:
        getPageBounds in interface DocumentViewModel
        Parameters:
        pageIndex - zero based page index.
        Returns:
        bounds of specified page. If page index. is not valid, null is returned.
      • setCurrentAnnotation

        public void setCurrentAnnotation​(AnnotationComponent currentAnnotation)
        Sets the current annotation. This is mainly called by the UI tools when editing and selecting page annotations.
        Specified by:
        setCurrentAnnotation in interface DocumentViewModel
        Parameters:
        currentAnnotation - annotation to make current.
      • setDocumentView

        public void setDocumentView​(DocumentView documentView)
      • setDocumentViewScrollPane

        public void setDocumentViewScrollPane​(JScrollPane documentViewScrollPane)
        Sets the parent scroll pane used by this view.
        Specified by:
        setDocumentViewScrollPane in interface DocumentViewModel
        Parameters:
        documentViewScrollPane - parent scroll pane
      • getAnnotationCareTaker

        public UndoCaretaker getAnnotationCareTaker()
        Gets annotation caretaker responsible for saving states as defined by the memento pattern.
        Specified by:
        getAnnotationCareTaker in interface DocumentViewModel
        Returns:
        document level annotation care taker.
      • addMemento

        public void addMemento​(Memento oldMementoState,
                               Memento newMementoState)
        Description copied from interface: DocumentViewModel
        Adds memento state to the care taker.
        Specified by:
        addMemento in interface DocumentViewModel
        Parameters:
        oldMementoState - original state.
        newMementoState - new state.