TextTransferable(JTextComponent c, int start, int end) { this.c = c; Document doc = c.getDocument(); try { p0 = doc.createPosition(start); p1 = doc.createPosition(end); plainData = c.getSelectedText(); } catch (BadLocationException ble) { } }
public Fold(int type, RSyntaxTextArea textArea, int startOffs) throws BadLocationException { this.type = type; this.textArea = textArea; this.startOffs = textArea.getDocument().createPosition(startOffs); }
/** * Sets the ending offset of this fold, such as the closing curly brace * of a code block in C or Java. {@link FoldParser} implementations should * call this on an existing <code>Fold</code> upon finding its end. If * this method isn't called, then this <code>Fold</code> is considered to * have no end, i.e., it will collapse everything to the end of the file. * * @param endOffs The end offset of this fold. * @throws BadLocationException If <code>endOffs</code> is not a valid * location in the text area. */ public void setEndOffset(int endOffs) throws BadLocationException { this.endOffs = textArea.getDocument().createPosition(endOffs); }
/** * Adds a special "marked occurrence" highlight. * * @param start * @param end * @param p * @return A tag to reference the highlight later. * @throws BadLocationException * @see #clearMarkAllHighlights() */ Object addMarkAllHighlight(int start, int end, HighlightPainter p) throws BadLocationException { Document doc = textArea.getDocument(); TextUI mapper = textArea.getUI(); // Always layered highlights for marked occurrences. HighlightInfoImpl i = new LayeredHighlightInfoImpl(); i.setPainter(p); i.p0 = doc.createPosition(start); // HACK: Use "end-1" to prevent chars the user types at the "end" of // the highlight to be absorbed into the highlight (default Highlight // behavior). i.p1 = doc.createPosition(end-1); markAllHighlights.add(i); mapper.damageRange(textArea, start, end); return i; }
/** * 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; }
offs); Position pos = textArea.getDocument().createPosition(offs); GutterIconImpl ti = new GutterIconImpl(icon, pos, tip); if (trackingIcons==null) {
/** * Adds a special "marked occurrence" highlight. * * @param start * @param end * @param p * @return A tag to reference the highlight later. * @throws BadLocationException * @see #clearMarkOccurrencesHighlights() */ Object addMarkedOccurrenceHighlight(int start, int end, SmartHighlightPainter p) throws BadLocationException { Document doc = textArea.getDocument(); TextUI mapper = textArea.getUI(); // Always layered highlights for marked occurrences. SyntaxLayeredHighlightInfoImpl i = new SyntaxLayeredHighlightInfoImpl(); i.setPainter(p); i.setStartOffset(doc.createPosition(start)); // HACK: Use "end-1" to prevent chars the user types at the "end" of // the highlight to be absorbed into the highlight (default Highlight // behavior). i.setEndOffset(doc.createPosition(end-1)); markedOccurrences.add(i); mapper.damageRange(textArea, start, end); return i; }
/** * Called when the document is modified. * * @param e The document event. */ @Override public void removeUpdate(DocumentEvent e) { // Keep track of the first and last offset modified. Some parsers are // smart and will only re-parse this section of the file. Note that // for removals, only the line at the removal start needs to be // re-parsed. try { int offs = e.getOffset(); if (firstOffsetModded==null || offs<firstOffsetModded.getOffset()) { firstOffsetModded = e.getDocument().createPosition(offs); } if (lastOffsetModded==null || offs>lastOffsetModded.getOffset()) { lastOffsetModded = e.getDocument().createPosition(offs); } } catch (BadLocationException ble) { // Never happens ble.printStackTrace(); } handleDocumentEvent(e); }
/** * Called when the document is modified. * * @param e The document event. */ @Override public void insertUpdate(DocumentEvent e) { // Keep track of the first and last offset modified. Some parsers are // smart and will only re-parse this section of the file. try { int offs = e.getOffset(); if (firstOffsetModded==null || offs<firstOffsetModded.getOffset()) { firstOffsetModded = e.getDocument().createPosition(offs); } offs = e.getOffset() + e.getLength(); if (lastOffsetModded==null || offs>lastOffsetModded.getOffset()) { lastOffsetModded = e.getDocument().createPosition(offs); } } catch (BadLocationException ble) { ble.printStackTrace(); // Shouldn't happen } handleDocumentEvent(e); }
public FoldInfo(Document doc, int start, int end, FoldTemplate template, boolean collapseByDefault) throws BadLocationException { this.start = doc.createPosition(start); this.end = doc.createPosition(end); this.template = template; this.collapseByDefault = collapseByDefault; }
/** * {@inheritDoc} */ @Override public Position createPosition(int offs) throws BadLocationException { return delegate.createPosition(offs); }
/** * {@inheritDoc} */ public Position createPosition(int offs) throws BadLocationException { return delegate.createPosition(offs); }
public FoldMarkInfo(boolean startMark, int offset, int length, boolean collapsed, String description) throws BadLocationException { this.startMark = startMark; this.pos = doc.createPosition(offset); this.length = length; this.collapsed = collapsed; this.description = description; }
i.setStartOffset(doc.createPosition(start)); i.setEndOffset(doc.createPosition(end-1));
TextTransferable(JTextComponent c, int start, int end) { this.c = c; Document doc = c.getDocument(); try { p0 = doc.createPosition(start); p1 = doc.createPosition(end); plainData = c.getSelectedText(); } catch (BadLocationException ble) { } }
TextTransferable(JTextComponent c, int start, int end) { this.c = c; Document doc = c.getDocument(); try { p0 = doc.createPosition(start); p1 = doc.createPosition(end); plainData = c.getSelectedText(); } catch (BadLocationException ble) { } }
public Fold(int type, RSyntaxTextArea textArea, int startOffs) throws BadLocationException { this.type = type; this.textArea = textArea; this.startOffs = textArea.getDocument().createPosition(startOffs); }
public static Position createPosition(Document doc, int offset) { try { return doc.createPosition(offset); } catch (BadLocationException ex) { throw new IndexOutOfBoundsException(ex.getMessage()); } }
private void setStartOffset(Fold fold, int startOffset, RSyntaxTextArea textArea) { try { Field field = Fold.class.getDeclaredField("startOffs"); field.setAccessible(true); field.set(fold, textArea.getDocument().createPosition(startOffset)); } catch (BadLocationException | IllegalAccessException | IllegalArgumentException | NoSuchFieldException | SecurityException excecao) { } } }
public FragmentView(Element elem, int offset, int length){ super(elem); try { Document doc = elem.getDocument(); this.startPos = doc.createPosition(super.getStartOffset() + offset); this.endPos = doc.createPosition(startPos.getOffset() + length); } catch (BadLocationException e) { ErrorManager.getDefault().notify(e); } }