private void writeAttributes(Element attrElements) throws WriteExternalException {
    List<TextAttributesKey> list = new ArrayList<TextAttributesKey>(myAttributesMap.keySet());
    Collections.sort(list);

    for (TextAttributesKey key : list) {
      TextAttributes defaultAttr =
          myParentScheme != null ? myParentScheme.getAttributes(key) : new TextAttributes();
      TextAttributesKey baseKey = key.getFallbackAttributeKey();
      TextAttributes defaultFallbackAttr =
          baseKey != null && myParentScheme instanceof AbstractColorsScheme
              ? ((AbstractColorsScheme) myParentScheme).getFallbackAttributes(baseKey)
              : null;
      TextAttributes value = myAttributesMap.get(key);
      if (!value.equals(defaultAttr) || defaultAttr == defaultFallbackAttr) {
        Element element = new Element(OPTION_ELEMENT);
        element.setAttribute(NAME_ATTR, key.getExternalName());
        if (baseKey == null || !value.isFallbackEnabled()) {
          Element valueElement = new Element(VALUE_ELEMENT);
          value.writeExternal(valueElement);
          element.addContent(valueElement);
          attrElements.addContent(element);
        } else if (defaultAttr != defaultFallbackAttr) {
          element.setAttribute(BASE_ATTRIBUTES_ATTR, baseKey.getExternalName());
          attrElements.addContent(element);
        }
      }
    }
  }
 @Override
 public Font getFont(EditorFontType key) {
   if (UISettings.getInstance().PRESENTATION_MODE) {
     final Font font = myFonts.get(key);
     return new Font(
         font.getName(), font.getStyle(), UISettings.getInstance().PRESENTATION_MODE_FONT_SIZE);
   }
   return myFonts.get(key);
 }
  private void readScheme(Element node) {
    myDeprecatedBackgroundColor = null;
    if (!SCHEME_ELEMENT.equals(node.getName())) {
      return;
    }

    setName(node.getAttributeValue(NAME_ATTR));
    int readVersion = Integer.parseInt(node.getAttributeValue(VERSION_ATTR, "0"));
    if (readVersion > CURR_VERSION) {
      throw new IllegalStateException("Unsupported color scheme version: " + readVersion);
    }

    myVersion = readVersion;
    String isDefaultScheme = node.getAttributeValue(DEFAULT_SCHEME_ATTR);
    boolean isDefault = isDefaultScheme != null && Boolean.parseBoolean(isDefaultScheme);
    if (!isDefault) {
      myParentScheme =
          DefaultColorSchemesManager.getInstance()
              .getScheme(node.getAttributeValue(PARENT_SCHEME_ATTR, DEFAULT_SCHEME_NAME));
    }

    for (final Object o : node.getChildren()) {
      Element childNode = (Element) o;
      String childName = childNode.getName();
      if (OPTION_ELEMENT.equals(childName)) {
        readSettings(childNode, isDefault);
      } else if (EDITOR_FONT.equals(childName)) {
        readFontSettings(childNode, myFontPreferences, isDefault);
      } else if (CONSOLE_FONT.equals(childName)) {
        readFontSettings(childNode, myConsoleFontPreferences, isDefault);
      } else if (COLORS_ELEMENT.equals(childName)) {
        readColors(childNode);
      } else if (ATTRIBUTES_ELEMENT.equals(childName)) {
        readAttributes(childNode);
      }
    }

    if (myDeprecatedBackgroundColor != null) {
      TextAttributes textAttributes = myAttributesMap.get(HighlighterColors.TEXT);
      if (textAttributes == null) {
        textAttributes =
            new TextAttributes(
                Color.black, myDeprecatedBackgroundColor, null, EffectType.BOXED, Font.PLAIN);
        myAttributesMap.put(HighlighterColors.TEXT, textAttributes);
      } else {
        textAttributes.setBackgroundColor(myDeprecatedBackgroundColor);
      }
    }

    if (myConsoleFontPreferences.getEffectiveFontFamilies().isEmpty()) {
      myFontPreferences.copyTo(myConsoleFontPreferences);
    }

    initFonts();
  }
  protected void initFonts() {
    String editorFontName = getEditorFontName();
    int editorFontSize = getEditorFontSize();

    myFallbackFontName =
        FontPreferences.getFallbackName(editorFontName, editorFontSize, myParentScheme);
    if (myFallbackFontName != null) {
      editorFontName = myFallbackFontName;
    }
    Font plainFont = new Font(editorFontName, Font.PLAIN, editorFontSize);
    Font boldFont = new Font(editorFontName, Font.BOLD, editorFontSize);
    Font italicFont = new Font(editorFontName, Font.ITALIC, editorFontSize);
    Font boldItalicFont = new Font(editorFontName, Font.BOLD | Font.ITALIC, editorFontSize);

    myFonts.put(EditorFontType.PLAIN, plainFont);
    myFonts.put(EditorFontType.BOLD, boldFont);
    myFonts.put(EditorFontType.ITALIC, italicFont);
    myFonts.put(EditorFontType.BOLD_ITALIC, boldItalicFont);

    String consoleFontName = getConsoleFontName();
    int consoleFontSize = getConsoleFontSize();

    Font consolePlainFont = new Font(consoleFontName, Font.PLAIN, consoleFontSize);
    Font consoleBoldFont = new Font(consoleFontName, Font.BOLD, consoleFontSize);
    Font consoleItalicFont = new Font(consoleFontName, Font.ITALIC, consoleFontSize);
    Font consoleBoldItalicFont =
        new Font(consoleFontName, Font.BOLD | Font.ITALIC, consoleFontSize);

    myFonts.put(EditorFontType.CONSOLE_PLAIN, consolePlainFont);
    myFonts.put(EditorFontType.CONSOLE_BOLD, consoleBoldFont);
    myFonts.put(EditorFontType.CONSOLE_ITALIC, consoleItalicFont);
    myFonts.put(EditorFontType.CONSOLE_BOLD_ITALIC, consoleBoldItalicFont);
  }
  private void writeColors(Element colorElements) {
    List<ColorKey> list = new ArrayList<ColorKey>(myColorsMap.keySet());
    Collections.sort(list);

    for (ColorKey key : list) {
      if (haveToWrite(key)) {
        Color value = myColorsMap.get(key);
        Element element = new Element(OPTION_ELEMENT);
        element.setAttribute(NAME_ATTR, key.getExternalName());
        element.setAttribute(
            VALUE_ELEMENT, value != null ? Integer.toString(value.getRGB() & 0xFFFFFF, 16) : "");
        colorElements.addContent(element);
      }
    }
  }
  public void copyTo(AbstractColorsScheme newScheme) {
    myFontPreferences.copyTo(newScheme.myFontPreferences);
    newScheme.myLineSpacing = myLineSpacing;
    newScheme.myQuickDocFontSize = myQuickDocFontSize;
    myConsoleFontPreferences.copyTo(newScheme.myConsoleFontPreferences);
    newScheme.myConsoleLineSpacing = myConsoleLineSpacing;

    final Set<EditorFontType> types = myFonts.keySet();
    for (EditorFontType type : types) {
      Font font = myFonts.get(type);
      newScheme.setFont(type, font);
    }

    newScheme.myAttributesMap = new HashMap<TextAttributesKey, TextAttributes>(myAttributesMap);
    newScheme.myColorsMap = new HashMap<ColorKey, Color>(myColorsMap);
    newScheme.myVersion = myVersion;
  }
 /**
  * Looks for explicitly specified attributes either in the scheme or its parent scheme. No
  * fallback keys are used.
  *
  * @param key The key to use for search.
  * @return Explicitly defined attribute or <code>null</code> if not found.
  */
 @Nullable
 public TextAttributes getDirectlyDefinedAttributes(@NotNull TextAttributesKey key) {
   TextAttributes attributes = myAttributesMap.get(key);
   if (attributes != null) {
     return attributes;
   }
   return myParentScheme instanceof AbstractColorsScheme
       ? ((AbstractColorsScheme) myParentScheme).getDirectlyDefinedAttributes(key)
       : null;
 }
 public void readAttributes(@NotNull Element childNode) {
   for (Element e : childNode.getChildren(OPTION_ELEMENT)) {
     TextAttributesKey name = TextAttributesKey.find(e.getAttributeValue(NAME_ATTR));
     Element valueElement = e.getChild(VALUE_ELEMENT);
     TextAttributes attr =
         valueElement != null ? new TextAttributes(valueElement) : new TextAttributes();
     myAttributesMap.put(name, attr);
     migrateErrorStripeColorFrom14(name, attr);
   }
 }
  private void readColors(Element childNode) {
    for (final Object o : childNode.getChildren(OPTION_ELEMENT)) {
      Element colorElement = (Element) o;
      Color valueColor = readColorValue(colorElement);
      final String colorName = colorElement.getAttributeValue(NAME_ATTR);
      if (BACKGROUND_COLOR_NAME.equals(colorName)) {
        // This setting has been deprecated to usages of HighlighterColors.TEXT attributes.
        myDeprecatedBackgroundColor = valueColor;
      }

      ColorKey name = ColorKey.find(colorName);
      myColorsMap.put(name, valueColor);
    }
  }
 private boolean haveToWrite(final ColorKey key) {
   Color value = myColorsMap.get(key);
   if (myParentScheme != null) {
     if (myParentScheme instanceof AbstractColorsScheme) {
       if (Comparing.equal(((AbstractColorsScheme) myParentScheme).getOwnColor(key), value)
           && ((AbstractColorsScheme) myParentScheme).myColorsMap.containsKey(key)) {
         return false;
       }
     } else {
       if (Comparing.equal((myParentScheme).getColor(key), value)) {
         return false;
       }
     }
   }
   return true;
 }
 protected Color getOwnColor(ColorKey key) {
   return myColorsMap.get(key);
 }
 @Override
 public void setFont(EditorFontType key, Font font) {
   myFonts.put(key, font);
 }