Refine search
private boolean getDoAdd(Document doc, Element map, int startLine, int endLine, String[] startEnd) throws BadLocationException { boolean doAdd = false; for (int i=startLine; i<=endLine; i++) { Element elem = map.getElement(i); int start = elem.getStartOffset(); String t = doc.getText(start, elem.getEndOffset()-start-1); if (!t.startsWith(startEnd[0]) || (startEnd[1]!=null && !t.endsWith(startEnd[1]))) { doAdd = true; break; } } return doAdd; }
private static Element getLineElem(Document d, int offs) { Element map = d.getDefaultRootElement(); int index = map.getElementIndex(offs); Element elem = map.getElement(index); if ((offs>=elem.getStartOffset()) && (offs<elem.getEndOffset())) { return elem; } return null; }
private void handleToggleComment(Element elem, Document doc, String[] startEnd, boolean add) throws BadLocationException { int start = elem.getStartOffset(); int end = elem.getEndOffset() - 1; if (add) { if (startEnd[1]!=null) { doc.insertString(end, startEnd[1], null); } doc.insertString(start, startEnd[0], null); } else { if (startEnd[1]!=null) { int temp = startEnd[1].length(); doc.remove(end-temp, temp); } doc.remove(start, startEnd[0].length()); } }
@Override protected int getWordEnd(RTextArea textArea, int offs) throws BadLocationException { RSyntaxDocument doc = (RSyntaxDocument)textArea.getDocument(); Element root = doc.getDefaultRootElement(); int line = root.getElementIndex(offs); Element elem = root.getElement(line); int end = elem.getEndOffset() - 1; int wordEnd = offs; while (wordEnd <= end) { if (!isIdentifierChar(doc.charAt(wordEnd))) { break; } wordEnd++; } return wordEnd; }
private void removeFromStart(Document document, Element root, int excess) { Element line = root.getElement(excess - 1); int end = line.getEndOffset(); try { document.remove(0, end); } catch (BadLocationException ble) { System.out.println(ble); } }
public int getLineOfOffset(final JTextComponent textComponent, final int line) throws BadLocationException { final Document doc = textComponent.getDocument(); final int lineCount = doc.getDefaultRootElement().getElementCount(); if (line < 0) { throw new BadLocationException("Negative line", -1); } else if (line > lineCount) { throw new BadLocationException("No such line", doc.getLength() + 1); } else { Element map = doc.getDefaultRootElement(); Element lineElem = map.getElement(line); return lineElem.getEndOffset(); } }
/** * Returns the leading whitespace of a specific line in a document. * * @param doc The document. * @param offs The offset whose line to get the leading whitespace for. * @return The leading whitespace. * @throws BadLocationException If <code>offs</code> is not a valid offset * in the document. * @see #getLeadingWhitespace(String) */ public static String getLeadingWhitespace(Document doc, int offs) throws BadLocationException { Element root = doc.getDefaultRootElement(); int line = root.getElementIndex(offs); Element elem = root.getElement(line); int startOffs = elem.getStartOffset(); int endOffs = elem.getEndOffset() - 1; String text = doc.getText(startOffs, endOffs-startOffs); return getLeadingWhitespace(text); }
/** * Makes our private <code>Segment s</code> point to the text in our * document referenced by the specified element. Note that * <code>line</code> MUST be a valid line number in the document. * * @param line The line number you want to get. */ private void setSharedSegment(int line) { Element map = getDefaultRootElement(); //int numLines = map.getElementCount(); Element element = map.getElement(line); if (element==null) { throw new InternalError("Invalid line number: " + line); } int startOffset = element.getStartOffset(); //int endOffset = (line==numLines-1 ? // element.getEndOffset()-1 : element.getEndOffset() - 1); int endOffset = element.getEndOffset()-1; // Why always "-1"? try { getText(startOffset, endOffset-startOffset, s); } catch (BadLocationException ble) { throw new InternalError("Text range not in document: " + startOffset + "-" + endOffset); } }
int tabSize) throws BadLocationException { int start = elem.getStartOffset(); int end = elem.getEndOffset() - 1; // Why always true?? doc.getText(start,end-start, s); int i = s.offset;
@Override public void actionPerformedImpl(ActionEvent e, RTextArea textArea) { try { // We use the elements instead of calling getLineOfOffset(), // etc. to speed things up just a tad (i.e. micro-optimize). Document document = textArea.getDocument(); int caretPosition = textArea.getCaretPosition(); Element map = document.getDefaultRootElement(); int currentLineNum = map.getElementIndex(caretPosition); Element currentLineElement = map.getElement(currentLineNum); // Always take -1 as we don't want to remove the newline. int currentLineEnd = currentLineElement.getEndOffset()-1; if (caretPosition<currentLineEnd) { document.remove(caretPosition, currentLineEnd-caretPosition); } } catch (BadLocationException ble) { ble.printStackTrace(); } }
private void removeFromStart(Document document, Element root) { Element line = root.getElement(0); int end = line.getEndOffset(); try { document.remove(0, end); } catch (BadLocationException ble) { System.out.println(ble); } }
public int getLineOfOffset(final JTextComponent textComponent, final int line) throws BadLocationException { final Document doc = textComponent.getDocument(); final int lineCount = doc.getDefaultRootElement().getElementCount(); if (line < 0) { throw new BadLocationException("Negative line", -1); } else if (line > lineCount) { throw new BadLocationException("No such line", doc.getLength() + 1); } else { Element map = doc.getDefaultRootElement(); Element lineElem = map.getElement(line); return lineElem.getEndOffset(); } }
private void doError(SAXParseException e, ParserNotice.Level level) { int line = e.getLineNumber() - 1; Element root = doc.getDefaultRootElement(); Element elem = root.getElement(line); int offs = elem.getStartOffset(); int len = elem.getEndOffset() - offs; if (line==root.getElementCount()-1) { len++; } DefaultParserNotice pn = new DefaultParserNotice(XmlParser.this, e.getMessage(), line, offs, len); pn.setLevel(level); result.addNotice(pn); }
/** * Returns whether a parser notice contains the specified offset. * * @param notice The notice. * @param offs The offset. * @return Whether the notice contains the offset. */ private boolean noticeContainsPosition(ParserNotice notice, int offs){ if (notice.getKnowsOffsetAndLength()) { return notice.containsPosition(offs); } Document doc = textArea.getDocument(); Element root = doc.getDefaultRootElement(); int line = notice.getLine(); if (line<0) { // Defensive against possible bad user-defined notices. return false; } Element elem = root.getElement(line); return elem != null && offs>=elem.getStartOffset() && offs<elem.getEndOffset(); }
if(offs < curPara.getStartOffset()) { offs = Utilities.getParagraphElement(textArea, offs). getEndOffset() - 1;
@Override public void actionPerformedImpl(ActionEvent e, RTextArea textArea) { int offs = textArea.getCaretPosition(); int endOffs = 0; try { if (textArea.getLineWrap()) { // Must check per character, since one logical line may be // many physical lines. // FIXME: Replace Utilities call with custom version to // cut down on all of the modelToViews, as each call causes // a getTokenList => expensive! endOffs = Utilities.getRowEnd(textArea, offs); } else { Element root = textArea.getDocument().getDefaultRootElement(); int line = root.getElementIndex(offs); endOffs = root.getElement(line).getEndOffset() - 1; } if (select) { textArea.moveCaretPosition(endOffs); } else { textArea.setCaretPosition(endOffs); } } catch (Exception ex) { UIManager.getLookAndFeel().provideErrorFeedback(textArea); } }
private void removeFromStart(Document document, Element root) { Element line = root.getElement(0); int end = line.getEndOffset(); try { document.remove(0, end); } catch (BadLocationException ble) { System.out.println(ble); } }
private void removeLines() { Element root = getDocument().getDefaultRootElement(); while (root.getElementCount() > maxLines) { Element firstLine = root.getElement(0); try { getDocument().remove(0, firstLine.getEndOffset()); } catch (BadLocationException ble) { ble.printStackTrace(); } } } }
Element root = doc.getDefaultRootElement(); int line = root.getElementIndex(offs); Element elem = root.getElement(line); int start = elem.getStartOffset(); if (offs > start) { char ch = doc.charAt(offs); return -1; elem = root.getElement(--line); offs = elem.getEndOffset() - 1; while (prevWordStart == -1 && line > 0) { line--; elem = root.getElement(line); prevWordStart = getPreviousWordStartInLine(doc, elem, elem.getEndOffset());
Element elem = root.getElement(line); int start = elem.getStartOffset(); elem = root.getElement(endLine); int end = elem.getEndOffset(); int lineCount = textArea.getLineCount(); boolean movingLastLine = false;