Codota Logo
NbDocument.findLineOffset
Code IndexAdd Codota to your IDE (free)

How to use
findLineOffset
method
in
org.openide.text.NbDocument

Best Java code snippets using org.openide.text.NbDocument.findLineOffset (Showing top 20 results out of 315)

  • Add the Codota plugin to your IDE and get smart completions
private void myMethod () {
StringBuilder s =
  • Codota Iconnew StringBuilder()
  • Codota Iconnew StringBuilder(32)
  • Codota IconString str;new StringBuilder(str)
  • Smart code suggestions by Codota
}
origin: org.netbeans.api/org-openide-text

private int offset(int line) {
  StyledDocument doc = listener.support.getDocument();
  int offset = doc == null ? 0 : NbDocument.findLineOffset(doc, line);
  return offset;
}
origin: dcaoyuan/nbscala

/** return the offset of the first non-whitespace character on the line,
or -1 when the line does not exist
 */
private static int findLineOffset(StyledDocument doc, int lineNumber) {
  int offset;
  try {
    offset = NbDocument.findLineOffset(doc, lineNumber - 1);
    int offset2 = NbDocument.findLineOffset(doc, lineNumber);
    try {
      String lineStr = doc.getText(offset, offset2 - offset);
      for (int i = 0; i < lineStr.length(); i++) {
        if (!Character.isWhitespace(lineStr.charAt(i))) {
          offset += i;
          break;
        }
      }
    } catch (BadLocationException ex) {
      // ignore
    }
  } catch (IndexOutOfBoundsException ioobex) {
    return -1;
  }
  return offset;
}
origin: org.netbeans.modules/org-netbeans-modules-debugger-jpda-projectsui

/** return the offset of the first non-whitespace character on the line,
      or -1 when the line does not exist
 */
private static int findLineOffset(StyledDocument doc, int lineNumber) {
  int offset;
  try {
    offset = NbDocument.findLineOffset (doc, lineNumber - 1);
    int offset2 = NbDocument.findLineOffset (doc, lineNumber);
    try {
      String lineStr = doc.getText(offset, offset2 - offset);
      for (int i = 0; i < lineStr.length(); i++) {
        if (!Character.isWhitespace(lineStr.charAt(i))) {
          offset += i;
          break;
        }
      }
    } catch (BadLocationException ex) {
      // ignore
    }
  } catch (IndexOutOfBoundsException ioobex) {
    return -1;
  }
  return offset;
}
origin: org.netbeans.modules/org-netbeans-modules-debugger-jpda-projects

/** return the offset of the first non-whitespace character on the line,
      or -1 when the line does not exist
 */
private static int findLineOffset(StyledDocument doc, int lineNumber) {
  int offset;
  try {
    offset = NbDocument.findLineOffset (doc, lineNumber - 1);
    int offset2 = NbDocument.findLineOffset (doc, lineNumber);
    try {
      String lineStr = doc.getText(offset, offset2 - offset);
      for (int i = 0; i < lineStr.length(); i++) {
        if (!Character.isWhitespace(lineStr.charAt(i))) {
          offset += i;
          break;
        }
      }
    } catch (BadLocationException ex) {
      // ignore
    }
  } catch (IndexOutOfBoundsException ioobex) {
    return -1;
  }
  return offset;
}
origin: org.netbeans.modules/org-netbeans-modules-gsf

public static HighlightImpl parse(StyledDocument doc, String line) throws ParseException, BadLocationException {
  MessageFormat f = new MessageFormat("[{0}], {1,number,integer}:{2,number,integer}-{3,number,integer}:{4,number,integer}");
  Object[] args = f.parse(line);
  
  String attributesString = (String) args[0];
  int    lineStart  = ((Long) args[1]).intValue();
  int    columnStart  = ((Long) args[2]).intValue();
  int    lineEnd  = ((Long) args[3]).intValue();
  int    columnEnd  = ((Long) args[4]).intValue();
  
  String[] attrElements = attributesString.split(",");
  List<ColoringAttributes> attributes = new ArrayList<ColoringAttributes>();
  
  for (String a : attrElements) {
    a = a.trim();
    
    attributes.add(ColoringAttributes.valueOf(a));
  }
  
  if (attributes.contains(null))
    throw new NullPointerException();
  
  int offsetStart = NbDocument.findLineOffset(doc, lineStart) + columnStart;
  int offsetEnd = NbDocument.findLineOffset(doc, lineEnd) + columnEnd;
  
  return new HighlightImpl(doc, offsetStart, offsetEnd, attributes);
}

origin: org.netbeans.modules/org-netbeans-modules-cnd-debugger-common2

  private static int getOffset(Frame frame, StyledDocument doc) {
    try {
      int lineNumber = Integer.valueOf(frame.getLineNo());
      if (lineNumber >= 0 && doc != null) {
        return NbDocument.findLineOffset(doc, lineNumber-1);
      }
    } catch(NumberFormatException ex) {
      Exceptions.printStackTrace(ex);
    } catch (IndexOutOfBoundsException ex) {
      return doc.getLength();
    }
    return -1;
  }
}
origin: org.netbeans.modules/org-netbeans-modules-mercurial

  @Override
  public void run() {
    StyledDocument sd = (StyledDocument) doc;
    Iterator<AnnotateLine> it = lines.iterator();
    previousRevisions = Collections.synchronizedMap(new HashMap<String, HgRevision>());
    originalFiles = Collections.synchronizedMap(new HashMap<String, File>());
    elementAnnotations = Collections.synchronizedMap(new HashMap<Element, AnnotateLine>(lines.size()));
    while (it.hasNext()) {
      AnnotateLine line = it.next();
      int lineNum = ann2editorPermutation[line.getLineNum() -1];
      if (lineNum == -1) {
        continue;
      }
      try {
        int lineOffset = NbDocument.findLineOffset(sd, lineNum -1);
        Element element = sd.getParagraphElement(lineOffset);                        
        elementAnnotations.put(element, line);
      } catch (IndexOutOfBoundsException ex) {
        // TODO how could I get line behind document end?
        // furtunately user does not spot it
        Mercurial.LOG.log(Level.INFO, null, ex);
      }
    }
  }
});
origin: net.sf.squirrel-sql.thirdpary-non-maven/openide

public Line getCurrent (int line) throws IndexOutOfBoundsException {
  int offset = NbDocument.findLineOffset (listener.doc, line);
  return safelyRegisterLine(createLine(offset));
}
origin: net.sf.squirrel-sql.thirdparty-non-maven/openide

public Line getCurrent (int line) throws IndexOutOfBoundsException {
  int offset = NbDocument.findLineOffset (listener.doc, line);
  return safelyRegisterLine(createLine(offset));
}
origin: org.netbeans.api/org-openide-text

  public void run() {
    // Part of #33165 - the following code is wrapped by doc.render()
    int lineNumber = getLineNumber();
    int lineStart = NbDocument.findLineOffset(doc, lineNumber);
    // #24434: Check whether the next line exists
    // (the current one could be the last one).
    int lineEnd;
    if ((lineNumber + 1) >= NbDocument.findLineRootElement(doc).getElementCount()) {
      lineEnd = doc.getLength();
    } else {
      lineEnd = NbDocument.findLineOffset(doc, lineNumber + 1);
    }
    try {
      retStringArray[0] = doc.getText(lineStart, lineEnd - lineStart);
    } catch (BadLocationException ex) {
      Logger.getLogger(DocumentLine.class.getName()).log(Level.WARNING, null, ex);
      retStringArray[0] = null;
    }
    // End of the code wrapped by doc.render()
  }
}
origin: net.sf.squirrel-sql.thirdparty-non-maven/openide

public Line getOriginal (int line) throws IndexOutOfBoundsException {
  int newLine = listener.getLine (line);
  int offset = NbDocument.findLineOffset (listener.doc, newLine);
  return safelyRegisterLine(createLine(offset));
}
origin: net.sf.squirrel-sql.thirdpary-non-maven/openide

public Line getOriginal (int line) throws IndexOutOfBoundsException {
  int newLine = listener.getLine (line);
  int offset = NbDocument.findLineOffset (listener.doc, newLine);
  return safelyRegisterLine(createLine(offset));
}
origin: org.netbeans.api/org-netbeans-modules-languages

private static boolean isEmpty (
  int                     ln,
  StyledDocument          document,
  Set<Integer>            whitespaces
) throws BadLocationException {
  int start = NbDocument.findLineOffset (document, ln);
  int end = document.getLength ();
  try {
    end = NbDocument.findLineOffset (document, ln + 1) - 1;
  } catch (IndexOutOfBoundsException ex) {
  }
  TokenSequence ts = Utils.getTokenSequence (document, start);
  if (ts.token () == null) return true;
  while (whitespaces.contains (ts.token ().id ().ordinal ())) {
    if (!ts.moveNext ()) return true;
    if (ts.offset () > end) return true;
  }
  return false;
}
origin: net.sf.squirrel-sql.thirdpary-non-maven/openide

doc.render(new Runnable() { public void run() {
// Part of #33165 - the following code is wrapped by doc.render()
int lineNumber = getLineNumber();
int lineStart = NbDocument.findLineOffset(doc, lineNumber);
// #24434: Check whether the next line exists
// (the current one could be the last one).
int lineEnd;
if((lineNumber + 1) 
>= NbDocument.findLineRootElement(doc).getElementCount()) {
  lineEnd = doc.getLength();
} else {
  lineEnd = NbDocument.findLineOffset(doc, lineNumber + 1);
}

try {
  retStringArray[0] = doc.getText(lineStart, lineEnd - lineStart);
} catch (BadLocationException ex) {
  ErrorManager.getDefault ().notify ( ErrorManager.EXCEPTION, ex);
  retStringArray[0] = null;
}
// End of the code wrapped by doc.render()
}});
return retStringArray[0];
origin: net.sf.squirrel-sql.thirdparty-non-maven/openide

doc.render(new Runnable() { public void run() {
// Part of #33165 - the following code is wrapped by doc.render()
int lineNumber = getLineNumber();
int lineStart = NbDocument.findLineOffset(doc, lineNumber);
// #24434: Check whether the next line exists
// (the current one could be the last one).
int lineEnd;
if((lineNumber + 1) 
>= NbDocument.findLineRootElement(doc).getElementCount()) {
  lineEnd = doc.getLength();
} else {
  lineEnd = NbDocument.findLineOffset(doc, lineNumber + 1);
}

try {
  retStringArray[0] = doc.getText(lineStart, lineEnd - lineStart);
} catch (BadLocationException ex) {
  ErrorManager.getDefault ().notify ( ErrorManager.EXCEPTION, ex);
  retStringArray[0] = null;
}
// End of the code wrapped by doc.render()
}});
return retStringArray[0];
origin: org.netbeans.modules/org-netbeans-modules-debugger-jpda-projectsui

/** Add the line offset into the jump history */
private void addPositionToJumpList(String url, Line l, int column) {
  DataObject dataObject = getDataObject (url);
  if (dataObject != null) {
    EditorCookie ec = dataObject.getLookup().lookup(EditorCookie.class);
    if (ec != null) {
      try {
        StyledDocument doc = ec.openDocument();
        JEditorPane[] eps = ec.getOpenedPanes();
        if (eps != null && eps.length > 0) {
          JumpList.addEntry(eps[0], NbDocument.findLineOffset(doc, l.getLineNumber()) + column);
        }
      } catch (java.io.IOException ioex) {
        ErrorManager.getDefault().notify(ioex);
      }
    }
  }
}
origin: dcaoyuan/nbscala

/** Add the line offset into the jump history */
private void addPositionToJumpList(String url, Line l, int column) {
  DataObject dataObject = getDataObject(url);
  if (dataObject != null) {
    EditorCookie ec = dataObject.getLookup().lookup(EditorCookie.class);
    if (ec != null) {
      try {
        StyledDocument doc = ec.openDocument();
        JEditorPane[] eps = ec.getOpenedPanes();
        if (eps != null && eps.length > 0) {
          JumpList.addEntry(eps[0], NbDocument.findLineOffset(doc, l.getLineNumber()) + column);
        }
      } catch (java.io.IOException ioex) {
        ErrorManager.getDefault().notify(ioex);
      }
    }
  }
}
origin: org.netbeans.modules/org-netbeans-modules-debugger-jpda-projects

/** Add the line offset into the jump history */
private void addPositionToJumpList(String url, Line l, int column) {
  DataObject dataObject = getDataObject (url);
  if (dataObject != null) {
    EditorCookie ec = dataObject.getLookup().lookup(EditorCookie.class);
    if (ec != null) {
      try {
        StyledDocument doc = ec.openDocument();
        JEditorPane[] eps = ec.getOpenedPanes();
        if (eps != null && eps.length > 0) {
          JumpList.addEntry(eps[0], NbDocument.findLineOffset(doc, l.getLineNumber()) + column);
        }
      } catch (java.io.IOException ioex) {
        ErrorManager.getDefault().notify(ioex);
      }
    }
  }
}
origin: org.netbeans.api/org-netbeans-modules-languages

  public String toString () {
    int offset = next (1) == null ?
      doc.getLength () : next (1).getOffset ();
    int lineNumber = NbDocument.findLineNumber (doc, offset);
    return (String) doc.getProperty ("title") + ":" + 
      (lineNumber + 1) + "," + 
      (offset - NbDocument.findLineOffset (doc, lineNumber) + 1);
//        StringBuffer sb = new StringBuffer ();
//        TokenItem t = next;
//        int i = 0;
//        while (i < 10) {
//            if (t == null) break;
//            EditorToken et = (EditorToken) t.getTokenID ();
//            sb.append (Token.create (
//                et.getMimeType (),
//                et.getType (),
//                t.getImage (),
//                null
//            ));
//            t = t.getNext ();
//            i++;
//        }
//        return sb.toString ();
  }
}
origin: org.netbeans.modules/org-netbeans-modules-spring-beans

private static boolean openFileAtOffset(DataObject dataObject, int offset) throws IOException {
  EditorCookie ec = dataObject.getCookie(EditorCookie.class);
  LineCookie lc = dataObject.getCookie(LineCookie.class);
  if (ec != null && lc != null) {
    StyledDocument doc = ec.openDocument();
    if (doc != null) {
      int lineNumber = NbDocument.findLineNumber(doc, offset);
      if (lineNumber != -1) {
        Line line = lc.getLineSet().getCurrent(lineNumber);
        if (line != null) {
          int lineOffset = NbDocument.findLineOffset(doc, lineNumber);
          int column = offset - lineOffset;
          line.show(ShowOpenType.OPEN, ShowVisibilityType.FOCUS, column);
          return true;
        }
      }
    }
  }
  return false;
}
org.openide.textNbDocumentfindLineOffset

Javadoc

Finds offset of the beginning of a line.

Popular methods of NbDocument

  • findLineNumber
    For given document and an offset, find the line number.
  • findLineColumn
    Finds column number given an offset.
  • findLineRootElement
    Find the root element of all lines. All conforming NetBeans documents should return a valid element.
  • runAtomic
    Locks the document to have exclusive access to it. Documents implementing Lockable can specify exact
  • createPosition
    Creates position with a bias. If the bias is javax.swing.text.Position.Bias#Backwardthen if an inser
  • findRecentEditorPane
    Gets recently selected editor pane opened by editor cookie Can be called from AWT event thread only.
  • addAnnotation
    Add annotation to the document. For annotation of whole line the length parameter can be ignored (sp
  • removeAnnotation
    Removal of added annotation. Note: since 6.35 the requests (delegated to document) are no longer rep
  • checkDocParameter
    Helper method for checking document parameter validity.
  • findPageable
    Find a way to print a given document. If the document implements the correct interface(s) then the d
  • getDocument
    Get the document associated with a file.Method will throw org.openide.util.UserQuestionExceptionexce
  • markBreakpoint
    Attach a breakpoint to a line in the document. If the document has a defined style named #BREAKPOINT
  • getDocument,
  • markBreakpoint,
  • markCurrent,
  • markError,
  • markNormal,
  • runAtomicAsUser,
  • doOpen,
  • doShow,
  • getEditToBeUndoneRedoneOfType

Popular in Java

  • Making http post requests using okhttp
  • getSharedPreferences (Context)
  • getExternalFilesDir (Context)
  • getSystemService (Context)
  • GridBagLayout (java.awt)
    The GridBagLayout class is a flexible layout manager that aligns components vertically and horizonta
  • BufferedReader (java.io)
    Reads text from a character-input stream, buffering characters so as to provide for the efficient re
  • FileOutputStream (java.io)
    A file output stream is an output stream for writing data to aFile or to a FileDescriptor. Whether
  • Executor (java.util.concurrent)
    An object that executes submitted Runnable tasks. This interface provides a way of decoupling task s
  • HttpServletRequest (javax.servlet.http)
    Extends the javax.servlet.ServletRequest interface to provide request information for HTTP servlets.
  • Location (org.springframework.beans.factory.parsing)
    Class that models an arbitrary location in a Resource.Typically used to track the location of proble
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now