- java.lang.Object
-
- org.icepdf.ri.common.tools.CommonToolHandler
-
- org.icepdf.ri.common.tools.SelectionBoxHandler
-
- org.icepdf.ri.common.tools.TextSelection
-
- Direct Known Subclasses:
EditTextHandler,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
Fields Modifier and Type Field Description protected intbottomMarginprotected Rectangle2DbottomMarginExclusionprotected static booleanenableMarginExclusionprotected static booleanenableMarginExclusionBorderprotected PointlastMouseLocationprotected PointlastMousePressedLocationprotected static Loggerloggerprotected PagepageLockintselectedCountprotected inttopMarginprotected Rectangle2DtopMarginExclusion-
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, pageViewComponent, preferences
-
-
Constructor Summary
Constructors Constructor Description TextSelection(DocumentViewController documentViewController, AbstractPageViewComponent pageViewComponent)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidcalculateTextSelectionExclusion()protected voidcheckAndApplyPreferences()voidclearSelection()voidclearSelectionState()static GeneralPathconvertTextShapesToBounds(ArrayList<Shape> textShapes)protected RectangleconvertToPageSpace(ArrayList<Shape> bounds, GeneralPath path)Convert the shapes that make up the annotation to page space so that they will scale correctly at different zooms.protected voidlineSelectHandler(Page currentPage, Point mouseLocation)Utility for selecting a LineText which is usually a sentence in the document.protected voidmultiLineSelectHandler(AbstractPageViewComponent pageViewComponent, Point mouseLocation, boolean isDown, boolean isLocalDown, boolean isMovingRight)Entry point for multiline text selection.static voidpaintSelectedText(Graphics g, AbstractPageViewComponent pageViewComponent, DocumentViewModel documentViewModel)Paints any text that is selected in the page wrapped by a pageViewComponent.protected voidpaintTextBounds(Graphics g)Utility for painting text bounds.voidselection(Point dragPoint, AbstractPageViewComponent pageViewComponent, boolean isDown, boolean isMovingRight)voidselectionEnd(Point endPoint, AbstractPageViewComponent pageViewComponent)Selection ended so we want to stop record the position and update the selection.voidselectionStart(Point startPoint, AbstractPageViewComponent pageViewComponent, boolean isFirst)Selection started so we want to record the position and update the selection rectangle.booleanselectionTextSelectIcon(Point mouseLocation, AbstractPageViewComponent pageViewComponent)voidsetBottomMargin(int bottomMargin)Sets the bottom margin used to define an exclusion zone for text selection.voidsetSelectionRectangle(Point cursorLocation, Rectangle selection)voidsetTopMargin(int topMargin)Sets the top margin used to define an exclusion zone for text selection.voidwordLineSelection(int clickCount, Point clickPoint, AbstractPageViewComponent pageViewComponent)Handles double and triple left mouse clicks to select a word or line of text respectively.protected voidwordSelectHandler(Page currentPage, 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, paintRectangle, paintSelectionBox, resetRectangle, setCurrentRect, setRectToDraw, setSelectionSize, updateDrawableRect, updateSelectionSize
-
Methods inherited from class org.icepdf.ri.common.tools.CommonToolHandler
convertToPageSpace, convertToPageSpace, convertToPageSpace, convertToPageSpace, getPageTransform, getPageTransform, getToPageSpaceTransform, getToPageSpaceTransform
-
-
-
-
Field Detail
-
logger
protected static final Logger logger
-
selectedCount
public int selectedCount
-
lastMousePressedLocation
protected Point lastMousePressedLocation
-
lastMouseLocation
protected Point lastMouseLocation
-
topMargin
protected int topMargin
-
bottomMargin
protected int bottomMargin
-
enableMarginExclusion
protected static boolean enableMarginExclusion
-
enableMarginExclusionBorder
protected static boolean enableMarginExclusionBorder
-
topMarginExclusion
protected Rectangle2D topMarginExclusion
-
bottomMarginExclusion
protected Rectangle2D bottomMarginExclusion
-
pageLock
protected Page pageLock
-
-
Constructor Detail
-
TextSelection
public TextSelection(DocumentViewController documentViewController, AbstractPageViewComponent pageViewComponent)
-
-
Method Detail
-
checkAndApplyPreferences
protected void checkAndApplyPreferences()
- Specified by:
checkAndApplyPreferencesin classCommonToolHandler
-
wordLineSelection
public void wordLineSelection(int clickCount, 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.pageViewComponent- parent page view component
-
selectionStart
public void selectionStart(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.isFirst- start of selection if truepageViewComponent- parent page component
-
selectionEnd
public void selectionEnd(Point endPoint, AbstractPageViewComponent pageViewComponent)
Selection ended so we want to stop record the position and update the selection.- Parameters:
pageViewComponent- page component viewendPoint- end point of drag
-
clearSelection
public void clearSelection()
-
clearSelectionState
public void clearSelectionState()
-
selection
public void selection(Point dragPoint, AbstractPageViewComponent pageViewComponent, boolean isDown, boolean isMovingRight)
-
selectionTextSelectIcon
public boolean selectionTextSelectIcon(Point mouseLocation, AbstractPageViewComponent pageViewComponent)
-
calculateTextSelectionExclusion
protected void calculateTextSelectionExclusion()
-
paintSelectedText
public static void paintSelectedText(Graphics g, AbstractPageViewComponent pageViewComponent, DocumentViewModel documentViewModel) throws InterruptedException
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.- Throws:
InterruptedException- thread interrupted.
-
paintTextBounds
protected void paintTextBounds(Graphics g) throws InterruptedException
Utility for painting text bounds.- Parameters:
g- graphics context to paint to.- Throws:
InterruptedException- thread interrupted.
-
multiLineSelectHandler
protected void multiLineSelectHandler(AbstractPageViewComponent pageViewComponent, Point mouseLocation, boolean isDown, boolean isLocalDown, boolean isMovingRight) throws InterruptedException
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 false it's left.isLocalDown- local movement is down.- Throws:
InterruptedException- thread interrupted.
-
wordSelectHandler
protected void wordSelectHandler(Page currentPage, Point mouseLocation) throws InterruptedException
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.- Throws:
InterruptedException- thread interrupted.
-
lineSelectHandler
protected void lineSelectHandler(Page currentPage, Point mouseLocation) throws InterruptedException
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 selectmouseLocation- location of mouse- Throws:
InterruptedException- thread interrupted.
-
setSelectionRectangle
public void setSelectionRectangle(Point cursorLocation, Rectangle selection)
- Specified by:
setSelectionRectanglein classSelectionBoxHandler
-
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.
-
convertTextShapesToBounds
public static GeneralPath convertTextShapesToBounds(ArrayList<Shape> textShapes)
-
convertToPageSpace
protected Rectangle convertToPageSpace(ArrayList<Shape> bounds, GeneralPath path)
Convert the shapes that make up the annotation to page space so that they will scale correctly at different zooms.- Parameters:
bounds- bounds to convert to page spacepath- path- Returns:
- transformed bBox.
-
-