int width = 0;
	public int xToOffset(int line, int x)	{		x -= textArea.getHorizontalOffset();		TokenMarker tokenMarker = getTokenMarker();		/* Use painter's cached info for speed */		TextAreaPainter painter = textArea.getPainter();		FontMetrics fm = painter.getFontMetrics();		Segment lineSegment = painter.currentLine;					if(painter.currentLineIndex != line)		{			getLineText(line,lineSegment);			painter.currentLineIndex = line;		}		char[] segmentArray = lineSegment.array;		int segmentOffset = lineSegment.offset;		int segmentCount = lineSegment.count;		if(tokenMarker == null)		{			int width = 0;			for(int i = 0; i < segmentCount; i++)			{				char c = segmentArray[i + segmentOffset];				int charWidth;				if(c == '\t')					charWidth = (int)painter.nextTabStop(width,i)						- width;				else					charWidth = fm.charWidth(c);				if(painter.isBlockCaretEnabled())				{					if(x + charWidth / 2 <= width)						return i;				}				else				{					if(x - charWidth / 2 <= width)						return i;				}				width += charWidth;			}			return segmentCount;		}		else		{			// XXX: token list is computed twice for lines			// that are highlighted			Token tokens = tokenMarker.markTokens(				lineSegment,line);			int offset = 0;			Toolkit toolkit = painter.getToolkit();			Font defaultFont = painter.getFont();			SyntaxStyle[] styles = painter.getStyles();			int width = 0;			for(;;)			{				byte id = tokens.id;				if(id == Token.END)					return offset;				if(id == Token.NULL)					fm = toolkit.getFontMetrics(defaultFont);				else				{					fm = toolkit.getFontMetrics(styles[id]						.getStyledFont(defaultFont));				}				int length = tokens.length;				for(int i = 0; i < length; i++)				{					char c = segmentArray[segmentOffset + offset + i];					int charWidth;					if(c == '\t')						charWidth = (int)painter.nextTabStop(width,offset + i)							- width;					else						charWidth = fm.charWidth(c);						if(x - charWidth / 2 <= width)						return offset + i;						width += charWidth;				}				offset += length;				tokens = tokens.next;			}		}	}