- java.lang.Object
-
- java.awt.font.TextHitInfo
-
public final class TextHitInfo extends Object
TheTextHitInfo
class represents a character position in a text model, and a bias, or "side," of the character. Biases are either leading (the left edge, for a left-to-right character) or trailing (the right edge, for a left-to-right character). Instances ofTextHitInfo
are used to specify caret and insertion positions within text.For example, consider the text "abc". TextHitInfo.trailing(1) corresponds to the right side of the 'b' in the text.
TextHitInfo
is used primarily byTextLayout
and clients ofTextLayout
. Clients ofTextLayout
queryTextHitInfo
instances for an insertion offset, where new text is inserted into the text model. The insertion offset is equal to the character position in theTextHitInfo
if the bias is leading, and one character after if the bias is trailing. The insertion offset for TextHitInfo.trailing(1) is 2.Sometimes it is convenient to construct a
TextHitInfo
with the same insertion offset as an existing one, but on the opposite character. ThegetOtherHit
method constructs a newTextHitInfo
with the same insertion offset as an existing one, with a hit on the character on the other side of the insertion offset. CallinggetOtherHit
on trailing(1) would return leading(2). In general,getOtherHit
for trailing(n) returns leading(n+1) andgetOtherHit
for leading(n) returns trailing(n-1).Example:
Converting a graphical point to an insertion point within a text model
TextLayout layout = ...; Point2D.Float hitPoint = ...; TextHitInfo hitInfo = layout.hitTestChar(hitPoint.x, hitPoint.y); int insPoint = hitInfo.getInsertionIndex(); // insPoint is relative to layout; may need to adjust for use // in a text model
- See Also:
TextLayout
-
-
Method Summary
Methods Modifier and Type Method and Description static TextHitInfo
afterOffset(int offset)
Creates aTextHitInfo
at the specified offset, associated with the character after the offset.static TextHitInfo
beforeOffset(int offset)
Creates aTextHitInfo
at the specified offset, associated with the character before the offset.boolean
equals(Object obj)
Returnstrue
if the specifiedObject
is aTextHitInfo
and equals thisTextHitInfo
.boolean
equals(TextHitInfo hitInfo)
Returnstrue
if the specifiedTextHitInfo
has the samecharIndex
andisLeadingEdge
as thisTextHitInfo
.int
getCharIndex()
Returns the index of the character hit.int
getInsertionIndex()
Returns the insertion index.TextHitInfo
getOffsetHit(int delta)
Creates aTextHitInfo
whose character index is offset bydelta
from thecharIndex
of thisTextHitInfo
.TextHitInfo
getOtherHit()
Creates aTextHitInfo
on the other side of the insertion point.int
hashCode()
Returns the hash code.boolean
isLeadingEdge()
Returnstrue
if the leading edge of the character was hit.static TextHitInfo
leading(int charIndex)
Creates aTextHitInfo
on the leading edge of the character at the specifiedcharIndex
.String
toString()
Returns aString
representing the hit for debugging use only.static TextHitInfo
trailing(int charIndex)
Creates a hit on the trailing edge of the character at the specifiedcharIndex
.
-
-
-
Method Detail
-
getCharIndex
public int getCharIndex()
Returns the index of the character hit.- Returns:
- the index of the character hit.
-
isLeadingEdge
public boolean isLeadingEdge()
Returnstrue
if the leading edge of the character was hit.- Returns:
true
if the leading edge of the character was hit;false
otherwise.
-
getInsertionIndex
public int getInsertionIndex()
Returns the insertion index. This is the character index if the leading edge of the character was hit, and one greater than the character index if the trailing edge was hit.- Returns:
- the insertion index.
-
hashCode
public int hashCode()
Returns the hash code.- Overrides:
hashCode
in classObject
- Returns:
- the hash code of this
TextHitInfo
, which is also thecharIndex
of thisTextHitInfo
. - See Also:
Object.equals(java.lang.Object)
,System.identityHashCode(java.lang.Object)
-
equals
public boolean equals(Object obj)
Returnstrue
if the specifiedObject
is aTextHitInfo
and equals thisTextHitInfo
.- Overrides:
equals
in classObject
- Parameters:
obj
- theObject
to test for equality- Returns:
true
if the specifiedObject
equals thisTextHitInfo
;false
otherwise.- See Also:
Object.hashCode()
,HashMap
-
equals
public boolean equals(TextHitInfo hitInfo)
Returnstrue
if the specifiedTextHitInfo
has the samecharIndex
andisLeadingEdge
as thisTextHitInfo
. This is not the same as having the same insertion offset.- Parameters:
hitInfo
- a specifiedTextHitInfo
- Returns:
true
if the specifiedTextHitInfo
has the samecharIndex
andisLeadingEdge
as thisTextHitInfo
.
-
toString
public String toString()
Returns aString
representing the hit for debugging use only.
-
leading
public static TextHitInfo leading(int charIndex)
Creates aTextHitInfo
on the leading edge of the character at the specifiedcharIndex
.- Parameters:
charIndex
- the index of the character hit- Returns:
- a
TextHitInfo
on the leading edge of the character at the specifiedcharIndex
.
-
trailing
public static TextHitInfo trailing(int charIndex)
Creates a hit on the trailing edge of the character at the specifiedcharIndex
.- Parameters:
charIndex
- the index of the character hit- Returns:
- a
TextHitInfo
on the trailing edge of the character at the specifiedcharIndex
.
-
beforeOffset
public static TextHitInfo beforeOffset(int offset)
Creates aTextHitInfo
at the specified offset, associated with the character before the offset.- Parameters:
offset
- an offset associated with the character before the offset- Returns:
- a
TextHitInfo
at the specified offset.
-
afterOffset
public static TextHitInfo afterOffset(int offset)
Creates aTextHitInfo
at the specified offset, associated with the character after the offset.- Parameters:
offset
- an offset associated with the character after the offset- Returns:
- a
TextHitInfo
at the specified offset.
-
getOtherHit
public TextHitInfo getOtherHit()
Creates aTextHitInfo
on the other side of the insertion point. ThisTextHitInfo
remains unchanged.- Returns:
- a
TextHitInfo
on the other side of the insertion point.
-
getOffsetHit
public TextHitInfo getOffsetHit(int delta)
Creates aTextHitInfo
whose character index is offset bydelta
from thecharIndex
of thisTextHitInfo
. ThisTextHitInfo
remains unchanged.- Parameters:
delta
- the value to offset thischarIndex
- Returns:
- a
TextHitInfo
whosecharIndex
is offset bydelta
from thecharIndex
of thisTextHitInfo
.
-
-
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-java/awt/font/TextHitInfo.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
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.