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

📄 foldvisibilitymanager.java

📁 用java 编写的源码开放的文本编辑器。有很多有用的特性
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
	 * Collapses the fold at the specified physical line index.	 * @param line A physical line index	 * @since jEdit 4.0pre1	 */	public void collapseFold(int line)	{		int lineCount = buffer.getLineCount();		int start = 0;		int end = lineCount - 1;		try		{			buffer.writeLock();			// if the caret is on a collapsed fold, collapse the			// parent fold			if(line != 0				&& line != buffer.getLineCount() - 1				&& buffer.isFoldStart(line)				&& !offsetMgr.isLineVisible(line + 1,index))			{				line--;			}			int initialFoldLevel = buffer.getFoldLevel(line);			//{{{ Find fold start and end...			if(line != lineCount - 1				&& buffer.getFoldLevel(line + 1) > initialFoldLevel)			{				// this line is the start of a fold				start = line + 1;				for(int i = line + 1; i < lineCount; i++)				{					if(buffer.getFoldLevel(i) <= initialFoldLevel)					{						end = i - 1;						break;					}				}			}			else			{				boolean ok = false;				// scan backwards looking for the start				for(int i = line - 1; i >= 0; i--)				{					if(buffer.getFoldLevel(i) < initialFoldLevel)					{						start = i + 1;						ok = true;						break;					}				}				if(!ok)				{					// no folds in buffer					return;				}				for(int i = line + 1; i < lineCount; i++)				{					if(buffer.getFoldLevel(i) < initialFoldLevel)					{						end = i - 1;						break;					}				}			} //}}}			//{{{ Collapse the fold...			int delta = (end - start + 1);			for(int i = start; i <= end; i++)			{				if(offsetMgr.isLineVisible(i,index))					offsetMgr.setLineVisible(i,index,false);				else					delta--;			}			if(delta == 0)			{				// user probably pressed A+BACK_SPACE twice				return;			}			offsetMgr.setVirtualLineCount(index,				offsetMgr.getVirtualLineCount(index)				- delta);			//}}}		}		finally		{			buffer.writeUnlock();		}		foldStructureChanged();		int virtualLine = physicalToVirtual(start);		if(textArea.getFirstLine() > virtualLine)			textArea.setFirstLine(virtualLine - textArea.getElectricScroll());	} //}}}	//{{{ expandFold() method	/**	 * Expands the fold at the specified physical line index.	 * @param line A physical line index	 * @param fully If true, all subfolds will also be expanded	 * @since jEdit 4.0pre3	 */	public int expandFold(int line, boolean fully)	{		// the first sub-fold. used by JEditTextArea.expandFold().		int returnValue = -1;		int lineCount = buffer.getLineCount();		int start = 0;		int end = lineCount - 1;		int delta = 0;		try		{			buffer.writeLock();			int initialFoldLevel = buffer.getFoldLevel(line);			//{{{ Find fold start and fold end...			if(line != lineCount - 1				&& offsetMgr.isLineVisible(line,index)				&& !offsetMgr.isLineVisible(line + 1,index)				&& buffer.getFoldLevel(line + 1) > initialFoldLevel)			{				// this line is the start of a fold				start = line + 1;				for(int i = line + 1; i < lineCount; i++)				{					if(/* offsetMgr.isLineVisible(i,index) && */						buffer.getFoldLevel(i) <= initialFoldLevel)					{						end = i - 1;						break;					}				}			}			else			{				boolean ok = false;				// scan backwards looking for the start				for(int i = line - 1; i >= 0; i--)				{					if(offsetMgr.isLineVisible(i,index) && buffer.getFoldLevel(i) < initialFoldLevel)					{						start = i + 1;						ok = true;						break;					}				}				if(!ok)				{					// no folds in buffer					return -1;				}				for(int i = line + 1; i < lineCount; i++)				{					if((offsetMgr.isLineVisible(i,index) &&						buffer.getFoldLevel(i) < initialFoldLevel)						|| i == getLastVisibleLine())					{						end = i - 1;						break;					}				}			} //}}}			//{{{ Expand the fold...			// we need a different value of initialFoldLevel here!			initialFoldLevel = buffer.getFoldLevel(start);			for(int i = start; i <= end; i++)			{				buffer.getFoldLevel(i);			}			for(int i = start; i <= end; i++)			{				if(buffer.getFoldLevel(i) > initialFoldLevel)				{					if(returnValue == -1						&& i != 0						&& buffer.isFoldStart(i - 1))					{						returnValue = i - 1;					}					if(!offsetMgr.isLineVisible(i,index) && fully)					{						delta++;						offsetMgr.setLineVisible(i,index,true);					}				}				else if(!offsetMgr.isLineVisible(i,index))				{					delta++;					offsetMgr.setLineVisible(i,index,true);				}			}			offsetMgr.setVirtualLineCount(index,				offsetMgr.getVirtualLineCount(index)				+ delta);			//}}}			if(!fully && !offsetMgr.isLineVisible(line,index))			{				// this is a hack, and really needs to be done better.				expandFold(line,false);				return returnValue;			}		}		finally		{			buffer.writeUnlock();		}		foldStructureChanged();		int virtualLine = physicalToVirtual(start);		int firstLine = textArea.getFirstLine();		int visibleLines = textArea.getVisibleLines();		if(virtualLine + delta >= firstLine + visibleLines			&& delta < visibleLines - 1)		{			textArea.setFirstLine(virtualLine + delta - visibleLines + 1);		}		return returnValue;	} //}}}	//{{{ expandAllFolds() method	/**	 * Expands all folds.	 * @since jEdit 4.0pre1	 */	public void expandAllFolds()	{		try		{			buffer.writeLock();			narrowed = false;			if(offsetMgr.getVirtualLineCount(index) == buffer.getLineCount())				return;			offsetMgr.setVirtualLineCount(index,buffer.getLineCount());			for(int i = 0; i < buffer.getLineCount(); i++)			{				offsetMgr.setLineVisible(i,index,true);			}			foldStructureChanged();		}		finally		{			buffer.writeUnlock();		}	} //}}}	//{{{ expandFolds() method	/**	 * This method should only be called from <code>actions.xml</code>.	 * @since jEdit 4.0pre1	 */	public void expandFolds(char digit)	{		if(digit < '1' || digit > '9')		{			Toolkit.getDefaultToolkit().beep();			return;		}		else			expandFolds((int)(digit - '1') + 1);	} //}}}	//{{{ expandFolds() method	/**	 * Expands all folds with the specified fold level.	 * @param foldLevel The fold level	 * @since jEdit 4.0pre1	 */	public void expandFolds(int foldLevel)	{		try		{			buffer.writeLock();			narrowed = false;			// so that getFoldLevel() calling fireFoldLevelsChanged()			// won't break			offsetMgr.setVirtualLineCount(index,buffer.getLineCount());			int newVirtualLineCount = 0;			foldLevel = (foldLevel - 1) * buffer.getIndentSize() + 1;			/* this ensures that the first line is always visible */			boolean seenVisibleLine = false;			for(int i = 0; i < buffer.getLineCount(); i++)			{				if(!seenVisibleLine || buffer.getFoldLevel(i) < foldLevel)				{					seenVisibleLine = true;					offsetMgr.setLineVisible(i,index,true);					newVirtualLineCount++;				}				else					offsetMgr.setLineVisible(i,index,false);			}			offsetMgr.setVirtualLineCount(index,newVirtualLineCount);		}		finally		{			buffer.writeUnlock();		}		foldStructureChanged();	} //}}}	//{{{ narrow() method	/**	 * Narrows the visible portion of the buffer to the specified	 * line range.	 * @param start The first line	 * @param end The last line	 * @since jEdit 4.0pre1	 */	public void narrow(int start, int end)	{		if(start > end || start < 0 || end >= offsetMgr.getLineCount())			throw new ArrayIndexOutOfBoundsException(start + ", " + end);		if(start < getFirstVisibleLine() || end > getLastVisibleLine())			expandAllFolds();		// ideally, this should somehow be rolled into the below loop.		else if(start != offsetMgr.getLineCount() - 1			&& !offsetMgr.isLineVisible(start + 1,index))			expandFold(start,false);		int virtualLineCount = offsetMgr.getVirtualLineCount(index);		for(int i = 0; i < start; i++)		{			if(offsetMgr.isLineVisible(i,index))			{				virtualLineCount--;				offsetMgr.setLineVisible(i,index,false);			}		}		for(int i = end + 1; i < buffer.getLineCount(); i++)		{			if(offsetMgr.isLineVisible(i,index))			{				virtualLineCount--;				offsetMgr.setLineVisible(i,index,false);			}		}		offsetMgr.setVirtualLineCount(index,virtualLineCount);		narrowed = true;		foldStructureChanged();		// Hack... need a more direct way of obtaining a view?		// JEditTextArea.getView() method?		GUIUtilities.getView(textArea).getStatus().setMessageAndClear(			jEdit.getProperty("view.status.narrow"));	} //}}}	//{{{ Methods for Buffer class to call	//{{{ _grab() method	/**	 * Do not call this method. The only reason it is public is so	 * that the <code>Buffer</code> class can call it.	 */	public final void _grab(int index)	{		this.index = index;		lastPhysical = lastVirtual = -1;	} //}}}	//{{{ _release() method	/**	 * Do not call this method. The only reason it is public is so	 * that the <code>Buffer</code> class can call it.	 */	public final void _release()	{		index = -1;	} //}}}	//{{{ _getIndex() method	/**	 * Do not call this method. The only reason it is public is so	 * that the <code>Buffer</code> class can call it.	 */	public final int _getIndex()	{		return index;	} //}}}	//{{{ _invalidate() method	/**	 * Do not call this method. The only reason it is public is so	 * that the <code>Buffer</code> class can call it.	 */	public void _invalidate(int startLine)	{		if(lastPhysical >= startLine)			lastPhysical = lastVirtual = -1;	} //}}}	//}}}	//{{{ foldStructureChanged() method	/**	 * This method is only public so that the EditPane class can call it in	 * response to a buffer's fold handler change.	 * @since jEdit 4.0pre8	 */	public void foldStructureChanged()	{		lastPhysical = lastVirtual = -1;		textArea.foldStructureChanged();	} //}}}	//{{{ Private members	//{{{ Instance variables	private Buffer buffer;	private OffsetManager offsetMgr;	private JEditTextArea textArea;	private int index;	private int lastPhysical;	private int lastVirtual;	private boolean narrowed;	//}}}	//}}}}

⌨️ 快捷键说明

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