当前位置: 首页>>代码示例>>Java>>正文


Java Document类代码示例

本文整理汇总了Java中javax.swing.text.Document的典型用法代码示例。如果您正苦于以下问题:Java Document类的具体用法?Java Document怎么用?Java Document使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Document类属于javax.swing.text包,在下文中一共展示了Document类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: insideToken

import javax.swing.text.Document; //导入依赖的package包/类
private boolean insideToken(final JTextComponent jtc, final JavaTokenId first, final JavaTokenId... rest) {
    final Document doc = jtc.getDocument();
    final boolean[] result = new boolean[1];
    
    doc.render(new Runnable() {
        @Override public void run() {
            int offset = jtc.getSelectionStart();
            TokenSequence<JavaTokenId> ts = SourceUtils.getJavaTokenSequence(TokenHierarchy.get(doc), offset);
            if (ts == null || !ts.moveNext() && !ts.movePrevious() || offset == ts.offset()) {
                result[0] = false;
            } else {
                EnumSet tokenIds = EnumSet.of(first, rest);
                result[0] = tokenIds.contains(ts.token().id());
            }
        }
    });
    
    return result[0];
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:20,代码来源:ClipboardHandler.java

示例2: getDetails

import javax.swing.text.Document; //导入依赖的package包/类
public @Override FileCoverageDetails getDetails(final FileObject fo, final Document doc) {
    String path = srcPath().getResourceName(fo);
    if (path == null) {
        return null;
    }
    MavenDetails det = null;
    synchronized (this) {
        MavenSummary summ = summaryCache != null ? summaryCache.get(path) : null;
        if (summ != null) {
            det = summ.getDetails();
            //we have to set the linecount here, as the entire line span is not apparent from the parsed xml, giving strange results then.
            det.lineCount = doc.getDefaultRootElement().getElementCount();
        }
    }
    return det;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:MavenCoverageProvider.java

示例3: targetOffsetReached

import javax.swing.text.Document; //导入依赖的package包/类
public @Override boolean targetOffsetReached(int offset, char ch, int x, int charWidth, DrawContext ctx) {
    if (offset <= eolOffset) {
        if (x + charWidth < targetX) {
            this.offset = offset;
            return true;
        } else { // target position inside the char
            this.offset = offset;
            if (targetX > x + charWidth / 2) {
                Document doc = getDocument();
                if (ch != '\n' && doc != null && offset < doc.getLength()) { //NOI18N
                    this.offset++;
                }
            }
            return false;
        }
    } else {
        return false;
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:20,代码来源:DrawEngineLineView.java

示例4: testSyncWithChangedProlog

import javax.swing.text.Document; //导入依赖的package包/类
public void testSyncWithChangedProlog() throws Exception {
    List<Difference> diffs = Util.diff("resources/test1.xml", "resources/test1_changedProlog.xml");
    assertEquals("should also include change in prolog", 1, diffs.size());

    defaultSetup();
    org.netbeans.modules.xml.xdm.nodes.Document oldDoc = 
        (org.netbeans.modules.xml.xdm.nodes.Document) mModel.getDocument();
    
    Util.setDocumentContentTo(mDoc, "resources/test1_changedProlog.xml");
    mModel.sync();
    
    org.netbeans.modules.xml.xdm.nodes.Document doc = 
        (org.netbeans.modules.xml.xdm.nodes.Document) mModel.getDocument();
    assertEquals("expect resulting document has no prolog", 6, doc.getTokens().size());
    String tokens = doc.getTokens().toString();
    assertFalse("prolog should changes: "+tokens, oldDoc.getTokens().toString().equals(tokens));
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:AbstractModelTest.java

示例5: getIndent

import javax.swing.text.Document; //导入依赖的package包/类
private static CharSequence getIndent(JTextComponent c) {
    StringBuilder sb = new StringBuilder();
    try {
        Document doc = c.getDocument();
        CodeStyle cs = CodeStyle.getDefault(doc);
        int indent = IndentUtils.lineIndent(c.getDocument(), IndentUtils.lineStartOffset(c.getDocument(), c.getCaretPosition()));
        int tabSize = cs.getTabSize();
        int col = 0;
        if (!cs.expandTabToSpaces()) {
            while (col + tabSize <= indent) {
                sb.append('\t'); //NOI18N
                col += tabSize;
            }
        }
        while (col < indent) {
            sb.append(' '); //NOI18N
            col++;
        }
    } catch (BadLocationException ex) {
    }
    return sb;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:23,代码来源:JavaCompletionItem.java

示例6: updateForNewDocument

import javax.swing.text.Document; //导入依赖的package包/类
private synchronized void updateForNewDocument() {
    data.unregister();
    Document newDocument = pane.getDocument();
    
    if (weakDocL != null && this.doc != null) {
        this.doc.removeDocumentListener(weakDocL);
        this.doc = null;
    }
    
    if (newDocument instanceof BaseDocument) {
        this.doc = (BaseDocument) pane.getDocument();
        weakDocL = WeakListeners.document(this, this.doc);
        this.doc.addDocumentListener(weakDocL);
    }
    
    data.register(this.doc);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:AnnotationView.java

示例7: findBlocks

import javax.swing.text.Document; //导入依赖的package包/类
public static FindReplaceResult findBlocks(Document doc, int startOffset, int endOffset, 
                Map<String, Object> props, int blocks[]) throws BadLocationException{
    BlocksFinder finder;
    try {
        finder = (BlocksFinder) getFinder(doc, props, false, true);
    } catch (PatternSyntaxException pse) {
        FindReplaceResult findReplaceResult = new FindReplaceResult(new int[]{-1, -1}, "");
        findReplaceResult.setErrorMsg(NbBundle.getMessage(DocumentFinder.class, "pattern-error-dialog-content") + " " + pse.getDescription());
        return findReplaceResult;
    }
    if (finder == null){
        return new FindReplaceResult(blocks, "");
    }
    CharSequence cs = DocumentUtilities.getText(doc, startOffset, endOffset - startOffset);
    if (cs==null){
        return null;
    }
    synchronized (finder) {
        finder.reset();
        finder.setBlocks(blocks);
        finder.find(startOffset, cs);
        int ret [] = finder.getBlocks();
        return new FindReplaceResult(ret, "");
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:26,代码来源:DocumentFinder.java

示例8: isGuarded

import javax.swing.text.Document; //导入依赖的package包/类
public static boolean isGuarded(Tree node, CompilationInfo javac, Document doc) {
    GuardedSectionManager guards = GuardedSectionManager.getInstance((StyledDocument) doc);
    if (guards != null) {
        try {
            final int startOff = (int) javac.getTrees().getSourcePositions().
                    getStartPosition(javac.getCompilationUnit(), node);
            final Position startPos = doc.createPosition(startOff);

            for (GuardedSection guard : guards.getGuardedSections()) {
                if (guard.contains(startPos, false)) {
                    return true;
                }
            }
        } catch (BadLocationException ex) {
            Logger.getLogger(Analyzer.class.getName()).log(Level.INFO, ex.getMessage(), ex);
            // consider it as guarded
            return true;
        }
    }
    return false;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:22,代码来源:JavadocUtilities.java

示例9: implement

import javax.swing.text.Document; //导入依赖的package包/类
@Override
    public void implement() throws Exception {
        Source source = Source.create(sourceFile);
        final Document doc = source.getDocument(false);
        ParserManager.parse(Collections.singleton(source), new UserTask() {

            @Override
            public void run(ResultIterator resultIterator) throws Exception {
                //html must be top level
                Result result = resultIterator.getParserResult();
                if(!(result instanceof HtmlParserResult)) {
                    return ;
                }
                ModificationResult modification = new ModificationResult();
                if(HtmlSourceUtils.importStyleSheet(modification, (HtmlParserResult)result, externalStylesheet)) {
                    modification.commit();
//                    if(doc != null) {
//                        //refresh the index for the modified file
//                        HtmlSourceUtils.forceReindex(sourceFile);
//                    }
                }
            }
        });
        
    }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:26,代码来源:AddStylesheetLinkHintFix.java

示例10: stateChanged

import javax.swing.text.Document; //导入依赖的package包/类
/** delayed change of query text */
@Override
public void stateChanged (ChangeEvent e) {
    Document doc = (Document)e.getSource();
    try {
        curTypedText = doc.getText(0, doc.getLength()).trim();
    } catch (BadLocationException ex) {
        // should never happen, nothing we can do probably
        return;
    }

    tfQuery.setForeground(defSearchC);
    if (curTypedText.length() < 3) {
        tfQuery.setForeground(Color.RED);
        //nls.setWarningMessage(NbBundle.getMessage(AddDependencyPanel.class, "MSG_QueryTooShort"));
    } else {
        tfQuery.setForeground(defSearchC);
        //nls.clearMessages();
        find(curTypedText);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:22,代码来源:NewPluginPanel.java

示例11: checkExpansionKeystroke

import javax.swing.text.Document; //导入依赖的package包/类
private void checkExpansionKeystroke(KeyEvent evt) {
    Position pos = null;
    Document d = null;
    synchronized (abbrevChars) {
        if (abbrevEndPosition != null && component != null && doc != null
            && component.getCaretPosition() == abbrevEndPosition.getOffset()
            && !isAbbrevDisabled()
            && doc.getProperty(EDITING_TEMPLATE_DOC_PROPERTY) == null
        ) {
            pos = abbrevEndPosition;
            d = component.getDocument();
        }
    }
    if (pos != null && d != null) {
        CodeTemplateManagerOperation operation = CodeTemplateManagerOperation.get(d, pos.getOffset());
        if (operation != null) {
            KeyStroke expandKeyStroke = operation.getExpansionKey();

            if (expandKeyStroke.equals(KeyStroke.getKeyStrokeForEvent(evt))) {
                if (expand(operation)) {
                    evt.consume();
                }
            }
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:27,代码来源:AbbrevDetection.java

示例12: setText

import javax.swing.text.Document; //导入依赖的package包/类
@Override
public final void setText(final String text) {
    synchronized (getDelegateLock()) {
        // JTextArea.setText() posts two different events (remove & insert).
        // Since we make no differences between text events,
        // the document listener has to be disabled while
        // JTextArea.setText() is called.
        final Document document = getTextComponent().getDocument();
        document.removeDocumentListener(this);
        getTextComponent().setText(text);
        revalidate();
        if (firstChangeSkipped) {
            postEvent(new TextEvent(getTarget(),
                                    TextEvent.TEXT_VALUE_CHANGED));
        }
        document.addDocumentListener(this);
    }
    repaintPeer();
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:20,代码来源:LWTextComponentPeer.java

示例13: getCodeStyle

import javax.swing.text.Document; //导入依赖的package包/类
private static CodeStyle getCodeStyle(CompilationInfo info) {
    if (info != null) {
        try {
            Document doc = info.getDocument();
            if (doc != null) {
                CodeStyle cs = (CodeStyle)doc.getProperty(CodeStyle.class);
                return cs != null ? cs : CodeStyle.getDefault(doc);
            }
        } catch (IOException ioe) {
            // ignore
        }
        
        FileObject file = info.getFileObject();
        if (file != null) {
            return CodeStyle.getDefault(file);
        }
    }
    
    return CodeStyle.getDefault((Document)null);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:GeneratorUtils.java

示例14: XhtmlElHighlighting

import javax.swing.text.Document; //导入依赖的package包/类
XhtmlElHighlighting(Document document) {
    this.document = document;
    
    // load the background color for the embedding token
    AttributeSet elAttribs = null;
    String mimeType = (String) document.getProperty("mimeType"); //NOI18N
    FontColorSettings fcs = MimeLookup.getLookup(mimeType).lookup(FontColorSettings.class);
    if (fcs != null) {
        Color elBC = getColoring(fcs, XhtmlElTokenId.EL.primaryCategory());
        if (elBC != null) {
            elAttribs = AttributesUtilities.createImmutable(
                StyleConstants.Background, elBC, 
                ATTR_EXTENDS_EOL, Boolean.TRUE);
        }
    }
    expressionLanguageBackground = elAttribs;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:XhtmlElHighlighting.java

示例15: getCssTokenSequence

import javax.swing.text.Document; //导入依赖的package包/类
private TokenSequence<CssTokenId> getCssTokenSequence(Document doc, int offset) {
    TokenHierarchy th = TokenHierarchy.get(doc);
    TokenSequence ts = th.tokenSequence();
    if (ts == null) {
        return null;
    }
    ts.move(offset);

    while (ts.moveNext() || ts.movePrevious()) {
        if (ts.language() == CssTokenId.language()) {
            return ts;
        }

        ts = ts.embedded();

        if (ts == null) {
            break;
        }

        //position the embedded ts so we can search deeper
        ts.move(offset);
    }

    return null;

}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:27,代码来源:CssCommentHandler.java


注:本文中的javax.swing.text.Document类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。