/** * Invokes <code>preferenceChanged</code> on the event displatching thread. */ private void safePreferenceChanged() { if (SwingUtilities.isEventDispatchThread()) { Document doc = getDocument(); if (doc instanceof AbstractDocument) { ((AbstractDocument) doc).readLock(); } preferenceChanged(null, true, true); if (doc instanceof AbstractDocument) { ((AbstractDocument) doc).readUnlock(); } } else { SwingUtilities.invokeLater(new Runnable() { public void run() { safePreferenceChanged(); } }); } }
static void refreshHack () { Iterator<Document> it = managers.keySet ().iterator (); while (it.hasNext ()) { AbstractDocument document = (AbstractDocument) it.next (); document.readLock (); try { MutableTextInput mti = (MutableTextInput) document.getProperty (MutableTextInput.class); mti.tokenHierarchyControl ().rebuild (); } finally { document.readUnlock (); } // final StyledDocument document = (StyledDocument) it.next (); // NbDocument.runAtomic (document, new Runnable () { // public void run() { // MutableTextInput mti = (MutableTextInput) document.getProperty (MutableTextInput.class); // mti.tokenHierarchyControl ().rebuild (); // } // }); } }
((AbstractDocument) context.getDocument()).readUnlock();
private static boolean isPreprocessorConditionalBlock(AbstractDocument doc, int offset) { if (doc == null) { return false; } doc.readLock(); try { TokenSequence<TokenId> ts = cppTokenSequence(doc, offset, false); if (ts != null) { int[] span = getPreprocConditionalOffsets(ts); if (isIn(span, offset)) { return true; } } } finally { doc.readUnlock(); } return false; }
/** * method should be called under document read lock * @param doc * @param offset * @return */ public static boolean isInPreprocessorDirective(Document doc, int offset) { AbstractDocument aDoc = (AbstractDocument)doc; aDoc.readLock(); try { TokenSequence<TokenId> cppTokenSequence = CndLexerUtilities.getCppTokenSequenceWithoutEmbeddings(doc, offset); if (cppTokenSequence != null) { return cppTokenSequence.token().id() == CppTokenId.PREPROCESSOR_DIRECTIVE; } } finally { aDoc.readUnlock(); } return false; }
/** * method should be called under document read lock * @param doc * @param offset * @return */ public static boolean isInProCDirective(Document doc, int offset) { AbstractDocument aDoc = (AbstractDocument)doc; aDoc.readLock(); try { TokenSequence<TokenId> cppTokenSequence = CndLexerUtilities.getCppTokenSequenceWithoutEmbeddings(doc, offset); if (cppTokenSequence != null) { return cppTokenSequence.token().id() == CppTokenId.PROC_DIRECTIVE; } } finally { aDoc.readUnlock(); } return false; }
public void run() { AbstractDocument doc = getCurrentDocument (); TokenSequence ts = null; if (doc != null) try { doc.readLock (); TokenHierarchy tokenHierarchy = TokenHierarchy.get (doc); if (tokenHierarchy == null) return; ts = tokenHierarchy.tokenSequence (); } finally { doc.readUnlock (); } if (ts == null) tree.setModel (new DefaultTreeModel (new DefaultMutableTreeNode ())); else tree.setModel (new DefaultTreeModel (new TSNode (null, ts, null, 0, 0))); JEditorPane editor = getCurrentEditor (); if (editor != null) { int position = getCurrentEditor ().getCaret ().getDot (); selectPath (position); } } });
} finally { if (doc instanceof AbstractDocument) { ((AbstractDocument) doc).readUnlock();
} finally { if (doc instanceof AbstractDocument) { ((AbstractDocument) doc).readUnlock();
public void propertyChange(java.beans.PropertyChangeEvent evt) { JTextComponent component = (JTextComponent)getContainer(); if (component==null || evt==null || !EditorUI.LINE_HEIGHT_CHANGED_PROP.equals(evt.getPropertyName())) return; AbstractDocument doc = (AbstractDocument)getDocument(); if (doc!=null) { doc.readLock(); try{ LockView lockView = LockView.get(this); lockView.lock(); try { rebuild(0, getViewCount()); } finally { lockView.unlock(); } } finally { doc.readUnlock(); } component.revalidate(); } }
public void actionPerformed(ActionEvent evt) { AbstractDocument doc = (AbstractDocument)getDocument(); if (doc!=null) { doc.readLock(); try { LockView lockView = LockView.get(DrawEngineDocView.this); if (lockView != null) { // if there is no lock view no async layout is done lockView.lock(); try { setEstimatedSpan(false); } finally { lockView.unlock(); } } } finally { doc.readUnlock(); } } } });
public Object evaluate (Context context) { if (context instanceof SyntaxContext) { Object l = ((SyntaxContext) context).getASTPath ().getLeaf (); if (l instanceof ASTNode) return evaluate ((ASTNode) l); if (l instanceof ASTToken) return evaluate ((ASTToken) l); } else { AbstractDocument document = (AbstractDocument) context.getDocument (); document.readLock (); ASTToken stoken = null; try { TokenSequence tokenSequence = Utils.getTokenSequence (document, context.getOffset ()); Token token = tokenSequence.token (); if (token != null) stoken = ASTToken.create ( null, token.id ().ordinal (), token.text ().toString (), tokenSequence.offset () ); } finally { document.readUnlock (); } return evaluate (stoken); } throw new IllegalArgumentException (); }
((AbstractDocument) context.getDocument()).readUnlock();
((AbstractDocument) context.getDocument()).readUnlock();
public void run() { AbstractDocument doc = (AbstractDocument)getDocument(); if (doc!=null){ doc.readLock(); try { LockView lockView = LockView.get(GapDocumentView.this); if (lockView != null) { lockView.lock(); try { layoutLock(); try { updateView(lockView); } finally { updateLayout(); layoutUnlock(); } } finally { lockView.unlock(); } } // missing lock view => likely disconnected from hierarchy } finally { doc.readUnlock(); } } }
public int [] findMatches() throws InterruptedException, BadLocationException { ((AbstractDocument) context.getDocument()).readLock(); try { BaseDocument doc = (BaseDocument) context.getDocument(); int offset = context.getSearchOffset(); char[] origin = doc.getChars(offset, 1); if (isRhtmlStartTag(doc, offset, origin)) { int limit = doc.getText().length(); int matching = matchChar(doc, offset, limit, '>'); while (matching != -1 && doc.getChars(matching - 1, 1)[0] == '=') { matching = matchChar(doc, matching + 1, limit, '>'); } return new int[] {matching, matching + 1}; } else if (isRhtmlEndTag(doc, offset, origin)) { int limit = 0; int matching = matchChar(doc, offset, limit, '<'); if (matching != -1) { return new int[] {matching, matching + 1}; } } } finally { ((AbstractDocument) context.getDocument()).readUnlock(); } return delegate.findMatches(); }
((AbstractDocument) context.getDocument()).readUnlock();