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

📄 buffer.java

📁 开源的java 编辑器源代码
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
	//{{{ getAutosaveFile() method	/**	 * Returns the autosave file for this buffer. This may be null if	 * the file is non-local.	 */	public File getAutosaveFile()	{		return autosaveFile;	} //}}}	//{{{ getName() method	/**	 * Returns the name of this buffer. This method is thread-safe.	 */	public String getName()	{		return name;	} //}}}	//{{{ getPath() method	/**	 * Returns the path name of this buffer. This method is thread-safe.	 */	public String getPath()	{		return path;	} //}}}	//{{{ getSymlinkPath() method	/**	 * If this file is a symbolic link, returns the link destination.	 * Otherwise returns the file's path. This method is thread-safe.	 * @since jEdit 4.2pre1	 */	public String getSymlinkPath()	{		return symlinkPath;	} //}}}	//{{{ getDirectory() method	/**	 * Returns the directory containing this buffer.	 * @since jEdit 4.1pre11	 */	public String getDirectory()	{		return directory;	} //}}}	//{{{ isClosed() method	/**	 * Returns true if this buffer has been closed with	 * {@link org.gjt.sp.jedit.jEdit#closeBuffer(View,Buffer)}.	 * This method is thread-safe.	 */	public boolean isClosed()	{		return getFlag(CLOSED);	} //}}}	//{{{ isLoaded() method	/**	 * Returns true if the buffer is loaded. This method is thread-safe.	 */	public boolean isLoaded()	{		return !getFlag(LOADING);	} //}}}	//{{{ isPerformingIO() method	/**	 * Returns true if the buffer is currently performing I/O.	 * This method is thread-safe.	 * @since jEdit 2.7pre1	 */	public boolean isPerformingIO()	{		return getFlag(LOADING) || getFlag(IO);	} //}}}	//{{{ isNewFile() method	/**	 * Returns whether this buffer lacks a corresponding version on disk.	 * This method is thread-safe.	 */	public boolean isNewFile()	{		return getFlag(NEW_FILE);	} //}}}	//{{{ setNewFile() method	/**	 * Sets the new file flag.	 * @param newFile The new file flag	 */	public void setNewFile(boolean newFile)	{		setFlag(NEW_FILE,newFile);		if(!newFile)			setFlag(UNTITLED,false);	} //}}}	//{{{ isUntitled() method	/**	 * Returns true if this file is 'untitled'. This method is thread-safe.	 */	public boolean isUntitled()	{		return getFlag(UNTITLED);	} //}}}	//{{{ isDirty() method	/**	 * Returns whether there have been unsaved changes to this buffer.	 * This method is thread-safe.	 */	public boolean isDirty()	{		return getFlag(DIRTY);	} //}}}	//{{{ isReadOnly() method	/**	 * Returns true if this file is read only, false otherwise.	 * This method is thread-safe.	 */	public boolean isReadOnly()	{		return getFlag(READ_ONLY) || getFlag(READ_ONLY_OVERRIDE);	} //}}}	//{{{ isEditable() method	/**	 * Returns true if this file is editable, false otherwise. A file may	 * become uneditable if it is read only, or if I/O is in progress.	 * This method is thread-safe.	 * @since jEdit 2.7pre1	 */	public boolean isEditable()	{		return !(getFlag(READ_ONLY) || getFlag(READ_ONLY_OVERRIDE)			|| getFlag(IO) || getFlag(LOADING));	} //}}}	//{{{ setReadOnly() method	/**	 * Sets the read only flag.	 * @param readOnly The read only flag	 */	public void setReadOnly(boolean readOnly)	{		setFlag(READ_ONLY_OVERRIDE,readOnly);	} //}}}	//{{{ setDirty() method	/**	 * Sets the 'dirty' (changed since last save) flag of this buffer.	 */	public void setDirty(boolean d)	{		boolean old_d = getFlag(DIRTY);		boolean editable = isEditable();		if(d)		{			if(editable)			{				setFlag(DIRTY,true);				setFlag(AUTOSAVE_DIRTY,true);			}		}		else		{			setFlag(DIRTY,false);			setFlag(AUTOSAVE_DIRTY,false);			if(autosaveFile != null)				autosaveFile.delete();			// fixes dirty flag not being reset on			// save/insert/undo/redo/undo			if(!getFlag(UNDO_IN_PROGRESS))			{				// this ensures that undo can clear the dirty flag properly				// when all edits up to a save are undone				undoMgr.bufferSaved();			}		}		if(d != old_d && editable)		{			EditBus.send(new BufferUpdate(this,null,				BufferUpdate.DIRTY_CHANGED));		}	} //}}}	//{{{ isTemporary() method	/**	 * Returns if this is a temporary buffer. This method is thread-safe.	 * @see jEdit#openTemporary(View,String,String,boolean)	 * @see jEdit#commitTemporary(Buffer)	 * @since jEdit 2.2pre7	 */	public boolean isTemporary()	{		return getFlag(TEMPORARY);	} //}}}	//{{{ getIcon() method	/**	 * Returns this buffer's icon.	 * @since jEdit 2.6pre6	 */	public Icon getIcon()	{		if(getFlag(DIRTY))			return GUIUtilities.DIRTY_BUFFER_ICON;		else if(getFlag(READ_ONLY) || getFlag(READ_ONLY_OVERRIDE))			return GUIUtilities.READ_ONLY_BUFFER_ICON;		else if(getFlag(NEW_FILE))			return GUIUtilities.NEW_BUFFER_ICON;		else			return GUIUtilities.NORMAL_BUFFER_ICON;	} //}}}	//}}}	//{{{ Thread safety	//{{{ readLock() method	/**	 * The buffer is guaranteed not to change between calls to	 * {@link #readLock()} and {@link #readUnlock()}.	 */	public void readLock()	{		lock.readLock();	} //}}}	//{{{ readUnlock() method	/**	 * The buffer is guaranteed not to change between calls to	 * {@link #readLock()} and {@link #readUnlock()}.	 */	public void readUnlock()	{		lock.readUnlock();	} //}}}	//{{{ writeLock() method	/**	 * Attempting to obtain read lock will block between calls to	 * {@link #writeLock()} and {@link #writeUnlock()}.	 */	public void writeLock()	{		lock.writeLock();	} //}}}	//{{{ writeUnlock() method	/**	 * Attempting to obtain read lock will block between calls to	 * {@link #writeLock()} and {@link #writeUnlock()}.	 */	public void writeUnlock()	{		lock.writeUnlock();	} //}}}	//}}}	//{{{ Line offset methods	//{{{ getLength() method	/**	 * Returns the number of characters in the buffer. This method is thread-safe.	 */	public int getLength()	{		// no need to lock since this just returns a value and that's it		return contentMgr.getLength();	} //}}}	//{{{ getLineCount() method	/**	 * Returns the number of physical lines in the buffer.	 * This method is thread-safe.	 * @since jEdit 3.1pre1	 */	public int getLineCount()	{		// no need to lock since this just returns a value and that's it		return lineMgr.getLineCount();	} //}}}	//{{{ getLineOfOffset() method	/**	 * Returns the line containing the specified offset.	 * This method is thread-safe.	 * @param offset The offset	 * @since jEdit 4.0pre1	 */	public int getLineOfOffset(int offset)	{		try		{			readLock();			if(offset < 0 || offset > getLength())				throw new ArrayIndexOutOfBoundsException(offset);			return lineMgr.getLineOfOffset(offset);		}		finally		{			readUnlock();		}	} //}}}	//{{{ getLineStartOffset() method	/**	 * Returns the start offset of the specified line.	 * This method is thread-safe.	 * @param line The line	 * @return The start offset of the specified line	 * @since jEdit 4.0pre1	 */	public int getLineStartOffset(int line)	{		try		{			readLock();			if(line < 0 || line >= lineMgr.getLineCount())				throw new ArrayIndexOutOfBoundsException(line);			else if(line == 0)				return 0;			return lineMgr.getLineEndOffset(line - 1);		}		finally		{			readUnlock();		}	} //}}}	//{{{ getLineEndOffset() method	/**	 * Returns the end offset of the specified line.	 * This method is thread-safe.	 * @param line The line	 * @return The end offset of the specified line	 * invalid.	 * @since jEdit 4.0pre1	 */	public int getLineEndOffset(int line)	{		try		{			readLock();			if(line < 0 || line >= lineMgr.getLineCount())				throw new ArrayIndexOutOfBoundsException(line);			return lineMgr.getLineEndOffset(line);		}		finally		{			readUnlock();		}	} //}}}	//{{{ getLineLength() method	/**	 * Returns the length of the specified line.	 * This method is thread-safe.	 * @param line The line	 * @since jEdit 4.0pre1	 */	public int getLineLength(int line)	{		try		{			readLock();			return getLineEndOffset(line)				- getLineStartOffset(line) - 1;		}		finally		{			readUnlock();		}	} //}}}	//{{{ invalidateCachedScreenLineCounts() method	/**	 * Invalidates all cached screen line count information.	 * @since jEdit 4.2pre7.	 */	public void invalidateCachedScreenLineCounts()	{		lineMgr.invalidateScreenLineCounts();	} //}}}	//}}}	//{{{ Text getters and setters	//{{{ getLineText() method	/**	 * Returns the text on the specified line.	 * This method is thread-safe.	 * @param line The line	 * @return The text, or null if the line is invalid	 * @since jEdit 4.0pre1	 */	public String getLineText(int line)	{		if(line < 0 || line >= lineMgr.getLineCount())			throw new ArrayIndexOutOfBoundsException(line);		try		{			readLock();			int start = (line == 0 ? 0				: lineMgr.getLineEndOffset(line - 1));			int end = lineMgr.getLineEndOffset(line);			return getText(start,end - start - 1);		}		finally		{			readUnlock();		}	} //}}}	//{{{ getLineText() method	/**	 * Returns the specified line in a <code>Segment</code>.<p>	 *	 * Using a <classname>Segment</classname> is generally more	 * efficient than using a <classname>String</classname> because it	 * results in less memory allocation and array copying.<p>	 *	 * This method is thread-safe.	 *	 * @param line The line	 * @since jEdit 4.0pre1	 */	public void getLineText(int line, Segment segment)	{		if(line < 0 || line >= lineMgr.getLineCount())			throw new ArrayIndexOutOfBoundsException(line);		try		{			readLock();			int start = (line == 0 ? 0				: lineMgr.getLineEndOffset(line - 1));			int end = lineMgr.getLineEndOffset(line);			getText(start,end - start - 1,segment);		}		finally		{			readUnlock();		}	} //}}}	//{{{ getText() method	/**	 * Returns the specified text range. This method is thread-safe.	 * @param start The start offset	 * @param length The number of characters to get	 */	public String getText(int start, int length)	{		try		{			readLock();			if(start < 0 || length < 0				|| start + length > contentMgr.getLength())				throw new ArrayIndexOutOfBoundsException(start + ":" + length);			return contentMgr.getText(start,length);		}		finally		{			readUnlock();		}	} //}}}	//{{{ getText() method	/**	 * Returns the specified text range in a <code>Segment</code>.<p>	 *	 * Using a <classname>Segment</classname> is generally more	 * efficient than using a <classname>String</classname> because it	 * results in less memory allocation and array copying.<p>	 *	 * This method is thread-safe.	 *	 * @param start The start offset	 * @param length The number of characters to get	 * @param seg The segment to copy the text to	 */	public void getText(int start, int length, Segment seg)	{		try		{			readLock();			if(start < 0 || length < 0				|| start + length > contentMgr.getLength())				throw new ArrayIndexOutOfBoundsException(start + ":" + length);			contentMgr.getText(start,length,seg);		}		finally		{			readUnlock();		}	} //}}}	//{{{ insert() method	/**	 * Inserts a string into the buffer.	 * @param offset The offset	 * @param str The string	 * @since jEdit 4.0pre1	 */	public void insert(int offset, String str)	{		if(str == null)			return;		int len = str.length();		if(len == 0)			return;		if(isReadOnly())			throw new RuntimeException("buffer read-only");		try		{			writeLock();			if(offset < 0 || offset > contentMgr.getLength())				throw new ArrayIndexOutOfBoundsException(offset);			contentMgr.insert(offset,str);			integerArray.clear();			for(int i = 0; i < len; i++)			{				if(str.charAt(i) == '\n')					integerArray.add(i + 1);			}			if(!getFlag(UNDO_IN_PROGRESS))			{				undoMgr.contentInserted(offset,len,str,					!getFlag(DIRTY));			}

⌨️ 快捷键说明

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