/** * 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); }
setupContext(editorPane, null); Line line = EditorContextDispatcher.getDefault().getMostRecentLine(); line.createPart(0, 0);
private static Pair<Line.Part, FileObject> getContext(EditorContextProvider ecp) { Line.Part lp = ecp.getContext(); if (lp == null) { Line line = EditorContextDispatcher.getDefault().getMostRecentLine(); if (line != null) { lp = line.createPart(0, 0); } } FileObject file; if (lp != null) { file = lp.getLine().getLookup().lookup(FileObject.class); } else { file = null; } return Pair.of(lp, file); }
private void addAnnotation( CdiAnalysisResult result, Element element , CDIAnnotaitonType type ) { if ( element == null ){ return; } Tree var = result.getInfo().getTrees().getTree( element ); if ( var == null ){ return; } List<Integer> position = CdiEditorAnalysisFactory.getElementPosition( result.getInfo(), var ); Document document; try { document = result.getInfo().getDocument(); if ( !( document instanceof StyledDocument) ){ return; } } catch (IOException e) { return; } int start = position.get(0); Line line = NbEditorUtilities.getLine( document , start, false); Part part = line.createPart( NbDocument.findLineColumn((StyledDocument) document, start), position.get( 1 ) -start); result.addAnnotation( new CDIAnnotation( type, part)); }