本文整理了Java中org.netbeans.editor.Utilities.getLineOffset()
方法的一些代码示例,展示了Utilities.getLineOffset()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Utilities.getLineOffset()
方法的具体详情如下:
包路径:org.netbeans.editor.Utilities
类名称:Utilities
方法名:getLineOffset
[英]Return line offset (line number - 1) for some position in the document
[中]文档中某个位置的返回行偏移量(行号-1)
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-cnd-completion
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;
}
代码示例来源:origin: net.java.abeille/abeille
public int getElementIndex(int offset) {
try {
return Utilities.getLineOffset(BaseDocument.this, offset);
} catch (BadLocationException e) {
return 0;
}
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-cnd-highlight
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;
}
}
代码示例来源:origin: net.java.abeille/abeille
/** 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;
}
代码示例来源:origin: net.sf.squirrel-sql.thirdparty-non-maven/org-netbeans-modules-editor-lib
/** 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;
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-groovy-editor
/**
* 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;
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-groovy-editor
/**
* 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;
}
代码示例来源:origin: net.sf.squirrel-sql.thirdparty-non-maven/org-netbeans-modules-editor-lib
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;
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-mercurial
/** 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;
}
代码示例来源:origin: net.java.abeille/abeille
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;
}
代码示例来源:origin: net.sf.squirrel-sql.thirdparty-non-maven/org-netbeans-modules-editor-lib
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;
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-php-editor
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);
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-mobility-editor
@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;
}
代码示例来源:origin: net.java.abeille/abeille
/** 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();
}
代码示例来源:origin: net.sf.squirrel-sql.thirdparty-non-maven/org-netbeans-modules-editor-lib
/** 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();
}
代码示例来源:origin: net.sf.squirrel-sql.thirdparty-non-maven/org-netbeans-modules-editor-lib
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();
}
}
}
}
代码示例来源:origin: net.java.abeille/abeille
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();
}
}
}
}
代码示例来源:origin: net.sf.squirrel-sql.thirdparty-non-maven/org-netbeans-modules-editor-lib
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;
}
}
代码示例来源:origin: net.java.abeille/abeille
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;
}
}
代码示例来源:origin: net.sf.squirrel-sql.thirdparty-non-maven/org-netbeans-modules-editor-lib
/** 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();
}
内容来源于网络,如有侵权,请联系作者删除!