javax.swing.text

Class Utilities


  • public class Utilities
    extends Object
    A collection of methods to deal with various text related activities.
    • Constructor Detail

      • Utilities

        public Utilities()
    • Method Detail

      • drawTabbedText

        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.
        Parameters:
        s - the source of the text
        x - the X origin >= 0
        y - the Y origin >= 0
        g - the graphics context
        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 >= 0
        Returns:
        the X location at the end of the rendered text
      • getTabbedTextWidth

        public 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.
        Parameters:
        s - the source of the text
        metrics - the font metrics to use for the calculation
        x - the X origin >= 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 >= 0
        Returns:
        the width of the text
      • getTabbedTextOffset

        public 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.
        Parameters:
        s - the source of the text
        metrics - the font metrics to use for the calculation
        x0 - 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 >= 0
        Returns:
        the offset into the text >= 0
      • getTabbedTextOffset

        public static final int getTabbedTextOffset(Segment s,
                              FontMetrics metrics,
                              int x0,
                              int x,
                              TabExpander e,
                              int startOffset,
                              boolean round)
      • getBreakLocation

        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.
        Parameters:
        s - the source of the text
        metrics - the font metrics to use for the calculation
        x0 - 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 text
        Returns:
        the offset into the given text
      • getRowStart

        public 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.
        Parameters:
        c - the editor
        offs - the offset in the document >= 0
        Returns:
        the position >= 0 if the request can be computed, otherwise a value of -1 will be returned.
        Throws:
        BadLocationException - if the offset is out of range
      • getRowEnd

        public 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.
        Parameters:
        c - the editor
        offs - the offset in the document >= 0
        Returns:
        the position >= 0 if the request can be computed, otherwise a value of -1 will be returned.
        Throws:
        BadLocationException - if the offset is out of range
      • getPositionAbove

        public 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.
        Parameters:
        c - the editor
        offs - the offset in the document >= 0
        x - the X coordinate >= 0
        Returns:
        the position >= 0 if the request can be computed, otherwise a value of -1 will be returned.
        Throws:
        BadLocationException - if the offset is out of range
      • getPositionBelow

        public 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.
        Parameters:
        c - the editor
        offs - the offset in the document >= 0
        x - the X coordinate >= 0
        Returns:
        the position >= 0 if the request can be computed, otherwise a value of -1 will be returned.
        Throws:
        BadLocationException - if the offset is out of range
      • getWordStart

        public 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.
        Parameters:
        c - the editor
        offs - the offset in the document >= 0
        Returns:
        the location in the model of the word start >= 0
        Throws:
        BadLocationException - if the offset is out of range
      • getWordEnd

        public 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.
        Parameters:
        c - the editor
        offs - the offset in the document >= 0
        Returns:
        the location in the model of the word end >= 0
        Throws:
        BadLocationException - if the offset is out of range
      • getNextWord

        public 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.
        Parameters:
        c - the editor
        offs - the offset in the document >= 0
        Returns:
        the location in the model of the word start >= 0
        Throws:
        BadLocationException - if the offset is out of range
      • getPreviousWord

        public 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.
        Parameters:
        c - the editor
        offs - the offset in the document >= 0
        Returns:
        the location in the model of the word start >= 0
        Throws:
        BadLocationException - if the offset is out of range
      • getParagraphElement

        public static final Element getParagraphElement(JTextComponent c,
                                  int offs)
        Determines the element to use for a paragraph/line.
        Parameters:
        c - the editor
        offs - the starting offset in the document >= 0
        Returns:
        the element

Nederlandse vertaling

U hebt gevraagd om deze site in het Nederlands te bezoeken. Voor nu wordt alleen de interface vertaald, maar nog niet alle inhoud.

Als je me wilt helpen met vertalingen, is je bijdrage welkom. Het enige dat u hoeft te doen, is u op de site registreren en mij een bericht sturen waarin u wordt gevraagd om u toe te voegen aan de groep vertalers, zodat u de gewenste pagina's kunt vertalen. Een link onderaan elke vertaalde pagina geeft aan dat u de vertaler bent en heeft een link naar uw profiel.

Bij voorbaat dank.

Document heeft de 11/06/2005 gemaakt, de laatste keer de 04/03/2020 gewijzigd
Bron van het afgedrukte document:https://www.gaudry.be/nl/java-api-rf-javax/swing/text/utilities.html

De infobrol is een persoonlijke site waarvan de inhoud uitsluitend mijn verantwoordelijkheid is. De tekst is beschikbaar onder CreativeCommons-licentie (BY-NC-SA). Meer info op de gebruiksvoorwaarden en de auteur.

Referenties

  1. Bekijk - html-document Taal van het document:fr Manuel PHP : https://docs.oracle.com

Deze verwijzingen en links verwijzen naar documenten die geraadpleegd zijn tijdens het schrijven van deze pagina, of die aanvullende informatie kunnen geven, maar de auteurs van deze bronnen kunnen niet verantwoordelijk worden gehouden voor de inhoud van deze pagina.
De auteur Deze site is als enige verantwoordelijk voor de manier waarop de verschillende concepten, en de vrijheden die met de referentiewerken worden genomen, hier worden gepresenteerd. Vergeet niet dat u meerdere broninformatie moet doorgeven om het risico op fouten te verkleinen.

Inhoudsopgave Haut