private Object getLock() { return support.getLock(); }
private Object getLock() { return support.getLock(); }
private Object getLock() { return support.getLock(); }
/** Get the document associated with this cookie. * It is an instance of Swing's {@link StyledDocument} but it should * also understand the NetBeans {@link NbDocument#GUARDED} to * prevent certain lines from being edited by the user. * <P> * If the document is not loaded the method blocks until * it is. * * @return the styled document for this cookie that * understands the guarded attribute * @exception IOException if the document could not be loaded */ public StyledDocument openDocument () throws IOException { synchronized (getLock()) { return openDocumentCheckIOE(); } }
/** Get the document associated with this cookie. * It is an instance of Swing's {@link StyledDocument} but it should * also understand the NetBeans {@link NbDocument#GUARDED} to * prevent certain lines from being edited by the user. * <P> * If the document is not loaded the method blocks until * it is. * * @return the styled document for this cookie that * understands the guarded attribute * @exception IOException if the document could not be loaded */ public StyledDocument openDocument () throws IOException { synchronized (getLock()) { return openDocumentCheckIOE(); } }
/** Clears all data from memory. */ private void closeDocument () { synchronized (getLock()) { while (true) { switch (documentStatus) { case DOCUMENT_NO: return; case DOCUMENT_LOADING: case DOCUMENT_RELOADING: // let it flow to default: // openDocumentImpl(); // break; // try to close again default: doCloseDocument(); return; } } } }
/** Clears all data from memory. */ private void closeDocument () { synchronized (getLock()) { while (true) { switch (documentStatus) { case DOCUMENT_NO: return; case DOCUMENT_LOADING: case DOCUMENT_RELOADING: // let it flow to default: // openDocumentImpl(); // break; // try to close again default: doCloseDocument(); return; } } } }
@Override public void run() { synchronized (getLock()) { switch (documentStatus) { case DOCUMENT_NO: break; case DOCUMENT_LOADING: case DOCUMENT_RELOADING: // let it flow to default: // openDocumentImpl(); // break; // try to close again default: Document currentDoc = getDoc(); if (currentDoc == doc) { fireEvent[0] = doCloseDocument(); } // else: probably best is to ignore the close request in such situation break; } } } });
/** Load the document into memory. This is done * in different thread. A task for the thread is returned * so anyone may test whether the loading has been finished * or is still in process. * * @return task for control over loading */ public Task prepareDocument() { synchronized (getLock()) { switch (documentStatus) { case DOCUMENT_NO: documentStatus = DOCUMENT_LOADING; return prepareDocument(false); default: if (prepareTask == null) { // should never happen throw new IllegalStateException(); } return prepareTask; } } }
/** Load the document into memory. This is done * in different thread. A task for the thread is returned * so anyone may test whether the loading has been finished * or is still in process. * * @return task for control over loading */ public Task prepareDocument() { synchronized (getLock()) { switch (documentStatus) { case DOCUMENT_NO: documentStatus = DOCUMENT_LOADING; return prepareDocument(false); default: if (prepareTask == null) { // should never happen throw new IllegalStateException(); } return prepareTask; } } }
/** Get the document. This method may be called before the document initialization * (<code>prepareTask</code>) * has been completed, in such a case the document must not be modified. * @return document or <code>null</code> if it is not yet loaded */ public StyledDocument getDocument () { synchronized (getLock()) { while (true) { switch (documentStatus) { case DOCUMENT_NO: return null; default: // ready, loading or reloading // XXX #16048. In case there is called this method from loadTask // (possible only via LineListener->DocumentLine..). // PENDING Needs to be tried to redesign DocumentLine to avoid this. if (LOCAL_LOAD_TASK.get() != null) { return doc; } try { return openDocumentCheckIOE(); } catch (IOException e) { return null; } } } } }
/** Get the document. This method may be called before the document initialization * (<code>prepareTask</code>) * has been completed, in such a case the document must not be modified. * @return document or <code>null</code> if it is not yet loaded */ public StyledDocument getDocument () { synchronized (getLock()) { while (true) { switch (documentStatus) { case DOCUMENT_NO: return null; default: // ready, loading or reloading // XXX #16048. In case there is called this method from loadTask // (possible only via LineListener->DocumentLine..). // PENDING Needs to be tried to redesign DocumentLine to avoid this. if (LOCAL_LOAD_TASK.get() != null) { return doc; } try { return openDocumentCheckIOE(); } catch (IOException e) { return null; } } } } }
/** Updates the line set. * @param clear clear any cached set? * @return the set */ Line.Set updateLineSet (boolean clear) { synchronized(getLock()) { if(lineSet != null && !clear) { return lineSet; } Line.Set oldSet = lineSet; if (doc == null || documentStatus == DOCUMENT_RELOADING) { lineSet = new EditorSupportLineSet.Closed(CloneableEditorSupport.this); } else { lineSet = new EditorSupportLineSet(CloneableEditorSupport.this, doc); } return lineSet; } }
/** Updates the line set. * @param clear clear any cached set? * @return the set */ Line.Set updateLineSet (boolean clear) { synchronized(getLock()) { if(lineSet != null && !clear) { return lineSet; } Line.Set oldSet = lineSet; if (doc == null || documentStatus == DOCUMENT_RELOADING) { lineSet = new EditorSupportLineSet.Closed(CloneableEditorSupport.this); } else { lineSet = new EditorSupportLineSet(CloneableEditorSupport.this, doc); } return lineSet; } }
getLock().wait(); } catch (InterruptedException e) { throw (InterruptedIOException)new InterruptedIOException().initCause(e);
getLock().wait(); } catch (InterruptedException e) { throw (InterruptedIOException) new InterruptedIOException().initCause(e);
/** Updates the line set. * @param clear clear any cached set? * @return the set */ Line.Set updateLineSet(boolean clear) { synchronized (getLock()) { if ((lineSet != null) && !clear) { return lineSet; } Line.Set oldSet = lineSet; if ((getDoc() == null) || (documentStatus == DOCUMENT_RELOADING)) { lineSet = new EditorSupportLineSet.Closed(CloneableEditorSupport.this); } else { lineSet = new EditorSupportLineSet(CloneableEditorSupport.this,getDoc()); } return lineSet; } }
public void run() { synchronized (editor.getLock()) { /* editor.getLock(): fixes deadlock - this lock is acquired later anyhow, so we are changing the order in which the locks are acquired */ try { // [MaM] remember doclen to compute new length // of the inserted string (the length changes // because insertString removes \r characters // from it) int docLen = doc.getLength(); int p1 = end.getOffset(); doc.insertString(p1, text, null); int p2 = (p1 + doc.getLength()) - docLen; end = editor.createPositionRef(p1, end.getPositionBias()); PositionRef posBegin = editor.createPositionRef(p1, Position.Bias.Forward); PositionRef posEnd = editor.createPositionRef(p2, Position.Bias.Backward); hold[1] = new PositionBounds(posBegin, posEnd); } catch (BadLocationException e) { hold[0] = e; } } } };
public void run() { synchronized (editor.getLock()) { /* editor.getLock(): fixes deadlock - this lock is acquired later anyhow, so we are changing the order in which the locks are acquired */ try { // [MaM] remember doclen to compute new length // of the inserted string (the length changes // because insertString removes \r characters // from it) int docLen = doc.getLength(); int p1 = end.getOffset(); doc.insertString (p1, text, null); int p2 = p1 + doc.getLength() - docLen; end = editor.createPositionRef(p1, end.getPositionBias()); PositionRef posBegin = editor.createPositionRef(p1, Position.Bias.Forward); PositionRef posEnd = editor.createPositionRef(p2, Position.Bias.Backward); hold[1] = new PositionBounds(posBegin, posEnd); } catch (BadLocationException e) { hold[0] = e; } } } };
public void run() { synchronized (editor.getLock()) { /* editor.getLock(): fixes deadlock - this lock is acquired later anyhow, so we are changing the order in which the locks are acquired */ try { // [MaM] remember doclen to compute new length // of the inserted string (the length changes // because insertString removes \r characters // from it) int docLen = doc.getLength(); int p1 = end.getOffset(); doc.insertString (p1, text, null); int p2 = p1 + doc.getLength() - docLen; end = editor.createPositionRef(p1, end.getPositionBias()); PositionRef posBegin = editor.createPositionRef(p1, Position.Bias.Forward); PositionRef posEnd = editor.createPositionRef(p2, Position.Bias.Backward); hold[1] = new PositionBounds(posBegin, posEnd); } catch (BadLocationException e) { hold[0] = e; } } } };