/*
 * Copyright 2000-2009 JetBrains s.r.o.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/**
 * @author Yura Cangea
 */
package com.intellij.openapi.editor.colors.impl;

import com.intellij.openapi.editor.colors.ColorKey;
import com.intellij.openapi.editor.colors.EditorColorsScheme;
import com.intellij.openapi.editor.colors.TextAttributesKey;
import com.intellij.openapi.editor.colors.ex.DefaultColorSchemesManager;
import com.intellij.openapi.editor.markup.TextAttributes;
import com.intellij.openapi.options.ExternalInfo;
import com.intellij.openapi.options.ExternalizableScheme;
import com.intellij.openapi.util.Comparing;
import org.jetbrains.annotations.NotNull;

import java.awt.*;

public class EditorColorsSchemeImpl extends AbstractColorsScheme implements ExternalizableScheme {
  private final ExternalInfo myExternalInfo = new ExternalInfo();

  public EditorColorsSchemeImpl(EditorColorsScheme parenScheme, DefaultColorSchemesManager defaultColorSchemesManager) {
    super(parenScheme, defaultColorSchemesManager);
  }

  // -------------------------------------------------------------------------
  // Getters & Setters
  // -------------------------------------------------------------------------
  @Override
  public void setAttributes(TextAttributesKey key, TextAttributes attributes) {
    if (!Comparing.equal(attributes, getAttributes(key))) {
      myAttributesMap.put(key, attributes);
    }
  }

  @Override
  public void setColor(ColorKey key, Color color) {
    if (!Comparing.equal(color, getColor(key))) {
      myColorsMap.put(key, color);
    }
  }

  @Override
  public TextAttributes getAttributes(TextAttributesKey key) {
    if (myAttributesMap.containsKey(key)) {
      return myAttributesMap.get(key);
    }
    TextAttributesKey fallbackKey = key.getFallbackAttributeKey();
    if (fallbackKey != null && myAttributesMap.containsKey(fallbackKey)) {
      return myAttributesMap.get(fallbackKey);
    }
    return myParentScheme.getAttributes(key);
  }

  @Override
  public Color getColor(ColorKey key) {
    if (myColorsMap.containsKey(key)) {
      return myColorsMap.get(key);
    } else {
      return myParentScheme.getColor(key);
    }
  }

  @Override
  public Object clone() {
    EditorColorsSchemeImpl newScheme = new EditorColorsSchemeImpl(myParentScheme, DefaultColorSchemesManager.getInstance());
    copyTo(newScheme);
    newScheme.setName(getName());
    return newScheme;
  }

  @Override
  @NotNull
  public ExternalInfo getExternalInfo() {
    return myExternalInfo;
  }
}

@@ -20,10 +20,10 @@
 0-20
-09
+12
  Jet
@@ -597,40 +597,8 @@
 %0A */
-%0A%0A/**%0A * @author Yura Cangea%0A */
 %0Apac
@@ -1165,16 +1165,47 @@
 awt.*;%0A%0A
+/**%0A * @author Yura Cangea%0A */%0A
 public c
@@ -1414,24 +1414,25 @@
 Scheme paren
+t
 Scheme, Defa
@@ -1499,16 +1499,17 @@
 er(paren
+t
 Scheme, 
@@ -1546,189 +1546,8 @@
  %7D%0A%0A
-  // -------------------------------------------------------------------------%0A  // Getters & Setters%0A  // -------------------------------------------------------------------------%0A
   @O
@@ -2069,24 +2069,49 @@
 key);%0A    %7D%0A
+    if (key != null) %7B%0A  
     TextAttr
@@ -2165,16 +2165,18 @@
 eKey();%0A
+  
     if (
@@ -2240,32 +2240,34 @@
 ckKey)) %7B%0A      
+ 
+ 
 return myAttribu
@@ -2287,24 +2287,32 @@
 llbackKey);%0A
+      %7D%0A
     %7D%0A    re
@@ -2488,16 +2488,20 @@
 );%0A    %7D
+%0A   
  else %7B%0A

Fix NPE in editor color schemes