Mercurial > projects > dwt-addons
comparison dwtx/jface/text/source/AnnotationPainter.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 |
---|---|
630 System.out.println("AP: INTERNAL CHANGE"); //$NON-NLS-1$ | 630 System.out.println("AP: INTERNAL CHANGE"); //$NON-NLS-1$ |
631 | 631 |
632 Iterator iter= decorationsMap.entrySet().iterator(); | 632 Iterator iter= decorationsMap.entrySet().iterator(); |
633 while (iter.hasNext()) { | 633 while (iter.hasNext()) { |
634 Map.Entry entry= (Map.Entry)iter.next(); | 634 Map.Entry entry= (Map.Entry)iter.next(); |
635 Annotation annotation= (Annotation)entry.getKey(); | 635 Annotation annotation= cast(Annotation)entry.getKey(); |
636 Decoration decoration= (Decoration)entry.getValue(); | 636 Decoration decoration= cast(Decoration)entry.getValue(); |
637 drawDecoration(decoration, null, annotation, clippingRegion, document); | 637 drawDecoration(decoration, null, annotation, clippingRegion, document); |
638 } | 638 } |
639 | 639 |
640 decorationsMap.clear(); | 640 decorationsMap.clear(); |
641 | 641 |
648 | 648 |
649 // Remove annotations | 649 // Remove annotations |
650 Annotation[] removedAnnotations= event.getRemovedAnnotations(); | 650 Annotation[] removedAnnotations= event.getRemovedAnnotations(); |
651 for (int i=0, length= removedAnnotations.length; i < length; i++) { | 651 for (int i=0, length= removedAnnotations.length; i < length; i++) { |
652 Annotation annotation= removedAnnotations[i]; | 652 Annotation annotation= removedAnnotations[i]; |
653 Decoration decoration= (Decoration)highlightedDecorationsMap.remove(annotation); | 653 Decoration decoration= cast(Decoration)highlightedDecorationsMap.remove(annotation); |
654 if (decoration !is null) { | 654 if (decoration !is null) { |
655 Position position= decoration.fPosition; | 655 Position position= decoration.fPosition; |
656 if (position !is null) { | 656 if (position !is null) { |
657 highlightAnnotationRangeStart= Math.min(highlightAnnotationRangeStart, position.offset); | 657 highlightAnnotationRangeStart= Math.min(highlightAnnotationRangeStart, position.offset); |
658 highlightAnnotationRangeEnd= Math.max(highlightAnnotationRangeEnd, position.offset + position.length); | 658 highlightAnnotationRangeEnd= Math.max(highlightAnnotationRangeEnd, position.offset + position.length); |
659 } | 659 } |
660 } | 660 } |
661 decoration= (Decoration)decorationsMap.remove(annotation); | 661 decoration= cast(Decoration)decorationsMap.remove(annotation); |
662 if (decoration !is null) { | 662 if (decoration !is null) { |
663 drawDecoration(decoration, null, annotation, clippingRegion, document); | 663 drawDecoration(decoration, null, annotation, clippingRegion, document); |
664 Position position= decoration.fPosition; | 664 Position position= decoration.fPosition; |
665 if (position !is null) { | 665 if (position !is null) { |
666 drawRangeStart= Math.min(drawRangeStart, position.offset); | 666 drawRangeStart= Math.min(drawRangeStart, position.offset); |
675 for (int i=0, length= changedAnnotations.length; i < length; i++) { | 675 for (int i=0, length= changedAnnotations.length; i < length; i++) { |
676 Annotation annotation= changedAnnotations[i]; | 676 Annotation annotation= changedAnnotations[i]; |
677 | 677 |
678 bool isHighlighting= false; | 678 bool isHighlighting= false; |
679 | 679 |
680 Decoration decoration= (Decoration)highlightedDecorationsMap.get(annotation); | 680 Decoration decoration= cast(Decoration)highlightedDecorationsMap.get(annotation); |
681 | 681 |
682 if (decoration !is null) { | 682 if (decoration !is null) { |
683 isHighlighting= true; | 683 isHighlighting= true; |
684 // The call below updates the decoration - no need to create new decoration | 684 // The call below updates the decoration - no need to create new decoration |
685 decoration= getDecoration(annotation, decoration); | 685 decoration= getDecoration(annotation, decoration); |
713 } else { | 713 } else { |
714 highlightedDecorationsMap.remove(annotation); | 714 highlightedDecorationsMap.remove(annotation); |
715 } | 715 } |
716 | 716 |
717 if (usesDrawingStrategy) { | 717 if (usesDrawingStrategy) { |
718 Decoration oldDecoration= (Decoration)decorationsMap.get(annotation); | 718 Decoration oldDecoration= cast(Decoration)decorationsMap.get(annotation); |
719 if (oldDecoration !is null) { | 719 if (oldDecoration !is null) { |
720 drawDecoration(oldDecoration, null, annotation, clippingRegion, document); | 720 drawDecoration(oldDecoration, null, annotation, clippingRegion, document); |
721 | 721 |
722 if (decoration !is null) | 722 if (decoration !is null) |
723 decorationsMap.put(annotation, decoration); | 723 decorationsMap.put(annotation, decoration); |
730 e= Arrays.asList(event.getAddedAnnotations()).iterator(); | 730 e= Arrays.asList(event.getAddedAnnotations()).iterator(); |
731 } | 731 } |
732 | 732 |
733 // Add new annotations | 733 // Add new annotations |
734 while (e.hasNext()) { | 734 while (e.hasNext()) { |
735 Annotation annotation= (Annotation) e.next(); | 735 Annotation annotation= cast(Annotation) e.next(); |
736 Decoration pp= getDecoration(annotation, null); | 736 Decoration pp= getDecoration(annotation, null); |
737 if (pp !is null) { | 737 if (pp !is null) { |
738 if (pp.fPaintingStrategy instanceof IDrawingStrategy) { | 738 if (pp.fPaintingStrategy instanceof IDrawingStrategy) { |
739 decorationsMap.put(annotation, pp); | 739 decorationsMap.put(annotation, pp); |
740 drawRangeStart= Math.min(drawRangeStart, pp.fPosition.offset); | 740 drawRangeStart= Math.min(drawRangeStart, pp.fPosition.offset); |
911 decoration= new Decoration(); | 911 decoration= new Decoration(); |
912 | 912 |
913 decoration.fPosition= position; | 913 decoration.fPosition= position; |
914 decoration.fColor= color; | 914 decoration.fColor= color; |
915 if (fAnnotationAccess instanceof IAnnotationAccessExtension) { | 915 if (fAnnotationAccess instanceof IAnnotationAccessExtension) { |
916 IAnnotationAccessExtension extension= (IAnnotationAccessExtension) fAnnotationAccess; | 916 IAnnotationAccessExtension extension= cast(IAnnotationAccessExtension) fAnnotationAccess; |
917 decoration.fLayer= extension.getLayer(annotation); | 917 decoration.fLayer= extension.getLayer(annotation); |
918 } else { | 918 } else { |
919 decoration.fLayer= IAnnotationAccessExtension.DEFAULT_LAYER; | 919 decoration.fLayer= IAnnotationAccessExtension.DEFAULT_LAYER; |
920 } | 920 } |
921 | 921 |
941 fCachedAnnotationType2PaintingStrategy.put(type, strategy); | 941 fCachedAnnotationType2PaintingStrategy.put(type, strategy); |
942 return strategy; | 942 return strategy; |
943 } | 943 } |
944 | 944 |
945 if (fAnnotationAccess instanceof IAnnotationAccessExtension) { | 945 if (fAnnotationAccess instanceof IAnnotationAccessExtension) { |
946 IAnnotationAccessExtension ext = (IAnnotationAccessExtension) fAnnotationAccess; | 946 IAnnotationAccessExtension ext = cast(IAnnotationAccessExtension) fAnnotationAccess; |
947 Object[] sts = ext.getSupertypes(type); | 947 Object[] sts = ext.getSupertypes(type); |
948 for (int i= 0; i < sts.length; i++) { | 948 for (int i= 0; i < sts.length; i++) { |
949 strategy= fPaintingStrategyId2PaintingStrategy.get(fAnnotationType2PaintingStrategyId.get(sts[i])); | 949 strategy= fPaintingStrategyId2PaintingStrategy.get(fAnnotationType2PaintingStrategyId.get(sts[i])); |
950 if (strategy !is null) { | 950 if (strategy !is null) { |
951 fCachedAnnotationType2PaintingStrategy.put(type, strategy); | 951 fCachedAnnotationType2PaintingStrategy.put(type, strategy); |
965 * @param annotationType the annotation type | 965 * @param annotationType the annotation type |
966 * @return the color | 966 * @return the color |
967 * @since 3.0 | 967 * @since 3.0 |
968 */ | 968 */ |
969 private Color getColor(final Object annotationType) { | 969 private Color getColor(final Object annotationType) { |
970 Color color= (Color)fCachedAnnotationType2Color.get(annotationType); | 970 Color color= cast(Color)fCachedAnnotationType2Color.get(annotationType); |
971 if (color !is null) | 971 if (color !is null) |
972 return color; | 972 return color; |
973 | 973 |
974 color= (Color)fAnnotationType2Color.get(annotationType); | 974 color= cast(Color)fAnnotationType2Color.get(annotationType); |
975 if (color !is null) { | 975 if (color !is null) { |
976 fCachedAnnotationType2Color.put(annotationType, color); | 976 fCachedAnnotationType2Color.put(annotationType, color); |
977 return color; | 977 return color; |
978 } | 978 } |
979 | 979 |
980 if (fAnnotationAccess instanceof IAnnotationAccessExtension) { | 980 if (fAnnotationAccess instanceof IAnnotationAccessExtension) { |
981 IAnnotationAccessExtension extension= (IAnnotationAccessExtension) fAnnotationAccess; | 981 IAnnotationAccessExtension extension= cast(IAnnotationAccessExtension) fAnnotationAccess; |
982 Object[] superTypes= extension.getSupertypes(annotationType); | 982 Object[] superTypes= extension.getSupertypes(annotationType); |
983 if (superTypes !is null) { | 983 if (superTypes !is null) { |
984 for (int i= 0; i < superTypes.length; i++) { | 984 for (int i= 0; i < superTypes.length; i++) { |
985 color= (Color)fAnnotationType2Color.get(superTypes[i]); | 985 color= cast(Color)fAnnotationType2Color.get(superTypes[i]); |
986 if (color !is null) { | 986 if (color !is null) { |
987 fCachedAnnotationType2Color.put(annotationType, color); | 987 fCachedAnnotationType2Color.put(annotationType, color); |
988 return color; | 988 return color; |
989 } | 989 } |
990 } | 990 } |
1019 } | 1019 } |
1020 if (r is null) | 1020 if (r is null) |
1021 return; | 1021 return; |
1022 | 1022 |
1023 if (fSourceViewer instanceof ITextViewerExtension2) { | 1023 if (fSourceViewer instanceof ITextViewerExtension2) { |
1024 if (DEBUG) | 1024 if cast(DEBUG) |
1025 System.out.println("AP: invalidating offset: " + r.getOffset() + ", length= " + r.getLength()); //$NON-NLS-1$ //$NON-NLS-2$ | 1025 System.out.println("AP: invalidating offset: " + r.getOffset() + ", length= " + r.getLength()); //$NON-NLS-1$ //$NON-NLS-2$ |
1026 | 1026 |
1027 ((ITextViewerExtension2)fSourceViewer).invalidateTextPresentation(r.getOffset(), r.getLength()); | 1027 (cast(ITextViewerExtension2)fSourceViewer).invalidateTextPresentation(r.getOffset(), r.getLength()); |
1028 | 1028 |
1029 } else { | 1029 } else { |
1030 fSourceViewer.invalidateTextPresentation(); | 1030 fSourceViewer.invalidateTextPresentation(); |
1031 } | 1031 } |
1032 } | 1032 } |
1045 decorations= new HashSet(fHighlightedDecorationsMap.entrySet()); | 1045 decorations= new HashSet(fHighlightedDecorationsMap.entrySet()); |
1046 } | 1046 } |
1047 | 1047 |
1048 IRegion region= tp.getExtent(); | 1048 IRegion region= tp.getExtent(); |
1049 | 1049 |
1050 if (DEBUG) | 1050 if cast(DEBUG) |
1051 System.out.println("AP: applying text presentation offset: " + region.getOffset() + ", length= " + region.getLength()); //$NON-NLS-1$ //$NON-NLS-2$ | 1051 System.out.println("AP: applying text presentation offset: " + region.getOffset() + ", length= " + region.getLength()); //$NON-NLS-1$ //$NON-NLS-2$ |
1052 | 1052 |
1053 for (int layer= 0, maxLayer= 1; layer < maxLayer; layer++) { | 1053 for (int layer= 0, maxLayer= 1; layer < maxLayer; layer++) { |
1054 | 1054 |
1055 for (Iterator iter= decorations.iterator(); iter.hasNext();) { | 1055 for (Iterator iter= decorations.iterator(); iter.hasNext();) { |
1056 Map.Entry entry= (Map.Entry)iter.next(); | 1056 Map.Entry entry= (Map.Entry)iter.next(); |
1057 | 1057 |
1058 Annotation a= (Annotation)entry.getKey(); | 1058 Annotation a= cast(Annotation)entry.getKey(); |
1059 if (a.isMarkedDeleted()) | 1059 if (a.isMarkedDeleted()) |
1060 continue; | 1060 continue; |
1061 | 1061 |
1062 Decoration pp = (Decoration)entry.getValue(); | 1062 Decoration pp = cast(Decoration)entry.getValue(); |
1063 | 1063 |
1064 maxLayer= Math.max(maxLayer, pp.fLayer + 1); // dynamically update layer maximum | 1064 maxLayer= Math.max(maxLayer, pp.fLayer + 1); // dynamically update layer maximum |
1065 if (pp.fLayer !is layer) // wrong layer: skip annotation | 1065 if (pp.fLayer !is layer) // wrong layer: skip annotation |
1066 continue; | 1066 continue; |
1067 | 1067 |
1068 Position p= pp.fPosition; | 1068 Position p= pp.fPosition; |
1069 if (fSourceViewer instanceof ITextViewerExtension5) { | 1069 if (fSourceViewer instanceof ITextViewerExtension5) { |
1070 ITextViewerExtension5 extension3= (ITextViewerExtension5) fSourceViewer; | 1070 ITextViewerExtension5 extension3= cast(ITextViewerExtension5) fSourceViewer; |
1071 if (null is extension3.modelRange2WidgetRange(new Region(p.getOffset(), p.getLength()))) | 1071 if (null is extension3.modelRange2WidgetRange(new Region(p.getOffset(), p.getLength()))) |
1072 continue; | 1072 continue; |
1073 } else if (!fSourceViewer.overlapsWithVisibleRegion(p.offset, p.length)) { | 1073 } else if (!fSourceViewer.overlapsWithVisibleRegion(p.offset, p.length)) { |
1074 continue; | 1074 continue; |
1075 } | 1075 } |
1079 if (pEnd >= region.getOffset() && regionEnd > p.getOffset()) { | 1079 if (pEnd >= region.getOffset() && regionEnd > p.getOffset()) { |
1080 int start= Math.max(p.getOffset(), region.getOffset()); | 1080 int start= Math.max(p.getOffset(), region.getOffset()); |
1081 int end= Math.min(regionEnd, pEnd); | 1081 int end= Math.min(regionEnd, pEnd); |
1082 int length= Math.max(end - start, 0); | 1082 int length= Math.max(end - start, 0); |
1083 StyleRange styleRange= new StyleRange(start, length, null, null); | 1083 StyleRange styleRange= new StyleRange(start, length, null, null); |
1084 ((ITextStyleStrategy)pp.fPaintingStrategy).applyTextStyle(styleRange, pp.fColor); | 1084 (cast(ITextStyleStrategy)pp.fPaintingStrategy).applyTextStyle(styleRange, pp.fColor); |
1085 tp.mergeStyleRange(styleRange); | 1085 tp.mergeStyleRange(styleRange); |
1086 } | 1086 } |
1087 } | 1087 } |
1088 } | 1088 } |
1089 } | 1089 } |
1090 | 1090 |
1091 /* | 1091 /* |
1092 * @see dwtx.jface.text.source.IAnnotationModelListener#modelChanged(dwtx.jface.text.source.IAnnotationModel) | 1092 * @see dwtx.jface.text.source.IAnnotationModelListener#modelChanged(dwtx.jface.text.source.IAnnotationModel) |
1093 */ | 1093 */ |
1094 public synchronized void modelChanged(final IAnnotationModel model) { | 1094 public synchronized void modelChanged(final IAnnotationModel model) { |
1095 if (DEBUG) | 1095 if cast(DEBUG) |
1096 System.err.println("AP: OLD API of AnnotationModelListener called"); //$NON-NLS-1$ | 1096 System.err.println("AP: OLD API of AnnotationModelListener called"); //$NON-NLS-1$ |
1097 | 1097 |
1098 modelChanged(new AnnotationModelEvent(model)); | 1098 modelChanged(new AnnotationModelEvent(model)); |
1099 } | 1099 } |
1100 | 1100 |
1433 */ | 1433 */ |
1434 ArrayList toBeDrawn= new ArrayList(10); | 1434 ArrayList toBeDrawn= new ArrayList(10); |
1435 for (Iterator e = decorations.iterator(); e.hasNext();) { | 1435 for (Iterator e = decorations.iterator(); e.hasNext();) { |
1436 Map.Entry entry= (Map.Entry)e.next(); | 1436 Map.Entry entry= (Map.Entry)e.next(); |
1437 | 1437 |
1438 Annotation a= (Annotation)entry.getKey(); | 1438 Annotation a= cast(Annotation)entry.getKey(); |
1439 Decoration pp = (Decoration)entry.getValue(); | 1439 Decoration pp = cast(Decoration)entry.getValue(); |
1440 // prune any annotation that is not drawable or does not need drawing | 1440 // prune any annotation that is not drawable or does not need drawing |
1441 if (!(a.isMarkedDeleted() || skip(a) || !pp.fPosition.overlapsWith(vOffset, vLength))) { | 1441 if (!(a.isMarkedDeleted() || skip(a) || !pp.fPosition.overlapsWith(vOffset, vLength))) { |
1442 // ensure sized appropriately | 1442 // ensure sized appropriately |
1443 for (int i= toBeDrawn.size(); i <= pp.fLayer; i++) | 1443 for (int i= toBeDrawn.size(); i <= pp.fLayer; i++) |
1444 toBeDrawn.add(new LinkedList()); | 1444 toBeDrawn.add(new LinkedList()); |
1445 ((List) toBeDrawn.get(pp.fLayer)).add(entry); | 1445 (cast(List) toBeDrawn.get(pp.fLayer)).add(entry); |
1446 } | 1446 } |
1447 } | 1447 } |
1448 IDocument document= fSourceViewer.getDocument(); | 1448 IDocument document= fSourceViewer.getDocument(); |
1449 for (Iterator it= toBeDrawn.iterator(); it.hasNext();) { | 1449 for (Iterator it= toBeDrawn.iterator(); it.hasNext();) { |
1450 List layer= (List) it.next(); | 1450 List layer= cast(List) it.next(); |
1451 for (Iterator e = layer.iterator(); e.hasNext();) { | 1451 for (Iterator e = layer.iterator(); e.hasNext();) { |
1452 Map.Entry entry= (Map.Entry)e.next(); | 1452 Map.Entry entry= (Map.Entry)e.next(); |
1453 Annotation a= (Annotation)entry.getKey(); | 1453 Annotation a= cast(Annotation)entry.getKey(); |
1454 Decoration pp = (Decoration)entry.getValue(); | 1454 Decoration pp = cast(Decoration)entry.getValue(); |
1455 drawDecoration(pp, gc, a, clippingRegion, document); | 1455 drawDecoration(pp, gc, a, clippingRegion, document); |
1456 } | 1456 } |
1457 } | 1457 } |
1458 } | 1458 } |
1459 | 1459 |
1462 return; | 1462 return; |
1463 | 1463 |
1464 if (!(pp.fPaintingStrategy instanceof IDrawingStrategy)) | 1464 if (!(pp.fPaintingStrategy instanceof IDrawingStrategy)) |
1465 return; | 1465 return; |
1466 | 1466 |
1467 IDrawingStrategy drawingStrategy= (IDrawingStrategy)pp.fPaintingStrategy; | 1467 IDrawingStrategy drawingStrategy= cast(IDrawingStrategy)pp.fPaintingStrategy; |
1468 | 1468 |
1469 int clippingOffset= clippingRegion.getOffset(); | 1469 int clippingOffset= clippingRegion.getOffset(); |
1470 int clippingLength= clippingRegion.getLength(); | 1470 int clippingLength= clippingRegion.getLength(); |
1471 | 1471 |
1472 Position p= pp.fPosition; | 1472 Position p= pp.fPosition; |
1587 | 1587 |
1588 if (fReusableRegion is null || fReusableRegion.getOffset() is Integer.MAX_VALUE) | 1588 if (fReusableRegion is null || fReusableRegion.getOffset() is Integer.MAX_VALUE) |
1589 return null; | 1589 return null; |
1590 | 1590 |
1591 if (fSourceViewer instanceof ITextViewerExtension5) { | 1591 if (fSourceViewer instanceof ITextViewerExtension5) { |
1592 ITextViewerExtension5 extension= (ITextViewerExtension5) fSourceViewer; | 1592 ITextViewerExtension5 extension= cast(ITextViewerExtension5) fSourceViewer; |
1593 return extension.modelRange2WidgetRange(fReusableRegion); | 1593 return extension.modelRange2WidgetRange(fReusableRegion); |
1594 } | 1594 } |
1595 | 1595 |
1596 IRegion region= fSourceViewer.getVisibleRegion(); | 1596 IRegion region= fSourceViewer.getVisibleRegion(); |
1597 int offset= region.getOffset(); | 1597 int offset= region.getOffset(); |
1617 private IRegion getModelRange(int offset, int length) { | 1617 private IRegion getModelRange(int offset, int length) { |
1618 if (offset is Integer.MAX_VALUE) | 1618 if (offset is Integer.MAX_VALUE) |
1619 return null; | 1619 return null; |
1620 | 1620 |
1621 if (fSourceViewer instanceof ITextViewerExtension5) { | 1621 if (fSourceViewer instanceof ITextViewerExtension5) { |
1622 ITextViewerExtension5 extension= (ITextViewerExtension5) fSourceViewer; | 1622 ITextViewerExtension5 extension= cast(ITextViewerExtension5) fSourceViewer; |
1623 return extension.widgetRange2ModelRange(new Region(offset, length)); | 1623 return extension.widgetRange2ModelRange(new Region(offset, length)); |
1624 } | 1624 } |
1625 | 1625 |
1626 IRegion region= fSourceViewer.getVisibleRegion(); | 1626 IRegion region= fSourceViewer.getVisibleRegion(); |
1627 return new Region(region.getOffset() + offset, length); | 1627 return new Region(region.getOffset() + offset, length); |