⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 chunkcache.java

📁 开源的java 编辑器源代码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
	 * is on	 */	int getBelowPosition(int physicalLine, int offset, int x,		boolean ignoreWrap)	{		LineInfo[] lineInfos = getLineInfosForPhysicalLine(physicalLine);		int subregion = getSubregionOfOffset(offset,lineInfos);		if(subregion != lineInfos.length - 1 && !ignoreWrap)		{			return textArea.getLineStartOffset(physicalLine)				+ xToSubregionOffset(lineInfos[subregion + 1],				x,true);		}		else		{			int nextLine = textArea.displayManager				.getNextVisibleLine(physicalLine);			if(nextLine == -1)				return -1;			else			{				return textArea.getLineStartOffset(nextLine)					+ xToSubregionOffset(nextLine,0,					x,true);			}		}	} //}}}	//{{{ getAbovePosition() method	/**	 * @param physicalLine The physical line number	 * @param offset The offset	 * @param x The location	 * @param ignoreWrap If true, behave as if soft wrap is off even if it	 * is on	 */	int getAbovePosition(int physicalLine, int offset, int x,		boolean ignoreWrap)	{		LineInfo[] lineInfos = getLineInfosForPhysicalLine(physicalLine);		int subregion = getSubregionOfOffset(offset,lineInfos);		if(subregion != 0 && !ignoreWrap)		{			return textArea.getLineStartOffset(physicalLine)				+ xToSubregionOffset(lineInfos[subregion - 1],				x,true);		}		else		{			int prevLine = textArea.displayManager				.getPrevVisibleLine(physicalLine);			if(prevLine == -1)				return -1;			else			{				return textArea.getLineStartOffset(prevLine)					+ xToSubregionOffset(prevLine,-1,					x,true);			}		}	} //}}}	//{{{ needFullRepaint() method	/**	 * The needFullRepaint variable becomes true when the number of screen	 * lines in a physical line changes.	 */	boolean needFullRepaint()	{		boolean retVal = needFullRepaint;		needFullRepaint = false;		return retVal;	} //}}}	//{{{ getLineInfosForPhysicalLine() method	LineInfo[] getLineInfosForPhysicalLine(int physicalLine)	{		out.clear();		if(buffer.isLoaded())			lineToChunkList(physicalLine,out);		if(out.size() == 0)			out.add(null);		ArrayList returnValue = new ArrayList(out.size());		getLineInfosForPhysicalLine(physicalLine,returnValue);		return (LineInfo[])returnValue.toArray(new LineInfo[out.size()]);	} //}}}	//{{{ Private members	//{{{ Instance variables	private JEditTextArea textArea;	private Buffer buffer;	private LineInfo[] lineInfo;	private ArrayList out;	private int firstInvalidLine;	private int lastScreenLineP;	private int lastScreenLine;	private boolean needFullRepaint;	private DisplayTokenHandler tokenHandler;	//}}}	//{{{ getLineInfosForPhysicalLine() method	private void getLineInfosForPhysicalLine(int physicalLine, List list)	{		for(int i = 0; i < out.size(); i++)		{			Chunk chunks = (Chunk)out.get(i);			LineInfo info = new LineInfo();			info.physicalLine = physicalLine;			if(i == 0)			{				info.firstSubregion = true;				info.offset = 0;			}			else				info.offset = chunks.offset;			if(i == out.size() - 1)			{				info.lastSubregion = true;				info.length = textArea.getLineLength(physicalLine)					- info.offset + 1;			}			else			{				info.length = ((Chunk)out.get(i + 1)).offset					- info.offset;			}			info.chunks = chunks;			list.add(info);		}	} //}}}	//{{{ updateChunksUpTo() method	private void updateChunksUpTo(int lastScreenLine)	{		// this method is a nightmare		if(lastScreenLine >= lineInfo.length)		{			throw new ArrayIndexOutOfBoundsException(lastScreenLine);		}		// if one line's chunks are invalid, remaining lines are also		// invalid		if(lastScreenLine < firstInvalidLine)			return;		// find a valid line closest to the last screen line		int firstScreenLine = 0;		for(int i = firstInvalidLine - 1; i >= 0; i--)		{			if(lineInfo[i].lastSubregion)			{				firstScreenLine = i + 1;				break;			}		}		int physicalLine;		// for the first line displayed, take its physical line to be		// the text area's first physical line		if(firstScreenLine == 0)		{			physicalLine = textArea.getFirstPhysicalLine();		}		// otherwise, determine the next visible line		else		{			int prevPhysLine = lineInfo[				firstScreenLine - 1]				.physicalLine;			// if -1, the empty space at the end of the text area			// when the buffer has less lines than are visible			if(prevPhysLine == -1)				physicalLine = -1;			else			{				physicalLine = textArea					.displayManager					.getNextVisibleLine(prevPhysLine);			}		}		if(Debug.CHUNK_CACHE_DEBUG)		{			Log.log(Log.DEBUG,this,"Updating chunks from " + firstScreenLine				+ " to " + lastScreenLine);		}		// Note that we rely on the fact that when a physical line is		// invalidated, all screen lines/subregions of that line are		// invalidated as well. See below comment for code that tries		// to uphold this assumption.		out.clear();		int offset = 0;		int length = 0;		for(int i = firstScreenLine; i <= lastScreenLine; i++)		{			LineInfo info = lineInfo[i];			Chunk chunks;			// get another line of chunks			if(out.size() == 0)			{				// unless this is the first time, increment				// the line number				if(physicalLine != -1 && i != firstScreenLine)				{					physicalLine = textArea.displayManager						.getNextVisibleLine(physicalLine);				}				// empty space				if(physicalLine == -1)				{					info.chunks = null;					info.physicalLine = -1;					continue;				}				// chunk the line.				lineToChunkList(physicalLine,out);				info.firstSubregion = true;				// if the line has no text, out.size() == 0				if(out.size() == 0)				{					textArea.displayManager						.setScreenLineCount(						physicalLine,1);					if(i == 0)					{						if(textArea.displayManager.firstLine.skew > 0)						{							Log.log(Log.ERROR,this,"BUG: skew=" + textArea.displayManager.firstLine.skew + ",out.size()=" + out.size());							textArea.displayManager.firstLine.skew = 0;							needFullRepaint = true;							lastScreenLine = lineInfo.length - 1;						}					}					chunks = null;					offset = 0;					length = 1;				}				// otherwise, the number of subregions				else				{					textArea.displayManager						.setScreenLineCount(						physicalLine,out.size());					if(i == 0)					{						int skew = textArea.displayManager.firstLine.skew;						if(skew >= out.size())						{							Log.log(Log.ERROR,this,"BUG: skew=" + skew + ",out.size()=" + out.size());							skew = 0;							needFullRepaint = true;							lastScreenLine = lineInfo.length - 1;						}						else if(skew > 0)						{							info.firstSubregion = false;							for(int j = 0; j < skew; j++)								out.remove(0);						}					}					chunks = (Chunk)out.get(0);					out.remove(0);					offset = chunks.offset;					if(out.size() != 0)						length = ((Chunk)out.get(0)).offset - offset;					else						length = textArea.getLineLength(physicalLine) - offset + 1;				}			}			else			{				info.firstSubregion = false;				chunks = (Chunk)out.get(0);				out.remove(0);				offset = chunks.offset;				if(out.size() != 0)					length = ((Chunk)out.get(0)).offset - offset;				else					length = textArea.getLineLength(physicalLine) - offset + 1;			}			boolean lastSubregion = (out.size() == 0);			if(i == lastScreenLine				&& lastScreenLine != lineInfo.length - 1)			{				/* if the user changes the syntax token at the				 * end of a line, need to do a full repaint. */				if(tokenHandler.getLineContext() !=					info.lineContext)				{					lastScreenLine++;					needFullRepaint = true;				}				/* If this line has become longer or shorter				 * (in which case the new physical line number				 * is different from the cached one) we need to:				 * - continue updating past the last line				 * - advise the text area to repaint				 * On the other hand, if the line wraps beyond				 * lastScreenLine, we need to keep updating the				 * chunk list to ensure proper alignment of				 * invalidation flags (see start of method) */				else if(info.physicalLine != physicalLine					|| info.lastSubregion != lastSubregion)				{					lastScreenLine++;					needFullRepaint = true;				}				/* We only cache entire physical lines at once;				 * don't want to split a physical line into				 * screen lines and only have some valid. */				else if(out.size() != 0)					lastScreenLine++;			}			info.physicalLine = physicalLine;			info.lastSubregion = lastSubregion;			info.offset = offset;			info.length = length;			info.chunks = chunks;			info.lineContext = tokenHandler.getLineContext();		}		firstInvalidLine = Math.max(lastScreenLine + 1,firstInvalidLine);	} //}}}	//{{{ lineToChunkList() method	private void lineToChunkList(int physicalLine, List out)	{		TextAreaPainter painter = textArea.getPainter();		tokenHandler.init(painter.getStyles(),			painter.getFontRenderContext(),			painter,out,			(textArea.displayManager.softWrap			? textArea.displayManager.wrapMargin : 0.0f));		buffer.markTokens(physicalLine,tokenHandler);	} //}}}	//}}}	//{{{ LineInfo class	static class LineInfo	{		int physicalLine;		int offset;		int length;		boolean firstSubregion;		boolean lastSubregion;		Chunk chunks;		int width;		TokenMarker.LineContext lineContext;	} //}}}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -