本文整理汇总了Java中javax.swing.text.Caret.getDot方法的典型用法代码示例。如果您正苦于以下问题:Java Caret.getDot方法的具体用法?Java Caret.getDot怎么用?Java Caret.getDot使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.text.Caret
的用法示例。
在下文中一共展示了Caret.getDot方法的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 > 0) {
c.setDot(--dot);
// Ensure moving left hasn't moved us up a line, thus
// hiding the popup window.
if (comp.isVisible()) {
if (lastLine!=-1) {
doAutocomplete();
}
}
}
}
}
示例2: insert
import javax.swing.text.Caret; //导入方法依赖的package包/类
private static int insert(String s, JTextComponent target, Document doc)
throws BadLocationException
{
int start = -1;
try {
//at first, find selected text range
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);
//replace selected text by the inserted one
start = caret.getDot();
doc.insertString(start, s, null);
}
catch (BadLocationException ble) {}
return start;
}
示例3: computeInsertionOffset
import javax.swing.text.Caret; //导入方法依赖的package包/类
private int computeInsertionOffset(Caret caret) {
if (Utilities.isSelectionShowing(caret)) {
return Math.min(caret.getMark(), caret.getDot());
} else {
return caret.getDot();
}
}
示例4: getTokenToMark
import javax.swing.text.Caret; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public Token getTokenToMark(RSyntaxTextArea textArea) {
// Get the token at the caret position.
int line = textArea.getCaretLineNumber();
Token tokenList = textArea.getTokenListForLine(line);
Caret c = textArea.getCaret();
int dot = c.getDot();
Token t = RSyntaxUtilities.getTokenAtOffset(tokenList, dot);
if (t==null /* EOL */ || !isValidType(textArea, t) ||
RSyntaxUtilities.isNonWordChar(t)) {
// Try to the "left" of the caret.
dot--;
try {
if (dot>=textArea.getLineStartOffset(line)) {
t = RSyntaxUtilities.getTokenAtOffset(tokenList, dot);
}
} catch (BadLocationException ble) {
ble.printStackTrace(); // Never happens
}
}
return t;
}
示例5: copy
import javax.swing.text.Caret; //导入方法依赖的package包/类
private void copy() {
Caret caret = view.getCaret();
if (caret.getDot() != caret.getMark()) {
view.copy();
} else {
editorComponent.copy();
}
}
示例6: setRoundedSelectionEdges
import javax.swing.text.Caret; //导入方法依赖的package包/类
/**
* Sets whether the edges of selections are rounded in this text area.
* This method fires a property change of type
* {@link #ROUNDED_SELECTION_PROPERTY}.
*
* @param rounded Whether selection edges should be rounded.
* @see #getRoundedSelectionEdges()
*/
public void setRoundedSelectionEdges(boolean rounded) {
if (roundedSelectionEdges!=rounded) {
roundedSelectionEdges = rounded;
Caret c = getCaret();
if (c instanceof ConfigurableCaret) {
((ConfigurableCaret)c).setRoundedSelectionEdges(rounded);
if (c.getDot()!=c.getMark()) { // e.g., there's is a selection
repaint();
}
}
firePropertyChange(ROUNDED_SELECTION_PROPERTY, !rounded,
rounded);
}
}
示例7: 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.
*/
private boolean isDragPossible(MouseEvent e) {
Object src = e.getSource();
if (src instanceof JComponent) {
JComponent comp = (JComponent) src;
boolean possible = (comp == null) ? false : (comp.getTransferHandler() != null);
if (possible && comp instanceof JTextComponent) {
JTextComponent c = (JTextComponent) comp;
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;
}
示例8: setCaret
import javax.swing.text.Caret; //导入方法依赖的package包/类
/** Overrides superclass method, to keep old caret position.
* While is reinstallation of UI in progress, there
* is a gap between the uninstallUI
* and intstallUI when caret set to <code>null</code>. */
@Override
public void setCaret(Caret caret) {
if (caret == null) {
Caret oldCaret = getCaret();
if (oldCaret != null) {
lastPosition = oldCaret.getDot();
}
}
super.setCaret(caret);
}
示例9: invoke
import javax.swing.text.Caret; //导入方法依赖的package包/类
/**
* Invokes this code template. The changes are made to the given text
* area.
*
* @param textArea The text area to operate on.
* @throws BadLocationException If something bad happens.
*/
@Override
public void invoke(RSyntaxTextArea textArea) throws BadLocationException {
Caret c = textArea.getCaret();
int dot = c.getDot();
int mark = c.getMark();
int p0 = Math.min(dot, mark);
int p1 = Math.max(dot, mark);
RSyntaxDocument doc = (RSyntaxDocument)textArea.getDocument();
Element map = doc.getDefaultRootElement();
int lineNum = map.getElementIndex(dot);
Element line = map.getElement(lineNum);
int start = line.getStartOffset();
int end = line.getEndOffset()-1; // Why always "-1"?
String s = textArea.getText(start,end-start);
int len = s.length();
// endWS is the end of the leading whitespace
// of the current line.
int endWS = 0;
while (endWS<len && RSyntaxUtilities.isWhitespace(s.charAt(endWS))) {
endWS++;
}
s = s.substring(0, endWS);
p0 -= getID().length();
String beforeText = getBeforeTextIndented(s);
String afterText = getAfterTextIndented(s);
doc.replace(p0,p1-p0, beforeText+afterText, null);
textArea.setCaretPosition(p0+beforeText.length());
}
示例10: getCurrentOffset
import javax.swing.text.Caret; //导入方法依赖的package包/类
/**
* Returns number of line currently selected in editor or <code>-1</code>.
*
* @return number of line currently selected in editor or <code>-1</code>
*/
public int getCurrentOffset () {
JEditorPane ep = contextDispatcher.getCurrentEditor();
if (ep == null) {
return -1;
}
Caret caret = ep.getCaret ();
if (caret == null) {
return -1;
}
return caret.getDot();
}
示例11: focusGained
import javax.swing.text.Caret; //导入方法依赖的package包/类
@Override
public void focusGained(FocusEvent e) {
Caret c = getCaret();
boolean enabled = c.getDot()!=c.getMark();
cutAction.setEnabled(enabled);
copyAction.setEnabled(enabled);
undoManager.updateActions(); // To reflect this text area.
}
示例12: getRecentColumn
import javax.swing.text.Caret; //导入方法依赖的package包/类
public static int getRecentColumn() {
JEditorPane mostRecentEditor = EditorContextDispatcher.getDefault().getMostRecentEditor();
if (mostRecentEditor != null) {
Caret caret = mostRecentEditor.getCaret();
if (caret != null) {
int offset = caret.getDot();
try {
int rs = javax.swing.text.Utilities.getRowStart(mostRecentEditor, offset);
return offset - rs;
} catch (BadLocationException blex) {}
}
}
return 0;
}
示例13: actionPerformedImpl
import javax.swing.text.Caret; //导入方法依赖的package包/类
@Override
public void actionPerformedImpl(ActionEvent e, RTextArea textArea) {
if (!textArea.isEditable() || !textArea.isEnabled()) {
UIManager.getLookAndFeel().provideErrorFeedback(textArea);
return;
}
RSyntaxTextArea rsta = (RSyntaxTextArea)textArea;
RSyntaxDocument doc = (RSyntaxDocument)rsta.getDocument();
Caret c = rsta.getCaret();
boolean selection = c.getDot()!=c.getMark();
rsta.replaceSelection("/");
// Don't automatically complete a tag if there was a selection
int dot = c.getDot();
if (doc.getLanguageIsMarkup() &&
doc.getCompleteMarkupCloseTags() &&
!selection && rsta.getCloseMarkupTags() && dot>1) {
try {
// Check actual char before token type, since it's quicker
char ch = doc.charAt(dot-2);
if (ch=='<' || ch=='[') {
Token t = doc.getTokenListForLine(
rsta.getCaretLineNumber());
t = RSyntaxUtilities.getTokenAtOffset(t, dot-1);
if (t!=null && t.getType()==Token.MARKUP_TAG_DELIMITER) {
//System.out.println("Huzzah - closing tag!");
String tagName = discoverTagName(doc, dot);
if (tagName!=null) {
rsta.replaceSelection(tagName + (char)(ch+2));
}
}
}
} catch (BadLocationException ble) { // Never happens
UIManager.getLookAndFeel().provideErrorFeedback(rsta);
ble.printStackTrace();
}
}
}
示例14: updateComponent
import javax.swing.text.Caret; //导入方法依赖的package包/类
/** Update the component according to the given update mask
* @param target target component to be updated.
* @param updateMask mask that specifies what will be updated
*/
public void updateComponent(JTextComponent target, int updateMask) {
if (target != null && target.getDocument() instanceof BaseDocument) {
BaseDocument doc = (BaseDocument)target.getDocument();
boolean writeLocked = false;
try {
// remove selected text
if ((updateMask & SELECTION_REMOVE) != 0) {
writeLocked = true;
doc.extWriteLock();
Caret caret = target.getCaret();
if (caret != null && Utilities.isSelectionShowing(caret)) {
int dot = caret.getDot();
int markPos = caret.getMark();
if (dot < markPos) { // swap positions
int tmpPos = dot;
dot = markPos;
markPos = tmpPos;
}
try {
target.getDocument().remove(markPos, dot - markPos);
} catch (BadLocationException e) {
Utilities.annotateLoggable(e);
}
}
}
// reset magic caret position
if ((updateMask & MAGIC_POSITION_RESET) != 0) {
if (target.getCaret() != null)
target.getCaret().setMagicCaretPosition(null);
}
// reset merging of undoable edits
if ((updateMask & UNDO_MERGE_RESET) != 0) {
doc.resetUndoMerge();
}
// reset word matching
if ((updateMask & WORD_MATCH_RESET) != 0) {
((BaseTextUI)target.getUI()).getEditorUI().getWordMatch().clear();
}
// Clear status bar text
if (!recording && (updateMask & CLEAR_STATUS_TEXT) != 0) {
Utilities.clearStatusText(target);
}
// Save current caret position in the jump-list
if ((updateMask & SAVE_POSITION) != 0) {
JumpList.checkAddEntry(target);
}
} finally {
if (writeLocked) {
doc.extWriteUnlock();
}
}
}
}
示例15: actionPerformed
import javax.swing.text.Caret; //导入方法依赖的package包/类
public void actionPerformed(ActionEvent evt) {
Caret c = caret;
JTextComponent component = editorUI.getComponent();
// Also check whether the component is last focused since when undocking an editor
// all the components' carets fire this listener and so invalid component's
// data would get displayed in the global status bar.
if (component != null && component == EditorRegistry.lastFocusedComponent()) {
if (c != null) {
BaseDocument doc = Utilities.getDocument(component);
if (doc != null && doc.getDefaultRootElement().getElementCount()>0) {
int pos = c.getDot();
String s = Utilities.debugPosition(doc, pos, ":");
if (CARET_OFFSET_LOG.isLoggable(Level.FINE)) { // Possibly add caret offset info
s += " <" + pos + ">"; // NOI18N
}
int countOfSelectedChars = component.getSelectionEnd() - component.getSelectionStart();
final boolean hasSelection = countOfSelectedChars > 0;
if (hasSelection) {
try {
//count of selected lines
int lineEnd = Utilities.getLineOffset(doc, component.getSelectionEnd());
int lineStart = Utilities.getLineOffset(doc, component.getSelectionStart());
s += "/" + (lineEnd - lineStart + 1);
} catch (BadLocationException ex) {
}
//count of selected characters
s += ":" + countOfSelectedChars;
}
//rows:cols/countRows:countCols
setText(CELL_POSITION, s);
}
}
Boolean b = (Boolean)editorUI.getProperty(EditorUI.OVERWRITE_MODE_PROPERTY);
boolean om = (b != null && b.booleanValue());
if (om != overwriteModeDisplayed) {
overwriteModeDisplayed = om;
setText(CELL_TYPING_MODE, overwriteModeDisplayed ? ovrText : insText);
}
}
}