1 11 package org.eclipse.jface.text.source; 12 13 import org.eclipse.swt.graphics.Color; 14 import org.eclipse.swt.graphics.GC; 15 import org.eclipse.swt.widgets.Composite; 16 import org.eclipse.swt.widgets.Control; 17 18 import org.eclipse.core.runtime.Assert; 19 20 import org.eclipse.jface.text.revisions.IRevisionListener; 21 import org.eclipse.jface.text.revisions.IRevisionRulerColumn; 22 import org.eclipse.jface.text.revisions.IRevisionRulerColumnExtension; 23 import org.eclipse.jface.text.revisions.RevisionInformation; 24 25 import org.eclipse.jface.internal.text.revisions.RevisionPainter; 26 import org.eclipse.jface.internal.text.source.DiffPainter; 27 import org.eclipse.jface.viewers.ISelectionProvider; 28 29 35 public final class LineNumberChangeRulerColumn extends LineNumberRulerColumn implements IVerticalRulerInfo, IVerticalRulerInfoExtension, IChangeRulerColumn, IRevisionRulerColumn, IRevisionRulerColumnExtension { 36 37 private IAnnotationModel fAnnotationModel; 38 39 private boolean fCharacterDisplay; 40 45 private final RevisionPainter fRevisionPainter; 46 51 private final DiffPainter fDiffPainter; 52 56 private boolean fShowNumbers= true; 57 58 63 public LineNumberChangeRulerColumn(ISharedTextColors sharedColors) { 64 Assert.isNotNull(sharedColors); 65 fRevisionPainter= new RevisionPainter(this, sharedColors); 66 fDiffPainter= new DiffPainter(this, sharedColors); 67 } 68 69 72 public Control createControl(CompositeRuler parentRuler, Composite parentControl) { 73 Control control= super.createControl(parentRuler, parentControl); 74 fRevisionPainter.setParentRuler(parentRuler); 75 fDiffPainter.setParentRuler(parentRuler); 76 return control; 77 } 78 79 82 public int getLineOfLastMouseButtonActivity() { 83 return getParentRuler().getLineOfLastMouseButtonActivity(); 84 } 85 86 89 public int toDocumentLineNumber(int y_coordinate) { 90 return getParentRuler().toDocumentLineNumber(y_coordinate); 91 } 92 93 96 public void setModel(IAnnotationModel model) { 97 setAnnotationModel(model); 98 fRevisionPainter.setModel(model); 99 fDiffPainter.setModel(model); 100 updateNumberOfDigits(); 101 computeIndentations(); 102 layout(true); 103 postRedraw(); 104 } 105 106 private void setAnnotationModel(IAnnotationModel model) { 107 if (fAnnotationModel != model) 108 fAnnotationModel= model; 109 } 110 111 112 118 public void setDisplayMode(boolean characterMode) { 119 if (characterMode != fCharacterDisplay) { 120 fCharacterDisplay= characterMode; 121 updateNumberOfDigits(); 122 computeIndentations(); 123 layout(true); 124 } 125 } 126 127 130 public IAnnotationModel getModel() { 131 return fAnnotationModel; 132 } 133 134 137 protected String createDisplayString(int line) { 138 StringBuffer buffer= new StringBuffer (); 139 if (fShowNumbers) 140 buffer.append(super.createDisplayString(line)); 141 if (fCharacterDisplay && getModel() != null) 142 buffer.append(fDiffPainter.getDisplayCharacter(line)); 143 return buffer.toString(); 144 } 145 146 149 protected int computeNumberOfDigits() { 150 int digits; 151 if (fCharacterDisplay && getModel() != null) { 152 if (fShowNumbers) 153 digits= super.computeNumberOfDigits() + 1; 154 else 155 digits= 1; 156 } else { 157 if (fShowNumbers) 158 digits= super.computeNumberOfDigits(); 159 else 160 digits= 0; 161 } 162 if (fRevisionPainter.hasInformation()) 163 digits+= fRevisionPainter.getRequiredWidth(); 164 return digits; 165 } 166 167 170 public void addVerticalRulerListener(IVerticalRulerListener listener) { 171 throw new UnsupportedOperationException (); 172 } 173 174 177 public void removeVerticalRulerListener(IVerticalRulerListener listener) { 178 throw new UnsupportedOperationException (); 179 } 180 181 184 void doPaint(GC gc, ILineRange visibleLines) { 185 Color foreground= gc.getForeground(); 186 if (visibleLines != null) { 187 if (fRevisionPainter.hasInformation()) 188 fRevisionPainter.paint(gc, visibleLines); 189 else if (fDiffPainter.hasInformation()) fDiffPainter.paint(gc, visibleLines); 191 } 192 gc.setForeground(foreground); 193 if (fShowNumbers || fCharacterDisplay) 194 super.doPaint(gc, visibleLines); 195 } 196 197 200 public IAnnotationHover getHover() { 201 int activeLine= getParentRuler().getLineOfLastMouseButtonActivity(); 202 if (fRevisionPainter.hasHover(activeLine)) 203 return fRevisionPainter.getHover(); 204 if (fDiffPainter.hasHover(activeLine)) 205 return fDiffPainter.getHover(); 206 return null; 207 } 208 209 212 public void setHover(IAnnotationHover hover) { 213 fRevisionPainter.setHover(hover); 214 fDiffPainter.setHover(hover); 215 } 216 217 220 public void setBackground(Color background) { 221 super.setBackground(background); 222 fRevisionPainter.setBackground(background); 223 fDiffPainter.setBackground(background); 224 } 225 226 229 public void setAddedColor(Color addedColor) { 230 fDiffPainter.setAddedColor(addedColor); 231 } 232 233 236 public void setChangedColor(Color changedColor) { 237 fDiffPainter.setChangedColor(changedColor); 238 } 239 240 243 public void setDeletedColor(Color deletedColor) { 244 fDiffPainter.setDeletedColor(deletedColor); 245 } 246 247 250 public void setRevisionInformation(RevisionInformation info) { 251 fRevisionPainter.setRevisionInformation(info); 252 updateNumberOfDigits(); 253 computeIndentations(); 254 layout(true); 255 postRedraw(); 256 } 257 258 262 public ISelectionProvider getRevisionSelectionProvider() { 263 return fRevisionPainter.getRevisionSelectionProvider(); 264 } 265 266 270 public void setRevisionRenderingMode(RenderingMode renderingMode) { 271 fRevisionPainter.setRenderingMode(renderingMode); 272 } 273 274 281 public void showLineNumbers(boolean showNumbers) { 282 if (fShowNumbers != showNumbers) { 283 fShowNumbers= showNumbers; 284 updateNumberOfDigits(); 285 computeIndentations(); 286 layout(true); 287 } 288 } 289 290 294 public int getWidth() { 295 int width= super.getWidth(); 296 return width > 0 ? width : 8; } 298 299 306 public boolean isShowingLineNumbers() { 307 return fShowNumbers; 308 } 309 310 317 public boolean isShowingRevisionInformation() { 318 return fRevisionPainter.hasInformation(); 319 } 320 321 328 public boolean isShowingChangeInformation() { 329 return fDiffPainter.hasInformation(); 330 } 331 332 336 public void showRevisionAuthor(boolean show) { 337 fRevisionPainter.showRevisionAuthor(show); 338 updateNumberOfDigits(); 339 computeIndentations(); 340 layout(true); 341 postRedraw(); 342 } 343 344 348 public void showRevisionId(boolean show) { 349 fRevisionPainter.showRevisionId(show); 350 updateNumberOfDigits(); 351 computeIndentations(); 352 layout(true); 353 postRedraw(); 354 } 355 356 360 public void addRevisionListener(IRevisionListener listener) { 361 fRevisionPainter.addRevisionListener(listener); 362 } 363 364 368 public void removeRevisionListener(IRevisionListener listener) { 369 fRevisionPainter.removeRevisionListener(listener); 370 } 371 372 376 protected void handleDispose() { 377 fRevisionPainter.setParentRuler(null); 378 fRevisionPainter.setModel(null); 379 fDiffPainter.setParentRuler(null); 380 fDiffPainter.setModel(null); 381 super.handleDispose(); 382 } 383 } 384 | Popular Tags |