Package org.eclipse.jface.text
Class JFaceTextUtil
java.lang.Object
org.eclipse.jface.text.JFaceTextUtil
A collection of JFace Text functions.
This class is neither intended to be instantiated nor subclassed.
- Since:
- 3.3
- Restriction:
- This class is not intended to be instantiated by clients.
-
Method Summary
Modifier and TypeMethodDescriptionstatic Rectangle
computeArea
(IRegion region, ITextViewer textViewer) Determines the graphical area covered by the given text region in the given viewer.static int
computeLineHeight
(StyledText styledText, int widgetLine) Computes the full line height for the text line corresponding to the given widget line, considering the possible line wrapping.static int
computeLineHeight
(StyledText textWidget, int startLine, int endLine, int lineCount) Computes the line height for the given line range.static int
getAverageCharWidth
(Control control) Returns the average character width of the given control's font.static int
getBottomIndex
(StyledText widget) Returns the last fully visible line of the widget.static IRegion[]
getCoveredRanges
(ITextViewer viewer, ITextSelection selection) Returns the text regions covered by the given selection in the given viewer.static int
getHiddenTopLinePixels
(StyledText textWidget) Returns the number of hidden pixels of the first partially visible line.static int
getLineIndex
(StyledText textWidget, int y) static int
getLinePixel
(StyledText textWidget, int line) static int
Returns the offset in the given viewer that corresponds to the current cursor location.static int
getPartialBottomIndex
(ITextViewer viewer) Returns the last, possibly partially, visible line in the view port.static int
getPartialBottomIndex
(StyledText widget) Returns the index of the last (possibly only partially) visible line of the widgetstatic int
getPartialTopIndex
(ITextViewer viewer) Returns the line index of the first visible model line in the viewer.static int
getPartialTopIndex
(StyledText widget) Returns the index of the first (possibly only partially) visible line of the widgetstatic ILineRange
getVisibleModelLines
(ITextViewer viewer) Returns the range of lines that is visible in the viewer, including any partially visible lines.static boolean
isEmpty
(ITextViewer viewer, ITextSelection selection) Returnstrue
if the text covered byselection
does not contain any characters in the given viewer.static boolean
isShowingEntireContents
(StyledText widget) Returnstrue
if the widget displays the entire contents, i.e. it cannot be vertically scrolled.static int
modelLineToWidgetLine
(ITextViewer viewer, int modelLine) Converts a model (i.e.static int
widgetLine2ModelLine
(ITextViewer viewer, int widgetLine) Converts a widget line into a model (i.e.
-
Method Details
-
computeLineHeight
Computes the full line height for the text line corresponding to the given widget line, considering the possible line wrapping.- Parameters:
styledText
- the widgetwidgetLine
- the widget line- Returns:
- the full real height of the corresponding line of text (which might wrap to multiple widget lines) in the widget
- Since:
- 3.11
-
computeLineHeight
public static int computeLineHeight(StyledText textWidget, int startLine, int endLine, int lineCount) Computes the line height for the given line range.- Parameters:
textWidget
- theStyledText
widgetstartLine
- the start lineendLine
- the end line (exclusive)lineCount
- the line count used by the old API- Returns:
- the height of all lines starting with
startLine
and ending aboveendLime
-
getBottomIndex
Returns the last fully visible line of the widget. The exact semantics of "last fully visible line" are:- the last line of which the last pixel is visible, if any
- otherwise, the only line that is partially visible
- Parameters:
widget
- the widget- Returns:
- the last fully visible line
-
getPartialTopIndex
Returns the index of the first (possibly only partially) visible line of the widget- Parameters:
widget
- the widget- Returns:
- the index of the first line of which a pixel is visible
-
getPartialBottomIndex
Returns the index of the last (possibly only partially) visible line of the widget- Parameters:
widget
- the text widget- Returns:
- the index of the last line of which a pixel is visible
-
getPartialTopIndex
Returns the line index of the first visible model line in the viewer. The line may be only partially visible.- Parameters:
viewer
- the text viewer- Returns:
- the first line of which a pixel is visible, or -1 for no line
-
getPartialBottomIndex
Returns the last, possibly partially, visible line in the view port.- Parameters:
viewer
- the text viewer- Returns:
- the last, possibly partially, visible line in the view port
-
getVisibleModelLines
Returns the range of lines that is visible in the viewer, including any partially visible lines.- Parameters:
viewer
- the viewer- Returns:
- the range of lines that is visible in the viewer,
null
if no lines are visible
-
widgetLine2ModelLine
Converts a widget line into a model (i.e.IDocument
) line using theITextViewerExtension5
if available, otherwise by adapting the widget line to the viewer'svisible region
.- Parameters:
viewer
- the viewerwidgetLine
- the widget line to convert.- Returns:
- the model line corresponding to
widgetLine
or -1 to signal that there is no corresponding model line
-
modelLineToWidgetLine
Converts a model (i.e.IDocument
) line into a widget line using theITextViewerExtension5
if available, otherwise by adapting the model line to the viewer'svisible region
.- Parameters:
viewer
- the viewermodelLine
- the model line to convert.- Returns:
- the widget line corresponding to
modelLine
or -1 to signal that there is no corresponding widget line
-
getHiddenTopLinePixels
Returns the number of hidden pixels of the first partially visible line. If there is no partially visible line, zero is returned.- Parameters:
textWidget
- the widget- Returns:
- the number of hidden pixels of the first partial line, always >= 0
-
getLinePixel
-
getLineIndex
-
isShowingEntireContents
Returnstrue
if the widget displays the entire contents, i.e. it cannot be vertically scrolled.- Parameters:
widget
- the widget- Returns:
true
if the widget displays the entire contents, i.e. it cannot be vertically scrolled,false
otherwise
-
computeArea
Determines the graphical area covered by the given text region in the given viewer.- Parameters:
region
- the region whose graphical extend must be computedtextViewer
- the text viewer containing the region- Returns:
- the graphical extend of the given region in the given viewer
- Since:
- 3.4
-
getAverageCharWidth
Returns the average character width of the given control's font.- Parameters:
control
- the control to calculate the average char width for- Returns:
- the average character width of the controls font
- Since:
- 3.4
-
isEmpty
public static boolean isEmpty(ITextViewer viewer, ITextSelection selection) throws BadLocationException Returnstrue
if the text covered byselection
does not contain any characters in the given viewer. Note the difference toISelection.isEmpty()
, which returnstrue
only for invalid selections.- Parameters:
viewer
- the viewerselection
- the selection- Returns:
true
ifselection
does not contain any text,false
otherwise- Throws:
BadLocationException
- if accessing the document failed- Since:
- 3.5
-
getCoveredRanges
public static IRegion[] getCoveredRanges(ITextViewer viewer, ITextSelection selection) throws BadLocationException Returns the text regions covered by the given selection in the given viewer.- Parameters:
viewer
- the viewerselection
- the selection- Returns:
- the text regions corresponding to
selection
- Throws:
BadLocationException
- if accessing the document failed- Since:
- 3.5
-
getOffsetForCursorLocation
Returns the offset in the given viewer that corresponds to the current cursor location.- Parameters:
viewer
- the viewer- Returns:
- the offset for the current cursor location or -1 if not available
- Since:
- 3.5
-