2 * Copyright 2000-2010 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com.intellij.openapi.vcs.actions;
18 import com.intellij.openapi.actionSystem.AnAction;
19 import com.intellij.openapi.editor.colors.ColorKey;
20 import com.intellij.openapi.editor.colors.EditorFontType;
21 import com.intellij.openapi.localVcs.UpToDateLineNumberProvider;
22 import com.intellij.openapi.vcs.annotate.*;
23 import com.intellij.openapi.vcs.history.VcsRevisionNumber;
24 import com.intellij.util.Consumer;
25 import com.intellij.util.ObjectUtils;
26 import org.jetbrains.annotations.NotNull;
27 import org.jetbrains.annotations.Nullable;
29 import java.util.ArrayList;
30 import java.util.List;
32 class AnnotationPresentation implements TextAnnotationPresentation {
33 @NotNull private final FileAnnotation myFileAnnotation;
34 @NotNull private final UpToDateLineNumberProvider myUpToDateLineNumberProvider;
35 @Nullable private final AnnotationSourceSwitcher mySwitcher;
36 private final ArrayList<AnAction> myActions = new ArrayList<>();
38 AnnotationPresentation(@NotNull FileAnnotation fileAnnotation,
39 @NotNull UpToDateLineNumberProvider upToDateLineNumberProvider,
40 @Nullable final AnnotationSourceSwitcher switcher) {
41 myUpToDateLineNumberProvider = upToDateLineNumberProvider;
42 myFileAnnotation = fileAnnotation;
43 mySwitcher = switcher;
46 public EditorFontType getFontType(final int line) {
47 VcsRevisionNumber revision = myFileAnnotation.originalRevision(line);
48 VcsRevisionNumber currentRevision = myFileAnnotation.getCurrentRevision();
49 return currentRevision != null && currentRevision.equals(revision) ? EditorFontType.BOLD : EditorFontType.PLAIN;
52 public ColorKey getColor(final int line) {
53 if (mySwitcher == null) return AnnotationSource.LOCAL.getColor();
54 return mySwitcher.getAnnotationSource(line).getColor();
57 public List<AnAction> getActions(int line) {
58 int correctedNumber = myUpToDateLineNumberProvider.getLineNumber(line);
59 for (AnAction action : myActions) {
60 UpToDateLineNumberListener upToDateListener = ObjectUtils.tryCast(action, UpToDateLineNumberListener.class);
61 if (upToDateListener != null) upToDateListener.consume(correctedNumber);
63 LineNumberListener listener = ObjectUtils.tryCast(action, LineNumberListener.class);
64 if (listener != null) listener.consume(line);
71 public List<AnAction> getActions() {
75 public void addAction(AnAction action) {
76 myActions.add(action);
79 public void addAction(AnAction action, int index) {
80 myActions.add(index, action);