當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。