Class JFaceTextUtil

java.lang.Object
org.eclipse.jface.text.JFaceTextUtil

public final class JFaceTextUtil extends Object
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 Details

    • computeLineHeight

      public 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.
      Parameters:
      styledText - the widget
      widgetLine - 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 - the StyledText widget
      startLine - the start line
      endLine - the end line (exclusive)
      lineCount - the line count used by the old API
      Returns:
      the height of all lines starting with startLine and ending above endLime
    • getBottomIndex

      public static int getBottomIndex(StyledText widget)
      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

      public static int getPartialTopIndex(StyledText widget)
      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

      public static int getPartialBottomIndex(StyledText widget)
      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

      public static int getPartialTopIndex(ITextViewer viewer)
      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

      public static int getPartialBottomIndex(ITextViewer viewer)
      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

      public static ILineRange getVisibleModelLines(ITextViewer viewer)
      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

      public static int widgetLine2ModelLine(ITextViewer viewer, int widgetLine)
      Converts a widget line into a model (i.e. IDocument) line using the ITextViewerExtension5 if available, otherwise by adapting the widget line to the viewer's visible region.
      Parameters:
      viewer - the viewer
      widgetLine - the widget line to convert.
      Returns:
      the model line corresponding to widgetLine or -1 to signal that there is no corresponding model line
    • modelLineToWidgetLine

      public static int modelLineToWidgetLine(ITextViewer viewer, int modelLine)
      Converts a model (i.e. IDocument) line into a widget line using the ITextViewerExtension5 if available, otherwise by adapting the model line to the viewer's visible region.
      Parameters:
      viewer - the viewer
      modelLine - the model line to convert.
      Returns:
      the widget line corresponding to modelLine or -1 to signal that there is no corresponding widget line
    • getHiddenTopLinePixels

      public static int getHiddenTopLinePixels(StyledText textWidget)
      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

      public static int getLinePixel(StyledText textWidget, int line)
    • getLineIndex

      public static int getLineIndex(StyledText textWidget, int y)
    • isShowingEntireContents

      public static boolean isShowingEntireContents(StyledText widget)
      Returns true 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

      public static Rectangle computeArea(IRegion region, ITextViewer textViewer)
      Determines the graphical area covered by the given text region in the given viewer.
      Parameters:
      region - the region whose graphical extend must be computed
      textViewer - the text viewer containing the region
      Returns:
      the graphical extend of the given region in the given viewer
      Since:
      3.4
    • getAverageCharWidth

      public static int getAverageCharWidth(Control control)
      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
      Returns true if the text covered by selection does not contain any characters in the given viewer. Note the difference to ISelection.isEmpty(), which returns true only for invalid selections.
      Parameters:
      viewer - the viewer
      selection - the selection
      Returns:
      true if selection 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 viewer
      selection - the selection
      Returns:
      the text regions corresponding to selection
      Throws:
      BadLocationException - if accessing the document failed
      Since:
      3.5
    • getOffsetForCursorLocation

      public static int getOffsetForCursorLocation(ITextViewer viewer)
      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