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

📄 jedittextarea.java

📁 用java 编写的源码开放的文本编辑器。有很多有用的特性
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
	//}}}	//{{{ Convenience methods	//{{{ physicalToVirtual() method	/**	 * Converts a physical line number to a virtual line number.	 * See {@link FoldVisibilityManager} for details.	 * @param line A physical line index	 * @since jEdit 4.0pre1	 */	public int physicalToVirtual(int line)	{		return foldVisibilityManager.physicalToVirtual(line);	} //}}}	//{{{ virtualToPhysical() method	/**	 * Converts a virtual line number to a physical line number.	 * See {@link FoldVisibilityManager} for details.	 * @param line A virtual line index	 * @since jEdit 4.0pre1	 */	public int virtualToPhysical(int line)	{		return foldVisibilityManager.virtualToPhysical(line);	} //}}}	//{{{ getBufferLength() method	/**	 * Returns the length of the buffer.	 */	public final int getBufferLength()	{		return buffer.getLength();	} //}}}	//{{{ getLineCount() method	/**	 * Returns the number of physical lines in the buffer.	 */	public final int getLineCount()	{		return buffer.getLineCount();	} //}}}	//{{{ getVirtualLineCount() method	/**	 * Returns the number of virtual lines in the buffer.	 */	public final int getVirtualLineCount()	{		return foldVisibilityManager.getVirtualLineCount();	} //}}}	//{{{ getLineOfOffset() method	/**	 * Returns the line containing the specified offset.	 * @param offset The offset	 */	public final int getLineOfOffset(int offset)	{		return buffer.getLineOfOffset(offset);	} //}}}	//{{{ getLineStartOffset() method	/**	 * Returns the start offset of the specified line.	 * @param line The line	 * @return The start offset of the specified line, or -1 if the line is	 * invalid	 */	public int getLineStartOffset(int line)	{		return buffer.getLineStartOffset(line);	} //}}}	//{{{ getLineEndOffset() method	/**	 * Returns the end offset of the specified line.	 * @param line The line	 * @return The end offset of the specified line, or -1 if the line is	 * invalid.	 */	public int getLineEndOffset(int line)	{		return buffer.getLineEndOffset(line);	} //}}}	//{{{ getLineLength() method	/**	 * Returns the length of the specified line.	 * @param line The line	 */	public int getLineLength(int line)	{		return buffer.getLineLength(line);	} //}}}	//{{{ getText() method	/**	 * Returns the specified substring of the buffer.	 * @param start The start offset	 * @param len The length of the substring	 * @return The substring	 */	public final String getText(int start, int len)	{		return buffer.getText(start,len);	} //}}}	//{{{ getText() method	/**	 * Copies the specified substring of the buffer into a segment.	 * @param start The start offset	 * @param len The length of the substring	 * @param segment The segment	 */	public final void getText(int start, int len, Segment segment)	{		buffer.getText(start,len,segment);	} //}}}	//{{{ getLineText() method	/**	 * Returns the text on the specified line.	 * @param lineIndex The line	 * @return The text, or null if the line is invalid	 */	public final String getLineText(int lineIndex)	{		return buffer.getLineText(lineIndex);	} //}}}	//{{{ getLineText() method	/**	 * Copies the text on the specified line into a segment. If the line	 * is invalid, the segment will contain a null string.	 * @param lineIndex The line	 */	public final void getLineText(int lineIndex, Segment segment)	{		buffer.getLineText(lineIndex,segment);	} //}}}	//{{{ getText() method	/**	 * Returns the entire text of this text area.	 */	public String getText()	{		return buffer.getText(0,buffer.getLength());	} //}}}	//{{{ setText() method	/**	 * Sets the entire text of this text area.	 */	public void setText(String text)	{		try		{			buffer.beginCompoundEdit();			buffer.remove(0,buffer.getLength());			buffer.insert(0,text);		}		finally		{			buffer.endCompoundEdit();		}	} //}}}	//}}}	//{{{ Selection	//{{{ selectAll() method	/**	 * Selects all text in the buffer.	 */	public final void selectAll()	{		setSelection(new Selection.Range(0,buffer.getLength()));		moveCaretPosition(buffer.getLength(),true);	} //}}}	//{{{ selectLine() method	/**	 * Selects the current line.	 * @since jEdit 2.7pre2	 */	public void selectLine()	{		int caretLine = getCaretLine();		int start = getLineStartOffset(caretLine);		int end = getLineEndOffset(caretLine) - 1;		Selection s = new Selection.Range(start,end);		if(multi)			addToSelection(s);		else			setSelection(s);		moveCaretPosition(end);	} //}}}	//{{{ selectParagraph() method	/**	 * Selects the paragraph at the caret position.	 * @since jEdit 2.7pre2	 */	public void selectParagraph()	{		int caretLine = getCaretLine();		if(getLineLength(caretLine) == 0)		{			view.getToolkit().beep();			return;		}		int start = caretLine;		int end = caretLine;		while(start >= 0)		{			if(getLineLength(start) == 0)				break;			else				start--;		}		while(end < getLineCount())		{			if(getLineLength(end) == 0)				break;			else				end++;		}		int selectionStart = getLineStartOffset(start + 1);		int selectionEnd = getLineEndOffset(end - 1) - 1;		Selection s = new Selection.Range(selectionStart,selectionEnd);		if(multi)			addToSelection(s);		else			setSelection(s);		moveCaretPosition(selectionEnd);	} //}}}	//{{{ selectWord() method			/**	 * Selects the word at the caret position.	 * @since jEdit 2.7pre2	 */	public void selectWord()	{		int line = getCaretLine();		int lineStart = getLineStartOffset(line);		int offset = getCaretPosition() - lineStart;		if(getLineLength(line) == 0)			return;		String lineText = getLineText(line);		String noWordSep = buffer.getStringProperty("noWordSep");		if(offset == getLineLength(line))			offset--;		int wordStart = TextUtilities.findWordStart(lineText,offset,noWordSep);		int wordEnd = TextUtilities.findWordEnd(lineText,offset+1,noWordSep);		Selection s = new Selection.Range(lineStart + wordStart,			lineStart + wordEnd);		if(multi)			addToSelection(s);		else			setSelection(s);		moveCaretPosition(lineStart + wordEnd);	} //}}}	//{{{ selectToMatchingBracket() method	/**	 * Selects from the bracket at the specified position to the 	 * corresponding bracket. Returns <code>true</code> if successful (i.e.	 * there's a bracket at the specified position and there's a matching 	 * bracket for it), <code>false</code> otherwise.	 * @since jEdit 4.1pre1	 */	public boolean selectToMatchingBracket(int position)	{		int positionLine = buffer.getLineOfOffset(position);		int lineOffset = position - buffer.getLineStartOffset(positionLine);		int bracket = TextUtilities.findMatchingBracket(buffer,positionLine,lineOffset);				if(bracket != -1)		{			Selection s;			if(bracket < position)			{				moveCaretPosition(position,false);				s = new Selection.Range(++bracket,position);			}			else			{				moveCaretPosition(position + 1,false);				s = new Selection.Range(position + 1,bracket);			}			if(!multi)				selectNone();			addToSelection(s);			return true;		}				return false;	} //}}}	//{{{ selectToMatchingBracket() method	/**	 * Selects from the bracket at the caret position to the corresponding	 * bracket.	 * @since jEdit 4.0pre2	 */	public void selectToMatchingBracket()	{		// since we might change it below		int caret = this.caret;		int offset = caret - buffer.getLineStartOffset(caretLine);		if(buffer.getLineLength(caretLine) == 0)			return;		if(offset == buffer.getLineLength(caretLine))			caret--;				selectToMatchingBracket(caret);	} //}}}	//{{{ selectBlock() method	/**	 * Selects the code block surrounding the caret.	 * @since jEdit 2.7pre2	 */	public void selectBlock()	{		String openBrackets = "([{";		String closeBrackets = ")]}";		Selection s = getSelectionAtOffset(caret);		int start, end;		if(s == null)			start = end = caret;		else		{			start = s.start;			end = s.end;		}		String text = getText(0,buffer.getLength());		// Scan backwards, trying to find a bracket		int count = 1;		char openBracket = '\0';		char closeBracket = '\0';		// We can't do the backward scan if start == 0		if(start == 0)		{			view.getToolkit().beep();			return;		}backward_scan:	while(--start > 0)		{			char c = text.charAt(start);			int index = openBrackets.indexOf(c);			if(index != -1)			{				if(--count == 0)				{					openBracket = c;					closeBracket = closeBrackets.charAt(index);					break backward_scan;				}			}			else if(closeBrackets.indexOf(c) != -1)				count++;		}		// Reset count		count = 1;		// Scan forward, matching that bracket		if(openBracket == '\0')		{			getToolkit().beep();			return;		}		else		{forward_scan:		do			{				char c = text.charAt(end);				if(c == closeBracket)				{					if(--count == 0)					{						end++;						break forward_scan;					}				}				else if(c == openBracket)					count++;			}			while(++end < buffer.getLength());		}		s = new Selection.Range(start,end);		if(multi)			addToSelection(s);		else			setSelection(s);		moveCaretPosition(end);	} //}}}	//{{{ invertSelection() method	/**	 * Inverts the selection.	 * @since jEdit 4.0pre1	 */	public final void invertSelection()	{		Selection[] newSelection = new Selection[selection.size() + 1];		int lastOffset = 0;		for(int i = 0; i < selection.size(); i++)		{			Selection s = (Selection)selection.elementAt(i);			newSelection[i] = new Selection.Range(lastOffset,				s.getStart());			lastOffset = s.getEnd();		}		newSelection[selection.size()] = new Selection.Range(			lastOffset,buffer.getLength());		setSelection(newSelection);	} //}}}	//{{{ getSelectionCount() method	/**	 * Returns the number of selections. This can be used to test	 * for the existence of selections.	 * @since jEdit 3.2pre2	 */	public int getSelectionCount()	{		return selection.size();	} //}}}	//{{{ getSelection() method	/**	 * Returns the current selection.	 * @since jEdit 3.2pre1	 */	public Selection[] getSelection()	{		Selection[] sel = new Selection[selection.size()];		selection.copyInto(sel);		return sel;	} //}}}	//{{{ selectNone() method	/**	 * Deselects everything.	 */	public void selectNone()	{		setSelection((Selection)null);	} //}}}	//{{{ setSelection() method	/**	 * Sets the selection. Nested and overlapping selections are merged	 * where possible.	 * @param selection The new selection	 * since jEdit 3.2pre1	 */	public void setSelection(Selection[] selection)	{		// invalidate the old selection		invalidateSelectedLines();		this.selection.removeAllElements();		if(selection != null)		{			for(int i = 0; i < selection.length; i++)				_addToSelection(selection[i]);		}		fireCaretEvent();	} //}}}	//{{{ setSelection() method	/**	 * Sets the selection. Nested and overlapping selections are merged	 * where possible.	 * @param selection The new selection	 * since jEdit 3.2pre1	 */	public void setSelection(Selection selection)	{		invalidateSelectedLines();		this.selection.removeAllElements();		if(selection != null)			_addToSelection(selection);		fireCaretEvent();	} //}}}	//{{{ addToSelection() method	/**	 * Adds to the selection. Nested and overlapping selections are merged	 * where possible.	 * @param selection The new selection	 * since jEdit 3.2pre1	 */	public void addToSelection(Selection[] selection)	{		if(selection != null)		{			for(int i = 0; i < selection.length; i++)				_addToSelection(selection[i]);		}		// to hide current line highlight		invalidateLine(caretLine);		fireCaretEvent();	} //}}}	//{{{ addToSelection() method	/**	 * Adds to the selection. Nested and overlapping selections are merged	 * where possible.	 * @param selection The new selection	 * since jEdit 3.2pre1	 */	public void addToSelection(Selection selection)	{		_addToSelection(selection);		// to hide current line highlight		invalidateLine(caretLine);		fireCaretEvent();	} //}}}	//{{{ getSelectionAtOffset() method	/**	 * Returns the selection containing the specific offset, or <code>null</code>	 * if there is no selection at that offset.	 * @param offset The offset	 * @since jEdit 3.2pre1	 */	public Selection getSelectionAtOffset(int offset)	{		if(selection != null)		{

⌨️ 快捷键说明

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