org.icepdf.ri.common.tools
Class TextSelection

java.lang.Object
  extended by org.icepdf.ri.common.tools.CommonToolHandler
      extended by org.icepdf.ri.common.tools.SelectionBoxHandler
          extended by org.icepdf.ri.common.tools.TextSelection
Direct Known Subclasses:
TextSelectionPageHandler, TextSelectionViewHandler

public class TextSelection
extends SelectionBoxHandler

TextSelection is a utility class that captures most of the work needed to do basic text, word and line selection.


Field Summary
protected  int bottomMargin
           
protected  java.awt.geom.Rectangle2D bottomMarginExclusion
           
protected static boolean enableMarginExclusion
           
protected static boolean enableMarginExclusionBorder
           
protected  java.awt.Point lastMouseLocation
           
protected  java.awt.Point lastMousePressedLocation
           
protected static java.util.logging.Logger logger
           
 int selectedCount
           
protected  int topMargin
           
protected  java.awt.geom.Rectangle2D topMarginExclusion
           
 
Fields inherited from class org.icepdf.ri.common.tools.SelectionBoxHandler
currentRect, dash1, previousRectDrawn, rectToDraw, selectionBoxColour, stroke
 
Fields inherited from class org.icepdf.ri.common.tools.CommonToolHandler
documentViewController, documentViewModel, pageViewComponent
 
Constructor Summary
TextSelection(DocumentViewController documentViewController, AbstractPageViewComponent pageViewComponent, DocumentViewModel documentViewModel)
           
 
Method Summary
protected  void calculateTextSelectionExclusion(java.awt.geom.AffineTransform pageTransform)
           
 void clearSelection()
           
 void clearSelectionState()
           
protected  void lineSelectHandler(org.icepdf.core.pobjects.Page currentPage, java.awt.Point mouseLocation)
          Utility for selecting a LineText which is usually a sentence in the document.
protected  void multiLineSelectHandler(AbstractPageViewComponent pageViewComponent, java.awt.Point mouseLocation, boolean isDown, boolean isLocalDown, boolean isMovingRight)
          Entry point for multiline text selection.
static void paintSelectedText(java.awt.Graphics g, AbstractPageViewComponent pageViewComponent, DocumentViewModel documentViewModel)
          Paints any text that is selected in the page wrapped by a pageViewComponent.
protected  void paintTextBounds(java.awt.Graphics g)
          Utility for painting text bounds.
 void selection(java.awt.Point dragPoint, AbstractPageViewComponent pageViewComponent, boolean isDown, boolean isMovingRight)
           
 void selectionEnd(java.awt.Point endPoint, AbstractPageViewComponent pageViewComponent)
          Selection ended so we want to stop record the position and update the selection.
 void selectionIcon(java.awt.Point mouseLocation, AbstractPageViewComponent pageViewComponent)
           
 void selectionStart(java.awt.Point startPoint, AbstractPageViewComponent pageViewComponent, boolean isFirst)
          Selection started so we want to record the position and update the selection rectangle.
 void setBottomMargin(int bottomMargin)
          Sets the bottom margin used to define an exclusion zone for text selection.
 void setSelectionRectangle(java.awt.Point cursorLocation, java.awt.Rectangle selection)
           
 void setTopMargin(int topMargin)
          Sets the top margin used to define an exclusion zone for text selection.
 void wordLineSelection(int clickCount, java.awt.Point clickPoint, AbstractPageViewComponent pageViewComponent)
          Handles double and triple left mouse clicks to select a word or line of text respectively.
protected  void wordSelectHandler(org.icepdf.core.pobjects.Page currentPage, java.awt.Point mouseLocation)
          Utility for selecting multiple lines via rectangle like tool.
 
Methods inherited from class org.icepdf.ri.common.tools.SelectionBoxHandler
clearRectangle, getCurrentRect, getRectToDraw, isOverPageComponent, paintSelectionBox, resetRectangle, setCurrentRect, setRectToDraw, setSelectionSize, updateDrawableRect, updateSelectionSize
 
Methods inherited from class org.icepdf.ri.common.tools.CommonToolHandler
convertMouseToPageSpace, convertRectangleToPageSpace, convertToPageSpace, convertToPageSpace, getPageTransform, getPageTransform
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected static final java.util.logging.Logger logger

selectedCount

public int selectedCount

lastMousePressedLocation

protected java.awt.Point lastMousePressedLocation

lastMouseLocation

protected java.awt.Point lastMouseLocation

topMargin

protected int topMargin

bottomMargin

protected int bottomMargin

enableMarginExclusion

protected static boolean enableMarginExclusion

enableMarginExclusionBorder

protected static boolean enableMarginExclusionBorder

topMarginExclusion

protected java.awt.geom.Rectangle2D topMarginExclusion

bottomMarginExclusion

protected java.awt.geom.Rectangle2D bottomMarginExclusion
Constructor Detail

TextSelection

public TextSelection(DocumentViewController documentViewController,
                     AbstractPageViewComponent pageViewComponent,
                     DocumentViewModel documentViewModel)
Method Detail

wordLineSelection

public void wordLineSelection(int clickCount,
                              java.awt.Point clickPoint,
                              AbstractPageViewComponent pageViewComponent)
Handles double and triple left mouse clicks to select a word or line of text respectively.

Parameters:
clickCount - number of mouse clicks to interpret for line or word selection.
clickPoint - point that mouse was clicked.

selectionStart

public void selectionStart(java.awt.Point startPoint,
                           AbstractPageViewComponent pageViewComponent,
                           boolean isFirst)
Selection started so we want to record the position and update the selection rectangle.

Parameters:
startPoint - starting selection position.

selectionEnd

public void selectionEnd(java.awt.Point endPoint,
                         AbstractPageViewComponent pageViewComponent)
Selection ended so we want to stop record the position and update the selection.


clearSelection

public void clearSelection()

clearSelectionState

public void clearSelectionState()

selection

public void selection(java.awt.Point dragPoint,
                      AbstractPageViewComponent pageViewComponent,
                      boolean isDown,
                      boolean isMovingRight)

selectionIcon

public void selectionIcon(java.awt.Point mouseLocation,
                          AbstractPageViewComponent pageViewComponent)

calculateTextSelectionExclusion

protected void calculateTextSelectionExclusion(java.awt.geom.AffineTransform pageTransform)

paintSelectedText

public static void paintSelectedText(java.awt.Graphics g,
                                     AbstractPageViewComponent pageViewComponent,
                                     DocumentViewModel documentViewModel)
Paints any text that is selected in the page wrapped by a pageViewComponent.

Parameters:
g - graphics context to paint to.
pageViewComponent - page view component to paint selected to on.
documentViewModel - document model contains view properties such as zoom and rotation.

paintTextBounds

protected void paintTextBounds(java.awt.Graphics g)
Utility for painting text bounds.

Parameters:
g - graphics context to paint to.

multiLineSelectHandler

protected void multiLineSelectHandler(AbstractPageViewComponent pageViewComponent,
                                      java.awt.Point mouseLocation,
                                      boolean isDown,
                                      boolean isLocalDown,
                                      boolean isMovingRight)
Entry point for multiline text selection. Contains logic for moving from once page to the next which boils down to defining a start position when a new page is entered.

Parameters:
pageViewComponent - page view that is being acted.
mouseLocation - current mouse location already normalized to page space. .
isDown - general selection trent is down, if false it's up.
isMovingRight - general selection trent is right, if alse it's left.

wordSelectHandler

protected void wordSelectHandler(org.icepdf.core.pobjects.Page currentPage,
                                 java.awt.Point mouseLocation)
Utility for selecting multiple lines via rectangle like tool. The selection works based on the intersection of the rectangle and glyph bounding box.

This method should only be called from within a locked page content

Parameters:
currentPage - page to looking for text intersection on.
mouseLocation - location of mouse.

lineSelectHandler

protected void lineSelectHandler(org.icepdf.core.pobjects.Page currentPage,
                                 java.awt.Point mouseLocation)
Utility for selecting a LineText which is usually a sentence in the document. This is usually triggered by a triple click of the mouse

Parameters:
currentPage - page to select
mouseLocation - location of mouse

setSelectionRectangle

public void setSelectionRectangle(java.awt.Point cursorLocation,
                                  java.awt.Rectangle selection)
Specified by:
setSelectionRectangle in class SelectionBoxHandler

setTopMargin

public void setTopMargin(int topMargin)
Sets the top margin used to define an exclusion zone for text selection. For this value to be applied the system property -Dorg.icepdf.core.views.page.marginExclusion.enabled=true must be set.

Parameters:
topMargin - top margin height in pixels.

setBottomMargin

public void setBottomMargin(int bottomMargin)
Sets the bottom margin used to define an exclusion zone for text selection. For this value to be applied the system property -Dorg.icepdf.core.views.page.marginExclusion.enabled=true must be set.

Parameters:
bottomMargin - bottom margin height in pixels.