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


Java Utilities.getDocument方法代码示例

本文整理汇总了Java中org.netbeans.editor.Utilities.getDocument方法的典型用法代码示例。如果您正苦于以下问题:Java Utilities.getDocument方法的具体用法?Java Utilities.getDocument怎么用?Java Utilities.getDocument使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.netbeans.editor.Utilities的用法示例。


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

示例1: findNextUnused

import org.netbeans.editor.Utilities; //导入方法依赖的package包/类
private int findNextUnused(JTextComponent comp, int offset) {
    try {
        BaseDocument doc = Utilities.getDocument(comp);
        int lineStart = Utilities.getRowStart(doc, offset);
        // "unused-browseable" in java.editor/.../ColoringManager and csl.api/.../ColoringManager
        HighlightsSequence s = HighlightingManager.getInstance(comp).getBottomHighlights().getHighlights(lineStart, Integer.MAX_VALUE);
        int lastUnusedEndOffset = -1;

        while (s.moveNext()) {
            AttributeSet attrs = s.getAttributes();
            if (attrs != null && attrs.containsAttribute("unused-browseable", Boolean.TRUE)) {
                
                if (lastUnusedEndOffset != s.getStartOffset() && s.getStartOffset() >= offset) {
                    return s.getStartOffset();
                }
                lastUnusedEndOffset = s.getEndOffset();
            }
        }

        return -1;
    } catch (BadLocationException ex) {
        Exceptions.printStackTrace(ex);
        return -1;
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:26,代码来源:NextErrorAction.java

示例2: gotoDeclaration

import org.netbeans.editor.Utilities; //导入方法依赖的package包/类
public boolean gotoDeclaration(JTextComponent target) {
    BaseDocument doc = Utilities.getDocument(target);
    if (doc == null)
        return false;
    try {
        Caret caret = target.getCaret();
        int dotPos = caret.getDot();
        int[] idBlk = Utilities.getIdentifierBlock(doc, dotPos);
        ExtSyntaxSupport extSup = (ExtSyntaxSupport)doc.getSyntaxSupport();
        if (idBlk != null) {
            int decPos = extSup.findDeclarationPosition(doc.getText(idBlk), idBlk[1]);
            if (decPos >= 0) {
                caret.setDot(decPos);
                return true;
            }
        }
    } catch (BadLocationException e) {
    }
    return false;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:ExtKit.java

示例3: getAutoQueryTypes

import org.netbeans.editor.Utilities; //导入方法依赖的package包/类
public int getAutoQueryTypes(JTextComponent component, String typedText) {
       BaseDocument doc = Utilities.getDocument(component);
if ( typedText ==null || typedText.trim().length() ==0 ){
           return 0;
       }
       // do not pop up if the end of text contains some whitespaces.
       if (Character.isWhitespace(typedText.charAt(typedText.length() - 1) )) {
           return 0;
       }
       if(doc == null)
           return 0;
       XMLSyntaxSupport support = XMLSyntaxSupport.getSyntaxSupport(doc);
       if(support != null && CompletionUtil.noCompletion(component) || 
               !CompletionUtil.canProvideCompletion(doc)) {
           return 0;
       }
       
       return COMPLETION_QUERY_TYPE;
   }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:20,代码来源:SchemaBasedCompletionProvider.java

示例4: actionPerformed

import org.netbeans.editor.Utilities; //导入方法依赖的package包/类
@Override
public void actionPerformed(ActionEvent evt, JTextComponent target) {
    BaseDocument bdoc = Utilities.getDocument(target);
    if(bdoc == null) {
        return ; //no document?!?!
    }
    DataObject csso = NbEditorUtilities.getDataObject(bdoc);
    if(csso == null) {
        return ; //document not backuped by DataObject
    }
    
    String pi = createText(csso);
    StringSelection ss = new StringSelection(pi);
    ExClipboard clipboard = Lookup.getDefault().lookup(ExClipboard.class);
    clipboard.setContents(ss, null);
    StatusDisplayer.getDefault().setStatusText( NbBundle.getMessage(CopyStyleAction.class, "MSG_Style_tag_in_clipboard"));  // NOI18N
    
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:CopyStyleAction.java

示例5: actionPerformed

import org.netbeans.editor.Utilities; //导入方法依赖的package包/类
@Override
public void actionPerformed(ActionEvent e) {
    EditorUI eui = Utilities.getEditorUI(editorPane);
    Point location = et.getLocation();
    location = eui.getStickyWindowSupport().convertPoint(location);
    eui.getToolTipSupport().setToolTipVisible(false);
    DebuggerManager dbMgr = DebuggerManager.getDebuggerManager();
    BaseDocument document = Utilities.getDocument(editorPane);
    DataObject dobj = (DataObject) document.getProperty(Document.StreamDescriptionProperty);
    FileObject fo = dobj.getPrimaryFile();
    Watch.Pin pin = new EditorPin(fo, pinnable.line, location);
    final Watch w = dbMgr.createPinnedWatch(pinnable.expression, pin);
    SwingUtilities.invokeLater(() -> {
        try {
            PinWatchUISupport.getDefault().pin(w, pinnable.valueProviderId);
        } catch (IllegalArgumentException ex) {
            Exceptions.printStackTrace(ex);
        }
    });
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:ToolTipUI.java

示例6: findNextError

import org.netbeans.editor.Utilities; //导入方法依赖的package包/类
private List<ErrorDescription> findNextError(JTextComponent comp, int offset) {
    Document doc = Utilities.getDocument(comp);
    Object stream = doc.getProperty(Document.StreamDescriptionProperty);
    
    if (!(stream instanceof DataObject)) {
        return Collections.emptyList();
    }
    
    AnnotationHolder holder = AnnotationHolder.getInstance(((DataObject) stream).getPrimaryFile());
    
    List<ErrorDescription> errors = holder.getErrorsGE(offset);
    
    return errors;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:15,代码来源:NextErrorAction.java

示例7: getContext

import org.netbeans.editor.Utilities; //导入方法依赖的package包/类
private JavaSource getContext(JTextComponent target) {
    final Document doc = Utilities.getDocument(target);
    if (doc == null) {
        return null;
    }
    return JavaSource.forDocument(doc);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:8,代码来源:ShowMembersAtCaretAction.java

示例8: hasTextBefore

import org.netbeans.editor.Utilities; //导入方法依赖的package包/类
protected boolean hasTextBefore(JTextComponent target, String typedText) {
    BaseDocument doc = Utilities.getDocument(target);
    int dotPos = target.getCaret().getDot();
    try {
        int fnw = Utilities.getRowFirstNonWhite(doc, dotPos);
        return dotPos != fnw+typedText.length();
    } catch (BadLocationException e) {
        return false;
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:11,代码来源:ExtFormatter.java

示例9: actionPerformed

import org.netbeans.editor.Utilities; //导入方法依赖的package包/类
@Override
public void actionPerformed(ActionEvent evt, JTextComponent target) {
    String actionName = actionName();
    if (EditorActionNames.gotoDeclaration.equals(actionName)) {
        resetCaretMagicPosition(target);
        if (target != null) {
            if (hyperlinkGoTo(target)) {
                return;
            }
            
            BaseDocument doc = Utilities.getDocument(target);
            if (doc != null) {
                try {
                    Caret caret = target.getCaret();
                    int dotPos = caret.getDot();
                    int[] idBlk = Utilities.getIdentifierBlock(doc, dotPos);
                    ExtSyntaxSupport extSup = (ExtSyntaxSupport) doc.getSyntaxSupport();
                    if (idBlk != null) {
                        int decPos = extSup.findDeclarationPosition(doc.getText(idBlk), idBlk[1]);
                        if (decPos >= 0) {
                            caret.setDot(decPos);
                        }
                    }
                } catch (BadLocationException e) {
                }
            }
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:30,代码来源:GotoAction.java

示例10: start

import org.netbeans.editor.Utilities; //导入方法依赖的package包/类
public static void start() {
    JTextComponent jtc = EditorRegistry.lastFocusedComponent();
    doc = jtc != null ? Utilities.getDocument(jtc) : null;
    if (doc != null) {
        doc.addDocumentListener(listener);
    }
    modified = false;
    active = true;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:10,代码来源:CompletionJListOperator.java

示例11: performActionAt

import org.netbeans.editor.Utilities; //导入方法依赖的package包/类
private void performActionAt(Mark mark, int mouseY) throws BadLocationException {
    if (mark != null) {
        return;
    }
    BaseDocument bdoc = Utilities.getDocument(component);
    BaseTextUI textUI = (BaseTextUI)component.getUI();

    View rootView = Utilities.getDocumentView(component);
    if (rootView == null) return;
    
    bdoc.readLock();
    try {
        int yOffset = textUI.getPosFromY(mouseY);
        FoldHierarchy hierarchy = FoldHierarchy.get(component);
        hierarchy.lock();
        try {
            Fold f = FoldUtilities.findOffsetFold(hierarchy, yOffset);
            if (f == null) {
                return;
            }
            if (f.isCollapsed()) {
                LOG.log(Level.WARNING, "Clicked on a collapsed fold {0} at {1}", new Object[] { f, mouseY });
                return;
            }
            int startOffset = f.getStartOffset();
            int endOffset = f.getEndOffset();
            
            int startY = textUI.getYFromPos(startOffset);
            int nextLineOffset = Utilities.getRowStart(bdoc, startOffset, 1);
            int nextY = textUI.getYFromPos(nextLineOffset);

            if (mouseY >= startY && mouseY <= nextY) {
                LOG.log(Level.FINEST, "Starting line clicked, ignoring. MouseY={0}, startY={1}, nextY={2}",
                        new Object[] { mouseY, startY, nextY });
                return;
            }

            startY = textUI.getYFromPos(endOffset);
            nextLineOffset = Utilities.getRowStart(bdoc, endOffset, 1);
            nextY = textUI.getYFromPos(nextLineOffset);

            if (mouseY >= startY && mouseY <= nextY) {
                // the mouse can be positioned above the marker (the fold found above), or
                // below it; in that case, the immediate enclosing fold should be used - should be the fold
                // that corresponds to the nextLineOffset, if any
                int h2 = (startY + nextY) / 2;
                if (mouseY >= h2) {
                    Fold f2 = f;
                    
                    f = FoldUtilities.findOffsetFold(hierarchy, nextLineOffset);
                    if (f == null) {
                        // fold does not exist for the position below end-of-fold indicator
                        return;
                    }
                }
                
            }
            
            LOG.log(Level.FINEST, "Collapsing fold: {0}", f);
            hierarchy.collapse(f);
        } finally {
            hierarchy.unlock();
        }
    } finally {
        bdoc.readUnlock();
    }        
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:68,代码来源:CodeFoldingSideBar.java

示例12: performGoto

import org.netbeans.editor.Utilities; //导入方法依赖的package包/类
/** Perform the goto operation.
 * @return whether the dialog should be made invisible or not
 */
protected boolean performGoto() {
    JTextComponent c = EditorRegistry.lastFocusedComponent();
    if (c != null) {
        try {
            int line = Integer.parseInt(getGotoValueText());

            //issue 188976
            if (line==0)
                line = 1;
            //end of issue 188976
            
            BaseDocument doc = Utilities.getDocument(c);
            if (doc != null) {
                int rowCount = Utilities.getRowCount(doc);
                if (line > rowCount)
                    line = rowCount;
                
                // Obtain the offset where to jump
                int pos = Utilities.getRowStartFromLineOffset(doc, line - 1);
                
                BaseKit kit = Utilities.getKit(c);
                if (kit != null) {
                    Action a = kit.getActionByName(ExtKit.gotoAction);
                    if (a instanceof ExtKit.GotoAction) {
                        pos = ((ExtKit.GotoAction)a).getOffsetFromLine(doc, line - 1);
                    }
                }
                
                if (pos != -1) {
                    Caret caret = c.getCaret();
                    caret.setDot(pos);
                } else {
                    c.getToolkit().beep();
                    return false;
                }
            }
        } catch (NumberFormatException e) {
            c.getToolkit().beep();
            return false;
        }
    }
    return true;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:47,代码来源:GotoDialogSupport.java

示例13: getReformatBlock

import org.netbeans.editor.Utilities; //导入方法依赖的package包/类
@Override public int[] getReformatBlock(JTextComponent target, String typedText) {
    BaseDocument doc = Utilities.getDocument(target);
    
    if (!hasValidSyntaxSupport(doc)){
        return null;
    }
    
    char lastChar = typedText.charAt(typedText.length() - 1);
    
    try{
        int dotPos = target.getCaret().getDot();
        
        if (lastChar == '>') {
            TokenItem tknPrecedingToken = getTagTokenEndingAtPosition(doc, dotPos - 1);
            
            if (isClosingTag(tknPrecedingToken)){
                // the user has just entered a closing tag
                // - reformat it unless matching opening tag is on the same line 
                
                TokenItem tknOpeningTag = getMatchingOpeningTag(tknPrecedingToken);
                
                if (tknOpeningTag != null){
                    int openingTagLine = Utilities.getLineOffset(doc, tknOpeningTag.getOffset());
                    int closingTagSymbolLine = Utilities.getLineOffset(doc, dotPos);
                    
                    if(openingTagLine != closingTagSymbolLine){
                        return new int[]{tknPrecedingToken.getOffset(), dotPos};
                    }
                }
            }
        }
        
        else if(lastChar == '\n') {
            // just pressed enter
            enterPressed(target, dotPos);
        }
        
    } catch (Exception e){
        ErrorManager.getDefault().notify(ErrorManager.WARNING, e);
    }
    
    return null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:44,代码来源:TagBasedFormatter.java

示例14: actionPerformed

import org.netbeans.editor.Utilities; //导入方法依赖的package包/类
public void actionPerformed(ActionEvent evt, JTextComponent target) {
    if (LOG.isLoggable(Level.FINE)) {
        LOG.fine("actionCommand='" + evt.getActionCommand() //NOI18N
                + "', modifiers=" + evt.getModifiers() //NOI18N
                + ", when=" + evt.getWhen() //NOI18N
                + ", paramString='" + evt.paramString() + "'"); //NOI18N
    }
    
    if (target == null) {
        return;
    }

    BaseKit kit = Utilities.getKit(target);
    if (kit == null) {
        return;
    }

    BaseDocument doc = Utilities.getDocument(target);
    if (doc == null) {
        return;
    }

    // changed as reponse to #250157: other events may get fired during
    // the course of key binding processing and if an event is processed
    // as nested (i.e. hierarchy change resulting from a component retracting from the screen),
    // thie following test would fail.
    AWTEvent maybeKeyEvent = EventQueue.getCurrentEvent();
    KeyStroke keyStroke = null;
    
    if (maybeKeyEvent instanceof KeyEvent) {
        keyStroke = KeyStroke.getKeyStrokeForEvent((KeyEvent) maybeKeyEvent);
    }

    // try simple keystorkes first
    MimePath mimeType = MimePath.parse(NbEditorUtilities.getMimeType(target));
    MacroDescription macro = null;
    if (keyStroke != null) {
        macro = findMacro(mimeType, keyStroke);
    } else {
        LOG.warning("KeyStroke could not be created for event " + maybeKeyEvent);
    }
    if (macro == null) {
        // if not found, try action command, which should contain complete multi keystroke
        KeyStroke[] shortcut = KeyStrokeUtils.getKeyStrokes(evt.getActionCommand());
        if (shortcut != null) {
            macro = findMacro(mimeType, shortcut);
        } else {
            LOG.warning("KeyStroke could not be created for action command " + evt.getActionCommand());
        }
    }

    if (macro == null) {
        error(target, "macro-not-found", KeyStrokeUtils.getKeyStrokeAsText(keyStroke)); // NOI18N
        return;
    }

    if (!runningActions.add(macro.getName())) { // this macro is already running, beware of loops
        error(target, "macro-loop", macro.getName()); // NOI18N
        return;
    }
    try {
        runMacro(target, doc, kit, macro);
    } finally {
        runningActions.remove(macro.getName());
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:67,代码来源:MacroDialogSupport.java


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