@Override protected StyledDocument createStyledDocument(EditorKit kit) { StyledDocument doc = super.createStyledDocument(kit); //#174763 workaround - there isn't any elegant place where to place //a code which needs to be run after document's COMPLETE initialization. //DataEditorSupport.createStyledDocument() creates the document via the //EditorKit.createDefaultDocument(), but some of the important properties //like Document.StreamDescriptionProperty or mimetype are set as the //document properties later. //A hacky solution is that a Runnable can be set to the postInitRunnable property //in the EditorKit.createDefaultDocument() and the runnable is run //once the document is completely initialized. Runnable postInitRunnable = (Runnable)doc.getProperty("postInitRunnable"); //NOI18N if(postInitRunnable != null) { postInitRunnable.run(); } return doc; }
@Override protected StyledDocument createStyledDocument (EditorKit kit) { org.netbeans.api.lexer.Language lexerlanguage = language.getGsfLanguage().getLexerLanguage(); StyledDocument doc = super.createStyledDocument(kit); // Enter the file object in to InputAtrributes. It can be used by lexer. InputAttributes attributes = new InputAttributes(); FileObject fileObject = NbEditorUtilities.getFileObject(doc); attributes.setValue(lexerlanguage, FileObject.class, fileObject, false); doc.putProperty(InputAttributes.class, attributes); return doc; }