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

📄 buffer.java

📁 用java 编写的源码开放的文本编辑器。有很多有用的特性
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
		else if(status == FILE_CHANGED)		{			String prop = (isDirty() ? "filechanged-dirty"				: "filechanged-focus");			Object[] args = { path };			int result = GUIUtilities.confirm(view,				prop,args,JOptionPane.YES_NO_OPTION,				JOptionPane.WARNING_MESSAGE);			if(result == JOptionPane.YES_OPTION)			{				editPane.saveCaretInfo();				load(view,true);			}		}	} //}}}	//}}}	//{{{ Getters/setter methods for various buffer meta-data	//{{{ getLastModified() method	/**	 * Returns the last time jEdit modified the file on disk.	 * This method is thread-safe.	 */	public long getLastModified()	{		return modTime;	} //}}}	//{{{ setLastModified() method	/**	 * Sets the last time jEdit modified the file on disk.	 * @param modTime The new modification time	 */	public void setLastModified(long modTime)	{		this.modTime = modTime;	} //}}}	//{{{ getVFS() method	/**	 * Returns the virtual filesystem responsible for loading and	 * saving this buffer. This method is thread-safe.	 */	public VFS getVFS()	{		return vfs;	} //}}}	//{{{ getAutosaveFile() method	/**	 * Returns the autosave file for this buffer. This may be null if	 * the file is non-local.	 */	public final File getAutosaveFile()	{		return autosaveFile;	} //}}}	//{{{ getName() method	/**	 * Returns the name of this buffer. This method is thread-safe.	 */	public final String getName()	{		return name;	} //}}}	//{{{ getPath() method	/**	 * Returns the path name of this buffer. This method is thread-safe.	 */	public final String getPath()	{		return path;	} //}}}	//{{{ 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 final boolean isClosed()	{		return getFlag(CLOSED);	} //}}}	//{{{ isLoaded() method	/**	 * Returns true if the buffer is loaded. This method is thread-safe.	 */	public final 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 final 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 final boolean isNewFile()	{		return getFlag(NEW_FILE);	} //}}}	//{{{ setNewFile() method	/**	 * Sets the new file flag.	 * @param newFile The new file flag	 */	public final 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 final boolean isUntitled()	{		return getFlag(UNTITLED);	} //}}}	//{{{ isDirty() method	/**	 * Returns whether there have been unsaved changes to this buffer.	 * This method is thread-safe.	 */	public final boolean isDirty()	{		return getFlag(DIRTY);	} //}}}	//{{{ isReadOnly() method	/**	 * Returns true if this file is read only, false otherwise.	 * This method is thread-safe.	 */	public final boolean isReadOnly()	{		return getFlag(READ_ONLY);	} //}}}	//{{{ isEditable() method	/**	 * Returns true if this file is editable, false otherwise.	 * This method is thread-safe.	 * @since jEdit 2.7pre1	 */	public final boolean isEditable()	{		return !(getFlag(READ_ONLY) || getFlag(IO) || getFlag(LOADING));	} //}}}	//{{{ isReadOnly() method	/**	 * Sets the read only flag.	 * @param readOnly The read only flag	 */	public final void setReadOnly(boolean readOnly)	{		setFlag(READ_ONLY,readOnly);	} //}}}	//{{{ setDirty() method	/**	 * Sets the 'dirty' (changed since last save) flag of this buffer.	 */	public void setDirty(boolean d)	{		boolean old_d = getFlag(DIRTY);		if(d)		{			if(getFlag(LOADING) || getFlag(READ_ONLY))				return;			if(getFlag(DIRTY) && getFlag(AUTOSAVE_DIRTY))				return;			setFlag(DIRTY,true);			setFlag(AUTOSAVE_DIRTY,true);		}		else		{			setFlag(DIRTY,false);			setFlag(AUTOSAVE_DIRTY,false);			if(autosaveFile != null)				autosaveFile.delete();			// 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)		{			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))			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 final void readLock()	{		lock.readLock();	} //}}}	//{{{ readUnlock() method	/**	 * The buffer is guaranteed not to change between calls to	 * {@link #readLock()} and {@link #readUnlock()}.	 */	public final void readUnlock()	{		lock.readUnlock();	} //}}}	//{{{ writeLock() method	/**	 * Attempting to obtain read lock will block between calls to	 * {@link #writeLock()} and {@link #writeUnlock()}.	 */	public final void writeLock()	{		lock.writeLock();	} //}}}	//{{{ writeUnlock() method	/**	 * Attempting to obtain read lock will block between calls to	 * {@link #writeLock()} and {@link #writeUnlock()}.	 */	public final 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 offsetMgr.getLineCount();	} //}}}	//{{{ getLineOfOffset() method	/**	 * Returns the line containing the specified offset.	 * This method is thread-safe.	 * @param offset The offset	 * @since jEdit 4.0pre1	 */	public final int getLineOfOffset(int offset)	{		try		{			readLock();			if(offset < 0 || offset > getLength())				throw new ArrayIndexOutOfBoundsException(offset);			return offsetMgr.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 >= offsetMgr.getLineCount())				throw new ArrayIndexOutOfBoundsException(line);			else if(line == 0)				return 0;			return offsetMgr.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 >= offsetMgr.getLineCount())				throw new ArrayIndexOutOfBoundsException(line);			return offsetMgr.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();		}	} //}}}	//}}}	//{{{ Text getters are setters	//{{{ getLineText() method	/**	 * Returns the text on the specified line.	 * This method is thread-safe.	 * @param lineIndex The line	 * @return The text, or null if the line is invalid	 * @since jEdit 4.0pre1	 */	public String getLineText(int lineIndex)	{		try		{			readLock();			return getText(getLineStartOffset(lineIndex),				getLineLength(lineIndex));		}		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 lineIndex The line	 * @since jEdit 4.0pre1	 */	public void getLineText(int lineIndex, Segment segment)	{		try		{			readLock();			getText(getLineStartOffset(lineIndex),				getLineLength(lineIndex),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);			}			if(!getFlag(UNDO_IN_PROGRESS))			{				undoMgr.contentInserted(offset,len,str,					!getFlag(DIRTY));

⌨️ 快捷键说明

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