- java.lang.Object
-
- org.icepdf.ri.common.views.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 Summary
Fields Modifier and Type Field Description protected AnnotationComponentcurrentAnnotationprotected DocumentcurrentDocumentprotected intcurrentPageIndexprotected DocumentViewdocumentViewprotected HashMap<AbstractPageViewComponent,ArrayList<PageViewAnnotationComponent>>documentViewAnnotationComponentsprotected JScrollPanedocumentViewScrollPaneprotected static intMAX_PAGE_SIZE_READ_AHEADprotected intoldPageIndexprotected floatoldUserRotationprotected intoldUserToolModeFlagprotected floatoldUserZoomprotected intpageBoundaryprotected List<AbstractPageViewComponent>pageComponentsprotected UndoCaretakerundoCaretakerprotected floatuserRotationprotected intuserToolModeFlagprotected floatuserZoom-
Fields inherited from interface org.icepdf.ri.common.views.DocumentViewModel
DISPLAY_TOOL_CIRCLE_ANNOTATION, DISPLAY_TOOL_FREE_TEXT_ANNOTATION, DISPLAY_TOOL_HIGHLIGHT_ANNOTATION, DISPLAY_TOOL_INK_ANNOTATION, DISPLAY_TOOL_LINE_ANNOTATION, DISPLAY_TOOL_LINE_ARROW_ANNOTATION, DISPLAY_TOOL_LINK_ANNOTATION, DISPLAY_TOOL_NONE, DISPLAY_TOOL_PAN, DISPLAY_TOOL_REDACTION_ANNOTATION, DISPLAY_TOOL_SELECTION, DISPLAY_TOOL_SIGNATURE_ANNOTATION, DISPLAY_TOOL_SQUARE_ANNOTATION, DISPLAY_TOOL_SQUIGGLY_ANNOTATION, DISPLAY_TOOL_STRIKEOUT_ANNOTATION, DISPLAY_TOOL_TEXT_ANNOTATION, DISPLAY_TOOL_TEXT_SELECTION, DISPLAY_TOOL_UNDERLINE_ANNOTATION, DISPLAY_TOOL_WAIT, DISPLAY_TOOL_ZOOM_DYNAMIC, DISPLAY_TOOL_ZOOM_IN, DISPLAY_TOOL_ZOOM_OUT
-
-
Constructor Summary
Constructors Constructor Description AbstractDocumentViewModel(Document currentDocument)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidaddDocumentViewAnnotationComponent(AbstractPageViewComponent pageViewComponent, PageViewAnnotationComponent annotationComponent)Adds an annotation component the list of floating annotation components that are painted in the DocumentView.voidaddMemento(Memento oldMementoState, Memento newMementoState)Adds memento state to the care taker.voidaddSelectedPageText(AbstractPageViewComponent pageComponent)Adds the specified page to selected page cache.protected abstract AbstractPageViewComponentbuildPageViewComponent(DocumentViewModel documentViewModel, PageTree pageTree, int pageIndex, int width, int height)voidclearSelectedPageText()Clears cache used to store which pages have selected state.voiddispose()Free resources associated with this model.UndoCaretakergetAnnotationCareTaker()Gets annotation caretaker responsible for saving states as defined by the memento pattern.AnnotationComponentgetCurrentAnnotation()Gets the currently selected annotation in the document model.DocumentgetDocument()Gets the PDF document object associated with this views.DocumentViewgetDocumentView()HashMap<AbstractPageViewComponent,ArrayList<PageViewAnnotationComponent>>getDocumentViewAnnotationComponents()ArrayList<PageViewAnnotationComponent>getDocumentViewAnnotationComponents(AbstractPageViewComponent pageViewComponent)Gets all the annotation components that float in the DocumentView and are not bound by page dimensions.JScrollPanegetDocumentViewScrollPane()Get the scroll pane used to contain the page view components.intgetPageBoundary()Gets the page boundary used to paint document pages.RectanglegetPageBounds(int pageIndex)Gets the page bound of the specified page Index.List<AbstractPageViewComponent>getPageComponents()Gets the page components associated with this view model.ArrayList<AbstractPageViewComponent>getSelectedPageText()Gets the list of components that have a selected state.intgetViewCurrentPageIndex()Gets the current page index represented in this model.floatgetViewRotation()Returns the zoom factor of the page visualization.intgetViewToolMode()Gets the tool mode.floatgetViewZoom()Gets the view model zoom level.booleanisSelectAll()Gets the selected all state of the document pages view.booleanisViewToolModeSelected(int viewToolMode)Checks if the specified tool mode is set in the view model.voidremoveAllFloatingAnnotationComponent(AbstractPageViewComponent pageViewComponent)voidremoveDocumentViewAnnotationComponent(DocumentView parentDocumentView, AbstractPageViewComponent pageViewComponent, PageViewAnnotationComponent annotationComponent)Removes an annotation component the list of floating annotation components that are painted in the DocumentView.voidremoveFloatingAnnotationComponent(AbstractAnnotationComponent annotationComponent)voidremoveSelectedPageText(AbstractPageViewComponent pageComponent)Removes the specified page to selected page cache.voidsetCurrentAnnotation(AnnotationComponent currentAnnotation)Sets the current annotation.voidsetDocumentView(DocumentView documentView)voidsetDocumentViewScrollPane(JScrollPane documentViewScrollPane)Sets the parent scroll pane used by this view.voidsetPageBoundary(int pageBoundary)Sets the page boundary used to paint a page.voidsetSelectAll(boolean selectAll)Sets the select all state of the text in the document.booleansetViewCurrentPageIndex(int pageIndex)Sets the view model current page index.booleansetViewRotation(float viewRotation)Sets the view rotation of this model.booleansetViewToolMode(int viewToolMode)Sets the view tool mode.booleansetViewZoom(float viewZoom)Sets the zoom factor of the page visualization.
-
-
-
Field Detail
-
currentDocument
protected final Document currentDocument
-
documentView
protected DocumentView documentView
-
pageComponents
protected List<AbstractPageViewComponent> pageComponents
-
documentViewAnnotationComponents
protected HashMap<AbstractPageViewComponent,ArrayList<PageViewAnnotationComponent>> documentViewAnnotationComponents
-
documentViewScrollPane
protected JScrollPane documentViewScrollPane
-
undoCaretaker
protected final UndoCaretaker undoCaretaker
-
currentAnnotation
protected AnnotationComponent currentAnnotation
-
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
-
buildPageViewComponent
protected abstract AbstractPageViewComponent buildPageViewComponent(DocumentViewModel documentViewModel, PageTree pageTree, int pageIndex, int width, int height)
-
getDocument
public Document getDocument()
Description copied from interface:DocumentViewModelGets the PDF document object associated with this views.- Specified by:
getDocumentin interfaceDocumentViewModel- Returns:
- PDF document which is associated with this view.
-
getPageComponents
public List<AbstractPageViewComponent> getPageComponents()
Description copied from interface:DocumentViewModelGets the page components associated with this view model.- Specified by:
getPageComponentsin interfaceDocumentViewModel- Returns:
- vector of page components.
-
getDocumentViewAnnotationComponents
public HashMap<AbstractPageViewComponent,ArrayList<PageViewAnnotationComponent>> getDocumentViewAnnotationComponents()
- Specified by:
getDocumentViewAnnotationComponentsin interfaceDocumentViewModel
-
getDocumentViewAnnotationComponents
public ArrayList<PageViewAnnotationComponent> getDocumentViewAnnotationComponents(AbstractPageViewComponent pageViewComponent)
Description copied from interface:DocumentViewModelGets all the annotation components that float in the DocumentView and are not bound by page dimensions.- Specified by:
getDocumentViewAnnotationComponentsin interfaceDocumentViewModel- Returns:
- list of annotation components that should be added the document view
-
addDocumentViewAnnotationComponent
public void addDocumentViewAnnotationComponent(AbstractPageViewComponent pageViewComponent, PageViewAnnotationComponent annotationComponent)
Description copied from interface:DocumentViewModelAdds an annotation component the list of floating annotation components that are painted in the DocumentView.- Specified by:
addDocumentViewAnnotationComponentin interfaceDocumentViewModelannotationComponent- annotation component to add
-
removeDocumentViewAnnotationComponent
public void removeDocumentViewAnnotationComponent(DocumentView parentDocumentView, AbstractPageViewComponent pageViewComponent, PageViewAnnotationComponent annotationComponent)
Description copied from interface:DocumentViewModelRemoves an annotation component the list of floating annotation components that are painted in the DocumentView.- Specified by:
removeDocumentViewAnnotationComponentin interfaceDocumentViewModelannotationComponent- annotation component to remove
-
removeAllFloatingAnnotationComponent
public void removeAllFloatingAnnotationComponent(AbstractPageViewComponent pageViewComponent)
- Specified by:
removeAllFloatingAnnotationComponentin interfaceDocumentViewModel
-
removeFloatingAnnotationComponent
public void removeFloatingAnnotationComponent(AbstractAnnotationComponent annotationComponent)
-
setViewCurrentPageIndex
public boolean setViewCurrentPageIndex(int pageIndex)
Description copied from interface:DocumentViewModelSets the view model current page index.- Specified by:
setViewCurrentPageIndexin interfaceDocumentViewModel- Parameters:
pageIndex- zero based current pages page index of the document.- Returns:
- true if the page index could be set, false otherwise.
-
getViewCurrentPageIndex
public int getViewCurrentPageIndex()
Description copied from interface:DocumentViewModelGets the current page index represented in this model.- Specified by:
getViewCurrentPageIndexin interfaceDocumentViewModel- Returns:
- zero based page page index.
-
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:
getSelectedPageTextin interfaceDocumentViewModel- 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:
isSelectAllin interfaceDocumentViewModel- 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:
setSelectAllin interfaceDocumentViewModel- 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:
addSelectedPageTextin interfaceDocumentViewModel- 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:
removeSelectedPageTextin interfaceDocumentViewModel- Parameters:
pageComponent- pageView component to add to list.
-
clearSelectedPageText
public void clearSelectedPageText()
Clears cache used to store which pages have selected state.- Specified by:
clearSelectedPageTextin interfaceDocumentViewModel
-
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:
setViewZoomin interfaceDocumentViewModel- Parameters:
viewZoom- zoom factor- Returns:
- if zoom actually changed
-
getViewZoom
public float getViewZoom()
Description copied from interface:DocumentViewModelGets the view model zoom level.- Specified by:
getViewZoomin interfaceDocumentViewModel- Returns:
- zoom level of this view model
-
setViewRotation
public boolean setViewRotation(float viewRotation)
Description copied from interface:DocumentViewModelSets the view rotation of this model.- Specified by:
setViewRotationin interfaceDocumentViewModel- 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:
getViewRotationin interfaceDocumentViewModel- Returns:
- zoom factor
-
setViewToolMode
public boolean setViewToolMode(int viewToolMode)
Description copied from interface:DocumentViewModelSets the view tool mode.- Specified by:
setViewToolModein interfaceDocumentViewModel- Parameters:
viewToolMode- selected tool mode, pan, zoom and et.- Returns:
- true if the view tool was set correctly, false otherwise.
-
getViewToolMode
public int getViewToolMode()
Description copied from interface:DocumentViewModelGets the tool mode.- Specified by:
getViewToolModein interfaceDocumentViewModel- Returns:
- tool mode.
-
isViewToolModeSelected
public boolean isViewToolModeSelected(int viewToolMode)
Description copied from interface:DocumentViewModelChecks if the specified tool mode is set in the view model.- Specified by:
isViewToolModeSelectedin interfaceDocumentViewModel- 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:
setPageBoundaryin interfaceDocumentViewModel- Parameters:
pageBoundary- page bounds
-
getPageBoundary
public int getPageBoundary()
Description copied from interface:DocumentViewModelGets the page boundary used to paint document pages.- Specified by:
getPageBoundaryin interfaceDocumentViewModel- Returns:
- page boundary type as defined in the class Page.
-
getPageBounds
public Rectangle getPageBounds(int pageIndex)
Description copied from interface:DocumentViewModelGets the page bound of the specified page Index.- Specified by:
getPageBoundsin interfaceDocumentViewModel- Parameters:
pageIndex- zero based page index.- Returns:
- bounds of specified page. If page index. is not valid, null is returned.
-
dispose
public void dispose()
Description copied from interface:DocumentViewModelFree resources associated with this model.- Specified by:
disposein interfaceDocumentViewModel
-
getCurrentAnnotation
public AnnotationComponent getCurrentAnnotation()
Gets the currently selected annotation in the document model.- Specified by:
getCurrentAnnotationin interfaceDocumentViewModel- Returns:
- currently selected annotation, null if there is none.
-
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:
setCurrentAnnotationin interfaceDocumentViewModel- Parameters:
currentAnnotation- annotation to make current.
-
getDocumentView
public DocumentView getDocumentView()
-
setDocumentView
public void setDocumentView(DocumentView documentView)
-
getDocumentViewScrollPane
public JScrollPane getDocumentViewScrollPane()
Get the scroll pane used to contain the page view components.- Specified by:
getDocumentViewScrollPanein interfaceDocumentViewModel- Returns:
- parent page view scroll pane.
-
setDocumentViewScrollPane
public void setDocumentViewScrollPane(JScrollPane documentViewScrollPane)
Sets the parent scroll pane used by this view.- Specified by:
setDocumentViewScrollPanein interfaceDocumentViewModel- Parameters:
documentViewScrollPane- parent scroll pane
-
getAnnotationCareTaker
public UndoCaretaker getAnnotationCareTaker()
Gets annotation caretaker responsible for saving states as defined by the memento pattern.- Specified by:
getAnnotationCareTakerin interfaceDocumentViewModel- Returns:
- document level annotation care taker.
-
addMemento
public void addMemento(Memento oldMementoState, Memento newMementoState)
Description copied from interface:DocumentViewModelAdds memento state to the care taker.- Specified by:
addMementoin interfaceDocumentViewModel- Parameters:
oldMementoState- original state.newMementoState- new state.
-
-