/** Return default root element */ public Element getDefaultRootElement() { if (defaultRootElem == null) { defaultRootElem = new org.netbeans.editor.LeafElement(this, null, null, 0, getLength(), false, false); } return defaultRootElem; }
public void run() { try { reformat.reformat(0, doc.getLength()); } catch (BadLocationException x) { throw new RuntimeException(x); } } });
@Override public void run() { try { reformat.reformat(0, document.getLength()); } catch (BadLocationException ex) { bleRef.set(ex); } }
/** Return number of lines in the document */ protected int getLineCount() { int lineCnt; try { lineCnt = Utilities.getLineOffset(doc, doc.getLength()) + 1; } catch (BadLocationException e) { lineCnt = 1; } return lineCnt; }
/** Get position of wrap mark for some document */ public int getWrapSearchMarkPos(BaseDocument doc) { Mark mark = (Mark) doc.getProperty(BaseDocument.WRAP_SEARCH_MARK_PROP); try { return (mark != null) ? mark.getOffset() : doc.getLength(); } catch (InvalidMarkException e) { throw new RuntimeException(); // shouldn't happen } }
@Override public void run() { try { reformat.reformat(0, baseDoc.getLength()); } catch (BadLocationException ex) { LOGGER.log(Level.INFO, "Cannot reformat file " + dataObject.getName(), ex); } } });
/** Get position of wrap mark for some document */ public int getWrapSearchMarkPos(BaseDocument doc) { Mark mark = (Mark)doc.getProperty(BaseDocument.WRAP_SEARCH_MARK_PROP); try { return (mark != null) ? mark.getOffset() : doc.getLength(); } catch (InvalidMarkException e) { throw new RuntimeException(); // shouldn't happen } }
@Override public void run() { try { //TODO apply just changes via diff! document.remove(0, document.getLength()); document.insertString(0, newContent, null); } catch (BadLocationException ex) { bleRef.set(ex); } }
/** Get the position of the global declaration of a given variable. * By default it's implemented to use the same token processor as for the local * variables but the whole file is searched. */ public int findGlobalDeclarationPosition(String varName, int varPos) { return findDeclarationPositionImpl(varName, 0, getDocument().getLength()); }
/** * The same as braceBalance but generalized to any pair of matching * tokens. * @param open the token that increses the count * @param close the token that decreses the count */ private static int tokenBalance(BaseDocument doc, CppTokenId open, CppTokenId close, int caretOffset) throws BadLocationException { BalanceTokenProcessor tp = new BalanceTokenProcessor(open, close); CndTokenUtilities.processTokens(tp, doc, 0, doc.getLength()); return tp.getBalance(); }
/** * Get the position of the global declaration of a given variable. By * default it's implemented to use the same token processor as for the local * variables but the whole file is searched. */ public int findGlobalDeclarationPosition(String varName, int varPos) { return findDeclarationPositionImpl(varName, 0, getDocument().getLength()); }
public static int getNextWord(BaseDocument doc, int offset) throws BadLocationException { Finder nextWordFinder = (Finder) doc.getProperty(SettingsNames.NEXT_WORD_FINDER); offset = doc.find(nextWordFinder, offset, -1); if (offset < 0) { offset = doc.getLength(); } return offset; }
public static int getWordEnd(BaseDocument doc, int offset) throws BadLocationException { int ret = doc.find(new FinderFactory.NextWordFwdFinder(doc, false, true), offset, -1); return (ret > 0) ? ret : doc.getLength(); }
private String showAssertionFor188809() { String result = ""; try { result = "The same token (index: " + ts.index() + " - " + ts.token().id() + ", format tokens: " + formatTokens.size() //NOI18N + ") was precessed before.\nPlease report this to help fix issue 188809.\n\n" //NOI18N + document.getText(0, document.getLength() - 1); } catch (BadLocationException ex) { Exceptions.printStackTrace(ex); } return result; }
/** Notify view that it is necessary to redraw the line of the document */ protected void refreshLine(int line) { fireChangedLine(line); int start = Utilities.getRowStartFromLineOffset(doc, line); int end = Utilities.getRowStartFromLineOffset(doc, line+1); if (end == -1) end = doc.getLength(); doc.repaintBlock(start, end); }
/** Gets the token-id of the token at the given position. * @param offset position at which the token should be returned * @return token-id of the token at the requested position. If there's no more * tokens in the text, the <tt>Syntax.INVALID</tt> is returned. */ public TokenID getTokenID(int offset) throws BadLocationException { FirstTokenTP fttp = new FirstTokenTP(); tokenizeText(fttp, offset, getDocument().getLength(), true); return fttp.getTokenID(); }
/** Return line offset (line number - 1) for some position in the document * @param doc document to operate on * @param offset position in document where to start searching */ public static int getLineOffset(BaseDocument doc, int offset) throws BadLocationException { checkOffsetValid(offset, doc.getLength() + 1); Element lineRoot = doc.getParagraphElement(0).getParentElement(); return lineRoot.getElementIndex(offset); }
private void findSupportChange(PropertyChangeEvent evt) { // set all finders to null putProperty(STRING_FINDER_PROP, null); putProperty(STRING_BWD_FINDER_PROP, null); putProperty(BLOCKS_FINDER_PROP, null); DrawLayerFactory.HighlightSearchLayer hsl = (DrawLayerFactory.HighlightSearchLayer) findLayer(DrawLayerFactory.HIGHLIGHT_SEARCH_LAYER_NAME); Boolean b = (Boolean) FindSupport.getFindSupport().getPropertyNoInit(SettingsNames.FIND_HIGHLIGHT_SEARCH); hsl.setEnabled((b != null) ? b.booleanValue() : false); fireChangedUpdate(createDocumentEvent(0, getLength(), DocumentEvent.EventType.CHANGE)); // refresh // whole // document }
public void print(PrintContainer container) { readLock(); try { EditorUI editorUI = BaseKit.getKit(kitClass).createPrintEditorUI(this); DrawGraphics.PrintDG printDG = new DrawGraphics.PrintDG(container); DrawEngine.getDrawEngine().draw(printDG, editorUI, 0, getLength(), 0, 0, Integer.MAX_VALUE); } catch (BadLocationException e) { e.printStackTrace(); } finally { readUnlock(); } }
public void modelToViewDG(int pos, DrawGraphics dg) throws BadLocationException { EditorUI editorUI = getEditorUI(); BaseDocument doc = (BaseDocument)getDocument(); if (pos < 0 || pos > doc.getLength()) { throw new BadLocationException("Invalid offset", pos); // NOI18N } int y = getYFromPos(pos); Element lineElement = doc.getParagraphElement(pos); DrawEngine.getDrawEngine().draw(dg, editorUI, lineElement.getStartOffset(), lineElement.getEndOffset() - 1, getBaseX(y), y, pos); }