/[classpath]/classpath/javax/swing/text/PlainView.java
ViewVC logotype

Diff of /classpath/javax/swing/text/PlainView.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.18 by abalkiss, Tue Oct 11 16:18:34 2005 UTC revision 1.19 by abalkiss, Tue Oct 11 18:34:09 2005 UTC
# Line 294  public class PlainView extends View Line 294  public class PlainView extends View
294     */     */
295    public int viewToModel(float x, float y, Shape a, Position.Bias[] b)    public int viewToModel(float x, float y, Shape a, Position.Bias[] b)
296    {    {
297      // FIXME: not implemented      Rectangle rec = a.getBounds();
298      return 0;      Document doc = getDocument();
299        Element root = doc.getDefaultRootElement();
300        
301        // PlainView doesn't support line-wrapping so we can find out which
302        // Element was clicked on just by the y-position    
303        int lineClicked = (int) (y - rec.y) / metrics.getHeight();
304        if (lineClicked >= root.getElementCount())
305          return getEndOffset() - 1;
306        
307        Element line = root.getElement(lineClicked);
308        Segment s = new Segment();
309    
310        int start = line.getStartOffset();
311        int end = line.getEndOffset();
312        try
313        {
314          doc.getText(start, end - start, s);
315        }
316        catch (BadLocationException ble)
317        {
318          //this should never happen
319        }
320        
321        int pos = Utilities.getTabbedTextOffset(s, metrics, rec.x, (int)x, this, start);
322        return Math.max (0, pos);
323    }    }
324        
325    /**    /**

Legend:
Removed from v.1.18  
changed lines
  Added in v.1.19

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26