|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.faceless.pdf2.viewer2.ViewerFeature
org.faceless.pdf2.viewer2.ViewerWidget
org.faceless.pdf2.viewer2.ToggleViewerWidget
org.faceless.pdf2.viewer2.feature.TextTool
public class TextTool
This widget allows text to be selected from the DocumentViewport. By default it
uses a translucent yellow highlight, but this can be set using the
setHighlightType()
method or the matching initialization
parameters. When the text is highlighted, right-clicking on the page will bring
up a list of any TextSelectionAction
features specified in the viewer.
The TextTool object selects text in a document-wide manner, not just from the currently
visible pages (which was the behaviour prior to 2.11.7). This means operations like
selectAll()
or select(Pattern)
require all the text in the PDF to be
extracted, which can cause these two operations to take some time to complete. One solution
is to add the BackgroundTextExtractor
feature, which will automatically begin the
text extaction when a PDF is loaded.
The TextHighlighter
class performs a similar job, except no mouse selection or
no copying to the clipboard is possible. These differences mean if you simply want to
highlight text matching a pattern, this class will have to extract text from the entire
PDF first, whereas that class will do it on a page by page basis.
highlightColor | A 32-bit color value, eg 0x80FF0000 (for translucent red) |
---|---|
highlightType | One of block , underline , outline , doubleunderline , strikeout or doublestrikeout |
highlightMargin | A floating point value >= 0 |
draggable | true or false , for setDraggable(boolean) |
selectPattern | A java.util.regex.Pattern to be searched for automatically when a PDF is loaded |
selectTextToolOnTextSelection | if specified, toggle text selection mode in the viewer when text is selected by other means (e.g. clicking a search result) |
selectionOrder | display or natural , to set the order text is selected in when dragging the mouse. Defaults to "natural".
|
This code is copyright the Big Faceless Organization. You're welcome to use, modify and distribute it in any form in your own projects, provided those projects continue to make use of the Big Faceless PDF library.
TextSelectionAction
Field Summary | |
---|---|
static int |
TYPE_BLOCK
A parameter to setHighlightType(int, java.awt.Paint, java.awt.Stroke, float) which will highlight the selected
text using a solid block of (usually translucent) color |
static int |
TYPE_DOUBLESTRIKEOUT
A parameter to setHighlightType(int, java.awt.Paint, java.awt.Stroke, float) which will strike-out the selected
text with a double line |
static int |
TYPE_DOUBLEUNDERLINE
A parameter to setHighlightType(int, java.awt.Paint, java.awt.Stroke, float) which will highlight the selected
text using a double underline. |
static int |
TYPE_OUTLINE
A parameter to setHighlightType(int, java.awt.Paint, java.awt.Stroke, float) which will outline the selected
text. |
static int |
TYPE_STRIKEOUT
A parameter to setHighlightType(int, java.awt.Paint, java.awt.Stroke, float) which will strike-out the selected
text. |
static int |
TYPE_UNDERLINE
A parameter to setHighlightType(int, java.awt.Paint, java.awt.Stroke, float) which will highlight the selected
text using a single underline. |
Constructor Summary | |
---|---|
TextTool()
Create a new TextTool object |
Method Summary | |
---|---|
void |
clear()
Deselect all the text on the viewport |
void |
copy()
Copy the selected text (if any) to the System clipboard |
void |
documentUpdated(DocumentPanelEvent event)
Called when an DocumentPanelEvent is raised |
void |
focusGained(FocusEvent event)
|
void |
focusLost(FocusEvent event)
|
TextSelection.RangeList |
getRangeList()
|
void |
initialize(PDFViewer viewer)
Called when the feature is first added to a viewer |
void |
pageAction(PagePanelInteractionEvent event)
Handle mousePressed, mouseDragged and mouseMoved events on this page, which are used to select text. |
void |
pageUpdated(PagePanelEvent event)
Called when a PagePanelEvent is raised |
void |
select(Collection texts)
Select the specified text objects. |
void |
select(PageExtractor.Text text)
Select the specified text. |
void |
select(Pattern pattern)
Select any text matching the specified Pattern. |
void |
selectAll()
Select all the text in the currently displayed viewport. |
void |
setDraggable(boolean draggable)
Set whether this TextTool can select text by dragging over it. |
void |
setHighlightType(int type,
Paint paint,
Stroke stroke,
float margin)
Set the type and color of the highlight. |
void |
setOrder(Comparator<PageExtractor.Text> order)
Set the order in which text is selected in this TextTool, either PageExtractor.NATURALORDER or PageExtractor.DISPLAYORDER . |
protected void |
updateViewport(DocumentViewport viewport,
boolean selected)
Called from ToggleViewerWidget.setSelected(boolean) , this method is called in each
viewport in use by the PDFViewer or DocumentPanel so
it can update its status. |
Methods inherited from class org.faceless.pdf2.viewer2.ToggleViewerWidget |
---|
action, getGroupName, getGroupOwner, getGroupSelection, getWidgets, isSelected, setGroupOwner, setSelected |
Methods inherited from class org.faceless.pdf2.viewer2.ViewerWidget |
---|
createActionListener, getComponent, getViewer, isButtonEnabledByDefault, isDocumentRequired, isMenuEnabledByDefault, setButton, setComponent, setDocumentRequired, setMenu, setMenu, setToolBarEnabled, setToolBarEnabledAlways, setToolBarFloatable, setToolBarFloating, toString |
Methods inherited from class org.faceless.pdf2.viewer2.ViewerFeature |
---|
getAllEnabledFeatures, getAllFeatures, getCustomJavaScript, getFeatureProperty, getFeatureURLProperty, getName, isEnabledByDefault, setFeatureName, teardown |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final int TYPE_BLOCK
setHighlightType(int, java.awt.Paint, java.awt.Stroke, float)
which will highlight the selected
text using a solid block of (usually translucent) color
public static final int TYPE_UNDERLINE
setHighlightType(int, java.awt.Paint, java.awt.Stroke, float)
which will highlight the selected
text using a single underline.
public static final int TYPE_DOUBLEUNDERLINE
setHighlightType(int, java.awt.Paint, java.awt.Stroke, float)
which will highlight the selected
text using a double underline.
public static final int TYPE_OUTLINE
setHighlightType(int, java.awt.Paint, java.awt.Stroke, float)
which will outline the selected
text.
public static final int TYPE_STRIKEOUT
setHighlightType(int, java.awt.Paint, java.awt.Stroke, float)
which will strike-out the selected
text.
public static final int TYPE_DOUBLESTRIKEOUT
setHighlightType(int, java.awt.Paint, java.awt.Stroke, float)
which will strike-out the selected
text with a double line
Constructor Detail |
---|
public TextTool()
Method Detail |
---|
public void setHighlightType(int type, Paint paint, Stroke stroke, float margin)
type
- the type of highlight - TYPE_BLOCK
, TYPE_OUTLINE
,
TYPE_UNDERLINE
, TYPE_DOUBLEUNDERLINE
, TYPE_STRIKEOUT
or TYPE_DOUBLESTRIKEOUT
paint
- the Paint to paint this highlight withstroke
- the Stroke to stroke this highlight with (not used for TYPE_BLOCK
)margin
- the distance in points from the textpublic void setDraggable(boolean draggable)
draggable
- whether this TextTool can select text with the mousepublic void setOrder(Comparator<PageExtractor.Text> order)
PageExtractor.NATURALORDER
or PageExtractor.DISPLAYORDER
.
For documents internally constructed in a logical order, natural is
usually the best choice as for text in columns, it will allow you to
select an individual column. However there is no way to determine this
in advance, so if there's any doubt, then "display" will always give
acceptable results. The default is "natural"
order
- the order in which text is selected.public void initialize(PDFViewer viewer)
ViewerFeature
initialize
in class ToggleViewerWidget
public TextSelection.RangeList getRangeList()
protected void updateViewport(DocumentViewport viewport, boolean selected)
ToggleViewerWidget
ToggleViewerWidget.setSelected(boolean)
, this method is called in each
viewport in use by the PDFViewer
or DocumentPanel
so
it can update its status. By default it is a no-op.
updateViewport
in class ToggleViewerWidget
public void focusGained(FocusEvent event)
focusGained
in interface FocusListener
public void focusLost(FocusEvent event)
focusLost
in interface FocusListener
public void documentUpdated(DocumentPanelEvent event)
DocumentPanelListener
DocumentPanelEvent
is raised
documentUpdated
in interface DocumentPanelListener
public void pageUpdated(PagePanelEvent event)
PagePanelListener
PagePanelEvent
is raised
pageUpdated
in interface PagePanelListener
public void copy()
public void selectAll()
Select all the text in the currently displayed viewport. This will cause all the text to be extracted if it hasn't already, which may be a slow operation.
Any subsequent selections, by the mouse or programatically, will replace this selection.
select(Pattern)
,
BackgroundTextExtractor
public void clear()
public void select(PageExtractor.Text text)
Select the specified text. If the text is on a different page to the current one, the page is changed first, and either way the viewport may be repositioned to display the specified text.
Any subsequent selections, by the mouse or programatically, will replace this selection.
text
- the Text item to display, or null
to select no text
IllegalArgumentException
- if the text item is from a different PDF to that currently displayedpublic void select(Collection texts)
Select the specified text objects. The viewport will not be scrolled to match the selections, so the text may be from any loaded PDF objects.
Any subsequent selections, by the mouse or programatically, will replace this selection.
texts
- a Collection of PageExtractor.Text
objects.TextHighlighter
,
TextSelectionAction
public void select(Pattern pattern)
Select any text matching the specified Pattern. This method has to run a pattern match against the entire PDF in the currently displayed viewport, so if the text has not yet been extracted this method could take some time to complete.
Any subsequent selections, by the mouse or programatically, will replace this selection.
BackgroundTextExtractor
,
PageExtractor.getMatchingText(java.lang.String)
,
TextHighlighter
,
TextSelectionAction
public void pageAction(PagePanelInteractionEvent event)
pageAction
in interface PagePanelInteractionListener
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |