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 |
/** |
/** |