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 RectanglecomputeArea(IRegion region, ITextViewer textViewer) Determines the graphical area covered by the given text region in the given viewer.static intcomputeLineHeight(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 intcomputeLineHeight(StyledText textWidget, int startLine, int endLine, int lineCount) Computes the line height for the given line range.static intgetAverageCharWidth(Control control) Returns the average character width of the given control's font.static intgetBottomIndex(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 intgetHiddenTopLinePixels(StyledText textWidget) Returns the number of hidden pixels of the first partially visible line.static intgetLineIndex(StyledText textWidget, int y) static intgetLinePixel(StyledText textWidget, int line) static intReturns the offset in the given viewer that corresponds to the current cursor location.static intgetPartialBottomIndex(ITextViewer viewer) Returns the last, possibly partially, visible line in the view port.static intgetPartialBottomIndex(StyledText widget) Returns the index of the last (possibly only partially) visible line of the widgetstatic intgetPartialTopIndex(ITextViewer viewer) Returns the line index of the first visible model line in the viewer.static intgetPartialTopIndex(StyledText widget) Returns the index of the first (possibly only partially) visible line of the widgetstatic ILineRangegetVisibleModelLines(ITextViewer viewer) Returns the range of lines that is visible in the viewer, including any partially visible lines.static booleanisEmpty(ITextViewer viewer, ITextSelection selection) Returnstrueif the text covered byselectiondoes not contain any characters in the given viewer.static booleanisShowingEntireContents(StyledText widget) Returnstrueif the widget displays the entire contents, i.e. it cannot be vertically scrolled.static intmodelLineToWidgetLine(ITextViewer viewer, int modelLine) Converts a model (i.e.static intwidgetLine2ModelLine(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- theStyledTextwidgetstartLine- the start lineendLine- the end line (exclusive)lineCount- the line count used by the old API- Returns:
- the height of all lines starting with
startLineand 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,
nullif no lines are visible
-
widgetLine2ModelLine
Converts a widget line into a model (i.e.IDocument) line using theITextViewerExtension5if 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
widgetLineor -1 to signal that there is no corresponding model line
-
modelLineToWidgetLine
Converts a model (i.e.IDocument) line into a widget line using theITextViewerExtension5if 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
modelLineor -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
Returnstrueif the widget displays the entire contents, i.e. it cannot be vertically scrolled.- Parameters:
widget- the widget- Returns:
trueif the widget displays the entire contents, i.e. it cannot be vertically scrolled,falseotherwise
-
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 Returnstrueif the text covered byselectiondoes not contain any characters in the given viewer. Note the difference toISelection.isEmpty(), which returnstrueonly for invalid selections.- Parameters:
viewer- the viewerselection- the selection- Returns:
trueifselectiondoes not contain any text,falseotherwise- 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
-