javax.swing.text
Class Utilities
A set of utilities to deal with text. This is used by several other classes
inside this package.
static int | drawTabbedText(Segment s, int x, int y, Graphics g, TabExpander e, int startOffset) - Draws the given text segment.
|
static int | getBreakLocation(Segment s, FontMetrics metrics, int x0, int x, TabExpander e, int startOffset) - Determine where to break the text in the given Segment, attempting to find
a word boundary.
|
static int | getNextWord(JTextComponent c, int offs) - Finds the start of the next word for the given offset.
|
static Element | getParagraphElement(JTextComponent c, int offset) - Returns the paragraph element in the text component
c at
the specified location offset .
|
static int | getPositionAbove(JTextComponent c, int offset, int x) - Returns the document position that is closest above to the specified x
coordinate in the row containing
offset .
|
static int | getPositionBelow(JTextComponent c, int offset, int x) - Returns the document position that is closest below to the specified x
coordinate in the row containing
offset .
|
static int | getPreviousWord(JTextComponent c, int offs) - Finds the start of the previous word for the given offset.
|
static int | getRowEnd(JTextComponent c, int offs) - Get the model position of the end of the row that contains the
specified model position.
|
static int | getRowStart(JTextComponent c, int offs) - Get the model position of the start of the row that contains the specified
model position.
|
static int | getTabbedTextOffset(Segment s, FontMetrics fm, int x0, int x, TabExpander te, int p0) - Provides a facility to map screen coordinates into a model location.
|
static int | getTabbedTextOffset(Segment s, FontMetrics fm, int x0, int x, TabExpander te, int p0, boolean round) - Provides a facility to map screen coordinates into a model location.
|
static int | getTabbedTextWidth(Segment s, FontMetrics metrics, int x, TabExpander e, int startOffset) - Determines the width, that the given text
s would take
if it was printed with the given FontMetrics on the
specified screen position.
|
static int | getWordEnd(JTextComponent c, int offs) - Finds the end of a word for the given location.
|
static int | getWordStart(JTextComponent c, int offs) - Finds the start of a word for the given location.
|
clone , equals , extends Object> getClass , finalize , hashCode , notify , notifyAll , toString , wait , wait , wait |
Utilities
public Utilities()
Creates a new Utilities
object.
drawTabbedText
public static final int drawTabbedText(Segment s,
int x,
int y,
Graphics g,
TabExpander e,
int startOffset)
Draws the given text segment. Contained tabs and newline characters
are taken into account. Tabs are expanded using the
specified
TabExpander
.
The X and Y coordinates denote the start of the
baseline where
the text should be drawn.
s
- the text fragment to be drawn.x
- the x position for drawing.y
- the y position for drawing.g
- the Graphics
context for drawing.e
- the TabExpander
which specifies the Tab-expanding
technique.startOffset
- starting offset in the text.
- the x coordinate at the end of the drawn text.
getBreakLocation
public static final int getBreakLocation(Segment s,
FontMetrics metrics,
int x0,
int x,
TabExpander e,
int startOffset)
Determine where to break the text in the given Segment, attempting to find
a word boundary.
s
- the Segment that holds the textmetrics
- the font metrics used for calculating the break pointx0
- starting view location representing the start of the textx
- the target view locatione
- the TabExpander used for expanding tabs (if this is null tabs
are expanded to 1 space)startOffset
- the offset in the Document of the start of the text
- the offset at which we should break the text
getNextWord
public static final int getNextWord(JTextComponent c,
int offs)
throws BadLocationException
Finds the start of the next word for the given offset.
c
- the text componentoffs
- the offset in the document
- the location in the model of the start of the next word.
getParagraphElement
public static final Element getParagraphElement(JTextComponent c,
int offset)
Returns the paragraph element in the text component c
at
the specified location offset
.
c
- the text componentoffset
- the offset of the paragraph element to return
- the paragraph element at
offset
getPositionAbove
public static final int getPositionAbove(JTextComponent c,
int offset,
int x)
throws BadLocationException
Returns the document position that is closest above to the specified x
coordinate in the row containing offset
.
c
- the text componentoffset
- the offsetx
- the x coordinate
- the document position that is closest above to the specified x
coordinate in the row containing
offset
getPositionBelow
public static final int getPositionBelow(JTextComponent c,
int offset,
int x)
throws BadLocationException
Returns the document position that is closest below to the specified x
coordinate in the row containing offset
.
c
- the text componentoffset
- the offsetx
- the x coordinate
- the document position that is closest above to the specified x
coordinate in the row containing
offset
getPreviousWord
public static final int getPreviousWord(JTextComponent c,
int offs)
throws BadLocationException
Finds the start of the previous word for the given offset.
c
- the text componentoffs
- the offset in the document
- the location in the model of the start of the previous word.
getRowEnd
public static final int getRowEnd(JTextComponent c,
int offs)
throws BadLocationException
Get the model position of the end of the row that contains the
specified model position. Return null if the given JTextComponent
does not have a size.
c
- the JTextComponentoffs
- the model position
- the model position of the end of the row containing the given
offset
getRowStart
public static final int getRowStart(JTextComponent c,
int offs)
throws BadLocationException
Get the model position of the start of the row that contains the specified
model position. Return null if the given JTextComponent does not have a
size.
c
- the JTextComponentoffs
- the model position
- the model position of the start of the row containing the given
offset
getTabbedTextOffset
public static final int getTabbedTextOffset(Segment s,
FontMetrics fm,
int x0,
int x,
TabExpander te,
int p0)
Provides a facility to map screen coordinates into a model location. For a
given text fragment and start location within this fragment, this method
determines the model location so that the resulting fragment fits best
into the span [x0, x]
.
This method rounds up to the next location, so that the resulting fragment
will be the smallest fragment of the text, that is greater than the
specified span.
s
- the text segmentfm
- the font metrics to usex0
- the starting screen locationx
- the target screen location at which the requested fragment should
endte
- the tab expander to use; if this is null
, TABs are
expanded to one space characterp0
- the starting model location
- the model location, so that the resulting fragment fits within the
specified span
getTabbedTextOffset
public static final int getTabbedTextOffset(Segment s,
FontMetrics fm,
int x0,
int x,
TabExpander te,
int p0,
boolean round)
Provides a facility to map screen coordinates into a model location. For a
given text fragment and start location within this fragment, this method
determines the model location so that the resulting fragment fits best
into the span [x0, x]
.
The parameter round
controls which model location is returned
if the view coordinates are on a character: If round
is
true
, then the result is rounded up to the next character, so
that the resulting fragment is the smallest fragment that is larger than
the specified span. If round
is false
, then the
resulting fragment is the largest fragment that is smaller than the
specified span.
s
- the text segmentfm
- the font metrics to usex0
- the starting screen locationx
- the target screen location at which the requested fragment should
endte
- the tab expander to use; if this is null
, TABs are
expanded to one space characterp0
- the starting model locationround
- if true
round up to the next location, otherwise
round down to the current location
- the model location, so that the resulting fragment fits within the
specified span
getTabbedTextWidth
public static final int getTabbedTextWidth(Segment s,
FontMetrics metrics,
int x,
TabExpander e,
int startOffset)
Determines the width, that the given text
s
would take
if it was printed with the given
FontMetrics
on the
specified screen position.
s
- the text fragmentmetrics
- the font metrics of the font to be usedx
- the x coordinate of the point at which drawing should be donee
- the TabExpander
to be usedstartOffset
- the index in s
where to start
getWordEnd
public static final int getWordEnd(JTextComponent c,
int offs)
throws BadLocationException
Finds the end of a word for the given location.
c
- the text componentoffs
- the offset location
- the location of the word end
getWordStart
public static final int getWordStart(JTextComponent c,
int offs)
throws BadLocationException
Finds the start of a word for the given location.
c
- the text componentoffs
- the offset location
- the location of the word beginning
Utilities.java --
Copyright (C) 2004, 2005, 2006 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version.