2 * Copyright 2000-2012 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.editor.colors.impl;
18 import com.intellij.openapi.editor.colors.ColorKey;
19 import com.intellij.openapi.editor.colors.EditorColorsScheme;
20 import com.intellij.openapi.editor.colors.TextAttributesKey;
21 import com.intellij.openapi.editor.colors.ex.DefaultColorSchemesManager;
22 import com.intellij.openapi.editor.markup.TextAttributes;
23 import com.intellij.openapi.options.ExternalInfo;
24 import com.intellij.openapi.options.ExternalizableScheme;
25 import com.intellij.openapi.util.Comparing;
26 import org.jetbrains.annotations.NotNull;
27 import org.jetbrains.annotations.Nullable;
34 public class EditorColorsSchemeImpl extends AbstractColorsScheme implements ExternalizableScheme {
35 private final ExternalInfo myExternalInfo = new ExternalInfo();
37 public EditorColorsSchemeImpl(EditorColorsScheme parentScheme, DefaultColorSchemesManager defaultColorSchemesManager) {
38 super(parentScheme, defaultColorSchemesManager);
42 public void setAttributes(TextAttributesKey key, TextAttributes attributes) {
43 if (attributes != getAttributes(key)) {
44 myAttributesMap.put(key, attributes);
49 public void setColor(ColorKey key, Color color) {
50 if (!Comparing.equal(color, getColor(key))) {
51 myColorsMap.put(key, color);
56 public TextAttributes getAttributes(TextAttributesKey key) {
58 TextAttributesKey fallbackKey = key.getFallbackAttributeKey();
59 TextAttributes attributes = myAttributesMap.get(key);
60 if (fallbackKey == null) {
61 if (attributes != null) return attributes;
64 if (attributes != null && !attributes.isFallbackEnabled()) return attributes;
65 attributes = getFallbackAttributes(fallbackKey);
66 if (attributes != null) return attributes;
69 return myParentScheme.getAttributes(key);
73 public boolean containsKey(TextAttributesKey key) {
74 return myAttributesMap.containsKey(key);
79 public Color getColor(ColorKey key) {
80 if (myColorsMap.containsKey(key)) {
81 return myColorsMap.get(key);
84 return myParentScheme.getColor(key);
89 public Object clone() {
90 EditorColorsSchemeImpl newScheme = new EditorColorsSchemeImpl(myParentScheme, DefaultColorSchemesManager.getInstance());
92 newScheme.setName(getName());
98 public ExternalInfo getExternalInfo() {
99 return myExternalInfo;