org.icepdf.ri.common.views
Class AbstractDocumentViewModel

java.lang.Object
  extended by org.icepdf.ri.common.views.AbstractDocumentViewModel
All Implemented Interfaces:
DocumentViewModel
Direct Known Subclasses:
DocumentViewModelImpl

public abstract class AbstractDocumentViewModel
extends java.lang.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
protected  AnnotationComponent currentAnnotation
           
protected  org.icepdf.core.pobjects.Document currentDocument
           
protected  int currentPageIndex
           
protected static int MAX_PAGE_SIZE_READ_AHEAD
           
protected  int oldPageIndex
           
protected  float oldUserRotation
           
protected  int oldUserToolModeFlag
           
protected  float oldUserZoom
           
protected  int pageBoundary
           
protected  java.util.List<AbstractPageViewComponent> pageComponents
           
protected  UndoCaretaker undoCaretaker
           
protected  float userRotation
           
protected  int userToolModeFlag
           
protected  float userZoom
           
 
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_SELECTION, 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
AbstractDocumentViewModel(org.icepdf.core.pobjects.Document currentDocument)
           
 
Method Summary
 void addMemento(org.icepdf.core.Memento oldMementoState, org.icepdf.core.Memento newMementoState)
          Adds memento state to the care taker.
 void addSelectedPageText(AbstractPageViewComponent pageComponent)
          Adds the specified page to selected page cache.
protected abstract  AbstractPageViewComponent buildPageViewComponent(DocumentViewModel documentViewModel, org.icepdf.core.pobjects.PageTree pageTree, int pageIndex, javax.swing.JScrollPane parentScrollPane, int width, int height)
           
 void clearSelectedPageText()
          Clears cache used to store which pages have selected state.
 void dispose()
          Free resources associated with this model.
 UndoCaretaker getAnnotationCareTaker()
          Gets annotation caretaker responsible for saving states as defined by the memento pattern.
 AnnotationComponent getCurrentAnnotation()
          Gets the currently selected annotation in the document model.
 org.icepdf.core.pobjects.Document getDocument()
          Gets the PDF document object associated with this views.
 int getPageBoundary()
          Gets the page boundary used to paint document pages.
 java.awt.Rectangle getPageBounds(int pageIndex)
          Gets the page bound of the specified page Index.
 java.util.List<AbstractPageViewComponent> getPageComponents()
          Gets the page components associated with this view model.
 java.util.ArrayList<AbstractPageViewComponent> getSelectedPageText()
          Gets the list of components that have a selected state.
 int getViewCurrentPageIndex()
          Gets the current page index represented in this model.
 float getViewRotation()
          Returns the zoom factor of the page visualization.
 int getViewToolMode()
          Gets the tool mode.
 float getViewZoom()
          Gets the view model zoom level.
 boolean isSelectAll()
          Gets the selected all state of the document pages view.
 boolean isViewToolModeSelected(int viewToolMode)
          Checks if the specified tool mode is set in the view model.
 void removeSelectedPageText(AbstractPageViewComponent pageComponent)
          Removes the specified page to selected page cache.
 void setCurrentAnnotation(AnnotationComponent currentAnnotation)
          Sets the current annotation.
 void setPageBoundary(int pageBoundary)
          Sets the page boundary used to paint a page.
 void setSelectAll(boolean selectAll)
          Sets the select all state of the text in the document.
 boolean setViewCurrentPageIndex(int pageIndex)
          Sets the view model current page index.
 boolean setViewRotation(float viewRotation)
          Sets the view rotation of this model.
 boolean setViewToolMode(int viewToolMode)
          Sets the view tool mode.
 boolean setViewZoom(float viewZoom)
          Sets the zoom factor of the page visualization.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

currentDocument

protected org.icepdf.core.pobjects.Document currentDocument

pageComponents

protected java.util.List<AbstractPageViewComponent> pageComponents

undoCaretaker

protected 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(org.icepdf.core.pobjects.Document currentDocument)
Method Detail

buildPageViewComponent

protected abstract AbstractPageViewComponent buildPageViewComponent(DocumentViewModel documentViewModel,
                                                                    org.icepdf.core.pobjects.PageTree pageTree,
                                                                    int pageIndex,
                                                                    javax.swing.JScrollPane parentScrollPane,
                                                                    int width,
                                                                    int height)

getDocument

public org.icepdf.core.pobjects.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.

getPageComponents

public java.util.List<AbstractPageViewComponent> getPageComponents()
Description copied from interface: DocumentViewModel
Gets the page components associated with this view model.

Specified by:
getPageComponents in interface DocumentViewModel
Returns:
vector of page components.

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.

getViewCurrentPageIndex

public int getViewCurrentPageIndex()
Description copied from interface: DocumentViewModel
Gets the current page index represented in this model.

Specified by:
getViewCurrentPageIndex in interface DocumentViewModel
Returns:
zero based page page index.

getSelectedPageText

public java.util.ArrayList<AbstractPageViewComponent> getSelectedPageText()
Gets the list of components that have a selected state. The WeakReference must be check to make sure the page was not disposed of for for some reason by the 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 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 is 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 is 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.

getViewToolMode

public int getViewToolMode()
Description copied from interface: DocumentViewModel
Gets the tool mode.

Specified by:
getViewToolMode in interface DocumentViewModel
Returns:
tool mode.

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 java.awt.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.

dispose

public void dispose()
Description copied from interface: DocumentViewModel
Free resources associated with this model.

Specified by:
dispose in interface DocumentViewModel

getCurrentAnnotation

public AnnotationComponent getCurrentAnnotation()
Gets the currently selected annotation in the document model.

Specified by:
getCurrentAnnotation in interface DocumentViewModel
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:
setCurrentAnnotation in interface DocumentViewModel
Parameters:
currentAnnotation - annotation to make current.

getAnnotationCareTaker

public UndoCaretaker getAnnotationCareTaker()
Gets annotation caretaker responsible for saving states as defined by the memento pattern.

Returns:
document level annotation care taker.

addMemento

public void addMemento(org.icepdf.core.Memento oldMementoState,
                       org.icepdf.core.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.