/** * Invoked when an action occurs. */ public void actionPerformed(ActionEvent e) { ExTextField target = (ExTextField)getTextComponent(e); target.saveLastEntry(); Document doc = target.getDocument(); Caret caret = target.getCaret(); try { doc.remove(caret.getDot(), doc.getLength()); } catch (BadLocationException ex) { // ignore } } }
/** * Invoked when an action occurs. */ public void actionPerformed(ActionEvent e) { ExTextField target = (ExTextField)getTextComponent(e); target.saveLastEntry(); Document doc = target.getDocument(); Caret caret = target.getCaret(); int offset = SearchHelper.findNextWord(target.getText(), caret.getDot(), target.getText().length(), -1, false, false); if (logger.isDebugEnabled()) logger.debug("offset=" + offset); try { int pos = caret.getDot(); doc.remove(offset, pos - offset); } catch (BadLocationException ex) { // ignore } } }
/** * Invoked when an action occurs. */ public void actionPerformed(ActionEvent e) { ExTextField target = (ExTextField)getTextComponent(e); target.saveLastEntry(); Document doc = target.getDocument(); Caret caret = target.getCaret(); try { doc.remove(0, caret.getDot()); } catch (BadLocationException ex) { // ignore } } }
Document doc = target.getDocument(); Caret caret = target.getCaret(); int dot = caret.getDot(); int mark = caret.getMark(); if (dot != mark) {
final int dot = field.getCaret().getDot(); final int mark = field.getCaret().getMark(); if ( field.isEnabled() && field.isEditable() ) {
/** * Makes the caret's dot and mark the same location so that, for the * next search in the specified direction, a match will be found even * if it was within the original dot and mark's selection. * * @param textArea The text area. * @param forward Whether the search will be forward through the * document (<code>false</code> means backward). * @return The new dot and mark position. */ private static int makeMarkAndDotEqual(JTextArea textArea, boolean forward) { Caret c = textArea.getCaret(); int val = forward ? Math.min(c.getDot(), c.getMark()) : Math.max(c.getDot(), c.getMark()); c.setDot(val); return val; }
@Override public void mouseDragged(MouseEvent e) { // WORKAROUND: Since JTextComponent only updates the caret // location on mouse clicked and released, we'll do it on dragged // events when the left mouse button is clicked. if ((e.getModifiers() & MouseEvent.BUTTON1_MASK) != 0) { Caret caret = getCaret(); dot = caret.getDot(); mark = caret.getMark(); fireCaretUpdate(this); } }
@Override public void mousePressed(MouseEvent e) { if (e.isPopupTrigger()) { // OS X popup triggers are on pressed showPopup(e); } else if ((e.getModifiers() & MouseEvent.BUTTON1_MASK) != 0) { Caret caret = getCaret(); dot = caret.getDot(); mark = caret.getMark(); fireCaretUpdate(this); } }
@Override public void actionPerformed(ActionEvent e) { JTextComponent target = this.getTextComponent(e); if (Objects.nonNull(target) && target.isEditable()) { Caret caret = target.getCaret(); int dot = caret.getDot(); int mark = caret.getMark(); if (DefaultEditorKit.deletePrevCharAction.equals(this.getValue(Action.NAME))) { // @see javax/swing/text/DefaultEditorKit.java DeletePrevCharAction if (dot == 0 && mark == 0) { return; } } else { // @see javax/swing/text/DefaultEditorKit.java DeleteNextCharAction Document doc = target.getDocument(); if (dot == mark && doc.getLength() == dot) { return; } } } this.deleteAction.actionPerformed(e); }
Document doc = target.getDocument(); Caret caret = target.getCaret(); int dot = caret.getDot(); int mark = caret.getMark(); if (dot != mark) {
Document doc = target.getDocument(); Caret caret = target.getCaret(); int dot = caret.getDot(); int mark = caret.getMark(); if (dot != mark) {
Document doc = textArea.getDocument(); Caret caret = textArea.getCaret(); int dot = caret.getDot(); int mark = caret.getMark(); if (dot != mark) {
Document doc = textArea.getDocument(); Caret caret = textArea.getCaret(); int dot = caret.getDot(); int mark = caret.getMark(); if (dot != mark) {
if (caret.getDot()==caret.getMark()) {
@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. }
/** * 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); } }
int dot = c.getDot(); int mark = c.getMark(); int p0 = Math.min(dot, mark);
@Override public void actionPerformedImpl(ActionEvent e, RTextArea textArea) { if (!textArea.isEditable() || !textArea.isEnabled()) { UIManager.getLookAndFeel().provideErrorFeedback(textArea); return; } try { Caret c = textArea.getCaret(); int caretPos = c.getDot(); Document doc = textArea.getDocument(); Element map = doc.getDefaultRootElement(); int lineCount = map.getElementCount(); int line = map.getElementIndex(caretPos); if (line==lineCount-1) { UIManager.getLookAndFeel(). provideErrorFeedback(textArea); return; } Element lineElem = map.getElement(line); caretPos = lineElem.getEndOffset() - 1; c.setDot(caretPos); // Gets rid of any selection. doc.remove(caretPos, 1); // Should be '\n'. } catch (BadLocationException ble) { /* Shouldn't ever happen. */ ble.printStackTrace(); } textArea.requestFocusInWindow(); }
/** * {@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; }