SVN auth
[fedora-idea.git] / plugins / svn4idea / src / org / jetbrains / idea / svn / ConflictState.java
blob1ae65c26dab0a2b63a7d2b7720b3bf92f64ac9da
1 /*
2 * Copyright 2000-2009 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 org.jetbrains.idea.svn;
18 import com.intellij.openapi.util.IconLoader;
19 import org.jetbrains.annotations.Nullable;
21 import javax.swing.*;
23 public enum ConflictState {
24 none(false, false, false, null),
25 tree(true, false, false, "/icons/conflictc.png"),
26 text(false, true, false, "/icons/conflictt.png"),
27 prop(false, false, true, "/icons/conflictp.png"),
28 tree_text(true, true, false, "/icons/conflictct.png"), // ? -
29 tree_prop(true, false, true, "/icons/conflictcp.png"), // now falls but marked
30 text_prop(false, true, true, "/icons/conflicttp.png"),
31 all3(true, true, true, "/icons/conflictctp.png"); // ? -
33 private final boolean myTree;
34 private final boolean myText;
35 private final boolean myProperty;
36 @Nullable
37 private final Icon myIcon;
38 private final String myDescription;
40 private ConflictState(final boolean tree, final boolean text, final boolean property, final String iconPath) {
41 myTree = tree;
42 myText = text;
43 myProperty = property;
45 if (iconPath != null) {
46 myIcon = IconLoader.getIcon(iconPath);
47 } else {
48 myIcon = null;
51 myDescription = createDescription();
54 @Nullable
55 private String createDescription() {
56 int cnt = 0;
57 final StringBuilder sb = new StringBuilder();
58 cnt = checkOne(myTree, cnt, sb, "tree");
59 cnt = checkOne(myText, cnt, sb, "text");
60 cnt = checkOne(myProperty, cnt, sb, "property");
61 if (cnt == 0) {
62 return null;
64 return sb.toString();
67 private int checkOne(final boolean value, final int init, final StringBuilder sb, final String text) {
68 if (value) {
69 if (sb.length() > 0) {
70 sb.append(", ");
72 sb.append(text);
73 return init + 1;
75 return init;
78 public boolean isTree() {
79 return myTree;
82 public boolean isText() {
83 return myText;
86 public boolean isProperty() {
87 return myProperty;
90 public boolean isConflict() {
91 return myProperty || myText || myTree;
94 @Nullable
95 public Icon getIcon() {
96 return myIcon;
99 public String getDescription() {
100 return myDescription;
103 public static ConflictState mergeState(final ConflictState leftState, final ConflictState rightState) {
104 return getInstance(leftState.myTree | rightState.myTree, leftState.myText | rightState.myText,
105 leftState.myProperty | rightState.myProperty);
108 public static ConflictState getInstance(final boolean tree, final boolean text, final boolean property) {
109 final ConflictState[] conflictStates = values();
110 for (ConflictState state : conflictStates) {
111 if ((state.isTree() == tree) && (state.isText() == text) && (state.isProperty() == property)) {
112 return state;
115 // all combinations are defined
116 assert false;
117 return null;