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

📄 registers.java

📁 Linux下面最好用的程序、文本编辑工具之一。
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * Registers.java - Register manager * :tabSize=8:indentSize=8:noTabs=false: * :folding=explicit:collapseFolds=1: * * Copyright (C) 1999, 2003 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;//{{{ Importsimport com.microstar.xml.*;import java.awt.datatransfer.*;import java.awt.Toolkit;import java.io.*;import org.gjt.sp.jedit.gui.*;import org.gjt.sp.jedit.textarea.*;import org.gjt.sp.util.Log;//}}}/** * jEdit's registers are an extension of the clipboard metaphor.<p> * * A {@link Registers.Register} is string of text indexed by a * single character. Typically the text is taken from selected buffer text * and the index character is a keyboard character selected by the user.<p> * * This class defines a number of static methods * that give each register the properties of a virtual clipboard.<p> * * Two classes implement the {@link Registers.Register} interface. A * {@link Registers.ClipboardRegister} is tied to the contents of the * system clipboard. jEdit assigns a * {@link Registers.ClipboardRegister} to the register indexed under * the character <code>$</code>. A * {@link Registers.StringRegister} is created for registers assigned * by the user. In addition, jEdit assigns <code>%</code> to * the last text segment selected in the text area. On Windows this is a * {@link Registers.StringRegister}, on Unix under Java 2 version 1.4, a * {@link Registers.ClipboardRegister}. * * @author Slava Pestov * @author John Gellene (API documentation) * @version $Id: Registers.java,v 1.21 2004/05/29 01:55:24 spestov Exp $ */public class Registers{	//{{{ copy() method	/**	 * Copies the text selected in the text area into the specified register.	 * This will replace the existing contents of the designated register.	 *	 * @param textArea The text area	 * @param register The register	 * @since jEdit 2.7pre2	 */	public static void copy(JEditTextArea textArea, char register)	{		String selection = textArea.getSelectedText();		if(selection == null)			return;		setRegister(register,selection);		HistoryModel.getModel("clipboard").addItem(selection);	} //}}}	//{{{ cut() method	/**	 * Copies the text selected in the text area into the specified	 * register, and then removes it from the buffer.	 *	 * @param textArea The text area	 * @param register The register	 * @since jEdit 2.7pre2	 */	public static void cut(JEditTextArea textArea, char register)	{		if(textArea.isEditable())		{			String selection = textArea.getSelectedText();			if(selection == null)				return;			setRegister(register,selection);			HistoryModel.getModel("clipboard").addItem(selection);			textArea.setSelectedText("");		}		else			textArea.getToolkit().beep();	} //}}}	//{{{ append() method	/**	 * Appends the text selected in the text area to the specified register,	 * with a newline between the old and new text.	 * @param textArea The text area	 * @param register The register	 */	public static void append(JEditTextArea textArea, char register)	{		append(textArea,register,"\n",false);	} //}}}	//{{{ append() method	/**	 * Appends the text selected in the text area to the specified register.	 * @param textArea The text area	 * @param register The register	 * @param separator The separator to insert between the old and new text	 */	public static void append(JEditTextArea textArea, char register,		String separator)	{		append(textArea,register,separator,false);	} //}}}	//{{{ append() method	/**	 * Appends the text selected in the  text area to the specified register.	 * @param textArea The text area	 * @param register The register	 * @param separator The text to insert between the old and new text	 * @param cut Should the current selection be removed?	 * @since jEdit 3.2pre1	 */	public static void append(JEditTextArea textArea, char register,		String separator, boolean cut)	{		if(cut && !textArea.isEditable())		{			textArea.getToolkit().beep();			return;		}		String selection = textArea.getSelectedText();		if(selection == null)			return;		Register reg = getRegister(register);		if(reg != null)		{			String registerContents = reg.toString();			if(registerContents != null)			{				if(registerContents.endsWith(separator))					selection = registerContents + selection;				else					selection = registerContents + separator + selection;			}		}		setRegister(register,selection);		HistoryModel.getModel("clipboard").addItem(selection);		if(cut)			textArea.setSelectedText("");	} //}}}	//{{{ paste() method	/**	 * Insets the contents of the specified register into the text area.	 * @param textArea The text area	 * @param register The register	 * @since jEdit 2.7pre2	 */	public static void paste(JEditTextArea textArea, char register)	{		paste(textArea,register,false);	} //}}}	//{{{ paste() method	/**	 * Inserts the contents of the specified register into the text area.	 * @param textArea The text area	 * @param register The register	 * @param vertical Vertical (columnar) paste	 * @since jEdit 4.1pre1	 */	public static void paste(JEditTextArea textArea, char register,		boolean vertical)	{		if(!textArea.isEditable())		{			textArea.getToolkit().beep();			return;		}		Register reg = getRegister(register);		if(reg == null)		{			textArea.getToolkit().beep();			return;		}		else		{			String selection = reg.toString();			if(selection == null)			{				textArea.getToolkit().beep();				return;			}			if(vertical && textArea.getSelectionCount() == 0)			{				Buffer buffer = textArea.getBuffer();				try				{					buffer.beginCompoundEdit();					int caret = textArea.getCaretPosition();					int caretLine = textArea.getCaretLine();					Selection.Rect rect = new Selection.Rect(						caretLine,caret,caretLine,caret);					textArea.setSelectedText(rect,selection);					caretLine = textArea.getCaretLine();					if(caretLine != textArea.getLineCount() - 1)					{						int startColumn = rect.getStartColumn(							buffer);						int offset = buffer							.getOffsetOfVirtualColumn(							caretLine + 1,startColumn,null);						if(offset == -1)						{							buffer.insertAtColumn(caretLine + 1,startColumn,"");							textArea.setCaretPosition(								buffer.getLineEndOffset(								caretLine + 1) - 1);						}						else						{							textArea.setCaretPosition(								buffer.getLineStartOffset(								caretLine + 1) + offset);						}					}				}				finally				{					buffer.endCompoundEdit();				}			}			else				textArea.setSelectedText(selection);			HistoryModel.getModel("clipboard").addItem(selection);		}	} //}}}	//{{{ getRegister() method	/**	 * Returns the specified register.	 * @param name The name	 */	public static Register getRegister(char name)	{		if(name != '$' && name != '%')		{			if(!loaded)				loadRegisters();		}		if(registers == null || name >= registers.length)			return null;		else			return registers[name];	} //}}}	//{{{ setRegister() method	/**	 * Sets the specified register.	 * @param name The name	 * @param newRegister The new value	 */	public static void setRegister(char name, Register newRegister)	{		if(name != '%' && name != '$')		{			if(!loaded)				loadRegisters();			if(!loading)				modified = true;		}		if(name >= registers.length)		{			Register[] newRegisters = new Register[				Math.min(1<<16,name * 2)];			System.arraycopy(registers,0,newRegisters,0,				registers.length);			registers = newRegisters;		}		registers[name] = newRegister;	} //}}}	//{{{ setRegister() method	/**	 * Sets the specified register.	 * @param name The name	 * @param value The new value	 */	public static void setRegister(char name, String value)	{		Register register = getRegister(name);		if(register != null)			register.setValue(value);		else			setRegister(name,new StringRegister(value));	} //}}}	//{{{ clearRegister() method	/**	 * Sets the value of the specified register to <code>null</code>.	 * @param name The register name	 */	public static void clearRegister(char name)	{		if(name >= registers.length)			return;		Register register = registers[name];		if(name == '$' || name == '%')			register.setValue("");		else			registers[name] = null;	} //}}}	//{{{ getRegisters() method	/**	 * Returns an array of all available registers. Some of the elements	 * of this array might be <code>null</code>.	 */	public static Register[] getRegisters()	{		if(!loaded)			loadRegisters();		return registers;	} //}}}	//{{{ getRegisterStatusPrompt() method	/**	 * Returns the status prompt for the given register action. Only	 * intended to be called from <code>actions.xml</code>.	 * @since jEdit 4.2pre2	 */	public static String getRegisterStatusPrompt(String action)	{		return jEdit.getProperty("view.status." + action,			new String[] { getRegisterNameString() });	} //}}}	//{{{ getRegisterNameString() method	/**	 * Returns a string of all defined registers, used by the status bar	 * (eg, "a b $ % ^").	 * @since jEdit 4.2pre2	 */	public static String getRegisterNameString()	{		if(!loaded)			loadRegisters();

⌨️ 快捷键说明

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