本文整理汇总了Java中javax.swing.text.Document.render方法的典型用法代码示例。如果您正苦于以下问题:Java Document.render方法的具体用法?Java Document.render怎么用?Java Document.render使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.text.Document
的用法示例。
在下文中一共展示了Document.render方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findIdentifierSpan
import javax.swing.text.Document; //导入方法依赖的package包/类
public static int[] findIdentifierSpan( final TreePath decl, final CompilationInfo info, final Document doc) {
final int[] result = new int[] {-1, -1};
Runnable r = new Runnable() {
public void run() {
Token<JavaTokenId> t = findIdentifierSpan(info, doc, decl);
if (t != null) {
result[0] = t.offset(null);
result[1] = t.offset(null) + t.length();
}
}
};
if (doc != null) {
doc.render(r);
} else {
r.run();
}
return result;
}
示例2: onlyWhitespacesBetween
import javax.swing.text.Document; //导入方法依赖的package包/类
private boolean onlyWhitespacesBetween(final int endOffset, final int dot) {
// autoexpand a fold that was JUST CREATED, if there's no non-whitespace (not lexical, but actual) in between the
// fold end and the caret:
final String[] cnt = new String[1];
final Document doc = component.getDocument();
doc.render(new Runnable() {
public void run() {
int dl = doc.getLength();
int from = Math.min(dl,
Math.min(endOffset, dot)
);
int to = Math.min(dl,
Math.max(endOffset, dot
));
try {
cnt[0] = doc.getText(from, to - from);
} catch (BadLocationException ex) {
Exceptions.printStackTrace(ex);
}
}
});
return (cnt[0] == null || cnt[0].trim().isEmpty());
}
示例3: insideToken
import javax.swing.text.Document; //导入方法依赖的package包/类
private boolean insideToken(final JTextComponent jtc, final JavaTokenId first, final JavaTokenId... rest) {
final Document doc = jtc.getDocument();
final boolean[] result = new boolean[1];
doc.render(new Runnable() {
@Override public void run() {
int offset = jtc.getSelectionStart();
TokenSequence<JavaTokenId> ts = SourceUtils.getJavaTokenSequence(TokenHierarchy.get(doc), offset);
if (ts == null || !ts.moveNext() && !ts.movePrevious() || offset == ts.offset()) {
result[0] = false;
} else {
EnumSet tokenIds = EnumSet.of(first, rest);
result[0] = tokenIds.contains(ts.token().id());
}
}
});
return result[0];
}
示例4: parse
import javax.swing.text.Document; //导入方法依赖的package包/类
/**
* Converts to InputSource and pass it.
*/
protected TreeDocumentRoot parse(final Document doc) throws IOException, TreeException {
InputSource in = new InputSource();
// safely take the text from the document
//??? what about DocumentReader
final String[] str = new String[1];
Runnable run = new Runnable() {
public void run () {
try {
str[0] = doc.getText(0, doc.getLength());
} catch (javax.swing.text.BadLocationException e) {
// impossible
e.printStackTrace();
}
}
};
doc.render(run);
in.setCharacterStream(new StringReader(str[0]));
return parse(in);
}
示例5: TokenList
import javax.swing.text.Document; //导入方法依赖的package包/类
public TokenList(CompilationInfo info, final Document doc, AtomicBoolean cancel) {
this.info = info;
this.doc = doc;
this.cancel = cancel;
this.sourcePositions = info.getTrees().getSourcePositions();
doc.render(new Runnable() {
@Override
public void run() {
if (TokenList.this.cancel.get()) {
return ;
}
topLevel = TokenHierarchy.get(doc).tokenSequence();
topLevelIsJava = topLevel.language() == JavaTokenId.language();
if (topLevelIsJava) {
ts = topLevel;
ts.moveStart();
ts.moveNext(); //XXX: what about empty document
}
}
});
}
示例6: documentToString
import javax.swing.text.Document; //导入方法依赖的package包/类
/**
* @return current state of Document as string
*/
private static String documentToString(final Document doc) {
final String[] str = new String[1];
// safely take the text from the document
Runnable run = new Runnable() {
public void run () {
try {
str[0] = doc.getText(0, doc.getLength());
} catch (javax.swing.text.BadLocationException e) {
// impossible
Exceptions.printStackTrace(e);
}
}
};
doc.render(run);
return str[0];
}
示例7: runViewHierarchyTransaction
import javax.swing.text.Document; //导入方法依赖的package包/类
/**
* Execute the given runnable with view hierarchy being locked.
* This is necessary when exploring the view hierarchy by views' methods
* since the views changes may happen due to changes from highlighting layers
* that cause the views to be rebuilt.
* @param component non-null text component of which the view hierarchy is being explored.
* @param readLockDocument if true lock the document before locking the view hierarchy.
* This parameter should only be false if it's known that the document was already read/write-locked
* prior calling this method.
* @r non-null runnable to execute.
*/
public static void runViewHierarchyTransaction(final JTextComponent component,
boolean readLockDocument, final Runnable r)
{
Runnable wrapRun = new Runnable() {
@Override
public void run() {
View documentView = getDocumentView(component);
if (documentView != null) {
((DocumentView) documentView).runTransaction(r);
}
}
};
Document doc;
if (readLockDocument && (doc = component.getDocument()) != null) {
doc.render(wrapRun);
} else {
wrapRun.run();
}
}
示例8: previousCamelCasePosition
import javax.swing.text.Document; //导入方法依赖的package包/类
static int previousCamelCasePosition(CamelCaseInterceptor.MutableContext context) throws BadLocationException {
// get current caret position
final int offset = context.getOffset();
final Document doc = context.getDocument();
final int[] retOffset = new int[1];
final BadLocationException[] retExc = new BadLocationException[1];
doc.render(new Runnable() {
@Override
public void run() {
try {
retOffset[0] = previousCamelCasePositionImpl(doc, offset);
} catch (BadLocationException ex) {
retExc[0] = ex;
}
}
});
if (retExc[0] != null) {
throw retExc[0];
}
return retOffset[0];
}
示例9: getMimePath
import javax.swing.text.Document; //导入方法依赖的package包/类
static MimePath getMimePath(final Document doc, final int offset) {
final MimePath[] mimePathR = new MimePath[1];
doc.render(new Runnable() {
@Override
public void run() {
List<TokenSequence<?>> seqs = TokenHierarchy.get(doc).embeddedTokenSequences(offset, true);
TokenSequence<?> seq = seqs.isEmpty() ? null : seqs.get(seqs.size() - 1);
seq = seq == null ? TokenHierarchy.get(doc).tokenSequence() : seq;
mimePathR[0] = seq == null ? MimePath.parse(DocumentUtilities.getMimeType(doc)) : MimePath.parse(seq.languagePath().mimePath());
}
});
return mimePathR[0];
}
示例10: verifyDocument
import javax.swing.text.Document; //导入方法依赖的package包/类
private static boolean verifyDocument(final Document doc) {
if (doc == null) {
Logger.getLogger(SemanticHighlighterBase.class.getName()).log(Level.FINE, "SemanticHighlighter: Cannot get document!");
return false;
}
final boolean[] tokenSequenceNull = new boolean[1];
doc.render(new Runnable() {
@Override
public void run() {
tokenSequenceNull[0] = (TokenHierarchy.get(doc).tokenSequence() == null);
}
});
return !tokenSequenceNull[0];
}
示例11: canFilter
import javax.swing.text.Document; //导入方法依赖的package包/类
@Override
protected boolean canFilter(final JTextComponent component) {
final Collection<PaletteCompletionItem> currentItems = items;
if(currentItems == null) {
return false;
}
final Document doc = component.getDocument();
final AtomicBoolean retval = new AtomicBoolean();
doc.render(new Runnable() {
@Override
public void run() {
try {
int offset = component.getCaretPosition();
if (completionExpressionStartOffset < 0 || offset < completionExpressionStartOffset) {
retval.set(false);
return;
}
String prefix = doc.getText(completionExpressionStartOffset, offset - completionExpressionStartOffset);
//check the items
for (PaletteCompletionItem item : currentItems) {
if (startsWithIgnoreCase(item.getItemName(), prefix)) {
retval.set(true); //at least one item will remain
return;
}
}
} catch (BadLocationException ex) {
Exceptions.printStackTrace(ex);
}
}
});
return retval.get();
}
示例12: checkDependencyList
import javax.swing.text.Document; //导入方法依赖的package包/类
private void checkDependencyList(List<Dependency> deps, final POMModel model, List<ErrorDescription> toRet, Map<String, String> managed) {
if (deps != null) {
for (final Dependency dep : deps) {
String ver = dep.getVersion();
if (ver != null) {
String art = dep.getArtifactId();
String gr = dep.getGroupId();
String key = gr + ":" + art; //NOI18N
if (managed.keySet().contains(key)) {
final String managedver = managed.get(key);
Document doc = model.getBaseDocument();
final Line[] line = new Line[1];
doc.render(new Runnable() {
@Override
public void run() {
int position = dep.findChildElementPosition(model.getPOMQNames().VERSION.getQName());
line[0] = NbEditorUtilities.getLine(model.getBaseDocument(), position, false);
}
});
toRet.add(ErrorDescriptionFactory.createErrorDescription(
configuration.getSeverity(configuration.getPreferences()).toEditorSeverity(),
NbBundle.getMessage(OverrideDependencyManagementError.class, "TXT_OverrideDependencyManagementError", managedver),
Collections.<Fix>singletonList(new OverrideFix(dep)),
doc, line[0].getLineNumber() + 1));
}
}
}
}
}
示例13: findBodyStart
import javax.swing.text.Document; //导入方法依赖的package包/类
public static int findBodyStart(final CompilationInfo info, final Tree cltree, final CompilationUnitTree cu, final SourcePositions positions, final Document doc) {
Kind kind = cltree.getKind();
if (!TreeUtilities.CLASS_TREE_KINDS.contains(kind) && kind != Kind.METHOD)
throw new IllegalArgumentException("Unsupported kind: "+ kind);
final int[] result = new int[1];
doc.render(new Runnable() {
public void run() {
result[0] = findBodyStartImpl(info, cltree, cu, positions, doc);
}
});
return result[0];
}
示例14: call
import javax.swing.text.Document; //导入方法依赖的package包/类
public Boolean call() {
sharp = true;
final Document doc = component.getDocument();
doc.render(this);
return res;
}
示例15: invokeDefaultAction
import javax.swing.text.Document; //导入方法依赖的package包/类
boolean invokeDefaultAction(final JTextComponent comp) {
final Document doc = comp.getDocument();
if (doc instanceof BaseDocument) {
final int currentPosition = comp.getCaretPosition();
final Annotations annotations = ((BaseDocument) doc).getAnnotations();
final Map<String, List<ElementDescription>> caption2Descriptions = new LinkedHashMap<String, List<ElementDescription>>();
final Point[] p = new Point[1];
doc.render(new Runnable() {
public void run() {
try {
int line = Utilities.getLineOffset((BaseDocument) doc, currentPosition);
int startOffset = Utilities.getRowStartFromLineOffset((BaseDocument) doc, line);
p[0] = comp.modelToView(startOffset).getLocation();
AnnotationDesc desc = annotations.getActiveAnnotation(line);
if (desc == null) {
return ;
}
Collection<IsOverriddenAnnotation> annots;
if (COMBINED_TYPES.contains(desc.getAnnotationType())) {
annots = findAnnotations(comp, startOffset);
} else {
annots = Collections.singletonList(findAnnotation(comp, desc, startOffset));
}
for (IsOverriddenAnnotation a : annots) {
if (a != null) {
caption2Descriptions.put(computeCaption(a.getType(), a.getShortDescription()), a.getDeclarations());
}
}
} catch (BadLocationException ex) {
ErrorManager.getDefault().notify(ex);
}
}
});
if (caption2Descriptions.isEmpty())
return false;
JumpList.checkAddEntry(comp, currentPosition);
mouseClicked(caption2Descriptions, comp, p[0]);
return true;
}
return false;
}