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.diff.impl.util;
18 import com.intellij.openapi.diff.DiffBundle;
19 import com.intellij.openapi.diff.DiffColors;
20 import com.intellij.openapi.diff.ex.DiffStatusBar;
21 import com.intellij.openapi.editor.Editor;
22 import com.intellij.openapi.editor.colors.EditorColorsScheme;
23 import com.intellij.openapi.editor.colors.TextAttributesKey;
24 import com.intellij.openapi.editor.markup.TextAttributes;
25 import com.intellij.util.containers.Convertor;
26 import org.jetbrains.annotations.NotNull;
27 import org.jetbrains.annotations.Nullable;
30 import java.util.Arrays;
31 import java.util.List;
33 public class TextDiffType implements DiffStatusBar.LegendTypeDescriptor {
34 public static final TextDiffType INSERT = new TextDiffType(TextDiffTypeEnum.INSERT, DiffBundle.message("diff.type.inserted.name"), DiffColors.DIFF_INSERTED);
35 public static final TextDiffType CHANGED = new TextDiffType(TextDiffTypeEnum.CHANGED, DiffBundle.message("diff.type.changed.name"), DiffColors.DIFF_MODIFIED);
36 public static final TextDiffType DELETED = new TextDiffType(TextDiffTypeEnum.DELETED, DiffBundle.message("diff.type.deleted.name"), DiffColors.DIFF_DELETED);
37 public static final TextDiffType CONFLICT = new TextDiffType(TextDiffTypeEnum.CONFLICT, DiffBundle.message("diff.type.conflict.name"), DiffColors.DIFF_CONFLICT);
39 public static final TextDiffType NONE = new TextDiffType(TextDiffTypeEnum.NONE, DiffBundle.message("diff.type.none.name"), null);
41 private final TextDiffTypeEnum myType;
42 public static final List<TextDiffType> DIFF_TYPES = Arrays.asList(DELETED, CHANGED, INSERT);
43 public static final List<TextDiffType> MERGE_TYPES = Arrays.asList(DELETED, CHANGED, INSERT, CONFLICT);
44 private final TextAttributesKey myAttributesKey;
45 private final String myDisplayName;
46 public static final Convertor<TextDiffType, TextAttributesKey> ATTRIBUTES_KEY = new Convertor<TextDiffType, TextAttributesKey>() {
47 public TextAttributesKey convert(TextDiffType textDiffType) {
48 return textDiffType.getAttributesKey();
52 public static TextDiffType create(@NotNull final TextDiffTypeEnum type) {
53 if (TextDiffTypeEnum.INSERT.equals(type)) {
55 } else if (TextDiffTypeEnum.CHANGED.equals(type)) {
57 } else if (TextDiffTypeEnum.DELETED.equals(type)) {
59 } else if (TextDiffTypeEnum.CONFLICT.equals(type)) {
67 private TextDiffType(TextDiffTypeEnum type, String displayName, TextAttributesKey attrubutesKey) {
69 myAttributesKey = attrubutesKey;
70 myDisplayName = displayName;
73 public String getDisplayName() {
78 public Color getLegendColor(EditorColorsScheme colorScheme) {
79 TextAttributes attributes = getTextAttributes(colorScheme);
80 return attributes != null ? attributes.getBackgroundColor() : null;
83 public TextAttributesKey getAttributesKey() {
84 return myAttributesKey;
87 public TextAttributes getTextAttributes(EditorColorsScheme scheme) {
88 return scheme.getAttributes(myAttributesKey);
92 public Color getPolygonColor(Editor editor) {
93 return getLegendColor(editor.getColorsScheme());
96 public TextAttributes getTextAttributes(Editor editor1) {
97 return getTextAttributes(editor1.getColorsScheme());
101 public Color getTextBackground(Editor editor) {
102 TextAttributes attributes = getTextAttributes(editor);
103 return attributes != null ? attributes.getBackgroundColor() : null;
106 public String toString(){
107 return myDisplayName;
110 public TextDiffTypeEnum getType() {