本文整理汇总了Java中javax.swing.text.StyledDocument.getParagraphElement方法的典型用法代码示例。如果您正苦于以下问题:Java StyledDocument.getParagraphElement方法的具体用法?Java StyledDocument.getParagraphElement怎么用?Java StyledDocument.getParagraphElement使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.text.StyledDocument
的用法示例。
在下文中一共展示了StyledDocument.getParagraphElement方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getRowFirstNonWhite
import javax.swing.text.StyledDocument; //导入方法依赖的package包/类
static int getRowFirstNonWhite(StyledDocument doc, int offset)
throws BadLocationException {
Element lineElement = doc.getParagraphElement(offset);
int start = lineElement.getStartOffset();
while (start + 1 < lineElement.getEndOffset()) {
try {
if (doc.getText(start, 1).charAt(0) != ' ') {
break;
}
} catch (BadLocationException ex) {
throw (BadLocationException) new BadLocationException(
"calling getText(" + start + ", " + (start + 1)
+ ") on doc of length: " + doc.getLength(), start).initCause(ex);
}
start++;
}
return start;
}
示例2: getAnnotateLine
import javax.swing.text.StyledDocument; //导入方法依赖的package包/类
/**
* Locates AnnotateLine associated with given line. The
* line is translated to Element that is used as map lookup key.
* The map is initially filled up with Elements sampled on
* annotate() method.
*
* <p>Key trick is that Element's identity is maintained
* until line removal (and is restored on undo).
*
* @param line
* @return found AnnotateLine or <code>null</code>
*/
private AnnotateLine getAnnotateLine(int line) {
StyledDocument sd = (StyledDocument) doc;
int lineOffset = NbDocument.findLineOffset(sd, line);
Element element = sd.getParagraphElement(lineOffset);
AnnotateLine al = elementAnnotations.get(element);
if (al != null) {
int startOffset = element.getStartOffset();
int endOffset = element.getEndOffset();
try {
int len = endOffset - startOffset;
String text = doc.getText(startOffset, len -1);
String content = al.getContent();
if (text.equals(content)) {
return al;
}
} catch (BadLocationException e) {
Mercurial.LOG.log(Level.INFO, "HG.AB: can not locate line annotation."); // NOI18N
}
}
return null;
}
示例3: getRowFirstNonWhite
import javax.swing.text.StyledDocument; //导入方法依赖的package包/类
/**
* Gets index of first not space/tab element in line where caret is or caret
* position if non found before its location
*
* @param doc edited document
* @param caretOffset current caret position
* @return Integer index of first space or offset passed in if none before
* it
* @throws BadLocationException
*/
static int getRowFirstNonWhite(StyledDocument doc, int caretOffset)
throws BadLocationException {
Element lineElement = doc.getParagraphElement(caretOffset);//line start&stop offsets
int start = lineElement.getStartOffset();
int failsafe = start;
while (start + 1 < lineElement.getEndOffset()) {
try {
if (doc.getText(start, 1).charAt(0) != ' ') {
break;
}
} catch (BadLocationException ex) {
throw (BadLocationException) new BadLocationException(
"calling getText(" + start + ", " + (start + 1)
+ ") on doc of length: " + doc.getLength(), start
).initCause(ex);
}
start++;
}
return start > caretOffset ? failsafe : start;
}
示例4: setHardCodedString
import javax.swing.text.StyledDocument; //导入方法依赖的package包/类
/** Implements superclass abstract method. */
protected void setHardCodedString(HardCodedString hcString, StyledDocument document) {
getStringText().setText(hcString == null ? "" : hcString.getText()); // NOI18N
int pos;
String hardLine;
if (hcString.getStartPosition() == null) {
hardLine = ""; // NOI18N
} else {
pos = hcString.getStartPosition().getOffset();
try {
Element paragraph = document.getParagraphElement(pos);
hardLine = document.getText(paragraph.getStartOffset(), paragraph.getEndOffset()-paragraph.getStartOffset()).trim();
} catch (BadLocationException ble) {
hardLine = ""; // NOI18N
}
}
getFoundInText().setText(hardLine);
if(hcString instanceof FormHardCodedString) {
getComponentText().setText( ((FormHardCodedString)hcString).getValidProperty().getRADComponentName());
getPropertyText().setText( ((FormHardCodedString)hcString).getNodeProperty().getName());
} else {
remove(getComponentLabel());
remove(getComponentText());
remove(getPropertyLabel());
remove(getPropertyText());
}
}
示例5: setHardCodedString
import javax.swing.text.StyledDocument; //导入方法依赖的package包/类
/** Implements superclass abstract method. */
protected void setHardCodedString(HardCodedString hcString, StyledDocument document) {
getStringText().setText(hcString == null ? "" //NOI18N
: hcString.getText());
int pos;
String hardLine;
if (hcString.getStartPosition() == null) {
hardLine = ""; //NOI18N
} else {
pos = hcString.getStartPosition().getOffset();
try {
Element paragraph = document.getParagraphElement(pos);
hardLine = document.getText(paragraph.getStartOffset(),
paragraph.getEndOffset() - paragraph.getStartOffset())
.trim();
} catch (BadLocationException ble) {
hardLine = ""; // NOI18N
}
}
getFoundInText().setText(hardLine);
remove(getComponentLabel());
remove(getComponentText());
remove(getPropertyLabel());
remove(getPropertyText());
}