本文整理了Java中javax.swing.text.Element.getStartOffset()
方法的一些代码示例,展示了Element.getStartOffset()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Element.getStartOffset()
方法的具体详情如下:
包路径:javax.swing.text.Element
类名称:Element
方法名:getStartOffset
暂无
代码示例来源:origin: SonarSource/sonarqube
protected String getTextLineNumber(int rowStartOffset) {
Element root = component.getDocument().getDefaultRootElement();
int index = root.getElementIndex(rowStartOffset);
Element line = root.getElement(index);
if (line.getStartOffset() == rowStartOffset)
return String.valueOf(index + 1);
else
return "";
}
代码示例来源: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: ron190/jsql-injection
/**
* Get position of the beginning of the line.
* @param line Index of the line
* @return Offset of line
* @throws BadLocationException
*/
public int getLineStartOffset(int line) throws BadLocationException {
Element map = this.getDocument().getDefaultRootElement();
if (line < 0) {
throw new BadLocationException("Negative line", -1);
} else if (line >= map.getElementCount()) {
throw new BadLocationException("No such line", this.getDocument().getLength() + 1);
} else {
Element lineElem = map.getElement(line);
return lineElem.getStartOffset();
}
}
代码示例来源: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
public int yForLine(Rectangle alloc, int line) throws BadLocationException {
return yForLineContaining(alloc,
getElement().getElement(line).getStartOffset());
//return alloc.y + getOffset(Y_AXIS, line);
}
代码示例来源: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: skylot/jadx
@Nullable
protected String getTextLineNumber(int rowStartOffset) {
Element root = codeArea.getDocument().getDefaultRootElement();
int index = root.getElementIndex(rowStartOffset);
Element line = root.getElement(index);
if (line.getStartOffset() != rowStartOffset) {
return null;
}
int lineNumber = index + 1;
if (useSourceLines) {
Integer sourceLine = codeArea.getSourceLine(lineNumber);
if (sourceLine == null) {
return null;
}
return String.valueOf(sourceLine);
}
return String.valueOf(lineNumber);
}
代码示例来源:origin: org.netbeans.api/org-netbeans-modules-mobility-svgcore
public int getOffsetByPosition(int line, int column) {
Element root = getDoc().getDefaultRootElement();
line = Math.max(line, 1);
line = Math.min(line, root.getElementCount());
int pos = root.getElement(line - 1).getStartOffset() + column;
return pos;
}
代码示例来源: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: nz.ac.waikato.cms.weka.thirdparty/bounce
private int getLineStart(int i) throws BadLocationException {
Element line = editor.getDocument().getDefaultRootElement().getElement(i);
Rectangle result = editor.modelToView(line.getStartOffset());
if (result != null) {
return result.y;
}
return -1;
}
代码示例来源: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: groovy/groovy-core
public int findTabLocation(int offset) {
// find first {
boolean cont = true;
while (offset > -1 && cont) {
Element el = doc.getCharacterElement(offset);
Object color =
el.getAttributes().getAttribute(StyleConstants.Foreground);
if (!COMMENT_COLOR.equals(color)) {
cont = segment.array[offset] != '{' &&
segment.array[offset] != '}';
}
offset -= cont ? 1 : 0;
}
if (offset > -1 && segment.array[offset] == '{') {
while (offset > -1 &&
!Character.isWhitespace(segment.array[offset--])) {
}
}
int index = offset < 0 || segment.array[offset] == '}' ? -4 : 0;
if (offset > -1) {
Element top = doc.getDefaultRootElement();
offset = top.getElement(top.getElementIndex(offset)).getStartOffset();
while (Character.isWhitespace(segment.array[offset++])) {
index++;
}
}
return index;
}
}
代码示例来源:origin: org.gosu-lang.gosu/gosu-lab
public int getLineOffset( int iLine )
{
Element root = getDocument().getRootElements()[0];
iLine = root.getElementCount() < iLine ? root.getElementCount() : iLine;
Element elemAtLine = root.getElement( iLine );
return elemAtLine == null ? 0 : elemAtLine.getStartOffset();
}
代码示例来源:origin: bobbylight/RSyntaxTextArea
if(offs < curPara.getStartOffset()) {
offs = Utilities.getParagraphElement(textArea, offs).
getEndOffset() - 1;
代码示例来源:origin: nz.ac.waikato.cms.weka.thirdparty/bounce
private int getLineStart(int i) throws BadLocationException {
Element line = editor.getDocument().getDefaultRootElement().getElement(i);
Rectangle result = editor.modelToView(line.getStartOffset());
if (result != null) {
return result.y;
}
return -1;
}
代码示例来源:origin: bobbylight/RSyntaxTextArea
Element currentLine = rootElement.getElement(currentDocLineNumber);
int startOffs = currentLine.getStartOffset();
try {
curLineString = doc.getText(startOffs, currentLine.getEndOffset()-startOffs);
} catch (BadLocationException ble) { // Never happens
ble.printStackTrace();
代码示例来源: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;
内容来源于网络,如有侵权,请联系作者删除!