1 22 23 package org.gjt.sp.jedit.textarea; 24 25 import java.awt.*; 27 29 36 class FastRepaintManager 37 { 38 FastRepaintManager(TextArea textArea, 40 TextAreaPainter painter) 41 { 42 this.textArea = textArea; 43 this.painter = painter; 44 } 46 void updateGraphics() 48 { 49 if(gfx != null) 50 gfx.dispose(); 51 52 int width = painter.getWidth(); 53 int height = painter.getHeight(); 54 55 if(width <= 0) 56 width = 1; 57 if(height <= 0) 58 height = 1; 59 img = painter.getGraphicsConfiguration() 60 .createCompatibleImage(width,height, 61 Transparency.OPAQUE); 62 gfx = (Graphics2D)img.getGraphics(); 63 gfx.clipRect(0,0,painter.getWidth(),painter.getHeight()); 64 fastScroll = false; 65 } 67 Graphics2D getGraphics() 69 { 70 return gfx; 71 } 73 static class RepaintLines 75 { 76 final int first; 77 final int last; 78 79 RepaintLines(int first, int last) 80 { 81 this.first = first; 82 this.last = last; 83 } 84 } 86 RepaintLines prepareGraphics(Rectangle clipRect, int firstLine, 88 Graphics2D gfx) 89 { 90 gfx.setFont(painter.getFont()); 91 gfx.setColor(painter.getBackground()); 92 93 int height = gfx.getFontMetrics().getHeight(); 94 95 if(fastScroll) 96 { 97 int lineDelta = this.firstLine - firstLine; 98 int yDelta = lineDelta * height; 99 int visibleLines = textArea.getVisibleLines(); 100 101 if(lineDelta > -visibleLines 102 && lineDelta < visibleLines) 103 { 104 if(lineDelta < 0) 105 { 106 gfx.copyArea(0,-yDelta,painter.getWidth(), 107 painter.getHeight() + yDelta,0,yDelta); 108 return new RepaintLines( 109 visibleLines + this.firstLine 110 - firstLine - 1, 111 visibleLines - 1); 112 } 113 else if(lineDelta > 0) 114 { 115 gfx.copyArea(0,0,painter.getWidth(), 116 painter.getHeight() - yDelta,0,yDelta); 117 return new RepaintLines(0, 118 this.firstLine - firstLine); 119 } 120 } 121 } 122 123 return new RepaintLines( 127 clipRect.y / height, 128 (clipRect.y + clipRect.height - 1) / height); 129 } 131 void paint(Graphics g) 133 { 134 firstLine = textArea.getFirstLine(); 135 g.drawImage(img,0,0,null); 136 } 138 void setFastScroll(boolean fastScroll) 140 { 141 this.fastScroll = fastScroll; 142 } 144 private TextArea textArea; 146 private TextAreaPainter painter; 147 private Graphics2D gfx; 148 private Image img; 149 private boolean fastScroll; 150 151 private int firstLine; 152 } 154 | Popular Tags |