public void install(RTextArea textArea) { if (installed) { uninstall(); } textArea.addComponentListener(this); textArea.getDocument().addDocumentListener(this); textArea.addPropertyChangeListener(this); if (textArea instanceof RSyntaxTextArea) { RSyntaxTextArea rsta = (RSyntaxTextArea)textArea; rsta.addActiveLineRangeListener(this); rsta.getFoldManager().addPropertyChangeListener(this); } installed = true; }
@Test public void testRecordingMacro_happyPath() { Assert.assertFalse(RTextArea.isRecordingMacro()); RTextArea.beginRecordingMacro(); Assert.assertTrue(RTextArea.isRecordingMacro()); RTextArea.endRecordingMacro(); Assert.assertFalse(RTextArea.isRecordingMacro()); }
@Override public void actionPerformedImpl(ActionEvent e, RTextArea textArea) { if (!textArea.isEditable() || !textArea.isEnabled()) { UIManager.getLookAndFeel().provideErrorFeedback(textArea); return; } int selStart = textArea.getSelectionStart(); int selEnd = textArea.getSelectionEnd(); try { int line1 = textArea.getLineOfOffset(selStart); int startOffs = textArea.getLineStartOffset(line1); int line2 = textArea.getLineOfOffset(selEnd); int endOffs = textArea.getLineEndOffset(line2); // Don't remove the last line if no actual chars are selected if (line2>line1) { if (selEnd==textArea.getLineStartOffset(line2)) { endOffs = selEnd; } } textArea.replaceRange(null, startOffs, endOffs); } catch (BadLocationException ble) { ble.printStackTrace(); // Never happens } }
/** * Returns the line rendered at the specified location. * * @param p The location in this row header. * @return The corresponding line in the editor. * @throws BadLocationException ble If an error occurs. */ private int viewToModelLine(Point p) throws BadLocationException { int offs = textArea.viewToModel(p); return offs>-1 ? textArea.getLineOfOffset(offs) : -1; }
@Override public void actionPerformedImpl(ActionEvent e, RTextArea textArea) { if (textArea.isEnabled() && textArea.isEditable()) { textArea.redoLastAction(); textArea.requestFocusInWindow(); } }
@Override public void actionPerformedImpl(ActionEvent e, RTextArea textArea) { Document doc = textArea.getDocument(); textArea.setCaretPosition(0); textArea.moveCaretPosition(doc.getLength()); }
Rectangle visible = textArea.getVisibleRect(); Rectangle newVis = new Rectangle(visible); int selectedIndex = textArea.getCaretPosition(); int scrollAmount = textArea.getScrollableBlockIncrement( visible, SwingConstants.VERTICAL, direction); int initialY = visible.y; Caret caret = textArea.getCaret(); Point magicPosition = caret.getMagicCaretPosition(); int yOffset; Rectangle dotBounds = textArea.modelToView(selectedIndex); int x = (magicPosition != null) ? magicPosition.x : dotBounds.x; newIndex = textArea.viewToModel( new Point(x, constrainY(textArea, dotBounds.y + yOffset, 0, 0))); newIndex = textArea.viewToModel(new Point( x, newVis.y)); newIndex = textArea.viewToModel(new Point( x, newVis.y + visible.height)); newIndex); if (select) { textArea.moveCaretPosition(newIndex); textArea.setCaretPosition(newIndex);
if (count>0) { int docLen = textArea.getDocument().getLength(); Rectangle vr = textArea.getVisibleRect(); int lineHeight = textArea.getLineHeight(); int offs = lhi.getOffset(); if (offs>=0 && offs<=docLen) { int y = textArea.yForLineContaining(offs); if (y>vr.y-lineHeight) { if (y<vr.y+vr.height) { g.setColor(lhi.getColor()); g.fillRect(0,y, textArea.getWidth(),lineHeight);
throws BadLocationException { RSyntaxDocument doc = (RSyntaxDocument)textArea.getDocument(); if (offs==doc.getLength()) { return offs; int line = textArea.getLineOfOffset(offs); int end = textArea.getLineEndOffset(line); if (line!=textArea.getLineCount()-1) {
/** * Repaints the line pointed to by the specified highlight information. * * @param lhi The highlight information. */ private void repaintLine(LineHighlightInfo lhi) { int offs = lhi.getOffset(); // May be > length if they deleted text including the highlight if (offs>=0 && offs<=textArea.getDocument().getLength()) { try { int y = textArea.yForLineContaining(offs); if (y>-1) { textArea.repaint(0, y, textArea.getWidth(), textArea.getLineHeight()); } } catch (BadLocationException ble) { ble.printStackTrace(); // Never happens } } }
@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(); }
@Override public void actionPerformedImpl(ActionEvent e, RTextArea textArea) { if (!textArea.isEditable() || !textArea.isEnabled()) { UIManager.getLookAndFeel().provideErrorFeedback(textArea); return; } try { int end = textArea.getSelectionStart(); int start = getPreviousWordStart(textArea, end); if (end>start) { textArea.getDocument().remove(start, end-start); } } catch (BadLocationException ex) { UIManager.getLookAndFeel().provideErrorFeedback(textArea); } }
@Test public void testCanRedo() { RTextArea textArea = new RTextArea(); Assert.assertFalse(textArea.canRedo()); textArea.replaceSelection("Hi"); Assert.assertFalse(textArea.canRedo()); textArea.undoLastAction(); Assert.assertTrue(textArea.canRedo()); textArea.redoLastAction(); Assert.assertFalse(textArea.canRedo()); }
int curLine = textArea.getCaretLineNumber(); GutterIconInfo bookmark = bookmarks[i]; int offs = bookmark.getMarkedOffset(); int line = textArea.getLineOfOffset(offs); if (line>curLine) { moveTo = bookmark; GutterIconInfo bookmark = bookmarks[i]; int offs = bookmark.getMarkedOffset(); int line = textArea.getLineOfOffset(offs); if (line<curLine) { moveTo = bookmark; int line = textArea.getLineOfOffset(offs); offs = textArea.getLineStartOffset(line); textArea.setCaretPosition(offs);
/** * Shows a popup menu with cut, copy, paste, etc. options if the * user clicked the right button. * * @param e The mouse event that caused this method to be called. */ private void showPopup(MouseEvent e) { JPopupMenu popupMenu = getPopupMenu(); if (popupMenu!=null) { configurePopupMenu(popupMenu); popupMenu.show(e.getComponent(), e.getX(), e.getY()); e.consume(); } }
RTextArea textArea = (RTextArea)textComponent; if (RTextArea.isRecordingMacro() && isRecordable()) { int mod = e.getModifiers(); ) { String command = e.getActionCommand(); RTextArea.addToCurrentMacro(macroID, command);
/** * We override this method because the super version gives us an entirely * new <code>Document</code>, thus requiring us to re-attach our Undo * manager. With this version we just replace the text. */ @Override public void read(Reader in, Object desc) throws IOException { RTextAreaEditorKit kit = (RTextAreaEditorKit)getUI().getEditorKit(this); setText(null); Document doc = getDocument(); if (desc != null) { doc.putProperty(Document.StreamDescriptionProperty, desc); } try { // NOTE: Resets the "line separator" property. kit.read(in, doc, 0); } catch (BadLocationException e) { throw new IOException(e.getMessage()); } }
public void uninstall() { if (installed) { textArea.removeComponentListener(this); textArea.getDocument().removeDocumentListener(this); textArea.removePropertyChangeListener(this); if (textArea instanceof RSyntaxTextArea) { RSyntaxTextArea rsta = (RSyntaxTextArea)textArea; rsta.removeActiveLineRangeListener(this); rsta.getFoldManager().removePropertyChangeListener(this); } installed = false; } }
/** * Ends recording a macro. If this method is called but the text component * is not recording a macro, nothing happens. * * @see #isRecordingMacro() * @see #beginRecordingMacro() */ /* * FIXME: This should throw an exception if we're not recording a macro. */ public static synchronized void endRecordingMacro() { if (!isRecordingMacro()) { //System.err.println("Not recording a macro!"); return; } recordingMacro = false; }