public static Line getLine(final FileObject fileObject, final int lineNumber) { if (fileObject != null) { LineCookie lineCookie = JSUtils.getLineCookie(fileObject); if (lineCookie != null) { Line.Set ls = lineCookie.getLineSet(); if (ls != null) { try { return ls.getCurrent(lineNumber - 1); } catch (IndexOutOfBoundsException ioob) { List<? extends Line> lines = ls.getLines(); if (lines.size() > 0) { return lines.get(lines.size() - 1); } else { return null; } } } } } return null; }
public Line getLine(EditorCookie editorCookie) { Line.Set lineSet = editorCookie.getLineSet(); int effectiveLineNumber = getLineNumber() <= 0 ? 1 : getLineNumber(); int index = Math.min(effectiveLineNumber, lineSet.getLines().size()) - 1; return lineSet.getCurrent(index); }
@Override public void setLineNumber(int lineNumber) { lineNumber--; // Line works with 0-based lines. if (line.getLineNumber() == lineNumber) { return ; } LineCookie lineCookie = line.getLookup().lookup(LineCookie.class); Line.Set lineSet = lineCookie.getLineSet(); List<? extends Line> lines = lineSet.getLines(); if (lines.size() > 0) { int lastLineNumber = lines.get(lines.size() - 1).getLineNumber(); if (lineNumber > lastLineNumber) { lineNumber = lastLineNumber; } } Line cline; try { cline = lineSet.getCurrent(lineNumber); } catch (IndexOutOfBoundsException ioobex) { cline = lineSet.getCurrent(0); } setLine(cline); }
Line l = null; try { l = lc.getLineSet().getCurrent(line - 1); } catch (IndexOutOfBoundsException e) { // try to open at least the file (line no. is too high?) l = lc.getLineSet().getCurrent(0);
final Line lineNew = lc.getLineSet().getCurrent(lb.getLineNumber() - 1); synchronized (this) { if (line != null) {
Line getLine (String url, int lineNumber, Object timeStamp) { //System.err.println("LineTranslations.getLine("+lineNumber+", "+timeStamp+")"); Line.Set ls = getLineSet (url, timeStamp); if (ls == null) { return null; } try { //System.err.println(" Line.Set = "+ls+", date = "+ls.getDate()); //System.err.println(" current("+(lineNumber-1)+") = "+ls.getCurrent (lineNumber - 1)); //System.err.println(" originl("+(lineNumber-1)+") = "+ls.getOriginal (lineNumber - 1)); if (timeStamp == null) { return ls.getCurrent (lineNumber - 1); } else { return ls.getOriginal (lineNumber - 1); } } catch (IndexOutOfBoundsException e) { } catch (IllegalArgumentException e) { } return null; }
@Override public FileObject getFileObject() { if (line instanceof FutureLine) { URL url = getURL(); FileObject fo = URLMapper.findFileObject(url); if (fo != null) { try { DataObject dobj = DataObject.find(fo); LineCookie lineCookie = dobj.getLookup().lookup(LineCookie.class); if (lineCookie == null) { return null; } Line l = lineCookie.getLineSet().getCurrent(getLineNumber() - 1); setLine(l); } catch (DataObjectNotFoundException ex) { } } return fo; } else { return line.getLookup().lookup(FileObject.class); } }
Line getLine (String url, int lineNumber, Object timeStamp) { //System.err.println("LineTranslations.getLine("+lineNumber+", "+timeStamp+")"); Line.Set ls = getLineSet (url, timeStamp); if (ls == null) { return null; } try { //System.err.println(" Line.Set = "+ls+", date = "+ls.getDate()); //System.err.println(" current("+(lineNumber-1)+") = "+ls.getCurrent (lineNumber - 1)); //System.err.println(" originl("+(lineNumber-1)+") = "+ls.getOriginal (lineNumber - 1)); if (timeStamp == null) { return ls.getCurrent (lineNumber - 1); } else { return ls.getOriginal (lineNumber - 1); } } catch (IndexOutOfBoundsException e) { } catch (IllegalArgumentException e) { } return null; }
/** * Only underline the part of the line that has text on it. */ public void attachToLineSet(Set lines) { docline = lines.getCurrent(line-1); char[] string = docline.getText().toCharArray(); int start = 0; int end = string.length-1; while (start <= end && string[start] <= ' ') start++; while (start <= end && string[end] <= ' ') end--; // XXX shouldn't we use the column??? But if so, chaining // gets trickier... Line.Part part; if (start <= end) part = docline.createPart(start, end-start+1); else part = docline.createPart(0, string.length); attach(part); }
public static Line getCurrentLine() { EditorCookie e = getCurrentEditorCookie(); if (e == null) return null; JEditorPane ep = getCurrentEditor(e); if (ep == null) return null; StyledDocument d = e.getDocument(); if (d == null) return null; int lineNo = NbDocument.findLineNumber(d, ep.getCaret().getDot()); // Editor numbers lines from 0! Line l = null; try { l = e.getLineSet().getCurrent(lineNo + 1); } catch (IndexOutOfBoundsException x) { // 6494346 } return l; }
@Override public EditorLineHandler get(FileObject fo, int lineNumber) { try { DataObject dobj = DataObject.find(fo); LineCookie lineCookie = dobj.getLookup().lookup(LineCookie.class); if (lineCookie == null) { return null; } try { Line line = lineCookie.getLineSet().getCurrent(lineNumber - 1); return new LineDelegate(line); } catch (IndexOutOfBoundsException ioobex) { // The line is gone. return null; } } catch (DataObjectNotFoundException ex) { return null; } }
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; }
Line getLine (String url, int lineNumber, Object timeStamp) { //System.err.println("LineTranslations.getLine("+lineNumber+", "+timeStamp+")"); Line.Set ls = getLineSet (url, timeStamp); //System.err.println(" Line.Set = "+ls+", date = "+ls.getDate()); //System.err.println(" current("+(lineNumber-1)+") = "+ls.getCurrent (lineNumber - 1)); //System.err.println(" originl("+(lineNumber-1)+") = "+ls.getOriginal (lineNumber - 1)); if (ls == null) return null; try { if (timeStamp == null) return ls.getCurrent (lineNumber - 1); else return ls.getOriginal (lineNumber - 1); } catch (IndexOutOfBoundsException e) { } catch (IllegalArgumentException e) { } return null; }
public void run () { int definitionOffset = definition.getOffset (); try { DataObject dobj = DataObject.find (fo); EditorCookie ec = dobj.getCookie (EditorCookie.class); StyledDocument doc2 = ec.openDocument (); LineCookie lc = dobj.getCookie (LineCookie.class); Line.Set lineSet = lc.getLineSet (); Line line = lineSet.getCurrent (NbDocument.findLineNumber (doc2, definitionOffset)); int column = NbDocument.findLineColumn (doc2, definitionOffset); line.show (ShowOpenType.OPEN, ShowVisibilityType.FOCUS, column); } catch (IOException ex) { ex.printStackTrace (); } } };
public @Override void run() { lineCookie.getLineSet().getCurrent(line.get() - 1).show(ShowOpenType.OPEN, ShowVisibilityType.FOCUS); } });
@Override public void run() { javax.swing.JEditorPane[] panes = support.getOpenedPanes(); if (panes != null) { if (lineNumber >= 0 && lineNumber < support.getLineSet().getLines().size()) { support.getLineSet().getCurrent(lineNumber).show(Line.ShowOpenType.NONE, Line.ShowVisibilityType.FRONT); } org.netbeans.modules.mercurial.ui.annotate.AnnotateAction.showAnnotations(panes[0], originalFile, revision.getRevisionNumber()); } } });
public synchronized void attach() throws IOException { this.lc = dataObject.getCookie (LineCookie.class); if (lc == null) return ; lb.addPropertyChangeListener(this); try { this.line = lc.getLineSet().getCurrent(lb.getLineNumber() - 1); line.addPropertyChangeListener(this); } catch (IndexOutOfBoundsException ioobex) { // ignore document changes for BP with bad line number } }
public void open() { try { PositionRef pos = ed.getRange().getBegin(); int line = pos.getLine(); int column = pos.getColumn(); Line l = pos.getCloneableEditorSupport().getLineSet().getCurrent(line); l.show(Line.SHOW_GOTO, column); } catch (IOException ex) { Exceptions.printStackTrace(ex); } }
/** Called when some sort of action is performed on a line. * @param ev the event describing the line */ public void outputLineAction(OutputEvent ev) { cookie.getLineSet().getCurrent(line).show(Line.SHOW_GOTO); }
void show () { DataObject dataObject = NbEditorUtilities.getDataObject (document); LineCookie lineCookie = dataObject.getCookie (LineCookie.class); Line.Set lineSet = lineCookie.getLineSet (); Line line = lineSet.getCurrent (NbDocument.findLineNumber (document, item.getOffset ())); int column = NbDocument.findLineColumn (document, item.getOffset ()); line.show (ShowOpenType.OPEN, ShowVisibilityType.FOCUS, column); }