private int offset(int line) { StyledDocument doc = listener.support.getDocument(); int offset = doc == null ? 0 : NbDocument.findLineOffset(doc, line); return offset; }
/** 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; }
/** 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; }
/** 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; }
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); }
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; } }
@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); } } } });
public Line getCurrent (int line) throws IndexOutOfBoundsException { int offset = NbDocument.findLineOffset (listener.doc, line); return safelyRegisterLine(createLine(offset)); }
public Line getCurrent (int line) throws IndexOutOfBoundsException { int offset = NbDocument.findLineOffset (listener.doc, line); return safelyRegisterLine(createLine(offset)); }
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() } }
public Line getOriginal (int line) throws IndexOutOfBoundsException { int newLine = listener.getLine (line); int offset = NbDocument.findLineOffset (listener.doc, newLine); return safelyRegisterLine(createLine(offset)); }
public Line getOriginal (int line) throws IndexOutOfBoundsException { int newLine = listener.getLine (line); int offset = NbDocument.findLineOffset (listener.doc, newLine); return safelyRegisterLine(createLine(offset)); }
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; }
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];
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];
/** 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); } } } }
/** 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); } } } }
/** 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); } } } }
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 (); } }
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; }