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

📄 selection.java

📁 开源的java 编辑器源代码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * Selection.java - Selected text * :tabSize=8:indentSize=8:noTabs=false: * :folding=explicit:collapseFolds=1: * * Copyright (C) 2001, 2002 Slava Pestov * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. */package org.gjt.sp.jedit.textarea;//{{{ Importsimport java.util.ArrayList;import org.gjt.sp.jedit.Buffer;import org.gjt.sp.jedit.MiscUtilities;//}}}/** * An abstract class that holds data on a region of selected text. * As an abstract class, it cannot be used * directly, but instead serves as a parent class for two specific types * of selection structures: * <ul> * <li>{@link Selection.Range} - represents an ordinary range of selected text.</li> * <li>{@link Selection.Rect} - represents a rectangular selection.</li> * </ul> * * @author Slava Pestov * @author John Gellene (API documentation) * @version $Id: Selection.java,v 1.21 2003/12/27 22:38:52 spestov Exp $ * @since jEdit 3.2pre1 */public abstract class Selection implements Cloneable{	//{{{ getStart() method	/**	 * Returns the start offset of this selection.	 */	public int getStart()	{		return start;	} //}}}	//{{{ getEnd() method	/**	 * Returns the end offset of this selection.	 */	public int getEnd()	{		return end;	} //}}}	//{{{ getStart() method	/**	 * Returns the beginning of the portion of the selection	 * falling on the specified line. Used to manipulate         * selection text on a line-by-line basis.	 * @param buffer The buffer	 * @param line The line number	 * @since jEdit 4.1pre1	 */	public abstract int getStart(Buffer buffer, int line);	//}}}	//{{{ getEnd() method	/**	 * Returns the end of the portion of the selection	 * falling on the specified line. Used to manipulate         * selection text on a line-by-line basis.	 * @param buffer The buffer	 * @param line The line number	 * @since jEdit 4.1pre1	 */	public abstract int getEnd(Buffer buffer, int line);	//}}}	//{{{ getStartLine() method	/**	 * Returns the starting line number of this selection.	 */	public int getStartLine()	{		return startLine;	} //}}}	//{{{ getEndLine() method	/**	 * Returns the ending line number of this selection.	 */	public int getEndLine()	{		return endLine;	} //}}}	//{{{ overlaps() method	/**	 * Returns if this selection and the specified selection overlap.	 * @param s The other selection	 * @since jEdit 4.1pre1	 */	public boolean overlaps(Selection s)	{		if((start >= s.start && start <= s.end)			|| (end >= s.start && end <= s.end))			return true;		else			return false;	} //}}}	//{{{ toString() method	public String toString()	{		return getClass().getName() + "[start=" + start			+ ",end=" + end + ",startLine=" + startLine			+ ",endLine=" + endLine + "]";	} //}}}	//{{{ clone() method	public Object clone()	{		try		{			return super.clone();		}		catch(CloneNotSupportedException e)		{			throw new InternalError("I just drank a whole "				+ "bottle of cough syrup and I feel "				+ "funny!");		}	} //}}}	//{{{ Package-private members	int start, end;	int startLine, endLine;	//{{{ Selection constructor	Selection()	{	} //}}}	//{{{ Selection constructor	Selection(Selection sel)	{		this.start = sel.start;		this.end = sel.end;	} //}}}	//{{{ Selection constructor	Selection(int start, int end)	{		this.start = start;		this.end = end;	} //}}}	// should the next two be public, maybe?	abstract void getText(Buffer buffer, StringBuffer buf);	abstract int setText(Buffer buffer, String text);	abstract boolean contentInserted(Buffer buffer, int startLine, int start,		int numLines, int length);	abstract boolean contentRemoved(Buffer buffer, int startLine, int start,		int numLines, int length);	//}}}	//{{{ Range class	/**	 * An ordinary range selection.	 * @since jEdit 3.2pre1	 */	public static class Range extends Selection	{		//{{{ Range constructor		public Range()		{		} //}}}		//{{{ Range constructor		public Range(Selection sel)		{			super(sel);		} //}}}		//{{{ Range constructor		public Range(int start, int end)		{			super(start,end);		} //}}}		//{{{ getStart() method		public int getStart(Buffer buffer, int line)		{			if(line == startLine)				return start;			else				return buffer.getLineStartOffset(line);		} //}}}		//{{{ getEnd() method		public int getEnd(Buffer buffer, int line)		{			if(line == endLine)				return end;			else				return buffer.getLineEndOffset(line) - 1;		} //}}}		//{{{ Package-private members		//{{{ getText() method		void getText(Buffer buffer, StringBuffer buf)		{			buf.append(buffer.getText(start,end - start));		} //}}}		//{{{ setText() method		int setText(Buffer buffer, String text)		{			buffer.remove(start,end - start);			if(text != null && text.length() != 0)			{				buffer.insert(start,text);				return start + text.length();			}			else				return start;		} //}}}		//{{{ contentInserted() method		boolean contentInserted(Buffer buffer, int startLine, int start,			int numLines, int length)		{			boolean changed = false;			if(this.start >= start)			{				this.start += length;				if(numLines != 0)					this.startLine = buffer.getLineOfOffset(this.start);				changed = true;			}			if(this.end >= start)			{				this.end += length;				if(numLines != 0)					this.endLine = buffer.getLineOfOffset(this.end);				changed = true;			}			return changed;		} //}}}		//{{{ contentRemoved() method		boolean contentRemoved(Buffer buffer, int startLine, int start,			int numLines, int length)		{			int end = start + length;			boolean changed = false;			if(this.start > start && this.start <= end)			{				this.start = start;				changed = true;			}			else if(this.start > end)			{				this.start -= length;				changed = true;			}			if(this.end > start && this.end <= end)			{				this.end = start;				changed = true;			}			else if(this.end > end)			{				this.end -= length;				changed = true;			}			if(changed && numLines != 0)			{				this.startLine = buffer.getLineOfOffset(this.start);				this.endLine = buffer.getLineOfOffset(this.end);			}			return changed;		} //}}}		//}}}	} //}}}	//{{{ Rect class	/**	 * A rectangular selection.	 * @since jEdit 3.2pre1	 */	// this class is not very fast...	public static class Rect extends Selection	{		//{{{ Rect constructor		public Rect()		{			super();		} //}}}		//{{{ Rect constructor		public Rect(Selection sel)		{			super(sel);		} //}}}		//{{{ Rect constructor		public Rect(int start, int end)		{			super(start,end);		} //}}}		//{{{ Rect constructor		public Rect(int startLine, int start, int endLine, int end)		{			this.startLine = startLine;			this.start = start;			this.endLine = endLine;			this.end = end;		} //}}}		//{{{ Rect constructor		public Rect(Buffer buffer, int startLine, int startColumn,			int endLine, int endColumn)		{			this.startLine = startLine;			this.endLine = endLine;			int[] width = new int[1];			int startOffset = buffer.getOffsetOfVirtualColumn(startLine,				startColumn,width);			if(startOffset == -1)			{				extraStartVirt = startColumn - width[0];				startOffset = buffer.getLineEndOffset(startLine) - 1;			}

⌨️ 快捷键说明

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