Search in sources :

Example 1 with RefGroup

use of com.intellij.vcs.log.RefGroup in project intellij-community by JetBrains.

the class SimpleRefGroup method buildGroups.

public static void buildGroups(@NotNull MultiMap<VcsRefType, VcsRef> groupedRefs, boolean compact, boolean showTagNames, @NotNull List<RefGroup> result) {
    if (groupedRefs.isEmpty())
        return;
    if (compact) {
        VcsRef firstRef = ObjectUtils.assertNotNull(ContainerUtil.getFirstItem(groupedRefs.values()));
        RefGroup group = ContainerUtil.getFirstItem(result);
        if (group == null) {
            result.add(new SimpleRefGroup(firstRef.getType().isBranch() || showTagNames ? firstRef.getName() : "", ContainerUtil.newArrayList(groupedRefs.values())));
        } else {
            group.getRefs().addAll(groupedRefs.values());
        }
    } else {
        for (Map.Entry<VcsRefType, Collection<VcsRef>> entry : groupedRefs.entrySet()) {
            if (entry.getKey().isBranch()) {
                for (VcsRef ref : entry.getValue()) {
                    result.add(new SimpleRefGroup(ref.getName(), ContainerUtil.newArrayList(ref)));
                }
            } else {
                result.add(new SimpleRefGroup(showTagNames ? ObjectUtils.notNull(ContainerUtil.getFirstItem(entry.getValue())).getName() : "", ContainerUtil.newArrayList(entry.getValue())));
            }
        }
    }
}
Also used : VcsRefType(com.intellij.vcs.log.VcsRefType) VcsRef(com.intellij.vcs.log.VcsRef) MultiMap(com.intellij.util.containers.MultiMap) RefGroup(com.intellij.vcs.log.RefGroup)

Example 2 with RefGroup

use of com.intellij.vcs.log.RefGroup in project intellij-community by JetBrains.

the class LabelPainter method calculateLongPresentation.

@NotNull
private static Pair<List<Pair<String, LabelIcon>>, Integer> calculateLongPresentation(@NotNull List<RefGroup> refGroups, @NotNull FontMetrics fontMetrics, int height, @NotNull Color background, int availableWidth) {
    int width = LEFT_PADDING + RIGHT_PADDING;
    List<Pair<String, LabelIcon>> labels = ContainerUtil.newArrayList();
    if (refGroups.isEmpty())
        return Pair.create(labels, width);
    for (int i = 0; i < refGroups.size(); i++) {
        RefGroup group = refGroups.get(i);
        int doNotFitWidth = 0;
        if (i < refGroups.size() - 1) {
            LabelIcon lastIcon = new LabelIcon(height, background, getColors(refGroups.subList(i + 1, refGroups.size())));
            doNotFitWidth = lastIcon.getIconWidth();
        }
        List<Color> colors = group.getColors();
        LabelIcon labelIcon = new LabelIcon(height, background, colors.toArray(new Color[colors.size()]));
        int newWidth = width + labelIcon.getIconWidth() + (i != refGroups.size() - 1 ? MIDDLE_PADDING : 0);
        String text = getGroupText(group, fontMetrics, availableWidth - newWidth - doNotFitWidth);
        newWidth += fontMetrics.stringWidth(text);
        if (availableWidth - newWidth - doNotFitWidth < 0) {
            LabelIcon lastIcon = new LabelIcon(height, background, getColors(refGroups.subList(i, refGroups.size())));
            String name = labels.isEmpty() ? text : "";
            labels.add(Pair.create(name, lastIcon));
            width += fontMetrics.stringWidth(name) + lastIcon.getIconWidth();
            break;
        } else {
            labels.add(Pair.create(text, labelIcon));
            width = newWidth;
        }
    }
    return Pair.create(labels, width);
}
Also used : JBColor(com.intellij.ui.JBColor) RefGroup(com.intellij.vcs.log.RefGroup) Pair(com.intellij.openapi.util.Pair) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with RefGroup

use of com.intellij.vcs.log.RefGroup in project intellij-community by JetBrains.

the class LabelPainter method calculateCompactPresentation.

@NotNull
private static Pair<List<Pair<String, LabelIcon>>, Integer> calculateCompactPresentation(@NotNull List<RefGroup> refGroups, @NotNull FontMetrics fontMetrics, int height, @NotNull Color background, int availableWidth) {
    int width = LEFT_PADDING + RIGHT_PADDING;
    List<Pair<String, LabelIcon>> labels = ContainerUtil.newArrayList();
    if (refGroups.isEmpty())
        return Pair.create(labels, width);
    for (RefGroup group : refGroups) {
        List<Color> colors = group.getColors();
        LabelIcon labelIcon = new LabelIcon(height, background, colors.toArray(new Color[colors.size()]));
        int newWidth = width + labelIcon.getIconWidth() + (group != ContainerUtil.getLastItem(refGroups) ? COMPACT_MIDDLE_PADDING : 0);
        String text = shortenRefName(group.getName(), fontMetrics, availableWidth - newWidth);
        newWidth += fontMetrics.stringWidth(text);
        labels.add(Pair.create(text, labelIcon));
        width = newWidth;
    }
    return Pair.create(labels, width);
}
Also used : JBColor(com.intellij.ui.JBColor) RefGroup(com.intellij.vcs.log.RefGroup) Pair(com.intellij.openapi.util.Pair) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with RefGroup

use of com.intellij.vcs.log.RefGroup in project intellij-community by JetBrains.

the class LabelPainter method customizePainter.

public void customizePainter(@NotNull JComponent component, @NotNull Collection<VcsRef> references, @NotNull Color background, @NotNull Color foreground, boolean isSelected, int availableWidth) {
    myBackground = background;
    myForeground = isSelected ? foreground : TEXT_COLOR;
    FontMetrics metrics = component.getFontMetrics(getReferenceFont());
    myHeight = metrics.getHeight() + TOP_TEXT_PADDING + BOTTOM_TEXT_PADDING;
    VcsLogRefManager manager = getRefManager(myLogData, references);
    List<RefGroup> refGroups = manager == null ? ContainerUtil.emptyList() : manager.groupForTable(references, myCompact, myShowTagNames);
    myGreyBackground = calculateGreyBackground(refGroups, background, isSelected, myCompact);
    Pair<List<Pair<String, LabelIcon>>, Integer> presentation = calculatePresentation(refGroups, metrics, myHeight, myGreyBackground != null ? myGreyBackground : myBackground, availableWidth, myCompact);
    myLabels = presentation.first;
    myWidth = presentation.second;
}
Also used : VcsLogRefManager(com.intellij.vcs.log.VcsLogRefManager) List(java.util.List) RefGroup(com.intellij.vcs.log.RefGroup)

Example 5 with RefGroup

use of com.intellij.vcs.log.RefGroup in project intellij-community by JetBrains.

the class LabelPainter method getColors.

@NotNull
private static Color[] getColors(@NotNull Collection<RefGroup> groups) {
    LinkedHashMap<Color, Integer> usedColors = ContainerUtil.newLinkedHashMap();
    for (RefGroup group : groups) {
        List<Color> colors = group.getColors();
        for (Color color : colors) {
            Integer count = usedColors.get(color);
            if (count == null)
                count = 0;
            usedColors.put(color, count + 1);
        }
    }
    List<Color> result = ContainerUtil.newArrayList();
    for (Map.Entry<Color, Integer> entry : usedColors.entrySet()) {
        result.add(entry.getKey());
        if (entry.getValue() > 1) {
            result.add(entry.getKey());
        }
    }
    return result.toArray(new Color[result.size()]);
}
Also used : JBColor(com.intellij.ui.JBColor) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) RefGroup(com.intellij.vcs.log.RefGroup) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

RefGroup (com.intellij.vcs.log.RefGroup)5 JBColor (com.intellij.ui.JBColor)3 NotNull (org.jetbrains.annotations.NotNull)3 Pair (com.intellij.openapi.util.Pair)2 MultiMap (com.intellij.util.containers.MultiMap)1 VcsLogRefManager (com.intellij.vcs.log.VcsLogRefManager)1 VcsRef (com.intellij.vcs.log.VcsRef)1 VcsRefType (com.intellij.vcs.log.VcsRefType)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1