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


Java Caret类代码示例

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


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

示例1: actionPerformed

import javax.swing.text.Caret; //导入依赖的package包/类
@Override
public void actionPerformed(ActionEvent e) {
	if (isVisible()) {
		JTextComponent comp = ac.getTextComponent();
		Caret c = comp.getCaret();
		int dot = c.getDot();
		if (dot < comp.getDocument().getLength()) {
			c.setDot(++dot);
			// Ensure moving right hasn't moved us up a line, thus
			// hiding the popup window.
			if (comp.isVisible()) {
				if (lastLine!=-1) {
					doAutocomplete();
				}
			}
		}
	}
}
 
开发者ID:Thecarisma,项目名称:powertext,代码行数:19,代码来源:AutoCompletePopupWindow.java

示例2: insertIntoDocument

import javax.swing.text.Caret; //导入依赖的package包/类
private int insertIntoDocument(String s, JEditorPane target)
        throws BadLocationException {
    Document doc = target.getDocument();
    if (s == null) {
        s = "";
        }
    if (doc == null) {
        return -1;
    }        
    int start = -1;
    try {
        Caret caret = target.getCaret();
        int p0 = Math.min(caret.getDot(), caret.getMark());
        int p1 = Math.max(caret.getDot(), caret.getMark());
        doc.remove(p0, p1 - p0);
        start = caret.getDot();
        doc.insertString(start, s + ";\n", null); // NOI18N
    } catch (BadLocationException ble) {
        LOGGER.log(Level.WARNING, org.openide.util.NbBundle.getMessage(SQLHistoryPanel.class, "LBL_InsertAtLocationError") + ble);
}
    return start;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:23,代码来源:SQLHistoryPanel.java

示例3: substituteText

import javax.swing.text.Caret; //导入依赖的package包/类
/**
 * If called with <code>SHIFT_MASK</code> modified it createa a start tag and
 * end tag pair and place caret between them.
 */
public boolean substituteText( JTextComponent c, int offset, int len, int modifiers ){
    String replacementText = getReplacementText(modifiers);
    replaceText(c, replacementText, offset, len);
    
    boolean shift = (modifiers & java.awt.event.InputEvent.SHIFT_MASK) != 0;

    if (shift && startElement) {
        Caret caret = c.getCaret();  // it is at the end of replacement
        int dot = caret.getDot();
        int rlen = replacementText.length();
        if (empty) {
            caret.setDot((dot  - rlen) + replacementText.indexOf('/'));
        }
    }
    
    return false;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:22,代码来源:ElementResultItem.java

示例4: releaseUI

import javax.swing.text.Caret; //导入依赖的package包/类
/**
 * Ends the method selection mode, clears all used ui elements. Notifies each registered
 * {@link ReleaseListener}.
 *
 * @param performAction <code>true</code> indicates that the current selection should
 *          be used to perform an action, <code>false</code> means that the selection mode
 *          has beencancelled
 */
public synchronized void releaseUI(boolean performAction) {
    if (!isInSelectMode) {
        return; // do nothing
    }
    getHighlightsBag(doc).clear();
    editorPane.removeKeyListener(mainListener);
    editorPane.removeMouseListener(mainListener);
    editorPane.removeMouseMotionListener(mainListener);
    editorPane.removeFocusListener(mainListener);
    editorPane.putClientProperty(MethodChooser.class, null);
    editorPane.setCursor(originalCursor);
    Caret caret = editorPane.getCaret();
    if (caret instanceof BaseCaret) {
        ((BaseCaret)caret).setVisible(true);
    }

    if (hintText != null && hintText.trim().length() > 0) {
        Utilities.clearStatusText(editorPane);
    }
    isInSelectMode = false;
    for (ReleaseListener listener : releaseListeners) {
        listener.released(performAction);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:33,代码来源:MethodChooser.java

示例5: actionPerformed

import javax.swing.text.Caret; //导入依赖的package包/类
public void actionPerformed(final ActionEvent evt, final JTextComponent target) {
    if (target != null) {
        final Caret caret = target.getCaret();
        final BaseDocument doc = (BaseDocument)target.getDocument();
        doc.render(new Runnable () {
            public void run () {
                DocumentUtilities.setTypingModification(doc, true);
                try {
                    int dotPos = caret.getDot();
                    int bolPos = Utilities.getRowStart(target, dotPos);
                    int eolPos = Utilities.getRowEnd(target, dotPos);
                    eolPos = Math.min(eolPos + 1, doc.getLength()); // include '\n'
                    caret.setDot(bolPos);
                    caret.moveDot(eolPos);
                } catch (BadLocationException e) {
                    target.getToolkit().beep();
                } finally {
                    DocumentUtilities.setTypingModification(doc, false);
                }
            }
        });
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:24,代码来源:BaseKit.java

示例6: actionPerformed

import javax.swing.text.Caret; //导入依赖的package包/类
@Override
public void actionPerformed(ActionEvent evt, JTextComponent target) {
    if (target != null) {
        Caret caret = target.getCaret();
        BookmarkList bookmarkList = BookmarkList.get(target.getDocument());
        int dotOffset = caret.getDot();
        Bookmark bookmark = gotoNext
            ? bookmarkList.getNextBookmark(dotOffset, true) // next (wrap)
            : bookmarkList.getPreviousBookmark(dotOffset, true); // previous (wrap)

        if (bookmark != null) {
            if (select) {
                caret.moveDot(bookmark.getOffset());
            } else {
                caret.setDot(bookmark.getOffset());
            }
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:20,代码来源:GotoBookmarkAction.java

示例7: actionPerformed

import javax.swing.text.Caret; //导入依赖的package包/类
public void actionPerformed(ActionEvent evt, JTextComponent target) {
    if (target != null) {
        Caret caret = target.getCaret();
        try {
            int pos = Utilities.getRowFirstNonWhite((BaseDocument)target.getDocument(),
                                                    caret.getDot());
            if (pos >= 0) {
                boolean select = BaseKit.selectionFirstNonWhiteAction.equals(getValue(Action.NAME));
                if (select) {
                    caret.moveDot(pos);
                } else {
                    caret.setDot(pos);
                }
            }
        } catch (BadLocationException e) {
            target.getToolkit().beep();
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:20,代码来源:ActionFactory.java

示例8: isDragPossible

import javax.swing.text.Caret; //导入依赖的package包/类
/**
 * Determines if the following are true:
 * <ul>
 * <li>the press event is located over a selection
 * <li>the dragEnabled property is true
 * <li>A TranferHandler is installed
 * </ul>
 * <p>
 * This is implemented to check for a TransferHandler.
 * Subclasses should perform the remaining conditions.
 */
protected boolean isDragPossible(MouseEvent e) {
    JComponent comp = getEventComponent(e);
    boolean possible =  (comp == null) ? false : (comp.getTransferHandler() != null);
    if (possible) {
        JTextComponent c = (JTextComponent) getEventComponent(e);
        if (c.getDragEnabled()) {
            Caret caret = c.getCaret();
            int dot = caret.getDot();
            int mark = caret.getMark();
            if (dot != mark) {
                Point p = new Point(e.getX(), e.getY());
                int pos = c.viewToModel(p);

                int p0 = Math.min(dot, mark);
                int p1 = Math.max(dot, mark);
                if ((pos >= p0) && (pos < p1)) {
                    return true;
                }
            }
        }
    }
    return false;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:35,代码来源:BaseCaret.java

示例9: getSelectionOrIdentifier

import javax.swing.text.Caret; //导入依赖的package包/类
/** Get the selection if there's any or get the identifier around
   * the position if there's no selection.
   */
   public static String getSelectionOrIdentifier(JTextComponent c, int offset)
   throws BadLocationException {
       Document doc = c.getDocument();
       Caret caret = c.getCaret();
       String ret;
       if (Utilities.isSelectionShowing(caret)) {
           ret = c.getSelectedText();
    if (ret != null) return ret;
       } 
if (doc instanceof BaseDocument){
    ret = getIdentifier((BaseDocument) doc, offset);
       } else {
    ret = getWord(c, offset);
}
       return ret;
   }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:20,代码来源:Utilities.java

示例10: gotoDeclaration

import javax.swing.text.Caret; //导入依赖的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

示例11: actionPerformed

import javax.swing.text.Caret; //导入依赖的package包/类
public @Override void actionPerformed(ActionEvent evt, JTextComponent target) {
    String cmd = evt.getActionCommand();
    int mod = evt.getModifiers();

    // Dirty fix for Completion shortcut on Unix !!!
    if (cmd != null && cmd.equals(" ") && (mod == ActionEvent.CTRL_MASK)) { // NOI18N
        // Ctrl + SPACE
    } else {
        Caret caret = target.getCaret();
        if (caret instanceof ExtCaret) {
            ((ExtCaret)caret).requestMatchBraceUpdateSync(); // synced bracket update
        }
        super.actionPerformed(evt, target);
    }

    if ((target != null) && (evt != null)) {
        if ((cmd != null) && (cmd.length() == 1)) {
            // Check whether char that should reindent the line was inserted
            checkIndentHotChars(target, cmd);

            // Check the completion
            checkCompletion(target, cmd);
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:26,代码来源:ExtKit.java

示例12: getMostRecentLine

import javax.swing.text.Caret; //导入依赖的package包/类
/**
 * Get the line of the caret in the most recent editor.
 * This returns the current line in the current editor if there's one,
 * or a line of the caret in the editor, that was most recently active.
 * @return the line or <code>null</code> when there was no recent active editor.
 */
public Line getMostRecentLine() {
    EditorCookie e = getMostRecentEditorCookie ();
    if (e == null) return null;
    JEditorPane ep = getMostRecentEditor ();
    if (ep == null) return null;
    StyledDocument d = e.getDocument ();
    if (d == null) return null;
    Caret caret = ep.getCaret ();
    if (caret == null) return null;
    int lineNumber = NbDocument.findLineNumber(d, caret.getDot());
    Line.Set lineSet = e.getLineSet();
    try {
        return lineSet.getCurrent(lineNumber);
    } catch (IndexOutOfBoundsException ex) {
        return null;
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:24,代码来源:EditorContextDispatcher.java

示例13: updateActiveCaret

import javax.swing.text.Caret; //导入依赖的package包/类
private void updateActiveCaret() {
    if (visible) {
        setVisible(false);
    }
    if (editorCaret != null) {
        editorCaret.removeEditorCaretListener(weakEditorCaretListener);
        weakEditorCaretListener = null;
        editorCaret = null;
        docText = null;
    }

    Caret caret = component.getCaret();
    if (caret instanceof EditorCaret) { // Only work for editor caret
        editorCaret = (EditorCaret) caret;
    }

    if (editorCaret != null) {
        updateDocText();
        weakEditorCaretListener = WeakListeners.create(EditorCaretListener.class, this, editorCaret);
        editorCaret.addEditorCaretListener(weakEditorCaretListener);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:23,代码来源:CaretOverwriteModeHighlighting.java

示例14: handleTransfer

import javax.swing.text.Caret; //导入依赖的package包/类
public boolean handleTransfer(JTextComponent targetComponent) {

            if (targetComponent == null)
                return false;

            try {
                Document doc = targetComponent.getDocument();
                Caret caret = targetComponent.getCaret();
                int p0 = Math.min(caret.getDot(), caret.getMark());
                int p1 = Math.max(caret.getDot(), caret.getMark());
                doc.remove(p0, p1 - p0);

                //replace selected text by the inserted one
                int start = caret.getDot();
                doc.insertString(start, body, null);
            }
            catch (BadLocationException ble) {
                return false;
            }

            return true;
        }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:23,代码来源:ActiveEditorDropDefaultProvider.java

示例15: computeSelIndex

import javax.swing.text.Caret; //导入依赖的package包/类
private int computeSelIndex(boolean inner) {
    Caret caret = target.getCaret();
    if (selectionInfos != null && caret != null && caret.getDot() != caret.getMark()) {
        int dot = caret.getDot();
        int mark = caret.getMark();
        int start = Math.min(dot,mark);
        //int end = Math.max(dot,mark);
        for (int i = 0; i < selectionInfos.length; i++) {
            if (selectionInfos[i].getStartOffset() == start) {
                // TODO - check end offset too
                return i;
            }
        }
        // No exact match - look at the editor selection and find the range
        // that most closely surround the selection (if inner is true, go
        // for the inner one, otherwise the outer)
        for (int i = selectionInfos.length-2; i >= 0; i--) {
            if (selectionInfos[i].getStartOffset() > start &&
                    selectionInfos[i+1].getStartOffset() < start) {
                return inner ? i : i-1;
            }
        }
    }
    
    return selIndex;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:27,代码来源:SelectCodeElementAction.java


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