本文整理了Java中javax.swing.text.Segment.charAt()
方法的一些代码示例,展示了Segment.charAt()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Segment.charAt()
方法的具体详情如下:
包路径:javax.swing.text.Segment
类名称:Segment
方法名:charAt
暂无
代码示例来源:origin: de.sciss/jsyntaxpane
static int getSmartHomeOffset(JTextComponent target, SyntaxDocument sDoc,
int dot) throws BadLocationException {
Element el = sDoc.getParagraphElement(dot);
Segment seg = new Segment();
sDoc.getText(el.getStartOffset(),
el.getEndOffset() - el.getStartOffset() - 1, seg);
int homeOffset = 0;
int dotLineOffset = dot - el.getStartOffset();
boolean inText = false;
// see the location of first non-space offset
for (int i = 0; i < dotLineOffset; i++) {
if (!Character.isWhitespace(seg.charAt(i))) {
inText = true;
break;
}
}
// if we are at first char in line, or we are past the non space
// chars in the line, then we move to non-space char
// otherwise, we move to first char of line
if (dotLineOffset == 0 || inText) {
for (char ch = seg.first();
ch != CharacterIterator.DONE && Character.isWhitespace(ch);
ch = seg.next()) {
homeOffset++;
}
}
return el.getStartOffset() + homeOffset;
}
}
代码示例来源:origin: de.sciss/syntaxpane
static int getSmartHomeOffset(JTextComponent target, SyntaxDocument sDoc,
int dot) throws BadLocationException {
Element el = sDoc.getParagraphElement(dot);
Segment seg = new Segment();
sDoc.getText(el.getStartOffset(),
el.getEndOffset() - el.getStartOffset() - 1, seg);
int homeOffset = 0;
int dotLineOffset = dot - el.getStartOffset();
boolean inText = false;
// see the location of first non-space offset
for (int i = 0; i < dotLineOffset; i++) {
if (!Character.isWhitespace(seg.charAt(i))) {
inText = true;
break;
}
}
// if we are at first char in line, or we are past the non space
// chars in the line, then we move to non-space char
// otherwise, we move to first char of line
if (dotLineOffset == 0 || inText) {
for (char ch = seg.first();
ch != CharacterIterator.DONE && Character.isWhitespace(ch);
ch = seg.next()) {
homeOffset++;
}
}
return el.getStartOffset() + homeOffset;
}
}
内容来源于网络,如有侵权,请联系作者删除!