本文整理了Java中org.openide.cookies.EditorCookie.getDocument()
方法的一些代码示例,展示了EditorCookie.getDocument()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。EditorCookie.getDocument()
方法的具体详情如下:
包路径:org.openide.cookies.EditorCookie
类名称:EditorCookie
方法名:getDocument
[英]Get the document (but do not block).
Note that this does not involve opening the actual Editor window. For that, use #open.
[中]
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-gsf
private static StyledDocument getDocument (EditorCookie ec) {
return ec == null ? null : ec.getDocument();
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-web-core
public javax.swing.text.StyledDocument getDocument() {
return currentEditorCookie().getDocument();
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-cnd-modelimpl
private Document getDocument() {
Document document = docRef.get();
if (document != null) {
return document;
}
DataObject dataObject = getDataObject();
EditorCookie ec = dataObject == null ? null : dataObject.getLookup().lookup(EditorCookie.class);
if (ec == null) {
return null;
}
Document doc = ec.getDocument();
docRef = new WeakReference<>(doc);
return doc;
}
代码示例来源:origin: dcaoyuan/nbscala
public HighlightAnnotatable(AttributeSet attrs, int start, int end, FileObject fo) {
this.attrs = attrs;
this.start = start;
this.end = end;
try {
DataObject dobj = DataObject.find(fo);
EditorCookie ec = dobj.getCookie(EditorCookie.class);
doc = ec.getDocument();
} catch (DataObjectNotFoundException ex) {
}
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-visualweb-insync
/** This method returns a BaseDocument for the configuration file. If the configuration
* file is not opened, then the document is not created yet and this method push to load
* the document to the memory.
*/
public static BaseDocument getBaseDocument(DataObject dataObject){
BaseDocument document = null;
if (dataObject != null){
synchronized (dataObject){
EditorCookie editor = dataObject.getLookup().lookup(EditorCookie.class);
if (editor != null){
document = (BaseDocument)editor.getDocument();
if (document == null){
Task preparing = editor.prepareDocument();
preparing.waitFinished();
document = (BaseDocument)editor.getDocument();
}
}
}
}
return document;
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-web-jsf
/** This method returns a BaseDocument for the configuration file. If the configuration
* file is not opened, then the document is not created yet and this method push to load
* the document to the memory.
*/
public static BaseDocument getBaseDocument(DataObject dataObject){
BaseDocument document = null;
if (dataObject != null){
synchronized (dataObject){
EditorCookie editor = dataObject.getLookup().lookup(EditorCookie.class);
if (editor != null){
document = (BaseDocument)editor.getDocument();
if (document == null){
Task preparing = editor.prepareDocument();
preparing.waitFinished();
document = (BaseDocument)editor.getDocument();
}
}
}
}
return document;
}
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-cnd-editor
private void checkClosed(Object o){
if (o instanceof Set<?>) {
Set<EditorCookie> editorCookies = new HashSet<EditorCookie>();
for(Object top : (Set<?>) o){
if (top instanceof EditorCookie){
EditorCookie cookie = (EditorCookie) top;
if (MIMENames.isFortranOrHeaderOrCppOrC(
DocumentUtilities.getMimeType(cookie.getDocument()))) {
editorCookies.add(cookie);
}
}
}
checkClosed(editorCookies);
}
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-cnd-toolchain-ui
@Override
public void outputLineCleared(OutputEvent ev) {
try {
DataObject dob = DataObject.find(file);
StyledDocument doc = null;
if (dob.isValid()) {
EditorCookie ec = dob.getLookup().lookup(EditorCookie.class);
if (ec != null) {
doc = ec.getDocument();
}
}
if (doc != null) {
HintsController.setErrors(doc, CC_compiler_errors, Collections.<ErrorDescription>emptyList());
}
} catch (DataObjectNotFoundException ex) {
}
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-cnd-toolchain
@Override
public void outputLineCleared(OutputEvent ev) {
try {
DataObject dob = DataObject.find(file);
StyledDocument doc = null;
if (dob.isValid()) {
EditorCookie ec = dob.getLookup().lookup(EditorCookie.class);
if (ec != null) {
doc = ec.getDocument();
}
}
if (doc != null) {
HintsController.setErrors(doc, CC_compiler_errors, Collections.<ErrorDescription>emptyList());
}
} catch (DataObjectNotFoundException ex) {
}
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-debugger-jpda-projects
public HighlightAnnotatable(AttributeSet attrs, int start, int end, FileObject fo) {
this.attrs = attrs;
this.start = start;
this.end = end;
try {
DataObject dobj = DataObject.find(fo);
EditorCookie ec = dobj.getLookup().lookup(EditorCookie.class);
if (ec != null) {
doc = ec.getDocument();
if (doc == null) {
try {
doc = ec.openDocument();
} catch (java.io.IOException ioex) {}
}
}
} catch (DataObjectNotFoundException ex) {
}
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-debugger-jpda-projectsui
public HighlightAnnotatable(AttributeSet attrs, int start, int end, FileObject fo) {
this.attrs = attrs;
this.start = start;
this.end = end;
try {
DataObject dobj = DataObject.find(fo);
EditorCookie ec = dobj.getLookup().lookup(EditorCookie.class);
if (ec != null) {
doc = ec.getDocument();
if (doc == null) {
try {
doc = ec.openDocument();
} catch (java.io.IOException ioex) {}
}
}
} catch (DataObjectNotFoundException ex) {
}
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-cnd-modelutil
public static Document getDocument(FileObject fo) {
if (fo != null && fo.isValid()) {
try {
DataObject dob = DataObject.find(fo);
if (dob != null && dob.isValid()) {
EditorCookie ec = dob.getLookup().lookup(EditorCookie.class);
if (ec != null) {
return ec.getDocument();
}
}
} catch (IOException ex) {
// file can be removed or became invalid
// we catch IOException, because FileStateInvalidException is IOException
// but is not declared to be thrown from DataObject.find
if (fo.isValid() && !fo.isVirtual()) {
Exceptions.printStackTrace(ex);
}
}
}
return null;
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-cnd-modelimpl
private static FileBuffer createFileBuffer(DataObject dao) {
FileObject fo = dao.getPrimaryFile();
if (fo.isValid()) {
if (dao.isModified()) {
EditorCookie editor = dao.getLookup().lookup(EditorCookie.class);
if (editor != null) {
Document doc = editor.getDocument();
if (doc != null) {
return new FileBufferDoc(fo, doc);
}
}
}
}
return new FileBufferFile(fo);
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-cnd-highlight
@Override
protected PhaseRunner createTask(final FileObject fo) {
PhaseRunner pr = null;
try {
DataObject dobj = DataObject.find(fo);
EditorCookie ec = dobj.getCookie(EditorCookie.class);
Document doc = ec.getDocument();
if (doc != null) {
pr = new SemanticHighlighter(doc);
}
} catch (DataObjectNotFoundException ex) {
ex.printStackTrace();
}
return pr != null ? pr : lazyRunner();
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-tomcat5
public static void updateDocument(DataObject dobj, org.w3c.dom.Document doc)
throws javax.swing.text.BadLocationException, java.io.IOException {
org.openide.cookies.EditorCookie editor = (EditorCookie)dobj.getCookie(EditorCookie.class);
javax.swing.text.Document textDoc = editor.getDocument();
if (textDoc == null) {
textDoc = editor.openDocument();
}
TomcatInstallUtil.updateDocument(textDoc,TomcatInstallUtil.getDocumentText(doc),"<Server"); //NOI18N
SaveCookie savec = (SaveCookie) dobj.getCookie(SaveCookie.class);
if (savec!=null) savec.save();
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-cnd-highlight
@Override
protected PhaseRunner createTask(FileObject fo) {
PhaseRunner pr = null;
try {
final DataObject dobj = DataObject.find(fo);
EditorCookie ec = dobj.getCookie(EditorCookie.class);
final CsmFile file = CsmUtilities.getCsmFile(dobj, false, false);
final Document doc = ec.getDocument();
if (doc != null && file != null) {
pr = new PhaseRunnerImpl(dobj, file, doc);
}
} catch (DataObjectNotFoundException ex) {
ex.printStackTrace();
}
return pr != null ? pr : lazyRunner();
}
代码示例来源:origin: dcaoyuan/nbscala
private static int findNumLines(String url) {
FileObject file;
try {
file = URLMapper.findFileObject (new URL(url));
} catch (MalformedURLException e) {
return 0;
}
if (file == null) return 0;
DataObject dataObject;
try {
dataObject = DataObject.find (file);
} catch (DataObjectNotFoundException ex) {
return 0;
}
EditorCookie ec = (EditorCookie) dataObject.getCookie(EditorCookie.class);
if (ec == null) return 0;
ec.prepareDocument().waitFinished();
Document d = ec.getDocument();
if (!(d instanceof StyledDocument)) return 0;
StyledDocument sd = (StyledDocument) d;
return NbDocument.findLineNumber(sd, sd.getLength());
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-cnd-highlight
/*package*/ static void navigateToOccurrence(boolean next) {
final Node[] activatedNodes = TopComponent.getRegistry().getActivatedNodes();
// check whether current file is C/C++
DataObject dobj = activatedNodes[0].getLookup().lookup(DataObject.class);
FileObject fo = (dobj == null) ? null : dobj.getPrimaryFile();
String mime = (fo == null) ? "" : fo.getMIMEType();
if (MIMENames.isHeaderOrCppOrC(mime)) {
EditorCookie ec = dobj.getLookup().lookup(EditorCookie.class);
Document doc = ec.getDocument();
int position = CaretAwareCsmFileTaskFactory.getLastPosition(dobj.getPrimaryFile());
int goTo = findOccurrencePosition(next, doc, position);
if (goTo > 0) {
JEditorPane pane = NbDocument.findRecentEditorPane(ec);
pane.setCaretPosition(goTo);
} else {
StatusDisplayer.getDefault().setStatusText(NbBundle.getMessage(SemanticUtils.class, "cpp-no-marked-occurrence"));
}
}
}
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-cnd-debugger-common2
public static Line getCurrentLine() {
EditorCookie e = getCurrentEditorCookie();
if (e == null)
return null;
JEditorPane ep = getCurrentEditor(e);
if (ep == null)
return null;
StyledDocument d = e.getDocument();
if (d == null)
return null;
int lineNo = NbDocument.findLineNumber(d, ep.getCaret().getDot());
// Editor numbers lines from 0!
Line l = null;
try {
l = e.getLineSet().getCurrent(lineNo + 1);
} catch (IndexOutOfBoundsException x) {
// 6494346
}
return l;
}
代码示例来源:origin: org.netbeans.api/org-netbeans-modules-languages
private ASTNode getCurrentRootNode () {
Node[] ns = TopComponent.getRegistry ().getActivatedNodes ();
if (ns.length != 1) return null;
EditorCookie editorCookie = ns [0].getLookup ().
lookup (EditorCookie.class);
if (editorCookie == null) return null;
if (editorCookie.getOpenedPanes () == null) return null;
if (editorCookie.getOpenedPanes ().length < 1) return null;
JEditorPane pane = editorCookie.getOpenedPanes () [0];
if (caretListener == null)
caretListener = new CListener ();
if (lastPane != null && lastPane != pane) {
lastPane.removeCaretListener (caretListener);
lastPane = null;
}
if (lastPane == null) {
pane.addCaretListener (caretListener);
lastPane = pane;
}
Document document = editorCookie.getDocument ();
if (document == null || !(document instanceof NbEditorDocument)) return null;
return ParserManagerImpl.getImpl (document).getAST ();
}
内容来源于网络,如有侵权,请联系作者删除!