Search in sources :

Example 1 with Comparing

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);
}
Also used : HashMap(java.util.HashMap) VcsRevisionNumber(com.intellij.openapi.vcs.history.VcsRevisionNumber) EditorColorsScheme(com.intellij.openapi.editor.colors.EditorColorsScheme) ArrayList(java.util.ArrayList) List(java.util.List) FileAnnotation(com.intellij.openapi.vcs.annotate.FileAnnotation) HashMap(java.util.HashMap) Map(java.util.Map) Comparing(com.intellij.openapi.util.Comparing) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

EditorColorsScheme (com.intellij.openapi.editor.colors.EditorColorsScheme)1 Comparing (com.intellij.openapi.util.Comparing)1 FileAnnotation (com.intellij.openapi.vcs.annotate.FileAnnotation)1 VcsRevisionNumber (com.intellij.openapi.vcs.history.VcsRevisionNumber)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Nullable (org.jetbrains.annotations.Nullable)1