當前位置: 首頁>>代碼示例>>Java>>正文


Java AbstractDocument類代碼示例

本文整理匯總了Java中javax.swing.text.AbstractDocument的典型用法代碼示例。如果您正苦於以下問題:Java AbstractDocument類的具體用法?Java AbstractDocument怎麽用?Java AbstractDocument使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


AbstractDocument類屬於javax.swing.text包,在下文中一共展示了AbstractDocument類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: run

import javax.swing.text.AbstractDocument; //導入依賴的package包/類
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();
        }
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:26,代碼來源:GapDocumentView.java

示例2: commentDoc

import javax.swing.text.AbstractDocument; //導入依賴的package包/類
private Document commentDoc() throws BadLocationException {
    Document doc = new ModificationTextDocument();
    // Assign a language to the document
    String text = "/**abc*/";
    doc.insertString(0, text, null);
    
    doc.putProperty(Language.class,TestTokenId.language());
    TokenHierarchy<?> hi = TokenHierarchy.get(doc);
    
    ((AbstractDocument)doc).readLock();
    try {
        TokenSequence<?> ts = hi.tokenSequence();
        assertTrue(ts.moveNext());
        assertNotNull(ts.embedded());
        return doc;
    } finally {
        ((AbstractDocument)doc).readUnlock();
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:20,代碼來源:TokenListUpdaterExtraTest.java

示例3: modelToView

import javax.swing.text.AbstractDocument; //導入依賴的package包/類
static Rectangle2D modelToView(JTextComponent tc, int pos, Position.Bias bias) throws BadLocationException {
Document doc = tc.getDocument();
if (doc instanceof AbstractDocument) {
    ((AbstractDocument)doc).readLock();
}
try {
    Rectangle alloc = getVisibleEditorRect(tc);
    if (alloc != null) {
               View rootView = tc.getUI().getRootView(tc);
	rootView.setSize(alloc.width, alloc.height);
	Shape s = rootView.modelToView(pos, alloc, bias);
	if (s != null) {
	  return s.getBounds2D();
	}
    }
} finally {
    if (doc instanceof AbstractDocument) {
	((AbstractDocument)doc).readUnlock();
    }
}
return null;
   }
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:23,代碼來源:Utilities.java

示例4: viewToModel

import javax.swing.text.AbstractDocument; //導入依賴的package包/類
static int viewToModel(JTextComponent tc, double x, double y, Position.Bias[] biasReturn) {
int offs = -1;
Document doc = tc.getDocument();
if (doc instanceof AbstractDocument) {
    ((AbstractDocument)doc).readLock();
}
try {
    Rectangle alloc = getVisibleEditorRect(tc);
    if (alloc != null) {
               View rootView = tc.getUI().getRootView(tc);
               View documentView = rootView.getView(0);
               if (documentView instanceof EditorView) {
                   documentView.setSize(alloc.width, alloc.height);
                   offs = ((EditorView) documentView).viewToModelChecked(x, y, alloc, biasReturn);
               } else {
                   rootView.setSize(alloc.width, alloc.height);
                   offs = rootView.viewToModel((float) x, (float) y, alloc, biasReturn);
               }
    }
} finally {
    if (doc instanceof AbstractDocument) {
	((AbstractDocument)doc).readUnlock();
    }
}
       return offs;
   }
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:27,代碼來源:Utilities.java

示例5: getNamespaceInsertionOffset

import javax.swing.text.AbstractDocument; //導入依賴的package包/類
/**
 * Finds the namespace insertion offset in the xml document.
 */
public static int getNamespaceInsertionOffset(Document document) {
    int offset = 0;
    ((AbstractDocument)document).readLock();
    try {
        TokenHierarchy th = TokenHierarchy.get(document);
        TokenSequence ts = th.tokenSequence();
        while(ts.moveNext()) {
            Token nextToken = ts.token();
            if(nextToken.id() == XMLTokenId.TAG && nextToken.text().toString().equals(">")) {
               offset = nextToken.offset(th);
               break;
            }
        }
    } finally {
        ((AbstractDocument)document).readUnlock();
    }
    
    return offset;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:23,代碼來源:CompletionUtil.java

示例6: create

import javax.swing.text.AbstractDocument; //導入依賴的package包/類
public View create(Element elem) {
    String kind = elem.getName();
    if (kind != null) {
        if (kind.equals(AbstractDocument.ContentElementName)) {
            return new LabelView(elem);
        } else if (kind.equals(AbstractDocument.ParagraphElementName)) {
            return null;
        } else if (kind.equals(AbstractDocument.SectionElementName)) {
            return new DocumentView(elem);
        } else if (kind.equals(StyleConstants.ComponentElementName)) {
            return new ComponentView(elem);
        } else if (kind.equals(StyleConstants.IconElementName)) {
            return new IconView(elem);
        }
    }
    return null;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:18,代碼來源:ViewFactoryImpl.java

示例7: requestUpdateAllCaretsBounds

import javax.swing.text.AbstractDocument; //導入依賴的package包/類
/**
 * Schedule recomputation of visual bounds of all carets.
 */
private void requestUpdateAllCaretsBounds() {
    JTextComponent c = component;
    AbstractDocument doc;
    if (c != null && (doc = activeDoc) != null) {
        doc.readLock();
        try {
            List<CaretInfo> sortedCarets = getSortedCarets();
            for (CaretInfo caret : sortedCarets) {
                caret.getCaretItem().markUpdateCaretBounds();
            }
        } finally {
            doc.readUnlock();
        }
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:19,代碼來源:EditorCaret.java

示例8: replaceRange

import javax.swing.text.AbstractDocument; //導入依賴的package包/類
/**
 * Replaces text from the indicated start to end position with the
 * new text specified.  Does nothing if the model is null.  Simply
 * does a delete if the new string is null or empty.
 * <p>
 * This method is thread safe, although most Swing methods
 * are not.<p>
 * This method is overridden so that our Undo manager remembers it as a
 * single operation (it has trouble with this, especially for
 * <code>RSyntaxTextArea</code> and the "auto-indent" feature).
 *
 * @param str the text to use as the replacement
 * @param start the start position &gt;= 0
 * @param end the end position &gt;= start
 * @exception IllegalArgumentException  if part of the range is an
 *  invalid position in the model
 * @see #insert(String, int)
 * @see #replaceRange(String, int, int)
 */
@Override
public void replaceRange(String str, int start, int end) {
	if (end < start) {
		throw new IllegalArgumentException("end before start");
	}
	Document doc = getDocument();
	if (doc != null) {
		try {
			// Without this, in some cases we'll have to do two undos
			// for one logical operation (for example, try editing a
			// Java source file in an RSyntaxTextArea, and moving a line
			// with text already on it down via Enter.  Without this
			// line, doing a single "undo" moves all later text up,
			// but the first line moved down isn't there!  Doing a
			// second undo puts it back.
			undoManager.beginInternalAtomicEdit();
			((AbstractDocument)doc).replace(start, end - start,
                              		                     str, null);
		} catch (BadLocationException e) {
			throw new IllegalArgumentException(e.getMessage());
		} finally {
			undoManager.endInternalAtomicEdit();
		}
	}
   }
 
開發者ID:Thecarisma,項目名稱:powertext,代碼行數:45,代碼來源:RTextArea.java

示例9: refreshHack

import javax.swing.text.AbstractDocument; //導入依賴的package包/類
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 ();
//                }
//            });
        }
    }
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:21,代碼來源:ParserManagerImpl.java

示例10: refresh

import javax.swing.text.AbstractDocument; //導入依賴的package包/類
private void refresh () {
    SwingUtilities.invokeLater(new Runnable() {
        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);
            }
        }
    });
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:27,代碼來源:TokensBrowserTopComponent.java

示例11: findOrigin

import javax.swing.text.AbstractDocument; //導入依賴的package包/類
public int[] findOrigin() throws BadLocationException {
    ((AbstractDocument) context.getDocument()).readLock();
    try {
        int offset;

        if (context.isSearchingBackward()) {
            offset = context.getSearchOffset() - 1;
        } else {
            offset = context.getSearchOffset();
        }

        block = ess.findMatchingBlock(offset, false);
        if (block == null) {
            return null;
        } else if (block.length == 0) {
            return block;
        } else {
            return new int [] { offset, offset };
        }
    } finally {
        ((AbstractDocument) context.getDocument()).readUnlock();
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:24,代碼來源:LegacyEssMatcher.java

示例12: findOrigin

import javax.swing.text.AbstractDocument; //導入依賴的package包/類
public int [] findOrigin() throws BadLocationException {
    ((AbstractDocument) context.getDocument()).readLock();
    try {
        int result [] = BracesMatcherSupport.findChar(
            context.getDocument(),
            context.getSearchOffset(),
            context.isSearchingBackward() ?
                Math.max(context.getLimitOffset(), lowerBound) :
                Math.min(context.getLimitOffset(), upperBound),
            matchingPairs
        );

        if (result != null) {
            originOffset = result[0];
            originalChar = matchingPairs[result[1]];
            matchingChar = matchingPairs[result[1] + result[2]];
            backward = result[2] < 0;
            return new int [] { originOffset, originOffset + 1 };
        } else {
            return null;
        }
    } finally {
        ((AbstractDocument) context.getDocument()).readUnlock();
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:26,代碼來源:CharacterMatcher.java

示例13: findMatches

import javax.swing.text.AbstractDocument; //導入依賴的package包/類
public int [] findMatches() throws BadLocationException {
    ((AbstractDocument) context.getDocument()).readLock();
    try {
        int offset = BracesMatcherSupport.matchChar(
            context.getDocument(),
            backward ? originOffset : originOffset + 1,
            backward ?
                Math.max(0, lowerBound) :
                Math.min(context.getDocument().getLength(), upperBound),
            originalChar,
            matchingChar
        );

        return offset != -1 ? new int [] { offset, offset + 1 } : null;
    } finally {
        ((AbstractDocument) context.getDocument()).readUnlock();
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:19,代碼來源:CharacterMatcher.java

示例14: parse

import javax.swing.text.AbstractDocument; //導入依賴的package包/類
/**
     * Parses a XML document using XMLLexer and loops through all tokens.
     * @param document
     * @throws java.lang.Exception
     */
    protected void parse(javax.swing.text.Document document) throws Exception {
        ((AbstractDocument)document).readLock();
        try {
            TokenHierarchy th = TokenHierarchy.get(document);
            TokenSequence ts = th.tokenSequence();
            assert(true);
            while(ts.moveNext()) {
                Token token = ts.token();
                assert(token.id() != null);
                if(DEBUG) {
//                    System.out.println("Id :["+ token.id().name() +
//                            "] [Text :["+ token.text()+"]");
                }
            }
        } finally {
            ((AbstractDocument)document).readUnlock();
        }
    }
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:24,代碼來源:AbstractTestCase.java

示例15: assertTokenSequence

import javax.swing.text.AbstractDocument; //導入依賴的package包/類
/**
 * This test validates all tokens obtained by parsing test.xml against
 * an array of expected tokens.
 */
public void assertTokenSequence(javax.swing.text.Document document, TokenId[] expectedIds) throws Exception {
    ((AbstractDocument)document).readLock();
    try {
        TokenHierarchy th = TokenHierarchy.get(document);
        TokenSequence ts = th.tokenSequence();
        //assert(ts.tokenCount() == expectedIds.length);
        int index = 0;
        while(ts.moveNext()) {
            Token token = ts.token();
            if(DEBUG) {
                System.out.println("Id :["+ token.id().name() +
                        "] [Text :["+ token.text()+"]");
            }
            assert(token.id() == expectedIds[index]);
            index++;
        }
    } finally {
        ((AbstractDocument)document).readUnlock();
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:25,代碼來源:AbstractTestCase.java


注:本文中的javax.swing.text.AbstractDocument類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。