/** * Sets the style of caret used when in insert or overwrite mode. * * @param mode Either {@link #INSERT_MODE} or {@link #OVERWRITE_MODE}. * @param style The style for the caret. * @see ConfigurableCaret */ public void setCaretStyle(int mode, CaretStyle style) { if (style==null) { style = CaretStyle.THICK_VERTICAL_LINE_STYLE; } carets[mode] = style; if (mode==getTextMode() && getCaret() instanceof ConfigurableCaret) { // Will repaint the caret if necessary. ((ConfigurableCaret)getCaret()).setStyle(style); } }
int mark = textArea.getCaret().getMark(); Document doc = textArea.getDocument(); Element root = doc.getDefaultRootElement();
@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); } }
visible, SwingConstants.VERTICAL, direction); int initialY = visible.y; Caret caret = textArea.getCaret(); Point magicPosition = caret.getMagicCaretPosition(); int yOffset;
@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); } }
/** * (Possibly) toggles the "always visible" state of the text area's * caret. * * @param visible Whether this popup window was just made visible (as * opposed to hidden). */ private void updateTextAreaCaret(boolean visible) { Caret caret = textArea.getCaret(); if (caret instanceof ConfigurableCaret) { // Always true by default ConfigurableCaret cc = (ConfigurableCaret)caret; if (visible) { prevCaretAlwaysVisible = cc.isAlwaysVisible(); cc.setAlwaysVisible(true); } else { cc.setAlwaysVisible(prevCaretAlwaysVisible); } } }
try { Document doc = textArea.getDocument(); Caret caret = textArea.getCaret(); int dot = caret.getDot(); int mark = caret.getMark();
try { Document doc = textArea.getDocument(); Caret caret = textArea.getCaret(); int dot = caret.getDot(); int mark = caret.getMark();
/** * Sets the text mode for this editor pane. If the currently installed * caret is an instance of {@link ConfigurableCaret}, it will be * automatically updated to render itself appropriately for the new text * mode. * * @param mode Either {@link #INSERT_MODE} or {@link #OVERWRITE_MODE}. * @see #getTextMode() */ public void setTextMode(int mode) { if (mode!=INSERT_MODE && mode!=OVERWRITE_MODE) { mode = INSERT_MODE; } if (textMode != mode) { Caret caret = getCaret(); if (caret instanceof ConfigurableCaret) { ((ConfigurableCaret)caret).setStyle(carets[mode]); } textMode = mode; // Prevent the caret from blinking while e.g. holding down the // Insert key to toggle insert/overwrite modes caret.setVisible(false); caret.setVisible(true); } }
Caret caret = textArea.getCaret(); 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. }
Caret caret = getCaret(); int caretPos = caret.getDot(); Document doc = getDocument();
Caret c = textArea.getCaret(); int dot = c.getDot(); int mark = c.getMark();
Caret c = textArea.getCaret(); int dot = c.getDot(); int mark = c.getMark();
@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(); }
Caret c = textArea.getCaret(); int dot = c.getDot(); int mark = c.getMark();
@Override public void actionPerformedImpl(ActionEvent e, RTextArea textArea) { Caret caret = textArea.getCaret(); int dot = caret.getDot();
Caret c = textArea.getCaret(); boolean forward = context.getSearchForward(); int start = makeMarkAndDotEqual(textArea, forward);
@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); } }