public SlimController(SlimRenderVisitor renderer, SlimFileContext fileContext) { this.fileContext = fileContext; this.fileContext.addListener(this); for (SlimFileWrapper file : this.fileContext.getFiles()) { numberOfLines += file.getLines().size(); } this.renderer = renderer; }
public SlimLineWrapper getLine(int linenum) { int totalLinesReached = 0, lastTotal = 0; for (SlimFileWrapper file : this.fileContext.getFiles()) { Collection<SlimLineWrapper> lines = file.getLines(); lastTotal = totalLinesReached; totalLinesReached += lines.size(); if (linenum < totalLinesReached) { SlimLineWrapper[] array = lines.toArray(new SlimLineWrapper[lines.size()]); return array[linenum - lastTotal]; } } return null; }
public Set<SlimFileWrapper> getFilesForLines(int startLine, int endLine) { Set<SlimFileWrapper> files = new HashSet<SlimFileWrapper>(); int fileEnd = 0, fileStart = 0; for (SlimFileWrapper file : this.fileContext.getFiles()) { Collection<SlimLineWrapper> lines = file.getLines(); fileStart = fileEnd; fileEnd += lines.size(); if ((fileStart > startLine && fileStart < endLine) || (fileEnd > startLine && fileEnd < endLine) || (startLine > fileStart && startLine < fileEnd) || (endLine > fileStart && endLine < fileEnd)) { files.add(file); } } return files; }
@Override public void onNewFileLoaded(SlimFileWrapper newFile) { numberOfLines += newFile.getLines().size(); renderer.refresh(); }