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

📄 jedittextarea.java

📁 开源的java 编辑器源代码
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
			int prevLine = displayManager.getPrevVisibleLine(physicalLine);			if(prevLine == -1)				break;			physicalLine = prevLine;		}		if(physFirstLine > physicalLine)			physFirstLine = physicalLine; */		//}}}		int amount = (physFirstLine - displayManager.firstLine.physicalLine);		int oldFirstLine = getFirstLine();		if(amount == 0)		{			skew -= displayManager.firstLine.skew;			// JEditTextArea.scrollTo() needs this to simplify			// its code			if(skew < 0)				displayManager.firstLine.scrollUp(-skew);			else if(skew > 0)				displayManager.firstLine.scrollDown(skew);			else			{				// nothing to do				return;			}		}		else if(amount > 0)			displayManager.firstLine.physDown(amount,skew);		else if(amount < 0)			displayManager.firstLine.physUp(-amount,skew);		int firstLine = getFirstLine();		if(firstLine == oldFirstLine)			/* do nothing */;		else if(firstLine >= oldFirstLine + visibleLines			|| firstLine <= oldFirstLine - visibleLines)		{			chunkCache.invalidateAll();		}		else if(firstLine > oldFirstLine)		{			chunkCache.scrollDown(firstLine - oldFirstLine);		}		else if(firstLine < oldFirstLine)		{			chunkCache.scrollUp(oldFirstLine - firstLine);		}		// we have to be careful		displayManager._notifyScreenLineChanges();		//if(buffer.isLoaded())		//	recalculateLastPhysicalLine();		repaint();		fireScrollEvent(true);	} //}}}	//{{{ getLastPhysicalLine() method	/**	 * Returns the last visible physical line index.	 * @since jEdit 4.0pre4	 */	public final int getLastPhysicalLine()	{		return physLastLine;	} //}}}	//{{{ getVisibleLines() method	/**	 * Returns the number of lines visible in this text area.	 */	public final int getVisibleLines()	{		return visibleLines;	} //}}}	//{{{ getHorizontalOffset() method	/**	 * Returns the horizontal offset of drawn lines.	 */	public final int getHorizontalOffset()	{		return horizontalOffset;	} //}}}	//{{{ setHorizontalOffset() method	/**	 * Sets the horizontal offset of drawn lines. This can be used to	 * implement horizontal scrolling.	 * @param horizontalOffset offset The new horizontal offset	 */	public void setHorizontalOffset(int horizontalOffset)	{		if(horizontalOffset > 0)			horizontalOffset = 0;		if(horizontalOffset == this.horizontalOffset)			return;		this.horizontalOffset = horizontalOffset;		if(horizontalOffset != horizontal.getValue())			updateScrollBars();		painter.repaint();		fireScrollEvent(false);	} //}}}	//{{{ scrollUpLine() method	/**	 * Scrolls up by one line.	 * @since jEdit 2.7pre2	 */	public void scrollUpLine()	{		setFirstLine(getFirstLine() - 1);	} //}}}	//{{{ scrollUpPage() method	/**	 * Scrolls up by one page.	 * @since jEdit 2.7pre2	 */	public void scrollUpPage()	{		setFirstLine(getFirstLine() - getVisibleLines()			+ (lastLinePartial ? 1 : 0));	} //}}}	//{{{ scrollDownLine() method	/**	 * Scrolls down by one line.	 * @since jEdit 2.7pre2	 */	public void scrollDownLine()	{		setFirstLine(getFirstLine() + 1);	} //}}}	//{{{ scrollDownPage() method	/**	 * Scrolls down by one page.	 * @since jEdit 2.7pre2	 */	public void scrollDownPage()	{		setFirstLine(getFirstLine() + getVisibleLines()			- (lastLinePartial ? 1 : 0));	} //}}}	//{{{ scrollToCaret() method	/**	 * Ensures that the caret is visible by scrolling the text area if	 * necessary.	 * @param doElectricScroll If true, electric scrolling will be performed	 */	public void scrollToCaret(boolean doElectricScroll)	{		scrollTo(caretLine,caret - buffer.getLineStartOffset(caretLine),			doElectricScroll);	} //}}}	//{{{ scrollTo() method	/**	 * Ensures that the specified location in the buffer is visible.	 * @param offset The offset from the start of the buffer	 * @param doElectricScroll If true, electric scrolling will be performed	 * @since jEdit 4.2pre3	 */	public void scrollTo(int offset, boolean doElectricScroll)	{		int line = buffer.getLineOfOffset(offset);		scrollTo(line,offset - buffer.getLineStartOffset(line),			doElectricScroll);	} //}}}	//{{{ scrollTo() method	/**	 * Ensures that the specified location in the buffer is visible.	 * @param line The line number	 * @param offset The offset from the start of the line	 * @param doElectricScroll If true, electric scrolling will be performed	 * @since jEdit 4.0pre6	 */	public void scrollTo(int line, int offset, boolean doElectricScroll)	{		if(Debug.SCROLL_TO_DEBUG)			Log.log(Log.DEBUG,this,"scrollTo(), lineCount="				+ getLineCount());		//{{{ Get ready		int extraEndVirt;		int lineLength = buffer.getLineLength(line);		if(offset > lineLength)		{			extraEndVirt = charWidth * (offset - lineLength);			offset = lineLength;		}		else			extraEndVirt = 0;		int _electricScroll = (doElectricScroll			&& visibleLines - 1 > electricScroll * 2			? electricScroll : 0); //}}}		if(visibleLines == 0)		{			if(Debug.SCROLL_TO_DEBUG)				Log.log(Log.DEBUG,this,"visibleLines == 0");			setFirstPhysicalLine(line,_electricScroll);			// it will figure itself out after being added...			return;		}		//{{{ Scroll vertically		int firstLine = getFirstLine();		int screenLine = chunkCache.getScreenLineOfOffset(line,offset);		int visibleLines = getVisibleLines();		if(screenLine == -1)		{			if(Debug.SCROLL_TO_DEBUG)				Log.log(Log.DEBUG,this,"screenLine == -1");			ChunkCache.LineInfo[] infos = chunkCache				.getLineInfosForPhysicalLine(line);			int subregion = chunkCache.getSubregionOfOffset(				offset,infos);			int prevLine = displayManager.getPrevVisibleLine(getFirstPhysicalLine());			int nextLine = displayManager.getNextVisibleLine(getLastPhysicalLine());			if(line == getFirstPhysicalLine())			{				if(Debug.SCROLL_TO_DEBUG)					Log.log(Log.DEBUG,this,line + " == " + getFirstPhysicalLine());				setFirstPhysicalLine(line,subregion					- _electricScroll);			}			else if(line == prevLine)			{				if(Debug.SCROLL_TO_DEBUG)					Log.log(Log.DEBUG,this,line + " == " + prevLine);				setFirstPhysicalLine(prevLine,subregion					- _electricScroll);			}			else if(line == getLastPhysicalLine())			{				if(Debug.SCROLL_TO_DEBUG)					Log.log(Log.DEBUG,this,line + " == " + getLastPhysicalLine());				setFirstPhysicalLine(line,					subregion + _electricScroll					- visibleLines					+ (lastLinePartial ? 2 : 1));			}			else if(line == nextLine)			{				if(Debug.SCROLL_TO_DEBUG)					Log.log(Log.DEBUG,this,line + " == " + nextLine);				setFirstPhysicalLine(nextLine,					subregion + electricScroll					- visibleLines					+ (lastLinePartial ? 2 : 1));			}			else			{				if(Debug.SCROLL_TO_DEBUG)				{					Log.log(Log.DEBUG,this,"neither");					Log.log(Log.DEBUG,this,"Last physical line is " + getLastPhysicalLine());				}				setFirstPhysicalLine(line,subregion					- visibleLines / 2);				if(Debug.SCROLL_TO_DEBUG)				{					Log.log(Log.DEBUG,this,"Last physical line is " + getLastPhysicalLine());				}			}		}		else if(screenLine < _electricScroll)		{			if(Debug.SCROLL_TO_DEBUG)				Log.log(Log.DEBUG,this,"electric up");			setFirstLine(getFirstLine() - _electricScroll + screenLine);		}		else if(screenLine > visibleLines - _electricScroll			- (lastLinePartial ? 2 : 1))		{			if(Debug.SCROLL_TO_DEBUG)				Log.log(Log.DEBUG,this,"electric down");			setFirstLine(getFirstLine() + _electricScroll - visibleLines + screenLine + (lastLinePartial ? 2 : 1));		} //}}}		//{{{ Scroll horizontally		if(!displayManager.isLineVisible(line))			return;		Point point = offsetToXY(line,offset,returnValue);		if(point == null)		{			Log.log(Log.ERROR,this,"BUG: screenLine=" + screenLine				+ ",visibleLines=" + visibleLines				+ ",physicalLine=" + line				+ ",firstPhysicalLine=" + getFirstPhysicalLine()				+ ",lastPhysicalLine=" + getLastPhysicalLine());		}		point.x += extraEndVirt;		if(point.x < 0)		{			setHorizontalOffset(horizontalOffset				- point.x + charWidth + 5);		}		else if(point.x >= painter.getWidth() - charWidth - 5)		{			setHorizontalOffset(horizontalOffset +				(painter.getWidth() - point.x)				- charWidth - 5);		} //}}}	} //}}}	//{{{ addScrollListener() method	/**	 * Adds a scroll listener to this text area.	 * @param listener The listener	 * @since jEdit 3.2pre2	 */	public final void addScrollListener(ScrollListener listener)	{		listenerList.add(ScrollListener.class,listener);	} //}}}	//{{{ removeScrollListener() method	/**	 * Removes a scroll listener from this text area.	 * @param listener The listener	 * @since jEdit 3.2pre2	 */	public final void removeScrollListener(ScrollListener listener)	{		listenerList.remove(ScrollListener.class,listener);	} //}}}	//}}}	//{{{ Screen line stuff	//{{{ getPhysicalLineOfScreenLine() method	/**	 * Returns the physical line number that contains the specified screen	 * line.	 * @param screenLine The screen line	 * @since jEdit 4.0pre6	 */	public int getPhysicalLineOfScreenLine(int screenLine)	{		return chunkCache.getLineInfo(screenLine).physicalLine;	} //}}}	//{{{ getScreenLineOfOffset() method	/**	 * Returns the screen (wrapped) line containing the specified offset.	 * Returns -1 if the line is not currently visible on the screen.	 * @param offset The offset	 * @since jEdit 4.0pre4	 */	public int getScreenLineOfOffset(int offset)	{		int line = buffer.getLineOfOffset(offset);		offset -= buffer.getLineStartOffset(line);		return chunkCache.getScreenLineOfOffset(line,offset);	} //}}}	//{{{ getScreenLineStartOffset() method	/**	 * Returns the start offset of the specified screen (wrapped) line.	 * @param line The line	 * @since jEdit 4.0pre4	 */	public int getScreenLineStartOffset(int line)	{		ChunkCache.LineInfo lineInfo = chunkCache.getLineInfo(line);		if(lineInfo.physicalLine == -1)			return -1;		return buffer.getLineStartOffset(lineInfo.physicalLine)			+ lineInfo.offset;	} //}}}	//{{{ getScreenLineEndOffset() method	/**	 * Returns the end offset of the specified screen (wrapped) line.	 * @param line The line	 * @since jEdit 4.0pre4	 */	public int getScreenLineEndOffset(int line)	{		ChunkCache.LineInfo lineInfo = chunkCache.getLineInfo(line);		if(lineInfo.physicalLine == -1)			return -1;		return buffer.getLineStartOffset(lineInfo.physicalLine)			+ lineInfo.offset + lineInfo.length;	} //}}}	//}}}	//{{{ Offset conversion	//{{{ xyToOffset() method	/**	 * Converts a point to an offset.	 * Note that unlike in previous jEdit versions, this method now returns	 * -1 if the y co-ordinate is out of bounds.	 *	 * @param x The x co-ordinate of the point	 * @param y The y co-ordinate of the point	 */	public int xyToOffset(int x, int y)	{		return xyToOffset(x,y,true);	} //}}}	//{{{ xyToOffset() method	/**	 * Converts a point to an offset.	 * Note that unlike in previous jEdit versions, this method now returns	 * -1 if the y co-ordinate is out of bounds.	 *	 * @param x The x co-ordinate of the point	 * @param y The y co-ordinate of the point	 * @param round Round up to next letter if past the middle of a letter?	 * @since jEdit 3.2pre6	 */	public int xyToOffset(int x, int y, boolean round)	{		FontMetrics fm = painter.getFontMetrics();		int height = fm.getHeight();		int line = y / height;		if(line < 0 || line >= visibleLines)			return -1;		return xToScreenLineOffset(line,x,round);	} //}}}	//{{{ xToScreenLineOffset() method	/**	 * Converts a point in a given screen line to an offset.	 * Note that unlike in previous jEdit versions, this method now returns	 * -1 if the y co-ordinate is out of bounds.	 *	 * @param x The x co-ordinate of the point	 * @param screenLine The screen line	 * @param round Round up to next letter if past the middle of a letter?	 * @since jEdit 3.2pre6	 */	public int xToScreenLineOffset(int screenLine, int x, boolean round)	{		ChunkCache.LineInfo lineInfo = chunkCache.getLineInfo(screenLine);		if(lineInfo.physicalLine == -1)		{			return getLineEndOffset(displayManager				.getLastVisibleLine()) - 1;		}		else		{			int offset = Chunk.xToOffset(lineInfo.chunks,				x - horizontalOffset,round);			if(offset == -1 || offset == lineInfo.offset + lineInfo.length)				offset = lineInfo.offset + lineInfo.length - 1;			return getLineStartOffset(lineInfo.physicalLine) + offset;		}	} //}}}	//{{{ offsetToXY() method	/**	 * Converts an offset into a point in the text area painter's	 * co-ordinate space.	 * @param offset The offset	 * @return The location of the offset on screen, or <code>null</code>	 * if the specified offset is not visible	 */	public Point offsetToXY(int offset)	{		int line = buffer.getLineOfOffset(offset);		offset -= buffer.getLineStartOffset(line);		Point retVal = new Point();		return offsetToXY(line,offset,retVal);	} //}}}	//{{{ offsetToXY() method	/**	 * Converts an offset into a point in the text area painter's	 * co-ordinate space.	 * @param line The physical line number	 * @param offset The offset, from the start of the line	 * @param retVal The point to store the return value in	 * @return <code>retVal</code> for convenience, or <code>null</code>	 * if the specified offset is not visible	 * @since jEdit 4.0pre4	 */	public Point offsetToXY(int line, int offset, Point retVal)	{		if(!displayManager.isLineVisible(line))			return null;		int screenLine = chunkCache.getScreenLineOfOffset(line,offset);		if(screenLine == -1)			return null;		FontMetrics fm = painter.getFontMetrics();		retVal.y = screenLine * fm.getHeight();		ChunkCache.LineInfo info = chunkCache.getLineInfo(screenLine);		retVal.x = (int)(horizontalOffset + Chunk.offsetToX(			info.chunks,offset));		return retVal;	} //}}}	//}}}	//{{{ Painting	//{{{ invalidateScreenLineRange() method	/**	 * Marks a range of screen lines as needing a repaint.	 * @param start The first line	 * @param end The last line	 * @since jEdit 4.0pre4	 */	public void invalidateScreenLineRange(int start, int end)	{		if(!buffer.isLoaded())			return;		//if(start != end)		//	System.err.println(start + ":" + end + ":" + chunkCache.needFullRepaint());		if(start > end)		{			int tmp = end;			end = start;			start = tmp;		}		if(chunkCache.needFullRepaint())			end = visibleLines;		FontMetrics fm = painter.getFontMetrics();		int y = start * fm.getHeight();		int height = (end - start + 1) * fm.getHeight();		painter.repaint(0,y,painter.getWidth(),height);		gutter.repaint(0,y,gutter.getWidth(),height);	} //}}}	//{{{ invalidateLine() method

⌨️ 快捷键说明

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