本文整理了Java中javax.swing.text.Element.getEndOffset()
方法的一些代码示例,展示了Element.getEndOffset()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Element.getEndOffset()
方法的具体详情如下:
包路径:javax.swing.text.Element
类名称:Element
方法名:getEndOffset
暂无
代码示例来源:origin: bobbylight/RSyntaxTextArea
private boolean getDoAdd(Document doc, Element map, int startLine,
int endLine, String[] startEnd)
throws BadLocationException {
boolean doAdd = false;
for (int i=startLine; i<=endLine; i++) {
Element elem = map.getElement(i);
int start = elem.getStartOffset();
String t = doc.getText(start, elem.getEndOffset()-start-1);
if (!t.startsWith(startEnd[0]) ||
(startEnd[1]!=null && !t.endsWith(startEnd[1]))) {
doAdd = true;
break;
}
}
return doAdd;
}
代码示例来源:origin: bobbylight/RSyntaxTextArea
private static Element getLineElem(Document d, int offs) {
Element map = d.getDefaultRootElement();
int index = map.getElementIndex(offs);
Element elem = map.getElement(index);
if ((offs>=elem.getStartOffset()) && (offs<elem.getEndOffset())) {
return elem;
}
return null;
}
代码示例来源:origin: bobbylight/RSyntaxTextArea
private void handleToggleComment(Element elem, Document doc,
String[] startEnd, boolean add) throws BadLocationException {
int start = elem.getStartOffset();
int end = elem.getEndOffset() - 1;
if (add) {
if (startEnd[1]!=null) {
doc.insertString(end, startEnd[1], null);
}
doc.insertString(start, startEnd[0], null);
}
else {
if (startEnd[1]!=null) {
int temp = startEnd[1].length();
doc.remove(end-temp, temp);
}
doc.remove(start, startEnd[0].length());
}
}
代码示例来源:origin: bobbylight/RSyntaxTextArea
@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;
}
代码示例来源:origin: SKCraft/Launcher
private void removeFromStart(Document document, Element root, int excess) {
Element line = root.getElement(excess - 1);
int end = line.getEndOffset();
try {
document.remove(0, end);
} catch (BadLocationException ble) {
System.out.println(ble);
}
}
代码示例来源:origin: fr.inria.wimmics/kggui
public int getLineOfOffset(final JTextComponent textComponent, final int line) throws BadLocationException {
final Document doc = textComponent.getDocument();
final int lineCount = doc.getDefaultRootElement().getElementCount();
if (line < 0) {
throw new BadLocationException("Negative line", -1);
} else if (line > lineCount) {
throw new BadLocationException("No such line", doc.getLength() + 1);
} else {
Element map = doc.getDefaultRootElement();
Element lineElem = map.getElement(line);
return lineElem.getEndOffset();
}
}
代码示例来源:origin: bobbylight/RSyntaxTextArea
/**
* Returns the leading whitespace of a specific line in a document.
*
* @param doc The document.
* @param offs The offset whose line to get the leading whitespace for.
* @return The leading whitespace.
* @throws BadLocationException If <code>offs</code> is not a valid offset
* in the document.
* @see #getLeadingWhitespace(String)
*/
public static String getLeadingWhitespace(Document doc, int offs)
throws BadLocationException {
Element root = doc.getDefaultRootElement();
int line = root.getElementIndex(offs);
Element elem = root.getElement(line);
int startOffs = elem.getStartOffset();
int endOffs = elem.getEndOffset() - 1;
String text = doc.getText(startOffs, endOffs-startOffs);
return getLeadingWhitespace(text);
}
代码示例来源:origin: bobbylight/RSyntaxTextArea
/**
* Makes our private <code>Segment s</code> point to the text in our
* document referenced by the specified element. Note that
* <code>line</code> MUST be a valid line number in the document.
*
* @param line The line number you want to get.
*/
private void setSharedSegment(int line) {
Element map = getDefaultRootElement();
//int numLines = map.getElementCount();
Element element = map.getElement(line);
if (element==null) {
throw new InternalError("Invalid line number: " + line);
}
int startOffset = element.getStartOffset();
//int endOffset = (line==numLines-1 ?
// element.getEndOffset()-1 : element.getEndOffset() - 1);
int endOffset = element.getEndOffset()-1; // Why always "-1"?
try {
getText(startOffset, endOffset-startOffset, s);
} catch (BadLocationException ble) {
throw new InternalError("Text range not in document: " +
startOffset + "-" + endOffset);
}
}
代码示例来源:origin: bobbylight/RSyntaxTextArea
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;
代码示例来源:origin: bobbylight/RSyntaxTextArea
@Override
public void actionPerformedImpl(ActionEvent e, RTextArea textArea) {
try {
// We use the elements instead of calling getLineOfOffset(),
// etc. to speed things up just a tad (i.e. micro-optimize).
Document document = textArea.getDocument();
int caretPosition = textArea.getCaretPosition();
Element map = document.getDefaultRootElement();
int currentLineNum = map.getElementIndex(caretPosition);
Element currentLineElement = map.getElement(currentLineNum);
// Always take -1 as we don't want to remove the newline.
int currentLineEnd = currentLineElement.getEndOffset()-1;
if (caretPosition<currentLineEnd) {
document.remove(caretPosition,
currentLineEnd-caretPosition);
}
} catch (BadLocationException ble) {
ble.printStackTrace();
}
}
代码示例来源:origin: SKCraft/SKMCLauncher
private void removeFromStart(Document document, Element root) {
Element line = root.getElement(0);
int end = line.getEndOffset();
try {
document.remove(0, end);
} catch (BadLocationException ble) {
System.out.println(ble);
}
}
代码示例来源:origin: Wimmics/corese
public int getLineOfOffset(final JTextComponent textComponent, final int line) throws BadLocationException {
final Document doc = textComponent.getDocument();
final int lineCount = doc.getDefaultRootElement().getElementCount();
if (line < 0) {
throw new BadLocationException("Negative line", -1);
} else if (line > lineCount) {
throw new BadLocationException("No such line", doc.getLength() + 1);
} else {
Element map = doc.getDefaultRootElement();
Element lineElem = map.getElement(line);
return lineElem.getEndOffset();
}
}
代码示例来源:origin: bobbylight/RSyntaxTextArea
private void doError(SAXParseException e, ParserNotice.Level level) {
int line = e.getLineNumber() - 1;
Element root = doc.getDefaultRootElement();
Element elem = root.getElement(line);
int offs = elem.getStartOffset();
int len = elem.getEndOffset() - offs;
if (line==root.getElementCount()-1) {
len++;
}
DefaultParserNotice pn = new DefaultParserNotice(XmlParser.this,
e.getMessage(), line, offs, len);
pn.setLevel(level);
result.addNotice(pn);
}
代码示例来源:origin: bobbylight/RSyntaxTextArea
/**
* 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();
}
代码示例来源:origin: bobbylight/RSyntaxTextArea
if(offs < curPara.getStartOffset()) {
offs = Utilities.getParagraphElement(textArea, offs).
getEndOffset() - 1;
代码示例来源:origin: bobbylight/RSyntaxTextArea
@Override
public void actionPerformedImpl(ActionEvent e, RTextArea textArea) {
int offs = textArea.getCaretPosition();
int endOffs = 0;
try {
if (textArea.getLineWrap()) {
// Must check per character, since one logical line may be
// many physical lines.
// FIXME: Replace Utilities call with custom version to
// cut down on all of the modelToViews, as each call causes
// a getTokenList => expensive!
endOffs = Utilities.getRowEnd(textArea, offs);
}
else {
Element root = textArea.getDocument().getDefaultRootElement();
int line = root.getElementIndex(offs);
endOffs = root.getElement(line).getEndOffset() - 1;
}
if (select) {
textArea.moveCaretPosition(endOffs);
}
else {
textArea.setCaretPosition(endOffs);
}
} catch (Exception ex) {
UIManager.getLookAndFeel().provideErrorFeedback(textArea);
}
}
代码示例来源:origin: Spoutcraft/LegacyLauncher
private void removeFromStart(Document document, Element root) {
Element line = root.getElement(0);
int end = line.getEndOffset();
try {
document.remove(0, end);
} catch (BadLocationException ble) {
System.out.println(ble);
}
}
代码示例来源:origin: cmu-phil/tetrad
private void removeLines() {
Element root = getDocument().getDefaultRootElement();
while (root.getElementCount() > maxLines) {
Element firstLine = root.getElement(0);
try {
getDocument().remove(0, firstLine.getEndOffset());
}
catch (BadLocationException ble) {
ble.printStackTrace();
}
}
}
}
代码示例来源:origin: bobbylight/RSyntaxTextArea
Element root = doc.getDefaultRootElement();
int line = root.getElementIndex(offs);
Element elem = root.getElement(line);
int start = elem.getStartOffset();
if (offs > start) {
char ch = doc.charAt(offs);
return -1;
elem = root.getElement(--line);
offs = elem.getEndOffset() - 1;
while (prevWordStart == -1 && line > 0) {
line--;
elem = root.getElement(line);
prevWordStart = getPreviousWordStartInLine(doc, elem,
elem.getEndOffset());
代码示例来源:origin: bobbylight/RSyntaxTextArea
Element elem = root.getElement(line);
int start = elem.getStartOffset();
elem = root.getElement(endLine);
int end = elem.getEndOffset();
int lineCount = textArea.getLineCount();
boolean movingLastLine = false;
内容来源于网络,如有侵权,请联系作者删除!