本文整理汇总了Java中org.openide.cookies.EditorCookie.getDocument方法的典型用法代码示例。如果您正苦于以下问题:Java EditorCookie.getDocument方法的具体用法?Java EditorCookie.getDocument怎么用?Java EditorCookie.getDocument使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.openide.cookies.EditorCookie
的用法示例。
在下文中一共展示了EditorCookie.getDocument方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getCurrentLineNumber
import org.openide.cookies.EditorCookie; //导入方法依赖的package包/类
/**
* Get the line number of the caret in the current editor.
* @return the line number or <code>-1</code> when there is no current editor.
*/
public int getCurrentLineNumber() {
EditorCookie e = getCurrentEditorCookie ();
if (e == null) return -1;
JEditorPane ep = getCurrentEditor ();
if (ep == null) return -1;
StyledDocument d = e.getDocument ();
if (d == null) return -1;
Caret caret = ep.getCaret ();
if (caret == null) return -1;
int ln = NbDocument.findLineNumber (
d,
caret.getDot ()
);
return ln + 1;
}
示例2: setUp
import org.openide.cookies.EditorCookie; //导入方法依赖的package包/类
@Before
public void setUp() throws Exception {
FileSystem fs = FileUtil.createMemoryFileSystem();
FileObject fo = fs.getRoot().createData("JFrame.java");
source = convertStreamToString(getClass().getResourceAsStream("resources/JFrame.txt"));
writeFile(source, fo);
DataObject sourceDataObject = DataObject.find(fo);
EditorCookie editorCookie = sourceDataObject.getCookie(EditorCookie.class);
if (editorCookie == null) {
throw new IllegalArgumentException("I18N: Illegal data object type"+ sourceDataObject); // NOI18N
}
StyledDocument document = editorCookie.getDocument();
while(document == null) {
document = editorCookie.openDocument();
}
instance = new JavaI18nFinder(document);
}
示例3: isDirty
import org.openide.cookies.EditorCookie; //导入方法依赖的package包/类
@Override
protected final Long isDirty() {
final FileObject file = getHandle().resolveFileObject(false);
if (file == null) {
return null;
}
final DataObject.Registry regs = DataObject.getRegistry();
final Set<DataObject> modified = regs.getModifiedSet();
for (DataObject dobj : modified) {
if (file.equals(dobj.getPrimaryFile())) {
final EditorCookie ec = dobj.getCookie(EditorCookie.class);
if (ec != null) {
final Document doc = ec.getDocument();
if (doc != null) {
return DocumentUtilities.getDocumentTimestamp(doc);
}
}
}
}
return null;
}
示例4: focused
import org.openide.cookies.EditorCookie; //导入方法依赖的package包/类
void focused(FileObject fo, JTextComponent target) {
Project project = FileOwnerQuery.getOwner(fo);
if (project != null) {
CoverageProvider provider = getProvider(project);
if (provider != null && provider.isEnabled()) {
try {
EditorCookie ec = DataLoadersBridge.getDefault().getCookie(fo, EditorCookie.class);
if (ec != null) {
Document doc = ec.getDocument();
if (doc == null) {
return;
}
doc.putProperty(COVERAGE_DOC_PROPERTY, null);
CoverageHighlightsContainer container = CoverageHighlightsLayerFactory.getContainer(target);
if (container != null) {
container.refresh();
}
}
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
}
}
}
}
示例5: getInstance
import org.openide.cookies.EditorCookie; //导入方法依赖的package包/类
public static synchronized AnnotationHolder getInstance(FileObject file) {
if (file == null)
return null;
try {
DataObject od = DataObject.find(file);
AnnotationHolder result = file2Holder.get(od);
if (result == null) {
EditorCookie editorCookie = od.getCookie(EditorCookie.class);
if (editorCookie == null) {
LOG.log(Level.WARNING,
"No EditorCookie.Observable for file: {0}", FileUtil.getFileDisplayName(file)); //NOI18N
} else {
Document doc = editorCookie.getDocument();
if (doc instanceof BaseDocument) {
file2Holder.put(od, result = new AnnotationHolder(file, od, (BaseDocument) doc));
}
}
}
return result;
} catch (IOException e) {
LOG.log(Level.FINE, null, e);
return null;
}
}
示例6: isOriginalDocumentLoaded
import org.openide.cookies.EditorCookie; //导入方法依赖的package包/类
private boolean isOriginalDocumentLoaded() {
try {
FileObject fo = element.getParentFile();
DataObject dObj = DataObject.find(fo);
EditorCookie ec = dObj != null ? dObj.getCookie(org.openide.cookies.EditorCookie.class) : null;
if (ec != null) {
StyledDocument doc = ec.getDocument();
return doc!=null;
}
} catch (DataObjectNotFoundException ex) {
//ignore;
}
return false;
}
示例7: getDocument
import org.openide.cookies.EditorCookie; //导入方法依赖的package包/类
@CheckForNull
private Document getDocument(FileObject fileObject) {
Document document = null;
try {
DataObject dataObject = DataObject.find(fileObject);
EditorCookie editorCookie = dataObject.getLookup().lookup(EditorCookie.class);
document = editorCookie.getDocument();
} catch (DataObjectNotFoundException ex) {
LOGGER.log(Level.WARNING, null, ex);
}
return document;
}
示例8: readDocument
import org.openide.cookies.EditorCookie; //导入方法依赖的package包/类
@Override
public Document readDocument(FileObject fileObject, boolean forceOpen) {
EditorCookie ec = null;
try {
DataObject dataObject = DataObject.find (fileObject);
ec = dataObject.getLookup ().lookup (EditorCookie.class);
} catch (DataObjectNotFoundException ex) {
//DataobjectNotFoundException may happen in case of deleting opened file
//handled by returning null
}
if (ec == null) return null;
Document doc = ec.getDocument ();
if (doc == null && forceOpen) {
try {
try {
doc = ec.openDocument ();
} catch (UserQuestionException uqe) {
uqe.confirmed ();
doc = ec.openDocument ();
}
} catch (IOException ioe) {
LOGGER.log (Level.WARNING, null, ioe);
}
}
return doc;
}
示例9: getDocument
import org.openide.cookies.EditorCookie; //导入方法依赖的package包/类
@Override
public StyledDocument getDocument(FileObject file) {
try {
DataObject d = DataObject.find(file);
EditorCookie ec = (EditorCookie) d.getCookie(EditorCookie.class);
if (ec == null) {
return null;
}
return ec.getDocument();
} catch (IOException e) {
LOG.log(Level.INFO, "SemanticHighlighter: Cannot find DataObject for file: " + FileUtil.getFileDisplayName(file), e); //NOI18N
return null;
}
}
示例10: getDocument
import org.openide.cookies.EditorCookie; //导入方法依赖的package包/类
public static @CheckForNull Document getDocument(@NonNull FileObject file) {
try {
DataObject od = DataObject.find(file);
EditorCookie ec = od.getLookup().lookup(EditorCookie.class);
if (ec == null) return null;
return ec.getDocument();
} catch (DataObjectNotFoundException ex) {
LOG.log(Level.FINE, null, ex);
return null;
}
}
示例11: resolveRoot
import org.openide.cookies.EditorCookie; //导入方法依赖的package包/类
public static void resolveRoot(final Lookup lookup, final boolean searchFromBase, final boolean isCallerGraph, final Task<Call> rootCallback) {
JavaSource js = null;
RootResolver resolver = null;
EditorCookie ec = lookup.lookup(EditorCookie.class);
if (ec != null/*RefactoringActionsProvider.isFromEditor(ec)*/) {
JEditorPane openedPane = NbDocument.findRecentEditorPane(ec);
Document doc = ec.getDocument();
js = JavaSource.forDocument(doc);
resolver = new RootResolver(openedPane.getCaretPosition(), isCallerGraph, searchFromBase);
}
// else {
// XXX resolve Node.class
// }
postResolveRoot(js, resolver, rootCallback);
}
示例12: assignDocListener
import org.openide.cookies.EditorCookie; //导入方法依赖的package包/类
private void assignDocListener(@NonNull final EditorCookie ec) {
if (currentDoc != null) {
currentDoc.removeDocumentListener(this);
}
currentDoc = ec.getDocument();
if (currentDoc != null) {
currentDoc.addDocumentListener(this);
}
}
示例13: perform
import org.openide.cookies.EditorCookie; //导入方法依赖的package包/类
public void perform(Node node) {
if (node == null) return;
EditorCookie editor = (EditorCookie) node.getCookie(EditorCookie.class);
if (editor == null) return;
Document doc = editor.getDocument();
if (doc == null) return;
GrammarManager cache = (GrammarManager)
doc.getProperty(XMLCompletionQuery.DOCUMENT_GRAMMAR_BINDING_PROP);
if (cache == null) return;
cache.invalidateGrammar();
}
示例14: fileForDataobject
import org.openide.cookies.EditorCookie; //导入方法依赖的package包/类
private FileObject fileForDataobject(Document doc, MultiDataObject dobj) {
for (MultiDataObject.Entry entry : dobj.secondaryEntries()) {
if (entry instanceof CookieSet.Factory) {
CookieSet.Factory factory = (CookieSet.Factory) entry;
EditorCookie ec = factory.createCookie(EditorCookie.class);
Document entryDocument = ec.getDocument();
if (entryDocument == doc) {
return entry.getFile();
}
}
}
return dobj.getPrimaryFile();
}
示例15: getDocument
import org.openide.cookies.EditorCookie; //导入方法依赖的package包/类
public Document getDocument() {
try {
DataObject d = DataObject.find(fileObject);
EditorCookie ec = d.getCookie(EditorCookie.class);
if (ec == null)
return null;
return ec.getDocument();
} catch (DataObjectNotFoundException donfe) {
fail();
}
return null;
}