/** * Adds an icon that tracks an offset in the document, and is displayed * adjacent to the line numbers. This is useful for marking things such * as source code errors. * * @param line The line to track (zero-based). * @param icon The icon to display. This should be small (say 16x16). * @param tip An optional tool tip for the icon. * @return A tag for this icon. This can later be used in a call to * {@link #removeTrackingIcon(GutterIconInfo)} to remove this * icon. * @throws BadLocationException If <code>offs</code> is an invalid offset * into the text area. * @see #addLineTrackingIcon(int, Icon) * @see #addOffsetTrackingIcon(int, Icon) * @see #removeTrackingIcon(GutterIconInfo) */ public GutterIconInfo addLineTrackingIcon(int line, Icon icon, String tip) throws BadLocationException { int offs = textArea.getLineStartOffset(line); return addOffsetTrackingIcon(offs, icon, tip); }
/** * Returns the y-coordinate of the specified line.<p> * * The default implementation is equivalent to: * <pre> * int startOffs = textArea.getLineStartOffset(line); * return yForLineContaining(startOffs); * </pre> * * Subclasses that can calculate this value more quickly than traditional * {@link #modelToView(JTextComponent, int)} calls should override this * method to do so. This method may be used when the entire bounding box * isn't needed, to speed up rendering. * * @param line The line number. * @return The y-coordinate of the top of the line, or <code>-1</code> if * this text area doesn't yet have a positive size or the line is * hidden (i.e. from folding). * @throws BadLocationException If <code>line</code> isn't a valid line * number for this document. */ public int yForLine(int line) throws BadLocationException { int startOffs = textArea.getLineStartOffset(line); return yForLineContaining(startOffs); }
int start = textArea.getLineStartOffset(line); int end = textArea.getLineEndOffset(line); if (line==textArea.getLineCount()-1) {
/** * Highlights the specified line. * * @param line The line to highlight. * @param color The color to highlight with. * @return A tag for the highlight. * @throws BadLocationException If <code>line</code> is not a valid line * number. * @see #removeLineHighlight(Object) */ public Object addLineHighlight(int line, Color color) throws BadLocationException { int offs = textArea.getLineStartOffset(line); LineHighlightInfo lhi = new LineHighlightInfo( textArea.getDocument().createPosition(offs), color); if (lineHighlights==null) { lineHighlights = new ArrayList<LineHighlightInfo>(1); } int index = Collections.binarySearch(lineHighlights, lhi, comparator); if (index<0) { // Common case index = -(index+1); } lineHighlights.add(index, lhi); repaintLine(lhi); return lhi; }
@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 } }
int offs = textArea.getLineStartOffset(line); addOffsetTrackingIcon(offs, bookmarkIcon); return true; int offs = textArea.getLineStartOffset(line); addOffsetTrackingIcon(offs, bookmarkIcon);
int insertOffs = textArea.getLineStartOffset(insertLine); doc.insertString(insertOffs, text, null); textArea.setSelectionStart(insertOffs);
int insertOffs = textArea.getLineStartOffset(insertLine); doc.insertString(insertOffs, text, null); textArea.setSelectionStart(insertOffs);
fm.isLineHidden(line)); if (line<lineCount) { dot = textArea.getLineStartOffset(line);
int start = textArea.getLineStartOffset(line); if (offs==start) { return start-1; // Just delete the newline
int start = textArea.getLineStartOffset(line); if (offs==start) { return start;
offs = textArea.getLineStartOffset(line); textArea.setCaretPosition(offs);
/** * Adds an icon that tracks an offset in the document, and is displayed * adjacent to the line numbers. This is useful for marking things such * as source code errors. * * @param line The line to track (zero-based). * @param icon The icon to display. This should be small (say 16x16). * @return A tag for this icon. * @throws BadLocationException If <code>offs</code> is an invalid offset * into the text area. * @see #addOffsetTrackingIcon(int, Icon) * @see #removeTrackingIcon(GutterIconInfo) */ public GutterIconInfo addLineTrackingIcon(int line, Icon icon) throws BadLocationException { int offs = textArea.getLineStartOffset(line); return addOffsetTrackingIcon(offs, icon); }
/** * Adds an icon that tracks an offset in the document, and is displayed * adjacent to the line numbers. This is useful for marking things such * as source code errors. * * @param line The line to track (zero-based). * @param icon The icon to display. This should be small (say 16x16). * @return A tag for this icon. * @throws BadLocationException If <code>offs</code> is an invalid offset * into the text area. * @see #addOffsetTrackingIcon(int, Icon) * @see #removeTrackingIcon(GutterIconInfo) */ public GutterIconInfo addLineTrackingIcon(int line, Icon icon) throws BadLocationException { int offs = textArea.getLineStartOffset(line); return addOffsetTrackingIcon(offs, icon); }
/** * Returns the y-coordinate of the specified line.<p> * * The default implementation is equivalent to: * <pre> * int startOffs = textArea.getLineStartOffset(line); * return yForLineContaining(startOffs); * </pre> * * Subclasses that can calculate this value more quickly than traditional * {@link #modelToView(JTextComponent, int)} calls should override this * method to do so. This method may be used when the entire bounding box * isn't needed, to speed up rendering. * * @param line The line number. * @return The y-coordinate of the top of the line, or <code>-1</code> if * this text area doesn't yet have a positive size or the line is * hidden (i.e. from folding). * @throws BadLocationException If <code>line</code> isn't a valid line * number for this document. */ public int yForLine(int line) throws BadLocationException { int startOffs = textArea.getLineStartOffset(line); return yForLineContaining(startOffs); }
/** * Adds an icon that tracks an offset in the document, and is displayed * adjacent to the line numbers. This is useful for marking things such * as source code errors. * * @param line The line to track (zero-based). * @param icon The icon to display. This should be small (say 16x16). * @param tip An optional tool tip for the icon. * @return A tag for this icon. This can later be used in a call to * {@link #removeTrackingIcon(GutterIconInfo)} to remove this * icon. * @throws BadLocationException If <code>offs</code> is an invalid offset * into the text area. * @see #addLineTrackingIcon(int, Icon) * @see #addOffsetTrackingIcon(int, Icon) * @see #removeTrackingIcon(GutterIconInfo) */ public GutterIconInfo addLineTrackingIcon(int line, Icon icon, String tip) throws BadLocationException { int offs = textArea.getLineStartOffset(line); return addOffsetTrackingIcon(offs, icon, tip); }
/** * Highlights the specified line. * * @param line The line to highlight. * @param color The color to highlight with. * @return A tag for the highlight. * @throws BadLocationException If <code>line</code> is not a valid line * number. * @see #removeLineHighlight(Object) */ public Object addLineHighlight(int line, Color color) throws BadLocationException { int offs = textArea.getLineStartOffset(line); LineHighlightInfo lhi = new LineHighlightInfo( textArea.getDocument().createPosition(offs), color); if (lineHighlights==null) { lineHighlights = new ArrayList(1); } int index = Collections.binarySearch(lineHighlights, lhi); if (index<0) { // Common case index = -(index+1); } lineHighlights.add(index, lhi); repaintLine(lhi); return lhi; }
/** * Highlights the specified line. * * @param line The line to highlight. * @param color The color to highlight with. * @return A tag for the highlight. * @throws BadLocationException If <code>line</code> is not a valid line * number. * @see #removeLineHighlight(Object) */ public Object addLineHighlight(int line, Color color) throws BadLocationException { int offs = textArea.getLineStartOffset(line); LineHighlightInfo lhi = new LineHighlightInfo( textArea.getDocument().createPosition(offs), color); if (lineHighlights==null) { lineHighlights = new ArrayList<LineHighlightInfo>(1); } int index = Collections.binarySearch(lineHighlights, lhi, comparator); if (index<0) { // Common case index = -(index+1); } lineHighlights.add(index, lhi); repaintLine(lhi); return lhi; }
@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 } }
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 } }