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


Java Caret.moveDot方法代码示例

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


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

示例1: actionPerformed

import javax.swing.text.Caret; //导入方法依赖的package包/类
public void actionPerformed(ActionEvent evt, JTextComponent target) {
    if (target != null) {
        Caret caret = target.getCaret();
        try {
            int newDotOffset = getPreviousWordOffset(target);
            boolean select = selectionPreviousWordAction.equals(getValue(Action.NAME));
            if (select) {
                if (caret instanceof EditorCaret && RectangularSelectionUtils.isRectangularSelection(target)) {
                    RectangularSelectionCaretAccessor.get().extendRectangularSelection((EditorCaret)caret, false, true);
                } else {
                    caret.moveDot(newDotOffset);
                }
            } else {
                caret.setDot(newDotOffset);
            }
        } catch (BadLocationException ex) {
            target.getToolkit().beep();
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:BaseKit.java

示例2: actionPerformed

import javax.swing.text.Caret; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public void actionPerformed(ActionEvent e) {
    JTextArea currentEditor = observer.getActiveEditor().getEditor();
    Document document = currentEditor.getDocument();
    Caret position = currentEditor.getCaret();

    int len = Math.abs(currentEditor.getCaret().getDot()
            - currentEditor.getCaret().getMark());
    int offset = Math.min(currentEditor.getCaret().getDot(), currentEditor
            .getCaret().getMark());

    try {
        String text = document.getText(offset, len);
        text = lowerCase(text);
        document.remove(offset, len);
        document.insertString(offset, text, null);
        // Reselect text
        position.setDot(offset);
        position.moveDot(offset + len);
        currentEditor.requestFocus();
    } catch (BadLocationException e1) {
        observer.errorMessage(e1);
    }
}
 
开发者ID:fgulan,项目名称:java-course,代码行数:28,代码来源:LowerCaseAction.java

示例3: 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

示例4: restoreLegacyCaret

import javax.swing.text.Caret; //导入方法依赖的package包/类
@Override
protected void restoreLegacyCaret(Caret caret) {
    int markOffsetAndBias = this.markOffsetAndBias;
    if (markOffsetAndBias == COMPLEX_POSITIONS_MARKER) { // complex positions at time of undo edit creation
        markOffsetAndBias = extraOffsets[1];
    }
    int markOffset = getOffset(markOffsetAndBias);
    int dotOffset = getOffset(dotOffsetAndBias);
    if (caret instanceof DefaultCaret) {
        DefaultCaret dCaret = (DefaultCaret) caret;
        dCaret.setDot(markOffset, getBias(markOffsetAndBias));
        dCaret.moveDot(dotOffset, getBias(dotOffsetAndBias));
    } else {
        caret.setDot(markOffset);
        caret.moveDot(dotOffset);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:CaretUndoEdit.java

示例5: 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

示例6: caretMoveDot

import javax.swing.text.Caret; //导入方法依赖的package包/类
/** Set the position of the caret and scroll the extent if necessary.
 * @param offset position where the caret should be placed
 * @param scrollRect rectangle that should become visible. It can be null
 *   when no scrolling should be done.
 * @param scrollPolicy policy to be used when scrolling.
 * @deprecated
 */
public void caretMoveDot(int offset, Rectangle scrollRect, int scrollPolicy) {
    if (component != null) {
        Caret caret = component.getCaret();
        if (caret instanceof BaseCaret) {
            ((BaseCaret)caret).moveDot(offset, scrollRect, scrollPolicy);
        } else {
            caret.moveDot(offset);
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:EditorUI.java

示例7: test

import javax.swing.text.Caret; //导入方法依赖的package包/类
public boolean test(int pos, int selectionLength, String todo, Object expectedResult) {
    Object v0 = getValue();

    Caret caret = getCaret();
    caret.setDot(pos);
    if (selectionLength > 0) {
        caret.moveDot(pos + selectionLength);
    }

    String desc = todo;
    if (todo == BACKSPACE) {
        backspace.actionPerformed(dummyEvent);
    } else if (todo == DELETE) {
        delete.actionPerformed(dummyEvent);
    } else {
        desc = "insert('" + todo + "')";
        insert.actionPerformed(new ActionEvent(this, 0, todo));
    }

    try {
        commitEdit();
    } catch (ParseException e) {
        e.printStackTrace();
        failed = true;
        return false;
    }

    Object v1 = getValue();
    if (! v1.equals(expectedResult)) {
        System.err.printf("Failure: value='%s', mark=%d, dot=%d, action=%s\n",
                v0, pos, pos + selectionLength, desc);
        System.err.printf("   Result: '%s', expected: '%s'\n", v1, expectedResult);
        failed = true;
        return false;
    }
    return true;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:38,代码来源:Test6462562.java

示例8: actionPerformed

import javax.swing.text.Caret; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public void actionPerformed(ActionEvent e) {
    JTextArea currentEditor = observer.getActiveEditor().getEditor();
    Document document = currentEditor.getDocument();
    Caret caret = currentEditor.getCaret();

    int startCaret = Math.min(caret.getDot(), caret.getMark());
    int endCaret = Math.max(caret.getDot(), caret.getMark());

    try {

        int startLine = currentEditor.getLineOfOffset(startCaret);
        int endLine = currentEditor.getLineOfOffset(endCaret);
        int fromPos = currentEditor.getLineStartOffset(startLine);
        int length = currentEditor.getLineEndOffset(endLine) - fromPos;

        String text = currentEditor.getText(fromPos, length);
        text = sortLinesAsc(text);
        document.remove(fromPos, length);
        document.insertString(fromPos, text, null);
        caret.setDot(fromPos);
        caret.moveDot(fromPos + length);
        currentEditor.requestFocus();
    } catch (BadLocationException e1) {
        observer.errorMessage(e1);
    }

}
 
开发者ID:fgulan,项目名称:java-course,代码行数:32,代码来源:SortLinesAscendingAction.java

示例9: actionPerformed

import javax.swing.text.Caret; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public void actionPerformed(ActionEvent e) {
    JTextArea currentEditor = observer.getActiveEditor().getEditor();
    Document document = currentEditor.getDocument();
    Caret caret = currentEditor.getCaret();

    int startCaret = Math.min(caret.getDot(), caret.getMark());
    int endCaret = Math.max(caret.getDot(), caret.getMark());

    try {

        int startLine = currentEditor.getLineOfOffset(startCaret);
        int endLine = currentEditor.getLineOfOffset(endCaret);
        int fromPos = currentEditor.getLineStartOffset(startLine);
        int length = currentEditor.getLineEndOffset(endLine) - fromPos + 1;

        String text = currentEditor.getText(fromPos, length);
        text = removeLines(text);
        document.remove(fromPos, length - 1);
        document.insertString(fromPos, text, null);
        caret.setDot(fromPos);
        caret.moveDot(length - 1);
        currentEditor.requestFocus();
    } catch (BadLocationException e1) {
        observer.errorMessage(e1);
    }
}
 
开发者ID:fgulan,项目名称:java-course,代码行数:31,代码来源:UniqueLinesAction.java

示例10: selectText

import javax.swing.text.Caret; //导入方法依赖的package包/类
private void selectText(JTextComponent c, int start, int end, boolean back){
    Caret caret = c.getCaret();
    ensureVisible(c, start, end);
    if (back) {
        caret.setDot(end);
        caret.moveDot(start);
    } else { // forward direction
        caret.setDot(start);
        caret.moveDot(end);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:12,代码来源:EditorFindSupport.java

示例11: select

import javax.swing.text.Caret; //导入方法依赖的package包/类
private void select(SelectionInfo selectionInfo) {
    Caret caret = target.getCaret();
    markIgnoreNextCaretUpdate();
    caret.setDot(selectionInfo.getStartOffset());
    markIgnoreNextCaretUpdate();
    caret.moveDot(selectionInfo.getEndOffset());
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:8,代码来源:SelectCodeElementAction.java

示例12: getTableCellEditorComponent

import javax.swing.text.Caret; //导入方法依赖的package包/类
/**
* It sets the cursot at the beginnig of edited cell, in case of searching it highlights the found text.
* At the end it request for focus so the editor component (JTextField) has it, not the table.
* This is also a hack with reason to figure out which cell is going to be edited, if a key or a value.
*/
@Override
public Component getTableCellEditorComponent(JTable table,
    Object value, boolean isSelected, int row, int column) {
        
    // Key or value? Only in the first column are keys.
    isKeyCell = (column == 0) ? true : false;
    
    valueComponent.getDocument().removeDocumentListener(listener);
    commentComponent.getDocument().removeDocumentListener(listener);
    final JTextField textField = (JTextField)super.getTableCellEditorComponent(table, value, isSelected, row, column);
    valueComponent.getDocument().addDocumentListener(listener);
    commentComponent.getDocument().addDocumentListener(listener);
    Caret caret = textField.getCaret();
    caret.setVisible(true);
    caret.setDot(0);
    
    textField.setFont(settings.getFont());
    
    // Check for search results.
    // If search was performed, highlight the found string.
    int[] result = (int[])table.getClientProperty(FindPerformer.TABLE_SEARCH_RESULT);
    if(result != null && row == result[0] && column == result[1]) {
        table.putClientProperty(FindPerformer.TABLE_SEARCH_RESULT, null); // removes property
        caret.setDot(result[2]);
        caret.moveDot(result[3]);
    }

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

示例13: actionPerformed

import javax.swing.text.Caret; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public void actionPerformed(ActionEvent e) {
    JTextArea currentEditor = observer.getActiveEditor().getEditor();
    Document document = currentEditor.getDocument();
    Caret caret = currentEditor.getCaret();

    int startCaret = Math.min(caret.getDot(), caret.getMark());
    int endCaret = Math.max(caret.getDot(), caret.getMark());

    try {

        int startLine = currentEditor.getLineOfOffset(startCaret);
        int endLine = currentEditor.getLineOfOffset(endCaret);
        int fromPos = currentEditor.getLineStartOffset(startLine);
        int length = currentEditor.getLineEndOffset(endLine) - fromPos;

        String text = currentEditor.getText(fromPos, length);
        text = sortLinesDesc(text);
        document.remove(fromPos, length);
        document.insertString(fromPos, text, null);
        caret.setDot(fromPos);
        caret.moveDot(fromPos + length);
        currentEditor.requestFocus();
    } catch (BadLocationException e1) {
        observer.errorMessage(e1);
    }

}
 
开发者ID:fgulan,项目名称:java-course,代码行数:32,代码来源:SortLinesDescendingAction.java

示例14: actionPerformed

import javax.swing.text.Caret; //导入方法依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public void actionPerformed(ActionEvent evt, JTextComponent target) {
    if (target != null) {
        Caret caret = target.getCaret();
        if (!Utilities.isSelectionShowing(caret)) {
            try {
                int[] identifierBlock = Utilities.getIdentifierBlock((BaseDocument) target.getDocument(), caret.getDot());
                if (identifierBlock != null) {
                    caret.setDot(identifierBlock[0]);
                    caret.moveDot(identifierBlock[1]);
                }
            } catch (BadLocationException e) {
                LOGGER.log(Level.WARNING, null, e);
            }
        }

        EditorFindSupport findSupport = EditorFindSupport.getInstance();
        HashMap<String, Object> props = new HashMap<>(findSupport.createDefaultFindProperties());
        String searchWord = target.getSelectedText();
        if (searchWord != null) {
            int n = searchWord.indexOf('\n');
            if (n >= 0) {
                searchWord = searchWord.substring(0, n);
            }
            props.put(EditorFindSupport.FIND_WHAT, searchWord);
            Document doc = target.getDocument();
            EditorUI eui = org.netbeans.editor.Utilities.getEditorUI(target);
            if (eui.getComponent().getClientProperty("AsTextField") == null) { //NOI18N
                findSupport.setFocusedTextComponent(eui.getComponent());
            }
            findSupport.putFindProperties(props);
            findSupport.find(null, false);

            if (caret instanceof EditorCaret) {
                EditorCaret editorCaret = (EditorCaret) caret;
                try {
                    int[] blocks = findSupport.getBlocks(new int[]{-1, -1}, doc, 0, doc.getLength());
                    if (blocks[0] >= 0 && blocks.length % 2 == 0) {
                        List<Position> newCarets = new ArrayList<>();

                        for (int i = 0; i < blocks.length; i += 2) {
                            int start = blocks[i];
                            int end = blocks[i + 1];
                            if (start == -1 || end == -1) {
                                break;
                            }
                            Position startPos = doc.createPosition(start);
                            Position endPos = doc.createPosition(end);
                            newCarets.add(endPos);
                            newCarets.add(startPos);
                        }

                        editorCaret.replaceCarets(newCarets, null); // TODO handle biases
                    }
                } catch (BadLocationException ex) {
                    Exceptions.printStackTrace(ex);
                }
            }
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:63,代码来源:AddCaretSelectAllAction.java

示例15: navigateAreas

import javax.swing.text.Caret; //导入方法依赖的package包/类
private static void navigateAreas(
    int [] origin, 
    int [] matches,
    int caretOffset,
    Object caretBias,
    Caret caret,
    boolean select
) {
    if (matches != null && matches.length >= 2) {
        int newDotBackwardIdx = -1;
        int newDotForwardIdx = -1;
        
        for(int i = 0; i < matches.length / 2; i++) {
            if (matches[i * 2] <= origin[0] && 
                (newDotBackwardIdx == -1 || matches[i * 2] > matches[newDotBackwardIdx * 2])
            ) {
                newDotBackwardIdx = i;
            }
            
            if (matches[i * 2] >= origin[1] && 
                (newDotForwardIdx == -1 || matches[i * 2] < matches[newDotForwardIdx * 2])
            ) {
                newDotForwardIdx = i;
            }
        }
        
        if (newDotBackwardIdx != -1) {
            if (select) {
                int set, move;
                
                if (caretOffset < origin[1]) {
                    set = origin[0];
                    move = matches[2 * newDotBackwardIdx + 1];
                } else {
                    set = origin[1];
                    move = matches[2 * newDotBackwardIdx];
                }

                if (caret.getDot() == caret.getMark()) { // || (move <= caret.getMark() && caret.getMark() <= set)
                    caret.setDot(set);
                }
                caret.moveDot(move);
            } else {
                if (B_BACKWARD.equalsIgnoreCase(caretBias.toString())) {
                    caret.setDot(matches[2 * newDotBackwardIdx + 1]);
                } else {
                    caret.setDot(matches[2 * newDotBackwardIdx]);
                }
            }
        } else if (newDotForwardIdx != -1) {
            if (select) {
                int set, move;

                if (caretOffset > origin[0]) {
                    set = origin[1];
                    move = matches[2 * newDotForwardIdx];
                } else {
                    set = origin[0];
                    move = matches[2 * newDotForwardIdx + 1];
                }
                
                if (caret.getDot() == caret.getMark()) { //  || (set <= caret.getMark() && caret.getMark() <= move)
                    caret.setDot(set);
                }
                caret.moveDot(move);
            } else {
                if (B_BACKWARD.equalsIgnoreCase(caretBias.toString())) {
                    caret.setDot(matches[2 * newDotForwardIdx + 1]);
                } else {
                    caret.setDot(matches[2 * newDotForwardIdx]);
                }
            }
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:76,代码来源:MasterMatcher.java


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