comparison dwtx/jface/internal/text/revisions/RevisionPainter.d @ 134:51e6e63f930e

Regex fix for casts
author Frank Benoit <benoit@tionex.de>
date Sun, 24 Aug 2008 01:46:20 +0200
parents 7d818bd32d63
children 65801ad2b265
comparison
equal deleted inserted replaced
133:7d818bd32d63 134:51e6e63f930e
170 170
171 if (info is null) 171 if (info is null)
172 return; 172 return;
173 List revisions= new ArrayList(); 173 List revisions= new ArrayList();
174 for (Iterator it= info.getRevisions().iterator(); it.hasNext();) { 174 for (Iterator it= info.getRevisions().iterator(); it.hasNext();) {
175 Revision revision= (Revision) it.next(); 175 Revision revision= cast(Revision) it.next();
176 revisions.add(new Long(computeAge(revision))); 176 revisions.add(new Long(computeAge(revision)));
177 } 177 }
178 Collections.sort(revisions); 178 Collections.sort(revisions);
179 fRevisions= revisions; 179 fRevisions= revisions;
180 } 180 }
204 // relative age: newest is 0, oldest is 1 204 // relative age: newest is 0, oldest is 1
205 // if there is only one revision, use an intermediate value to avoid extreme coloring 205 // if there is only one revision, use an intermediate value to avoid extreme coloring
206 if (index is -1 || size < 2) 206 if (index is -1 || size < 2)
207 scale= 0.5f; 207 scale= 0.5f;
208 else 208 else
209 scale= (float) index / (size - 1); 209 scale= cast(float) index / (size - 1);
210 } else { 210 } else {
211 Assert.isTrue(false); 211 Assert.isTrue(false);
212 return null; // dummy 212 return null; // dummy
213 } 213 }
214 rgb= getShadedColor(rgb, scale, focus); 214 rgb= getShadedColor(rgb, scale, focus);
257 * @param focus <code>true</code> to return the focus color 257 * @param focus <code>true</code> to return the focus color
258 * @return the color for a revision 258 * @return the color for a revision
259 */ 259 */
260 public RGB getColor(Revision revision, bool focus) { 260 public RGB getColor(Revision revision, bool focus) {
261 Map map= focus ? fFocusColors : fColors; 261 Map map= focus ? fFocusColors : fColors;
262 RGB color= (RGB) map.get(revision); 262 RGB color= cast(RGB) map.get(revision);
263 if (color !is null) 263 if (color !is null)
264 return color; 264 return color;
265 265
266 color= adaptColor(revision, focus); 266 color= adaptColor(revision, focus);
267 map.put(revision, color); 267 map.put(revision, color);
414 /* 414 /*
415 * @see dwtx.jface.text.AbstractReusableInformationControlCreator#canReplace(dwtx.jface.text.IInformationControlCreator) 415 * @see dwtx.jface.text.AbstractReusableInformationControlCreator#canReplace(dwtx.jface.text.IInformationControlCreator)
416 */ 416 */
417 public bool canReplace(IInformationControlCreator creator) { 417 public bool canReplace(IInformationControlCreator creator) {
418 return creator.getClass() is getClass() 418 return creator.getClass() is getClass()
419 && ((HoverInformationControlCreator) creator).fIsFocusable is fIsFocusable; 419 && (cast(HoverInformationControlCreator) creator).fIsFocusable is fIsFocusable;
420 } 420 }
421 } 421 }
422 422
423 private static final String fgStyleSheet= "/* Font definitions */\n" + //$NON-NLS-1$ 423 private static final String fgStyleSheet= "/* Font definitions */\n" + //$NON-NLS-1$
424 "body, h1, h2, h3, h4, h5, h6, p, table, td, caption, th, ul, ol, dl, li, dd, dt {font-family: sans-serif; font-size: 9pt }\n" + //$NON-NLS-1$ 424 "body, h1, h2, h3, h4, h5, h6, p, table, td, caption, th, ul, ol, dl, li, dd, dt {font-family: sans-serif; font-size: 9pt }\n" + //$NON-NLS-1$
655 fRequiredWidth= -1; 655 fRequiredWidth= -1;
656 fRevisionIdChars= 0; 656 fRevisionIdChars= 0;
657 fRevisionInfo= info; 657 fRevisionInfo= info;
658 clearRangeCache(); 658 clearRangeCache();
659 updateFocusRange(null); 659 updateFocusRange(null);
660 handleRevisionSelected((Revision) null); 660 handleRevisionSelected(cast(Revision) null);
661 fColorTool.setInfo(info); 661 fColorTool.setInfo(info);
662 postRedraw(); 662 postRedraw();
663 informListeners(); 663 informListeners();
664 } 664 }
665 } 665 }
733 } 733 }
734 734
735 // draw change regions 735 // draw change regions
736 List/* <RevisionRange> */ranges= getRanges(visibleLines); 736 List/* <RevisionRange> */ranges= getRanges(visibleLines);
737 for (Iterator it= ranges.iterator(); it.hasNext();) { 737 for (Iterator it= ranges.iterator(); it.hasNext();) {
738 RevisionRange region= (RevisionRange) it.next(); 738 RevisionRange region= cast(RevisionRange) it.next();
739 paintRange(region, gc); 739 paintRange(region, gc);
740 } 740 }
741 } 741 }
742 742
743 /** 743 /**
792 * @see IVerticalRulerColumn#setModel(IAnnotationModel) 792 * @see IVerticalRulerColumn#setModel(IAnnotationModel)
793 */ 793 */
794 public void setModel(IAnnotationModel model) { 794 public void setModel(IAnnotationModel model) {
795 IAnnotationModel diffModel; 795 IAnnotationModel diffModel;
796 if (model instanceof IAnnotationModelExtension) 796 if (model instanceof IAnnotationModelExtension)
797 diffModel= ((IAnnotationModelExtension) model).getAnnotationModel(IChangeRulerColumn.QUICK_DIFF_MODEL_ID); 797 diffModel= (cast(IAnnotationModelExtension) model).getAnnotationModel(IChangeRulerColumn.QUICK_DIFF_MODEL_ID);
798 else 798 else
799 diffModel= model; 799 diffModel= model;
800 800
801 setDiffer(diffModel); 801 setDiffer(diffModel);
802 setAnnotationModel(model); 802 setAnnotationModel(model);
819 */ 819 */
820 private void setDiffer(IAnnotationModel differ) { 820 private void setDiffer(IAnnotationModel differ) {
821 if (differ instanceof ILineDiffer || differ is null) { 821 if (differ instanceof ILineDiffer || differ is null) {
822 if (fLineDiffer !is differ) { 822 if (fLineDiffer !is differ) {
823 if (fLineDiffer !is null) 823 if (fLineDiffer !is null)
824 ((IAnnotationModel) fLineDiffer).removeAnnotationModelListener(fAnnotationListener); 824 (cast(IAnnotationModel) fLineDiffer).removeAnnotationModelListener(fAnnotationListener);
825 fLineDiffer= (ILineDiffer) differ; 825 fLineDiffer= cast(ILineDiffer) differ;
826 if (fLineDiffer !is null) 826 if (fLineDiffer !is null)
827 ((IAnnotationModel) fLineDiffer).addAnnotationModelListener(fAnnotationListener); 827 (cast(IAnnotationModel) fLineDiffer).addAnnotationModelListener(fAnnotationListener);
828 } 828 }
829 } 829 }
830 } 830 }
831 831
832 /** 832 /**
834 */ 834 */
835 private void handleDispose() { 835 private void handleDispose() {
836 updateFocusLine(-1); 836 updateFocusLine(-1);
837 837
838 if (fLineDiffer !is null) { 838 if (fLineDiffer !is null) {
839 ((IAnnotationModel) fLineDiffer).removeAnnotationModelListener(fAnnotationListener); 839 (cast(IAnnotationModel) fLineDiffer).removeAnnotationModelListener(fAnnotationListener);
840 fLineDiffer= null; 840 fLineDiffer= null;
841 } 841 }
842 842
843 fRevisionSelectionProvider.uninstall(); 843 fRevisionSelectionProvider.uninstall();
844 } 844 }
945 945
946 if (ranges.isEmpty() || line is -1) 946 if (ranges.isEmpty() || line is -1)
947 return null; 947 return null;
948 948
949 for (Iterator it= ranges.iterator(); it.hasNext();) { 949 for (Iterator it= ranges.iterator(); it.hasNext();) {
950 RevisionRange range= (RevisionRange) it.next(); 950 RevisionRange range= cast(RevisionRange) it.next();
951 if (contains(range, line)) 951 if (contains(range, line))
952 return range; 952 return range;
953 } 953 }
954 954
955 // line may be right after the last region 955 // line may be right after the last region
956 RevisionRange lastRegion= (RevisionRange) ranges.get(ranges.size() - 1); 956 RevisionRange lastRegion= cast(RevisionRange) ranges.get(ranges.size() - 1);
957 if (line is end(lastRegion)) 957 if (line is end(lastRegion))
958 return lastRegion; 958 return lastRegion;
959 return null; 959 return null;
960 } 960 }
961 961
970 970
971 // return the interesting subset 971 // return the interesting subset
972 int end= end(lines); 972 int end= end(lines);
973 int first= -1, last= -1; 973 int first= -1, last= -1;
974 for (int i= 0; i < ranges.size(); i++) { 974 for (int i= 0; i < ranges.size(); i++) {
975 RevisionRange range= (RevisionRange) ranges.get(i); 975 RevisionRange range= cast(RevisionRange) ranges.get(i);
976 int rangeEnd= end(range); 976 int rangeEnd= end(range);
977 if (first is -1 && rangeEnd > lines.getStartLine()) 977 if (first is -1 && rangeEnd > lines.getStartLine())
978 first= i; 978 first= i;
979 if (first !is -1 && rangeEnd > end) { 979 if (first !is -1 && rangeEnd > end) {
980 last= i; 980 last= i;
1051 */ 1051 */
1052 private ILineRange modelLinesToWidgetLines(ILineRange range) { 1052 private ILineRange modelLinesToWidgetLines(ILineRange range) {
1053 int widgetStartLine= -1; 1053 int widgetStartLine= -1;
1054 int widgetEndLine= -1; 1054 int widgetEndLine= -1;
1055 if (fViewer instanceof ITextViewerExtension5) { 1055 if (fViewer instanceof ITextViewerExtension5) {
1056 ITextViewerExtension5 extension= (ITextViewerExtension5) fViewer; 1056 ITextViewerExtension5 extension= cast(ITextViewerExtension5) fViewer;
1057 int modelEndLine= end(range); 1057 int modelEndLine= end(range);
1058 for (int modelLine= range.getStartLine(); modelLine < modelEndLine; modelLine++) { 1058 for (int modelLine= range.getStartLine(); modelLine < modelEndLine; modelLine++) {
1059 int widgetLine= extension.modelLine2WidgetLine(modelLine); 1059 int widgetLine= extension.modelLine2WidgetLine(modelLine);
1060 if (widgetLine !is -1) { 1060 if (widgetLine !is -1) {
1061 if (widgetStartLine is -1) 1061 if (widgetStartLine is -1)
1116 1116
1117 Map added= null; 1117 Map added= null;
1118 if (revision !is null) { 1118 if (revision !is null) {
1119 added= new HashMap(); 1119 added= new HashMap();
1120 for (Iterator it= revision.getRegions().iterator(); it.hasNext();) { 1120 for (Iterator it= revision.getRegions().iterator(); it.hasNext();) {
1121 RevisionRange range= (RevisionRange) it.next(); 1121 RevisionRange range= cast(RevisionRange) it.next();
1122 try { 1122 try {
1123 IRegion charRegion= toCharRegion(range); 1123 IRegion charRegion= toCharRegion(range);
1124 Position position= new Position(charRegion.getOffset(), charRegion.getLength()); 1124 Position position= new Position(charRegion.getOffset(), charRegion.getLength());
1125 Annotation annotation= new RevisionAnnotation(revision.getId()); 1125 Annotation annotation= new RevisionAnnotation(revision.getId());
1126 added.put(annotation, position); 1126 added.put(annotation, position);
1129 } 1129 }
1130 } 1130 }
1131 } 1131 }
1132 1132
1133 if (fAnnotationModel instanceof IAnnotationModelExtension) { 1133 if (fAnnotationModel instanceof IAnnotationModelExtension) {
1134 IAnnotationModelExtension ext= (IAnnotationModelExtension) fAnnotationModel; 1134 IAnnotationModelExtension ext= cast(IAnnotationModelExtension) fAnnotationModel;
1135 ext.replaceAnnotations((Annotation[]) fAnnotations.toArray(new Annotation[fAnnotations.size()]), added); 1135 ext.replaceAnnotations((Annotation[]) fAnnotations.toArray(new Annotation[fAnnotations.size()]), added);
1136 } else { 1136 } else {
1137 for (Iterator it= fAnnotations.iterator(); it.hasNext();) { 1137 for (Iterator it= fAnnotations.iterator(); it.hasNext();) {
1138 Annotation annotation= (Annotation) it.next(); 1138 Annotation annotation= cast(Annotation) it.next();
1139 fAnnotationModel.removeAnnotation(annotation); 1139 fAnnotationModel.removeAnnotation(annotation);
1140 } 1140 }
1141 if (added !is null) { 1141 if (added !is null) {
1142 for (Iterator it= added.entrySet().iterator(); it.hasNext();) { 1142 for (Iterator it= added.entrySet().iterator(); it.hasNext();) {
1143 Entry entry= (Entry) it.next(); 1143 Entry entry= cast(Entry) it.next();
1144 fAnnotationModel.addAnnotation((Annotation) entry.getKey(), (Position) entry.getValue()); 1144 fAnnotationModel.addAnnotation(cast(Annotation) entry.getKey(), cast(Position) entry.getValue());
1145 } 1145 }
1146 } 1146 }
1147 } 1147 }
1148 fAnnotations.clear(); 1148 fAnnotations.clear();
1149 if (added !is null) 1149 if (added !is null)
1191 Assert.isLegal(id !is null); 1191 Assert.isLegal(id !is null);
1192 if (fRevisionInfo is null) 1192 if (fRevisionInfo is null)
1193 return; 1193 return;
1194 1194
1195 for (Iterator it= fRevisionInfo.getRevisions().iterator(); it.hasNext();) { 1195 for (Iterator it= fRevisionInfo.getRevisions().iterator(); it.hasNext();) {
1196 Revision revision= (Revision) it.next(); 1196 Revision revision= cast(Revision) it.next();
1197 if (id.equals(revision.getId())) { 1197 if (id.equals(revision.getId())) {
1198 handleRevisionSelected(revision); 1198 handleRevisionSelected(revision);
1199 return; 1199 return;
1200 } 1200 }
1201 } 1201 }
1202 1202
1203 // clear selection if it does not exist 1203 // clear selection if it does not exist
1204 handleRevisionSelected((Revision) null); 1204 handleRevisionSelected(cast(Revision) null);
1205 } 1205 }
1206 1206
1207 /** 1207 /**
1208 * Returns the selection provider. 1208 * Returns the selection provider.
1209 * 1209 *
1228 * 1228 *
1229 * @param previousLine the old focus line (-1 for no focus) 1229 * @param previousLine the old focus line (-1 for no focus)
1230 * @param nextLine the new focus line (-1 for no focus) 1230 * @param nextLine the new focus line (-1 for no focus)
1231 */ 1231 */
1232 private void onFocusLineChanged(int previousLine, int nextLine) { 1232 private void onFocusLineChanged(int previousLine, int nextLine) {
1233 if (DEBUG) 1233 if cast(DEBUG)
1234 System.out.println("line: " + previousLine + " > " + nextLine); //$NON-NLS-1$ //$NON-NLS-2$ 1234 System.out.println("line: " + previousLine + " > " + nextLine); //$NON-NLS-1$ //$NON-NLS-2$
1235 fFocusLine= nextLine; 1235 fFocusLine= nextLine;
1236 RevisionRange region= getRange(nextLine); 1236 RevisionRange region= getRange(nextLine);
1237 updateFocusRange(region); 1237 updateFocusRange(region);
1238 } 1238 }
1252 * 1252 *
1253 * @param previousRange the old focus range (<code>null</code> for no focus) 1253 * @param previousRange the old focus range (<code>null</code> for no focus)
1254 * @param nextRange the new focus range (<code>null</code> for no focus) 1254 * @param nextRange the new focus range (<code>null</code> for no focus)
1255 */ 1255 */
1256 private void onFocusRangeChanged(RevisionRange previousRange, RevisionRange nextRange) { 1256 private void onFocusRangeChanged(RevisionRange previousRange, RevisionRange nextRange) {
1257 if (DEBUG) 1257 if cast(DEBUG)
1258 System.out.println("range: " + previousRange + " > " + nextRange); //$NON-NLS-1$ //$NON-NLS-2$ 1258 System.out.println("range: " + previousRange + " > " + nextRange); //$NON-NLS-1$ //$NON-NLS-2$
1259 fFocusRange= nextRange; 1259 fFocusRange= nextRange;
1260 Revision revision= nextRange is null ? null : nextRange.getRevision(); 1260 Revision revision= nextRange is null ? null : nextRange.getRevision();
1261 updateFocusRevision(revision); 1261 updateFocusRevision(revision);
1262 } 1262 }
1271 * 1271 *
1272 * @param previousRevision the old focus revision (<code>null</code> for no focus) 1272 * @param previousRevision the old focus revision (<code>null</code> for no focus)
1273 * @param nextRevision the new focus revision (<code>null</code> for no focus) 1273 * @param nextRevision the new focus revision (<code>null</code> for no focus)
1274 */ 1274 */
1275 private void onFocusRevisionChanged(Revision previousRevision, Revision nextRevision) { 1275 private void onFocusRevisionChanged(Revision previousRevision, Revision nextRevision) {
1276 if (DEBUG) 1276 if cast(DEBUG)
1277 System.out.println("revision: " + previousRevision + " > " + nextRevision); //$NON-NLS-1$ //$NON-NLS-2$ 1277 System.out.println("revision: " + previousRevision + " > " + nextRevision); //$NON-NLS-1$ //$NON-NLS-2$
1278 fFocusRevision= nextRevision; 1278 fFocusRevision= nextRevision;
1279 uninstallWheelHandler(); 1279 uninstallWheelHandler();
1280 installWheelHandler(); 1280 installWheelHandler();
1281 updateOverviewAnnotations(); 1281 updateOverviewAnnotations();
1315 ILineRange nextWidgetRange= null; 1315 ILineRange nextWidgetRange= null;
1316 ILineRange last= null; 1316 ILineRange last= null;
1317 List ranges= fFocusRevision.getRegions(); 1317 List ranges= fFocusRevision.getRegions();
1318 if (up) { 1318 if (up) {
1319 for (Iterator it= ranges.iterator(); it.hasNext();) { 1319 for (Iterator it= ranges.iterator(); it.hasNext();) {
1320 RevisionRange range= (RevisionRange) it.next(); 1320 RevisionRange range= cast(RevisionRange) it.next();
1321 ILineRange widgetRange= modelLinesToWidgetLines(range); 1321 ILineRange widgetRange= modelLinesToWidgetLines(range);
1322 if (contains(range, documentHoverLine)) { 1322 if (contains(range, documentHoverLine)) {
1323 nextWidgetRange= last; 1323 nextWidgetRange= last;
1324 break; 1324 break;
1325 } 1325 }
1326 if (widgetRange !is null) 1326 if (widgetRange !is null)
1327 last= widgetRange; 1327 last= widgetRange;
1328 } 1328 }
1329 } else { 1329 } else {
1330 for (ListIterator it= ranges.listIterator(ranges.size()); it.hasPrevious();) { 1330 for (ListIterator it= ranges.listIterator(ranges.size()); it.hasPrevious();) {
1331 RevisionRange range= (RevisionRange) it.previous(); 1331 RevisionRange range= cast(RevisionRange) it.previous();
1332 ILineRange widgetRange= modelLinesToWidgetLines(range); 1332 ILineRange widgetRange= modelLinesToWidgetLines(range);
1333 if (contains(range, documentHoverLine)) { 1333 if (contains(range, documentHoverLine)) {
1334 nextWidgetRange= last; 1334 nextWidgetRange= last;
1335 break; 1335 break;
1336 } 1336 }
1438 * 1438 *
1439 * @param activeLine the document line of interest 1439 * @param activeLine the document line of interest
1440 * @return <code>true</code> if the receiver can provide a hover 1440 * @return <code>true</code> if the receiver can provide a hover
1441 */ 1441 */
1442 public bool hasHover(int activeLine) { 1442 public bool hasHover(int activeLine) {
1443 return fViewer instanceof ISourceViewer && fHover.getHoverLineRange((ISourceViewer) fViewer, activeLine) !is null; 1443 return fViewer instanceof ISourceViewer && fHover.getHoverLineRange(cast(ISourceViewer) fViewer, activeLine) !is null;
1444 } 1444 }
1445 1445
1446 /** 1446 /**
1447 * Returns the revision at a certain document offset, or <code>null</code> for none. 1447 * Returns the revision at a certain document offset, or <code>null</code> for none.
1448 * 1448 *
1484 if (fRequiredWidth is -1) { 1484 if (fRequiredWidth is -1) {
1485 if (hasInformation() && (fShowRevision || fShowAuthor)) { 1485 if (hasInformation() && (fShowRevision || fShowAuthor)) {
1486 int revisionWidth= 0; 1486 int revisionWidth= 0;
1487 int authorWidth= 0; 1487 int authorWidth= 0;
1488 for (Iterator it= fRevisionInfo.getRevisions().iterator(); it.hasNext();) { 1488 for (Iterator it= fRevisionInfo.getRevisions().iterator(); it.hasNext();) {
1489 Revision revision= (Revision) it.next(); 1489 Revision revision= cast(Revision) it.next();
1490 revisionWidth= Math.max(revisionWidth, revision.getId().length()); 1490 revisionWidth= Math.max(revisionWidth, revision.getId().length());
1491 authorWidth= Math.max(authorWidth, revision.getAuthor().length()); 1491 authorWidth= Math.max(authorWidth, revision.getAuthor().length());
1492 } 1492 }
1493 fRevisionIdChars= revisionWidth + 1; 1493 fRevisionIdChars= revisionWidth + 1;
1494 if (fShowAuthor && fShowRevision) 1494 if (fShowAuthor && fShowRevision)
1562 return; 1562 return;
1563 1563
1564 RevisionEvent event= new RevisionEvent(fRevisionInfo); 1564 RevisionEvent event= new RevisionEvent(fRevisionInfo);
1565 Object[] listeners= fRevisionListeners.getListeners(); 1565 Object[] listeners= fRevisionListeners.getListeners();
1566 for (int i= 0; i < listeners.length; i++) { 1566 for (int i= 0; i < listeners.length; i++) {
1567 IRevisionListener listener= (IRevisionListener) listeners[i]; 1567 IRevisionListener listener= cast(IRevisionListener) listeners[i];
1568 listener.revisionInformationChanged(event); 1568 listener.revisionInformationChanged(event);
1569 } 1569 }
1570 } 1570 }
1571 } 1571 }