use of com.intellij.openapi.util.Comparing in project intellij-community by JetBrains.
the class AnnotateToggleAction method computeBgColors.
@Nullable
private static Couple<Map<VcsRevisionNumber, Color>> computeBgColors(@NotNull FileAnnotation fileAnnotation, @NotNull Editor editor) {
Map<VcsRevisionNumber, Color> commitOrderColors = new HashMap<>();
Map<VcsRevisionNumber, Color> commitAuthorColors = new HashMap<>();
EditorColorsScheme colorScheme = editor.getColorsScheme();
AnnotationsSettings settings = AnnotationsSettings.getInstance();
List<Color> authorsColorPalette = settings.getAuthorsColors(colorScheme);
List<Color> orderedColorPalette = settings.getOrderedColors(colorScheme);
FileAnnotation.AuthorsMappingProvider authorsMappingProvider = fileAnnotation.getAuthorsMappingProvider();
if (authorsMappingProvider != null) {
Map<VcsRevisionNumber, String> authorsMap = authorsMappingProvider.getAuthors();
Map<String, Color> authorColors = new HashMap<>();
for (String author : ContainerUtil.sorted(authorsMap.values(), Comparing::compare)) {
int index = authorColors.size();
Color color = authorsColorPalette.get(index % authorsColorPalette.size());
authorColors.put(author, color);
}
for (Map.Entry<VcsRevisionNumber, String> entry : authorsMap.entrySet()) {
VcsRevisionNumber revision = entry.getKey();
String author = entry.getValue();
Color color = authorColors.get(author);
commitAuthorColors.put(revision, color);
}
}
FileAnnotation.RevisionsOrderProvider revisionsOrderProvider = fileAnnotation.getRevisionsOrderProvider();
if (revisionsOrderProvider != null) {
List<List<VcsRevisionNumber>> orderedRevisions = revisionsOrderProvider.getOrderedRevisions();
int revisionsCount = orderedRevisions.size();
for (int index = 0; index < revisionsCount; index++) {
Color color = orderedColorPalette.get(orderedColorPalette.size() * index / revisionsCount);
for (VcsRevisionNumber number : orderedRevisions.get(index)) {
commitOrderColors.put(number, color);
}
}
}
return Couple.of(commitOrderColors.size() > 1 ? commitOrderColors : null, commitAuthorColors.size() > 1 ? commitAuthorColors : null);
}
Aggregations