public class Utilities extends Object
A collection of methods to deal with various text related activities.
public Utilities()
public static final int drawTabbedText(Segment s, int x, int y, Graphics g, TabExpander e, int startOffset)
Draws the given text, expanding any tabs that are contained using the given tab expansion technique. This particular implementation renders in a 1.1 style coordinate system where ints are used and 72dpi is assumed.
s
- the source of the textx
- the X origin >= 0y
- the Y origin >= 0g
- the graphics contexte
- how to expand the tabs. If this value is null, tabs will be expanded as a space character.startOffset
- starting offset of the text in the document >= 0public static final int getTabbedTextWidth(Segment s, FontMetrics metrics, int x, TabExpander e, int startOffset)
Determines the width of the given segment of text taking tabs into consideration. This is implemented in a 1.1 style coordinate system where ints are used and 72dpi is assumed.
s
- the source of the textmetrics
- the font metrics to use for the calculationx
- the X origin >= 0e
- how to expand the tabs. If this value is null, tabs will be expanded as a space character.startOffset
- starting offset of the text in the document >= 0public static final int getTabbedTextOffset(Segment s, FontMetrics metrics, int x0, int x, TabExpander e, int startOffset)
Determines the relative offset into the given text that best represents the given span in the view coordinate system. This is implemented in a 1.1 style coordinate system where ints are used and 72dpi is assumed.
s
- the source of the textmetrics
- the font metrics to use for the calculationx0
- the starting view location representing the start of the given text >= 0.x
- the target view location to translate to an offset into the text >= 0.e
- how to expand the tabs. If this value is null, tabs will be expanded as a space character.startOffset
- starting offset of the text in the document >= 0public static final int getTabbedTextOffset(Segment s, FontMetrics metrics, int x0, int x, TabExpander e, int startOffset, boolean round)
public static final int getBreakLocation(Segment s, FontMetrics metrics, int x0, int x, TabExpander e, int startOffset)
Determine where to break the given text to fit within the given span. This tries to find a word boundary.
s
- the source of the textmetrics
- the font metrics to use for the calculationx0
- the starting view location representing the start of the given text.x
- the target view location to translate to an offset into the text.e
- how to expand the tabs. If this value is null, tabs will be expanded as a space character.startOffset
- starting offset in the document of the textpublic static final int getRowStart(JTextComponent c, int offs) throws BadLocationException
Determines the starting row model position of the row that contains the specified model position. The component given must have a size to compute the result. If the component doesn't have a size a value of -1 will be returned.
c
- the editoroffs
- the offset in the document >= 0BadLocationException
- if the offset is out of rangepublic static final int getRowEnd(JTextComponent c, int offs) throws BadLocationException
Determines the ending row model position of the row that contains the specified model position. The component given must have a size to compute the result. If the component doesn't have a size a value of -1 will be returned.
c
- the editoroffs
- the offset in the document >= 0BadLocationException
- if the offset is out of rangepublic static final int getPositionAbove(JTextComponent c, int offs, int x) throws BadLocationException
Determines the position in the model that is closest to the given view location in the row above. The component given must have a size to compute the result. If the component doesn't have a size a value of -1 will be returned.
c
- the editoroffs
- the offset in the document >= 0x
- the X coordinate >= 0BadLocationException
- if the offset is out of rangepublic static final int getPositionBelow(JTextComponent c, int offs, int x) throws BadLocationException
Determines the position in the model that is closest to the given view location in the row below. The component given must have a size to compute the result. If the component doesn't have a size a value of -1 will be returned.
c
- the editoroffs
- the offset in the document >= 0x
- the X coordinate >= 0BadLocationException
- if the offset is out of rangepublic static final int getWordStart(JTextComponent c, int offs) throws BadLocationException
Determines the start of a word for the given model location. Uses BreakIterator.getWordInstance() to actually get the words.
c
- the editoroffs
- the offset in the document >= 0BadLocationException
- if the offset is out of rangepublic static final int getWordEnd(JTextComponent c, int offs) throws BadLocationException
Determines the end of a word for the given location. Uses BreakIterator.getWordInstance() to actually get the words.
c
- the editoroffs
- the offset in the document >= 0BadLocationException
- if the offset is out of rangepublic static final int getNextWord(JTextComponent c, int offs) throws BadLocationException
Determines the start of the next word for the given location. Uses BreakIterator.getWordInstance() to actually get the words.
c
- the editoroffs
- the offset in the document >= 0BadLocationException
- if the offset is out of rangepublic static final int getPreviousWord(JTextComponent c, int offs) throws BadLocationException
Determine the start of the prev word for the given location. Uses BreakIterator.getWordInstance() to actually get the words.
c
- the editoroffs
- the offset in the document >= 0BadLocationException
- if the offset is out of rangepublic static final Element getParagraphElement(JTextComponent c, int offs)
Determines the element to use for a paragraph/line.
c
- the editoroffs
- the starting offset in the document >= 0
© 1993–2017, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.