1 22 23 package org.gjt.sp.jedit.textarea; 24 25 import org.gjt.sp.jedit.buffer.*; 27 import org.gjt.sp.jedit.Debug; 28 import org.gjt.sp.util.Log; 29 31 38 class ScreenLineManager 39 { 40 ScreenLineManager(DisplayManager displayManager, JEditBuffer buffer) 42 { 43 this.displayManager = displayManager; 44 this.buffer = buffer; 45 if(!buffer.isLoading()) 46 reset(); 47 } 49 boolean isScreenLineCountValid(int line) 51 { 52 return (screenLines[line] & SCREEN_LINES_VALID_MASK) != 0; 53 } 55 int getScreenLineCount(int line) 57 { 58 return screenLines[line] >> SCREEN_LINES_SHIFT; 59 } 61 void setScreenLineCount(int line, int count) 63 { 64 if(count > Short.MAX_VALUE) 65 { 66 count = Short.MAX_VALUE; 68 } 69 70 if(Debug.SCREEN_LINES_DEBUG) 71 Log.log(Log.DEBUG,this,new Exception ("setScreenLineCount(" + line + "," + count + ")")); 72 screenLines[line] = (short)(count << SCREEN_LINES_SHIFT 73 | SCREEN_LINES_VALID_MASK); 74 } 76 void invalidateScreenLineCounts() 78 { 79 int lineCount = buffer.getLineCount(); 80 for(int i = 0; i < lineCount; i++) 81 screenLines[i] &= ~SCREEN_LINES_VALID_MASK; 82 } 84 void reset() 86 { 87 screenLines = new short[buffer.getLineCount()]; 88 for(int i = 0; i < screenLines.length; i++) 89 screenLines[i] = 0; 90 } 92 public void contentInserted(int startLine, int numLines) 94 { 95 int endLine = startLine + numLines; 96 screenLines[startLine] &= ~SCREEN_LINES_VALID_MASK; 97 98 int lineCount = buffer.getLineCount(); 99 100 if(numLines > 0) 101 { 102 if(screenLines.length <= lineCount) 103 { 104 short[] screenLinesN = new short[(lineCount + 1) * 2]; 105 System.arraycopy(screenLines,0,screenLinesN,0, 106 screenLines.length); 107 screenLines = screenLinesN; 108 } 109 110 System.arraycopy(screenLines,startLine,screenLines, 111 endLine,lineCount - endLine); 112 113 for(int i = 0; i < numLines; i++) 114 screenLines[startLine + i] = 0; 115 } 116 } 118 public void contentRemoved(int startLine, int numLines) 120 { 121 int endLine = startLine + numLines; 122 screenLines[startLine] &= ~SCREEN_LINES_VALID_MASK; 123 124 if(numLines > 0 && endLine != screenLines.length) 125 { 126 System.arraycopy(screenLines,endLine + 1,screenLines, 127 startLine + 1,screenLines.length - endLine - 1); 128 } 129 } 131 private static final int SCREEN_LINES_SHIFT = 1; 133 private static final int SCREEN_LINES_VALID_MASK = 1; 134 135 private DisplayManager displayManager; 136 private JEditBuffer buffer; 137 private short[] screenLines; 138 } 140 | Popular Tags |