update copyrights
[fedora-idea.git] / platform / lang-api / src / com / intellij / execution / ui / ConsoleViewContentType.java
blob8a9ad71450f9ee307f71c9c9df09c141dceb175e
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 com.intellij.execution.ui;
18 import com.intellij.execution.process.ProcessOutputTypes;
19 import com.intellij.openapi.editor.colors.EditorColorsManager;
20 import com.intellij.openapi.editor.colors.TextAttributesKey;
21 import com.intellij.openapi.editor.colors.ColorKey;
22 import com.intellij.openapi.editor.markup.TextAttributes;
23 import com.intellij.openapi.util.Key;
24 import com.intellij.util.containers.HashMap;
25 import org.jetbrains.annotations.NonNls;
27 import java.util.Map;
29 /**
30 * @author Alexey Kudravtsev
32 public class ConsoleViewContentType {
33 private final String myName;
34 private final TextAttributes myTextAttributes;
35 private final TextAttributesKey myTextAttributesKey;
37 private static final Map<Key, ConsoleViewContentType> ourRegisteredTypes = new HashMap<Key, ConsoleViewContentType>();
39 public static final ColorKey CONSOLE_BACKGROUND_KEY = ColorKey.createColorKey("CONSOLE_BACKGROUND_KEY");
41 public static final TextAttributesKey NORMAL_OUTPUT_KEY = TextAttributesKey.createTextAttributesKey("CONSOLE_NORMAL_OUTPUT");
42 public static final TextAttributesKey ERROR_OUTPUT_KEY = TextAttributesKey.createTextAttributesKey("CONSOLE_ERROR_OUTPUT");
43 public static final TextAttributesKey USER_INPUT_KEY = TextAttributesKey.createTextAttributesKey("CONSOLE_USER_INPUT");
44 public static final TextAttributesKey SYSTEM_OUTPUT_KEY = TextAttributesKey.createTextAttributesKey("CONSOLE_SYSTEM_OUTPUT");
46 public static final ConsoleViewContentType NORMAL_OUTPUT = new ConsoleViewContentType("NORMAL_OUTPUT", NORMAL_OUTPUT_KEY);
47 public static final ConsoleViewContentType ERROR_OUTPUT = new ConsoleViewContentType("ERROR_OUTPUT", ERROR_OUTPUT_KEY);
48 public static final ConsoleViewContentType USER_INPUT = new ConsoleViewContentType("USER_OUTPUT", USER_INPUT_KEY);
49 public static final ConsoleViewContentType SYSTEM_OUTPUT = new ConsoleViewContentType("SYSTEM_OUTPUT", SYSTEM_OUTPUT_KEY);
51 static {
52 ourRegisteredTypes.put(ProcessOutputTypes.SYSTEM, SYSTEM_OUTPUT);
53 ourRegisteredTypes.put(ProcessOutputTypes.STDOUT, NORMAL_OUTPUT);
54 ourRegisteredTypes.put(ProcessOutputTypes.STDERR, ERROR_OUTPUT);
57 public ConsoleViewContentType(@NonNls final String name, final TextAttributes textAttributes) {
58 myName = name;
59 myTextAttributes = textAttributes;
60 myTextAttributesKey = null;
63 public ConsoleViewContentType(@NonNls String name, TextAttributesKey textAttributesKey) {
64 myName = name;
65 myTextAttributes = null;
66 myTextAttributesKey = textAttributesKey;
69 public String toString() {
70 return myName;
73 public TextAttributes getAttributes() {
74 if (myTextAttributesKey != null) {
75 return EditorColorsManager.getInstance().getGlobalScheme().getAttributes(myTextAttributesKey);
77 return myTextAttributes;
80 public synchronized static void registerNewConsoleViewType(final Key processOutputType, final ConsoleViewContentType attributes) {
81 ourRegisteredTypes.put(processOutputType, attributes);
84 public synchronized static ConsoleViewContentType getConsoleViewType(final Key processOutputType) {
85 if (ourRegisteredTypes.containsKey(processOutputType)) {
86 return ourRegisteredTypes.get(processOutputType);
88 else {
89 return SYSTEM_OUTPUT;