public int getLine(boolean create) { if (create && this.line == -1 && this.doc != null) { try { this.line = Utilities.getLineOffset(this.doc, this.offset) + 1; } catch (BadLocationException ex) { this.line = -1; } } return this.line; }
public int getElementIndex(int offset) { try { return Utilities.getLineOffset(BaseDocument.this, offset); } catch (BadLocationException e) { return 0; } }
public static boolean isVeryBigDocument(Document doc) { if (!(doc instanceof BaseDocument) || MAX_LINE_NUMBER < 0) { return false; } try { if (doc.getLength() < MAX_LINE_NUMBER) { return false; } return Utilities.getLineOffset((BaseDocument)doc, doc.getLength() - 1) > MAX_LINE_NUMBER; } catch (BadLocationException ex) { // skip return true; } }
/** 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; }
/** Return number of lines in the document */ protected int getLineCount() { int lineCnt; try { if (doc != null) { lineCnt = Utilities.getLineOffset(doc, doc.getLength()) + 1; } else { // deactivated lineCnt = 1; } } catch (BadLocationException e) { lineCnt = 1; } return lineCnt; }
/** * Returns line index (line number - 1) of the last import statement or {@literal -1} * if no import statement was found within this in {@link BaseDocument}. * * @param doc document * @return line index (line number - 1) of the last import statement or {@literal -1} * if no import statement was found within this {@link BaseDocument}. */ private static int getLastImportLineIndex(BaseDocument doc) { try { int lastImportOffset = getLastImportStatementOffset(doc); if (lastImportOffset != -1) { return Utilities.getLineOffset(doc, lastImportOffset); } } catch (BadLocationException ex) { Exceptions.printStackTrace(ex); } return -1; }
/** * Returns line index (line number - 1) of the package statement or {@literal -1} * if no package statement was found within this in {@link BaseDocument}. * * @param doc document * @return line index (line number - 1) of the package statement or {@literal -1} * if no package statement was found within this {@link BaseDocument}. */ private static int getPackageLineIndex(BaseDocument doc) { try { int lastPackageOffset = getLastPackageStatementOffset(doc); if (lastPackageOffset != -1) { return Utilities.getLineOffset(doc, lastPackageOffset); } } catch (BadLocationException ex) { Exceptions.printStackTrace(ex); } return -1; }
private int getLineFromMouseEvent(MouseEvent e){ int line = -1; if (editorUI != null) { try{ JTextComponent component = editorUI.getComponent(); BaseTextUI textUI = (BaseTextUI)component.getUI(); int clickOffset = textUI.viewToModel(component, new Point(0, e.getY())); line = Utilities.getLineOffset(doc, clickOffset); }catch (BadLocationException ble){ } } return line; }
/** GlyphGutter copy pasted utility method. */ private int getLineFromMouseEvent(MouseEvent e){ int line = -1; if (editorUI != null) { try{ JTextComponent component = editorUI.getComponent(); BaseTextUI textUI = (BaseTextUI)component.getUI(); int clickOffset = textUI.viewToModel(component, new Point(0, e.getY())); line = Utilities.getLineOffset(doc, clickOffset); }catch (BadLocationException ble){ } } return line; }
public static String debugPosition(BaseDocument doc, int offset) { String ret; if (offset >= 0) { try { int line = getLineOffset(doc, offset) + 1; int col = getVisualColumn(doc, offset) + 1; ret = String.valueOf(line) + ":" + String.valueOf(col); // NOI18N } catch (BadLocationException e) { ret = LocaleSupport.getString(WRONG_POSITION_LOCALE) + ' ' + offset + " > " + doc.getLength(); // NOI18N } } else { ret = String.valueOf(offset); } return ret; }
public static String debugPosition(BaseDocument doc, int offset) { String ret; if (offset >= 0) { try { int line = getLineOffset(doc, offset) + 1; int col = getVisualColumn(doc, offset) + 1; ret = String.valueOf(line) + ":" + String.valueOf(col); // NOI18N } catch (BadLocationException e) { ret = LocaleSupport.getString( WRONG_POSITION_LOCALE ) + ' ' + offset + " > " + doc.getLength(); // NOI18N } } else { ret = String.valueOf(offset); } return ret; }
private int tryCountLines(Block block) throws BadLocationException { int searchOffset = block.getStartOffset() + 1; int firstNonWhiteFwd = Utilities.getFirstNonWhiteFwd(baseDocument, searchOffset); int startLineOffset = Utilities.getLineOffset(baseDocument, firstNonWhiteFwd == -1 ? searchOffset : firstNonWhiteFwd); int endLineOffset = Utilities.getLineOffset(baseDocument, Utilities.getFirstNonWhiteBwd(baseDocument, block.getEndOffset())); return countLinesBetweenLineOffsets(startLineOffset, endLineOffset); }
@SuppressWarnings("unchecked") private PPBlockInfo getBlock(final JTextComponent component) { try { final BaseDocument doc = (BaseDocument) component.getDocument(); final int lineNumber = Utilities.getLineOffset(doc, component.getCaret().getDot()); final ArrayList<PPLine> lineList = (ArrayList) doc.getProperty(DocumentPreprocessor.PREPROCESSOR_LINE_LIST); if (lineList != null) { PPLine myPpLine = null; if (lineNumber >= 0 && lineNumber < lineList.size()) { myPpLine = lineList.get(lineNumber); if (myPpLine != null) return myPpLine.getBlock(); } } } catch (BadLocationException ble) { } return null; }
/** Repaint whole gutter. */ public void changedAll() { if (!init) return; // reset cache if there was some change cachedCountOfAnnos = -1; int lineCnt; try { lineCnt = Utilities.getLineOffset(doc, doc.getLength()) + 1; } catch (BadLocationException e) { lineCnt = 1; } repaint(); checkSize(); }
/** Repaint whole gutter.*/ public void changedAll() { if (!init || editorUI == null) return; // reset cache if there was some change cachedCountOfAnnos = -1; int lineCnt; try { lineCnt = Utilities.getLineOffset(doc, doc.getLength()) + 1; } catch (BadLocationException e) { lineCnt = 1; } repaint(); checkSize(); }
public void actionPerformed(ActionEvent evt, JTextComponent target) { if (target != null) { try { Caret caret = target.getCaret(); BaseDocument doc = Utilities.getDocument(target); int caretLine = Utilities.getLineOffset(doc, caret.getDot()); AnnotationDesc aDesc = doc.getAnnotations().activateNextAnnotation(caretLine); } catch (BadLocationException e) { e.printStackTrace(); } } } }
public void actionPerformed(ActionEvent evt, JTextComponent target) { if (target != null) { try { Caret caret = target.getCaret(); BaseDocument doc = Utilities.getDocument(target); int caretLine = Utilities.getLineOffset(doc, caret.getDot()); AnnotationDesc aDesc = doc.getAnnotations().activateNextAnnotation(caretLine); } catch (BadLocationException e) { e.printStackTrace(); } } } }
public JMenuItem getPopupMenuItem(JTextComponent target) { EditorUI ui = Utilities.getEditorUI(target); try { return ui.getDocument().getAnnotations().createMenu(Utilities.getKit(target), Utilities.getLineOffset(ui.getDocument(),target.getCaret().getDot())); } catch (BadLocationException ex) { return null; } }
public JMenuItem getPopupMenuItem(JTextComponent target) { EditorUI ui = Utilities.getEditorUI(target); try { return ui.getDocument().getAnnotations().createMenu(Utilities.getKit(target), Utilities.getLineOffset(ui.getDocument(), target.getCaret().getDot())); } catch (BadLocationException ex) { return null; } }
/** Get y coordinate from position. * The position can lay anywhere inside this view. */ protected int getYFromPos(int pos) throws BadLocationException { int relLine = 0; try { relLine = Utilities.getLineOffset(((BaseDocument)getDocument()), pos) - ((BaseElement)getElement()).getStartMark().getLine(); } catch (InvalidMarkException e) { Utilities.annotateLoggable(e); } return getStartY() + ((insets != null) ? insets.top : 0) + relLine * getEditorUI().getLineHeight(); }