public int viewToModel(float fx,float fy,Shape a,Position.Bias[] bias){
  bias[0]=Position.Bias.Forward;
  Rectangle alloc=a.getBounds();
  Document doc=getDocument();
  int x=(int)fx;
  int y=(int)fy;
  if (y < alloc.y) {
    return getStartOffset();
  }
 else   if (y > alloc.y + alloc.height) {
    return getEndOffset() - 1;
  }
 else {
    Element map=doc.getDefaultRootElement();
    int fontHeight=metrics.getHeight();
    int lineIndex=(fontHeight > 0 ? Math.abs((y - alloc.y) / fontHeight) : map.getElementCount() - 1);
    if (lineIndex >= map.getElementCount()) {
      return getEndOffset() - 1;
    }
    Element line=map.getElement(lineIndex);
    int dx=0;
    if (lineIndex == 0) {
      alloc.x+=firstLineOffset;
      alloc.width-=firstLineOffset;
    }
    if (x < alloc.x) {
      return line.getStartOffset();
    }
 else     if (x > alloc.x + alloc.width) {
      return line.getEndOffset() - 1;
    }
 else {
      try {
        int p0=line.getStartOffset();
        int p1=line.getEndOffset() - 1;
        Segment s=SegmentCache.getSharedSegment();
        doc.getText(p0,p1 - p0,s);
        tabBase=alloc.x;
        int offs=p0 + Utilities.getTabbedTextOffset(s,metrics,tabBase,x,this,p0);
        SegmentCache.releaseSharedSegment(s);
        return offs;
      }
 catch (      BadLocationException e) {
        return -1;
      }
    }
  }
}

public int viewToModel ( float fx , float fy , Shape a , Position . Bias [ ] bias ) { bias [ 0 ] = Position . Bias . Forward ; Rectangle alloc = a . getBounds ( ) ; Document doc = getDocument ( ) ; int x = ( int ) fx ; int y = ( int ) fy ; if ( y < alloc . y ) { return getStartOffset ( ) ; } else if ( y > alloc . y + alloc . height ) { return getEndOffset ( ) - 1 ; } else { Element map = doc . getDefaultRootElement ( ) ; int fontHeight = metrics . getHeight ( ) ; int lineIndex = ( fontHeight > 0 ? Math . abs ( ( y - alloc . y ) / fontHeight ) : map . getElementCount ( ) - 1 ) ; if ( lineIndex >= map . getElementCount ( ) ) { return getEndOffset ( ) - 1 ; } Element line = map . getElement ( lineIndex ) ; int dx = 0 ; if ( lineIndex == 0 ) { alloc . x += firstLineOffset ; alloc . width -= firstLineOffset ; } if ( x < alloc . x ) { return line . getStartOffset ( ) ; } else if ( x > alloc . x + alloc . width ) { return line . getEndOffset ( ) - 1 ; } else { try { int p0 = line . getStartOffset ( ) ; int p1 = line . getEndOffset ( ) - 1 ; Segment s = SegmentCache . getSharedSegment ( ) ; doc . getText ( p0 , p1 - p0 , s ) ; tabBase = alloc . x ; int offs = p0 + Utilities . getTabbedTextOffset ( s , metrics , tabBase , x , this , p0 ) ; SegmentCache . releaseSharedSegment ( s ) ; return offs ; } catch ( BadLocationException e ) { return - 1 ; } } } }
provides a mapping from the view coordinate space to the logical coordinate space of the model .
