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


Java Element.getEndOffset方法代码示例

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


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

示例1: moveLineUp

import javax.swing.text.Element; //导入方法依赖的package包/类
private void moveLineUp(RTextArea textArea, int line)
							throws BadLocationException {
	Document doc = textArea.getDocument();
	Element root = doc.getDefaultRootElement();
	int lineCount = root.getElementCount();
	Element elem = root.getElement(line);
	int start = elem.getStartOffset();
	int end = line==lineCount-1 ? elem.getEndOffset()-1 :
							elem.getEndOffset();
	int caret = textArea.getCaretPosition();
	int caretOffset = caret - start;
	String text = doc.getText(start, end-start);
	if (line==lineCount-1) {
		start--; // Remove previous line's ending \n
	}
	doc.remove(start, end-start);
	Element elem2 = root.getElement(line-1);
	int start2 = elem2.getStartOffset();
	//int end2 = elem2.getEndOffset();
	if (line==lineCount-1) {
		text += '\n';
	}
	doc.insertString(start2, text, null);
	//caretOffset = Math.min(start2+caretOffset, end2-1);
	textArea.setCaretPosition(start2+caretOffset);
}
 
开发者ID:Thecarisma,项目名称:powertext,代码行数:27,代码来源:RTextAreaEditorKit.java

示例2: getWordEnd

import javax.swing.text.Element; //导入方法依赖的package包/类
@Override
protected int getWordEnd(RTextArea textArea, int offs)
		throws BadLocationException {

	RSyntaxDocument doc = (RSyntaxDocument)textArea.getDocument();
	Element root = doc.getDefaultRootElement();
	int line = root.getElementIndex(offs);
	Element elem = root.getElement(line);
	int end = elem.getEndOffset() - 1;

	int wordEnd = offs;
	while (wordEnd <= end) {
		if (!isIdentifierChar(doc.charAt(wordEnd))) {
			break;
		}
		wordEnd++;
	}

	return wordEnd;

}
 
开发者ID:Thecarisma,项目名称:powertext,代码行数:22,代码来源:RSyntaxTextAreaEditorKit.java

示例3: removeIfEmpty

import javax.swing.text.Element; //导入方法依赖的package包/类
void removeIfEmpty(Element elem) {
	if (elem.getEndOffset() - elem.getStartOffset() < 2) {
		try {
			document.remove(elem.getStartOffset(), elem.getEndOffset());
		} catch (Exception ex) {
			//ex.printStackTrace();
		}
	}
}
 
开发者ID:ser316asu,项目名称:Neukoelln_SER316,代码行数:10,代码来源:HTMLEditor.java

示例4: reloadChildren

import javax.swing.text.Element; //导入方法依赖的package包/类
protected @Override void reloadChildren(int index, int removeLength, int startOffset, int endOffset) {
    // TODO uncomment assert (index == 0 && removeLength == 0
        // && startOffset == getStartOffset() && endOffset == getEndOffset());

    // Rebuild all the present child views completely
    index = 0;
    removeLength = getViewCount();

    Element lineElem = getElement(); // starting line element
    View[] added = null;
    ViewFactory f = getViewFactory();
    if (f != null) {
        int lineElemEndOffset = lineElem.getEndOffset();
        // Ending offset of the previously created view - here start with
        //   begining of the first line
        int lastViewEndOffset = lineElem.getStartOffset();

        List childViews = new ArrayList();
        // Append ending fragment if necessary
        // asserted non-empty list => foldEndOffset populated
        if (lastViewEndOffset < lineElemEndOffset) { // need ending fragment
            View lineView = f.create(lineElem);
            View endingFrag = lineView.createFragment(lastViewEndOffset, lineElemEndOffset);
            childViews.add(endingFrag);
            // lastViewEndOffset = lineElemEndOffset;  <- can be ignored here
        }

        added = new View[childViews.size()];
        childViews.toArray(added);
    }

    
    replace(index, removeLength, added);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:35,代码来源:FoldMultiLineView.java

示例5: createFragment

import javax.swing.text.Element; //导入方法依赖的package包/类
public @Override View createFragment(int p0, int p1) {
    Element elem = getElement();
    return  // necessary conditions in accordance with javadoc
            p0>=0 && p0>=elem.getStartOffset() && p0<elem.getEndOffset() &&
            p1>0 && p1<=elem.getEndOffset() && p1>elem.getStartOffset() &&
            // create fragment only if one of the element differs from valid start or end offset
            (p0!=elem.getStartOffset() || p1!=elem.getEndOffset()) ?
                new FragmentView(getElement(), p0 - elem.getStartOffset(), p1 - p0) :
                this;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:11,代码来源:DrawEngineLineView.java

示例6: getCompletionsAt

import javax.swing.text.Element; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public List<Completion> getCompletionsAt(JTextComponent tc, Point p) {

	int offset = tc.viewToModel(p);
	if (offset<0 || offset>=tc.getDocument().getLength()) {
		lastCompletionsAtText = null;
		return lastParameterizedCompletionsAt = null;
	}

	Segment s = new Segment();
	Document doc = tc.getDocument();
	Element root = doc.getDefaultRootElement();
	int line = root.getElementIndex(offset);
	Element elem = root.getElement(line);
	int start = elem.getStartOffset();
	int end = elem.getEndOffset() - 1;

	try {

		doc.getText(start, end-start, s);

		// Get the valid chars before the specified offset.
		int startOffs = s.offset + (offset-start) - 1;
		while (startOffs>=s.offset && isValidChar(s.array[startOffs])) {
			startOffs--;
		}

		// Get the valid chars at and after the specified offset.
		int endOffs = s.offset + (offset-start);
		while (endOffs<s.offset+s.count && isValidChar(s.array[endOffs])) {
			endOffs++;
		}

		int len = endOffs - startOffs - 1;
		if (len<=0) {
			return lastParameterizedCompletionsAt = null;
		}
		String text = new String(s.array, startOffs+1, len);

		if (text.equals(lastCompletionsAtText)) {
			return lastParameterizedCompletionsAt;
		}

		// Get a list of all Completions matching the text.
		List<Completion> list = getCompletionByInputText(text);
		lastCompletionsAtText = text;
		return lastParameterizedCompletionsAt = list;

	} catch (BadLocationException ble) {
		ble.printStackTrace(); // Never happens
	}

	lastCompletionsAtText = null;
	return lastParameterizedCompletionsAt = null;

}
 
开发者ID:Thecarisma,项目名称:powertext,代码行数:60,代码来源:DefaultCompletionProvider.java

示例7: noticeContainsPosition

import javax.swing.text.Element; //导入方法依赖的package包/类
/**
 * Returns whether a parser notice contains the specified offset.
 *
 * @param notice The notice.
 * @param offs The offset.
 * @return Whether the notice contains the offset.
 */
private boolean noticeContainsPosition(ParserNotice notice, int offs){
	if (notice.getKnowsOffsetAndLength()) {
		return notice.containsPosition(offs);
	}
	Document doc = textArea.getDocument();
	Element root = doc.getDefaultRootElement();
	int line = notice.getLine();
	if (line<0) { // Defensive against possible bad user-defined notices.
		return false;
	}
	Element elem = root.getElement(line);
	return elem != null && offs>=elem.getStartOffset() && offs<elem.getEndOffset();
}
 
开发者ID:Thecarisma,项目名称:powertext,代码行数:21,代码来源:ParserManager.java

示例8: invoke

import javax.swing.text.Element; //导入方法依赖的package包/类
/**
 * Invokes this code template.  The changes are made to the given text
 * area.
 *
 * @param textArea The text area to operate on.
 * @throws BadLocationException If something bad happens.
 */
@Override
public void invoke(RSyntaxTextArea textArea) throws BadLocationException {

	Caret c = textArea.getCaret();
	int dot = c.getDot();
	int mark = c.getMark();
	int p0 = Math.min(dot, mark);
	int p1 = Math.max(dot, mark);
	RSyntaxDocument doc = (RSyntaxDocument)textArea.getDocument();
	Element map = doc.getDefaultRootElement();

	int lineNum = map.getElementIndex(dot);
	Element line = map.getElement(lineNum);
	int start = line.getStartOffset();
	int end = line.getEndOffset()-1; // Why always "-1"?
	String s = textArea.getText(start,end-start);
	int len = s.length();

	// endWS is the end of the leading whitespace
	// of the current line.
	int endWS = 0;
	while (endWS<len && RSyntaxUtilities.isWhitespace(s.charAt(endWS))) {
		endWS++;
	}
	s = s.substring(0, endWS);
	p0 -= getID().length();
	String beforeText = getBeforeTextIndented(s);
	String afterText = getAfterTextIndented(s);
	doc.replace(p0,p1-p0, beforeText+afterText, null);
	textArea.setCaretPosition(p0+beforeText.length());

}
 
开发者ID:Thecarisma,项目名称:powertext,代码行数:40,代码来源:StaticCodeTemplate.java

示例9: getLineEndOffset

import javax.swing.text.Element; //导入方法依赖的package包/类
/**
 * Returns the end offset of the specified line.
 * 
 * @param line
 *            The line
 * @return The end offset of the specified line, or -1 if the line is invalid.
 */
public int getLineEndOffset(int line) {
	Element lineElement = document.getDefaultRootElement().getElement(line);
	if (lineElement == null) {
		return -1;
	} else {
		return lineElement.getEndOffset();
	}
}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:16,代码来源:JEditTextArea.java

示例10: addParserHighlight

import javax.swing.text.Element; //导入方法依赖的package包/类
/**
 * Adds a highlight from a parser.
 *
 * @param notice The notice from a {@link Parser}.
 * @return A tag with which to reference the highlight.
 * @throws BadLocationException
 * @see #clearParserHighlights()
 * @see #clearParserHighlights(Parser)
 */
HighlightInfo addParserHighlight(ParserNotice notice, HighlightPainter p)
							throws BadLocationException {

	Document doc = textArea.getDocument();
	TextUI mapper = textArea.getUI();

	int start = notice.getOffset();
	int end = 0;
	if (start==-1) { // Could just define an invalid line number
		int line = notice.getLine();
		Element root = doc.getDefaultRootElement();
		if (line>=0 && line<root.getElementCount()) {
			Element elem = root.getElement(line);
			start = elem.getStartOffset();
			end = elem.getEndOffset();
		}
	}
	else {
		end = start + notice.getLength();
	}

	// Always layered highlights for parser highlights.
	SyntaxLayeredHighlightInfoImpl i = new SyntaxLayeredHighlightInfoImpl();
	i.setPainter(p);
	i.setStartOffset(doc.createPosition(start));
	// HACK: Use "end-1" to prevent chars the user types at the "end" of
	// the highlight to be absorbed into the highlight (default Highlight
	// behavior).
	i.setEndOffset(doc.createPosition(end-1));
	i.notice = notice;//i.color = notice.getColor();

	parserHighlights.add(i);
	mapper.damageRange(textArea, start, end);
	return i;

}
 
开发者ID:Thecarisma,项目名称:powertext,代码行数:46,代码来源:RSyntaxTextAreaHighlighter.java

示例11: handleDecreaseIndent

import javax.swing.text.Element; //导入方法依赖的package包/类
/**
 * Actually does the "de-indentation."  This method finds where the
 * given element's leading whitespace ends, then, if there is indeed
 * leading whitespace, removes either the last char in it (if it is a
 * tab), or removes up to the number of spaces equal to a tab in the
 * specified document (i.e., if the tab size was 5 and there were 3
 * spaces at the end of the leading whitespace, the three will be
 * removed; if there were 8 spaces, only the first 5 would be
 * removed).
 *
 * @param elem The element to "de-indent."
 * @param doc The document containing the specified element.
 * @param tabSize The size of a tab, in spaces.
 */
private void handleDecreaseIndent(Element elem, Document doc,
							int tabSize)
							throws BadLocationException {
	int start = elem.getStartOffset();
	int end = elem.getEndOffset() - 1; // Why always true??
	doc.getText(start,end-start, s);
	int i = s.offset;
	end = i+s.count;
	if (end>i) {
		// If the first character is a tab, remove it.
		if (s.array[i]=='\t') {
			doc.remove(start, 1);
		}
		// Otherwise, see if the first character is a space.  If it
		// is, remove all contiguous whitespaces at the beginning of
		// this line, up to the tab size.
		else if (s.array[i]==' ') {
			i++;
			int toRemove = 1;
			while (i<end && s.array[i]==' ' && toRemove<tabSize) {
				i++;
				toRemove++;
			}
			doc.remove(start, toRemove);
		}
	}
}
 
开发者ID:Thecarisma,项目名称:powertext,代码行数:42,代码来源:RSyntaxTextAreaEditorKit.java

示例12: splitByLines

import javax.swing.text.Element; //导入方法依赖的package包/类
private List<Integer> splitByLines(int sentenceStart, int sentenceEnd) {
    ArrayList<Integer> lines = new ArrayList<Integer>();
    int offset = sentenceStart;
    
    try {
        while (offset < sentenceEnd) {
            Element lineElement = document.getDefaultRootElement().getElement(
                document.getDefaultRootElement().getElementIndex(offset));

            int rowStart = offset == sentenceStart ? offset : lineElement.getStartOffset();
            int rowEnd = lineElement.getEndOffset();

            String line = document.getText(rowStart, rowEnd - rowStart);
            int idx = 0;
            while (idx < line.length() && 
                (line.charAt(idx) == ' ' || 
                line.charAt(idx) == '\t' || 
                line.charAt(idx) == '*'))
            {
                idx++;
            }

            if (rowStart + idx < rowEnd) {
                lines.add(rowStart + idx);
                lines.add(Math.min(rowEnd, sentenceEnd));
            }

            offset = rowEnd + 1;
        }
    } catch (BadLocationException e) {
        LOG.log(Level.WARNING, "Can't determine javadoc first sentence", e);
    }
    
    return lines.isEmpty() ? null : lines;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:36,代码来源:Highlighting.java

示例13: fetchPreviousNonEmptyRegion

import javax.swing.text.Element; //导入方法依赖的package包/类
private boolean fetchPreviousNonEmptyRegion() {
    while (--modElementIndex >= 0) {
        Element modElement = modRootElement.getElement(modElementIndex);
        modElementStartOffset = modElement.getStartOffset();
        modElementEndOffset = modElement.getEndOffset();
        if (modElementStartOffset >= modElementEndOffset)// Empty region - continue
            continue;
        return true;
    }
    return false;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:12,代码来源:TrailingWhitespaceRemoveProcessor.java

示例14: actionPerformedImpl

import javax.swing.text.Element; //导入方法依赖的package包/类
@Override
public void actionPerformedImpl(ActionEvent e, RTextArea textArea) {
	if (!textArea.isEditable() || !textArea.isEnabled()) {
		UIManager.getLookAndFeel().provideErrorFeedback(textArea);
		return;
	}
	try {
		Caret c = textArea.getCaret();
		int caretPos = c.getDot();
		Document doc = textArea.getDocument();
		Element map = doc.getDefaultRootElement();
		int lineCount = map.getElementCount();
		int line = map.getElementIndex(caretPos);
		if (line==lineCount-1) {
			UIManager.getLookAndFeel().
						provideErrorFeedback(textArea);
			return;
		}
		Element lineElem = map.getElement(line);
		caretPos = lineElem.getEndOffset() - 1;
		c.setDot(caretPos);		// Gets rid of any selection.
		doc.remove(caretPos, 1);	// Should be '\n'.
	} catch (BadLocationException ble) {
		/* Shouldn't ever happen. */
		ble.printStackTrace();
	}
	textArea.requestFocusInWindow();
}
 
开发者ID:Thecarisma,项目名称:powertext,代码行数:29,代码来源:RTextAreaEditorKit.java

示例15: caretUpdate

import javax.swing.text.Element; //导入方法依赖的package包/类
/**
 * Messaged when the selection in the editor has changed. Will update
 * the selection in the tree.
 */
public void caretUpdate(CaretEvent e) {
    if (!updatingSelection) {
        int selBegin = Math.min(e.getDot(), e.getMark());
        int end = Math.max(e.getDot(), e.getMark());
        List<TreePath> paths = new ArrayList<TreePath>();
        TreeModel model = getTreeModel();
        Object root = model.getRoot();
        int rootCount = model.getChildCount(root);

        // Build an array of all the paths to all the character elements
        // in the selection.
        for (int counter = 0; counter < rootCount; counter++) {
            int start = selBegin;

            while (start <= end) {
                TreePath path = getPathForIndex(start, root,
                        (Element) model.getChild(root, counter));
                Element charElement = (Element) path.getLastPathComponent();

                paths.add(path);
                if (start >= charElement.getEndOffset()) {
                    start++;
                } else {
                    start = charElement.getEndOffset();
                }
            }
        }

        // If a path was found, select it (them).
        int numPaths = paths.size();

        if (numPaths > 0) {
            TreePath[] pathArray = new TreePath[numPaths];

            paths.toArray(pathArray);
            updatingSelection = true;
            try {
                getTree().setSelectionPaths(pathArray);
                getTree().scrollPathToVisible(pathArray[0]);
            } finally {
                updatingSelection = false;
            }
        }
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:50,代码来源:ElementTreePanel.java


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