Skip to content

Instantly share code, notes, and snippets.

@sharwell
Last active December 12, 2015 04:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sharwell/4716408 to your computer and use it in GitHub Desktop.
Save sharwell/4716408 to your computer and use it in GitHub Desktop.
NetBeans API: Create and open a temporary in-memory file with explicit non-serialized semantic data.
FileSystem fileSystem = FileUtil.createMemoryFileSystem();
// Store the actual text that will be displayed to the memory file system
FileObject tempFileObject = FileUtil.copyFile(FileUtil.toFileObject(inputFile), fileSystem.getRoot(), inputFile.getName(), "linterp");
DataObject od = DataObject.find(tempFileObject);
EditorCookie ec = od.getLookup().lookup(EditorCookie.class);
Document opened = ec.openDocument();
if (opened != null) {
// here I add the additional data as a property to the Document without needing to serialize it
opened.putProperty(LexerDebuggerEditorKit.PROP_INTERP_DATA, lexerInterpreterData);
final OpenCookie oc = od.getLookup().lookup(OpenCookie.class);
if (oc != null) {
if (SwingUtilities.isEventDispatchThread()) {
oc.open();
} else {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
oc.open();
}
});
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment