1 22 23 package org.gjt.sp.jedit.textarea; 24 25 import java.awt.Graphics2D ; 26 import java.util.*; 27 import org.gjt.sp.util.Log; 28 29 35 class ExtensionManager 36 { 37 45 void addExtension(int layer, TextAreaExtension ext) 46 { 47 Entry entry = new Entry(layer,ext); 48 49 int i = 0; 50 for (Entry extension : extensions) { 51 int _layer = extension.layer; 52 if (layer < _layer) { 53 extensions.add(i, entry); 54 return; 55 } 56 i++; 57 } 58 59 extensions.add(entry); 60 } 62 void removeExtension(TextAreaExtension ext) 64 { 65 Iterator<Entry> iter = extensions.iterator(); 66 while(iter.hasNext()) 67 { 68 if(iter.next().ext == ext) 69 { 70 iter.remove(); 71 return; 72 } 73 } 74 } 76 TextAreaExtension[] getExtensions() 78 { 79 TextAreaExtension[] retVal = new TextAreaExtension[ 80 extensions.size()]; 81 Iterator<Entry> iter = extensions.iterator(); 82 int i = 0; 83 while(iter.hasNext()) 84 retVal[i++] = iter.next().ext; 85 86 return retVal; 87 } 89 void paintScreenLineRange(TextArea textArea, Graphics2D gfx, 91 int firstLine, int lastLine, int y, int lineHeight) 92 { 93 try 94 { 95 int[] physicalLines = new int[lastLine - firstLine + 1]; 96 int[] start = new int[physicalLines.length]; 97 int[] end = new int[physicalLines.length]; 98 99 for(int i = 0; i < physicalLines.length; i++) 100 { 101 int screenLine = i + firstLine; 102 ChunkCache.LineInfo lineInfo = textArea 103 .chunkCache.getLineInfo(screenLine); 104 105 if(lineInfo.physicalLine == -1) 106 physicalLines[i] = -1; 107 else 108 { 109 physicalLines[i] = lineInfo.physicalLine; 110 start[i] = textArea.getScreenLineStartOffset(screenLine); 111 end[i] = textArea.getScreenLineEndOffset(screenLine); 112 } 113 } 114 115 paintScreenLineRange(gfx,firstLine,lastLine,physicalLines, 116 start,end,y,lineHeight); 117 } 118 catch(Exception e) 119 { 120 Log.log(Log.ERROR,this,"Error repainting line" 121 + " range {" + firstLine + ',' 122 + lastLine + "}:"); 123 Log.log(Log.ERROR,this,e); 124 } 125 } 127 String getToolTipText(int x, int y) 129 { 130 for(int i = 0; i < extensions.size(); i++) 131 { 132 TextAreaExtension ext = extensions.get(i).ext; 133 String toolTip = ext.getToolTipText(x,y); 134 if(toolTip != null) 135 return toolTip; 136 } 137 138 return null; 139 } 141 private final List<Entry> extensions = new LinkedList<Entry>(); 143 144 private void paintScreenLineRange(Graphics2D gfx, int firstLine, 146 int lastLine, int[] physicalLines, int[] start, int[] end, 147 int y, int lineHeight) 148 { 149 Iterator<Entry> iter = extensions.iterator(); 150 while(iter.hasNext()) 151 { 152 TextAreaExtension ext = iter.next().ext; 153 try 154 { 155 ext.paintScreenLineRange(gfx,firstLine,lastLine, 156 physicalLines,start,end,y,lineHeight); 157 } 158 catch(Throwable t) 159 { 160 Log.log(Log.ERROR,this,t); 161 162 iter.remove(); 165 } 166 } 167 } 169 171 173 static class Entry 174 { 175 int layer; 176 TextAreaExtension ext; 177 178 Entry(int layer, TextAreaExtension ext) 179 { 180 this.layer = layer; 181 this.ext = ext; 182 } 183 } } 185 | Popular Tags |