1 22 23 package org.gjt.sp.jedit.textarea; 24 25 import org.gjt.sp.jedit.Debug; 26 import org.gjt.sp.util.Log; 27 28 32 class FirstLine extends Anchor 33 { 34 int skew; 35 36 FirstLine(DisplayManager displayManager, 38 TextArea textArea) 39 { 40 super(displayManager,textArea); 41 } 43 public void changed() 45 { 46 if(Debug.SCROLL_DEBUG) 48 { 49 Log.log(Log.DEBUG,this,"changed() before: " 50 + physicalLine + ":" + scrollLine 51 + ":" + skew); 52 } 54 ensurePhysicalLineIsVisible(); 55 56 int screenLines = displayManager 57 .getScreenLineCount(physicalLine); 58 if(skew >= screenLines) 59 skew = screenLines - 1; 60 61 if(Debug.SCROLL_VERIFY) 63 { 64 System.err.println("SCROLL_VERIFY"); 65 int verifyScrollLine = 0; 66 67 for(int i = 0; i < displayManager.getBuffer() 68 .getLineCount(); i++) 69 { 70 if(!displayManager.isLineVisible(i)) 71 continue; 72 73 if(i >= physicalLine) 74 break; 75 76 verifyScrollLine += displayManager 77 .getScreenLineCount(i); 78 } 79 80 if(verifyScrollLine != scrollLine) 81 { 82 Exception ex = new Exception (scrollLine + ":" + verifyScrollLine); 83 Log.log(Log.ERROR,this,ex); 84 } 85 } 86 87 if(Debug.SCROLL_DEBUG) 88 { 89 Log.log(Log.DEBUG,this,"changed() after: " 90 + physicalLine + ":" + scrollLine 91 + ":" + skew); 92 } } 95 public void reset() 97 { 98 if(Debug.SCROLL_DEBUG) 99 Log.log(Log.DEBUG,this,"reset()"); 100 101 int oldPhysicalLine = physicalLine; 102 physicalLine = 0; 103 scrollLine = 0; 104 105 int i = displayManager.getFirstVisibleLine(); 106 107 for(;;) 108 { 109 if(i >= oldPhysicalLine) 110 break; 111 112 int before = scrollLine; 113 displayManager.updateScreenLineCount(i); 114 if(before != scrollLine) 115 throw new RuntimeException (this + " nudged"); 116 scrollLine += displayManager.getScreenLineCount(i); 117 118 int nextLine = displayManager.getNextVisibleLine(i); 119 if(nextLine == -1) 120 break; 121 else 122 i = nextLine; 123 } 124 125 physicalLine = i; 126 127 displayManager.updateScreenLineCount(i); 128 int screenLines = displayManager.getScreenLineCount(physicalLine); 129 if(skew >= screenLines) 130 skew = screenLines - 1; 131 132 textArea.updateScrollBar(); 133 } 135 void physDown(int amount, int screenAmount) 138 { 139 if(Debug.SCROLL_DEBUG) 140 { 141 Log.log(Log.DEBUG,this,"physDown() start: " 142 + physicalLine + ":" + scrollLine); 143 } 144 145 skew = 0; 146 147 if(!displayManager.isLineVisible(physicalLine)) 148 { 149 int lastVisibleLine = displayManager.getLastVisibleLine(); 150 if(physicalLine > lastVisibleLine) 151 physicalLine = lastVisibleLine; 152 else 153 { 154 int nextPhysicalLine = displayManager.getNextVisibleLine(physicalLine); 155 amount -= (nextPhysicalLine - physicalLine); 156 scrollLine += displayManager.getScreenLineCount(physicalLine); 157 physicalLine = nextPhysicalLine; 158 } 159 } 160 161 for(;;) 162 { 163 int nextPhysicalLine = displayManager.getNextVisibleLine( 164 physicalLine); 165 if(nextPhysicalLine == -1) 166 break; 167 else if(nextPhysicalLine > physicalLine + amount) 168 break; 169 else 170 { 171 scrollLine += displayManager.getScreenLineCount(physicalLine); 172 amount -= (nextPhysicalLine - physicalLine); 173 physicalLine = nextPhysicalLine; 174 } 175 } 176 177 if(Debug.SCROLL_DEBUG) 178 { 179 Log.log(Log.DEBUG,this,"physDown() end: " 180 + physicalLine + ":" + scrollLine); 181 } 182 183 callChanged = true; 184 185 if(screenAmount < 0) 188 scrollUp(-screenAmount); 189 else if(screenAmount > 0) 190 scrollDown(screenAmount); 191 } 193 void physUp(int amount, int screenAmount) 196 { 197 if(Debug.SCROLL_DEBUG) 198 { 199 Log.log(Log.DEBUG,this,"physUp() start: " 200 + physicalLine + ":" + scrollLine); 201 } 202 203 skew = 0; 204 205 if(!displayManager.isLineVisible(physicalLine)) 206 { 207 int firstVisibleLine = displayManager.getFirstVisibleLine(); 208 if(physicalLine < firstVisibleLine) 209 physicalLine = firstVisibleLine; 210 else 211 { 212 int prevPhysicalLine = displayManager.getPrevVisibleLine(physicalLine); 213 amount -= (physicalLine - prevPhysicalLine); 214 } 215 } 216 217 for(;;) 218 { 219 int prevPhysicalLine = displayManager.getPrevVisibleLine( 220 physicalLine); 221 if(prevPhysicalLine == -1) 222 break; 223 else if(prevPhysicalLine < physicalLine - amount) 224 break; 225 else 226 { 227 amount -= (physicalLine - prevPhysicalLine); 228 physicalLine = prevPhysicalLine; 229 scrollLine -= displayManager.getScreenLineCount( 230 prevPhysicalLine); 231 } 232 } 233 234 if(Debug.SCROLL_DEBUG) 235 { 236 Log.log(Log.DEBUG,this,"physUp() end: " 237 + physicalLine + ":" + scrollLine); 238 } 239 240 callChanged = true; 241 242 if(screenAmount < 0) 245 scrollUp(-screenAmount); 246 else if(screenAmount > 0) 247 scrollDown(screenAmount); 248 } 250 void scrollDown(int amount) 253 { 254 if(Debug.SCROLL_DEBUG) 255 Log.log(Log.DEBUG,this,"scrollDown()"); 256 257 ensurePhysicalLineIsVisible(); 258 259 amount += skew; 260 261 skew = 0; 262 263 while(amount > 0) 264 { 265 int screenLines = displayManager.getScreenLineCount(physicalLine); 266 if(amount < screenLines) 267 { 268 skew = amount; 269 break; 270 } 271 else 272 { 273 int nextLine = displayManager.getNextVisibleLine(physicalLine); 274 if(nextLine == -1) 275 break; 276 boolean visible = displayManager.isLineVisible(physicalLine); 277 physicalLine = nextLine; 278 if(visible) 279 { 280 amount -= screenLines; 281 scrollLine += screenLines; 282 } 283 } 284 } 285 286 callChanged = true; 287 } 289 void scrollUp(int amount) 292 { 293 if(Debug.SCROLL_DEBUG) 294 Log.log(Log.DEBUG,this,"scrollUp()"); 295 296 ensurePhysicalLineIsVisible(); 297 298 if(amount <= skew) 299 { 300 skew -= amount; 301 } 302 else 303 { 304 amount -= skew; 305 skew = 0; 306 307 while(amount > 0) 308 { 309 int prevLine = displayManager.getPrevVisibleLine(physicalLine); 310 if(prevLine == -1) 311 break; 312 physicalLine = prevLine; 313 314 int screenLines = displayManager.getScreenLineCount(physicalLine); 315 scrollLine -= screenLines; 316 if(amount < screenLines) 317 { 318 skew = screenLines - amount; 319 break; 320 } 321 else 322 amount -= screenLines; 323 } 324 } 325 326 callChanged = true; 327 } 329 void ensurePhysicalLineIsVisible() 331 { 332 if(!displayManager.isLineVisible(physicalLine)) 333 { 334 if(physicalLine > displayManager.getLastVisibleLine()) 335 { 336 physicalLine = displayManager.getLastVisibleLine(); 337 scrollLine = displayManager.getScrollLineCount() - 1; 338 } 339 else if(physicalLine < displayManager.getFirstVisibleLine()) 340 { 341 physicalLine = displayManager.getFirstVisibleLine(); 342 scrollLine = 0; 343 } 344 else 345 { 346 physicalLine = displayManager.getNextVisibleLine(physicalLine); 347 scrollLine += displayManager.getScreenLineCount(physicalLine); 348 } 349 } 350 } } 352 | Popular Tags |