当前位置: 首页>>代码示例>>Java>>正文


Java RTextArea.getTabSize方法代码示例

本文整理汇总了Java中org.fife.ui.rtextarea.RTextArea.getTabSize方法的典型用法代码示例。如果您正苦于以下问题:Java RTextArea.getTabSize方法的具体用法?Java RTextArea.getTabSize怎么用?Java RTextArea.getTabSize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.fife.ui.rtextarea.RTextArea的用法示例。


在下文中一共展示了RTextArea.getTabSize方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: actionPerformedImpl

import org.fife.ui.rtextarea.RTextArea; //导入方法依赖的package包/类
@Override
public void actionPerformedImpl(ActionEvent e, RTextArea textArea) {

	if (!textArea.isEditable() || !textArea.isEnabled()) {
		UIManager.getLookAndFeel().provideErrorFeedback(textArea);
		return;
	}

	Document document = textArea.getDocument();
	Element map = document.getDefaultRootElement();
	Caret c = textArea.getCaret();
	int dot = c.getDot();
	int mark = c.getMark();
	int dotLine = map.getElementIndex(dot);
	int markLine = map.getElementIndex(mark);

	// If there is a multi-line selection, indent all lines in
	// the selection.
	if (dotLine!=markLine) {
		int first = Math.min(dotLine, markLine);
		int last = Math.max(dotLine, markLine);
		Element elem; int start;

		// Since we're using Document.insertString(), we must mimic the
		// soft tab behavior provided by RTextArea.replaceSelection().
		String replacement = "\t";
		if (textArea.getTabsEmulated()) {
			StringBuilder sb = new StringBuilder();
			int temp = textArea.getTabSize();
			for (int i=0; i<temp; i++) {
				sb.append(' ');
			}
			replacement = sb.toString();
		}

		textArea.beginAtomicEdit();
		try {
			for (int i=first; i<last; i++) {
				elem = map.getElement(i);
				start = elem.getStartOffset();
				document.insertString(start, replacement, null);
			}
			// Don't do the last line if the caret is at its
			// beginning.  We must call getDot() again and not just
			// use 'dot' as the caret's position may have changed
			// due to the insertion of the tabs above.
			elem = map.getElement(last);
			start = elem.getStartOffset();
			if (Math.max(c.getDot(), c.getMark())!=start) {
				document.insertString(start, replacement, null);
			}
		} catch (BadLocationException ble) { // Never happens.
			ble.printStackTrace();
			UIManager.getLookAndFeel().
							provideErrorFeedback(textArea);
		} finally {
			textArea.endAtomicEdit();
		}
	}
	else {
		textArea.replaceSelection("\t");
	}

}
 
开发者ID:curiosag,项目名称:ftc,代码行数:65,代码来源:RSyntaxTextAreaEditorKit.java

示例2: actionPerformedImpl

import org.fife.ui.rtextarea.RTextArea; //导入方法依赖的package包/类
public void actionPerformedImpl(ActionEvent e, RTextArea textArea) {

			if (!textArea.isEditable() || !textArea.isEnabled()) {
				UIManager.getLookAndFeel().provideErrorFeedback(textArea);
				return;
			}

			Document document = textArea.getDocument();
			Element map = document.getDefaultRootElement();
			Caret c = textArea.getCaret();
			int dot = c.getDot();
			int mark = c.getMark();
			int dotLine = map.getElementIndex(dot);
			int markLine = map.getElementIndex(mark);

			// If there is a multi-line selection, indent all lines in
			// the selection.
			if (dotLine!=markLine) {
				int first = Math.min(dotLine, markLine);
				int last = Math.max(dotLine, markLine);
				Element elem; int start;

				// Since we're using Document.insertString(), we must mimic the
				// soft tab behavior provided by RTextArea.replaceSelection().
				String replacement = "\t";
				if (textArea.getTabsEmulated()) {
					StringBuffer sb = new StringBuffer();
					int temp = textArea.getTabSize();
					for (int i=0; i<temp; i++) {
						sb.append(' ');
					}
					replacement = sb.toString();
				}

				textArea.beginAtomicEdit();
				try {
					for (int i=first; i<last; i++) {
						elem = map.getElement(i);
						start = elem.getStartOffset();
						document.insertString(start, replacement, null);
					}
					// Don't do the last line if the caret is at its
					// beginning.  We must call getDot() again and not just
					// use 'dot' as the caret's position may have changed
					// due to the insertion of the tabs above.
					elem = map.getElement(last);
					start = elem.getStartOffset();
					if (Math.max(c.getDot(), c.getMark())!=start) {
						document.insertString(start, replacement, null);
					}
				} catch (BadLocationException ble) { // Never happens.
					ble.printStackTrace();
					UIManager.getLookAndFeel().
									provideErrorFeedback(textArea);
				} finally {
					textArea.endAtomicEdit();
				}
			}
			else {
				textArea.replaceSelection("\t");
			}

		}
 
开发者ID:Nanonid,项目名称:RSyntaxTextArea,代码行数:64,代码来源:RSyntaxTextAreaEditorKit.java


注:本文中的org.fife.ui.rtextarea.RTextArea.getTabSize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。