public void addImportedScheme(@NotNull final EditorColorsScheme imported) {
    MyColorScheme newScheme = new MyColorScheme(imported);
    initScheme(newScheme);

    mySchemes.put(imported.getName(), newScheme);
    selectScheme(newScheme.getName());
    resetSchemesCombo(null);
  }
  private static void initScopesDescriptors(
      @NotNull List<EditorSchemeAttributeDescriptor> descriptions, @NotNull MyColorScheme scheme) {
    Set<Pair<NamedScope, NamedScopesHolder>> namedScopes =
        new THashSet<Pair<NamedScope, NamedScopesHolder>>(
            new TObjectHashingStrategy<Pair<NamedScope, NamedScopesHolder>>() {
              @Override
              public int computeHashCode(
                  @NotNull final Pair<NamedScope, NamedScopesHolder> object) {
                return object.getFirst().getName().hashCode();
              }

              @Override
              public boolean equals(
                  @NotNull final Pair<NamedScope, NamedScopesHolder> o1,
                  @NotNull final Pair<NamedScope, NamedScopesHolder> o2) {
                return o1.getFirst().getName().equals(o2.getFirst().getName());
              }
            });
    Project[] projects = ProjectManager.getInstance().getOpenProjects();
    for (Project project : projects) {
      DependencyValidationManagerImpl validationManager =
          (DependencyValidationManagerImpl) DependencyValidationManager.getInstance(project);
      List<Pair<NamedScope, NamedScopesHolder>> cachedScopes =
          validationManager.getScopeBasedHighlightingCachedScopes();
      namedScopes.addAll(cachedScopes);
    }

    List<Pair<NamedScope, NamedScopesHolder>> list =
        new ArrayList<Pair<NamedScope, NamedScopesHolder>>(namedScopes);

    Collections.sort(
        list,
        new Comparator<Pair<NamedScope, NamedScopesHolder>>() {
          @Override
          public int compare(
              @NotNull final Pair<NamedScope, NamedScopesHolder> o1,
              @NotNull final Pair<NamedScope, NamedScopesHolder> o2) {
            return o1.getFirst().getName().compareToIgnoreCase(o2.getFirst().getName());
          }
        });
    for (Pair<NamedScope, NamedScopesHolder> pair : list) {
      NamedScope namedScope = pair.getFirst();
      String name = namedScope.getName();
      TextAttributesKey textAttributesKey = ScopeAttributesUtil.getScopeTextAttributeKey(name);
      if (scheme.getAttributes(textAttributesKey) == null) {
        scheme.setAttributes(textAttributesKey, new TextAttributes());
      }
      NamedScopesHolder holder = pair.getSecond();

      PackageSet value = namedScope.getValue();
      String toolTip = holder.getDisplayName() + (value == null ? "" : ": " + value.getText());
      addSchemedDescription(
          descriptions, name, SCOPES_GROUP, textAttributesKey, scheme, holder.getIcon(), toolTip);
    }
  }
 private boolean isInherited(@NotNull MyColorScheme scheme) {
   TextAttributes attributes = scheme.getAttributes(key);
   TextAttributesKey fallbackKey = key.getFallbackAttributeKey();
   if (fallbackKey != null && !scheme.containsKey(key)) {
     TextAttributes fallbackAttributes = scheme.getAttributes(fallbackKey);
     if (attributes != null && attributes == fallbackAttributes) {
       return true;
     }
   }
   return false;
 }
  private boolean isSchemeListModified() {
    if (mySomeSchemesDeleted) return true;

    if (!mySelectedScheme
        .getName()
        .equals(EditorColorsManager.getInstance().getGlobalScheme().getName())) return true;

    for (MyColorScheme scheme : mySchemes.values()) {
      if (scheme.isNew()) return true;
    }

    return false;
  }
 private SchemeTextAttributesDescription(
     String name,
     String group,
     @NotNull TextAttributesKey key,
     @NotNull MyColorScheme scheme,
     Icon icon,
     String toolTip) {
   super(name, group, getInitialAttributes(scheme, key).clone(), key, scheme, icon, toolTip);
   this.key = key;
   myAttributesToApply = getInitialAttributes(scheme, key);
   TextAttributesKey fallbackKey = key.getFallbackAttributeKey();
   if (fallbackKey != null) {
     myFallbackAttributes = scheme.getAttributes(fallbackKey);
     myBaseAttributeDescriptor =
         ColorSettingsPages.getInstance().getAttributeDescriptor(fallbackKey);
     if (myBaseAttributeDescriptor == null) {
       myBaseAttributeDescriptor =
           new Pair<ColorSettingsPage, AttributesDescriptor>(
               null, new AttributesDescriptor(fallbackKey.getExternalName(), fallbackKey));
     }
   }
   myIsInheritedInitial = isInherited(scheme);
   setInherited(myIsInheritedInitial);
   initCheckedStatus();
 }
  private void initAll() {
    EditorColorsManager colorsManager = EditorColorsManager.getInstance();
    EditorColorsScheme[] allSchemes = colorsManager.getAllSchemes();

    mySchemes = new HashMap<String, MyColorScheme>();
    for (EditorColorsScheme allScheme : allSchemes) {
      MyColorScheme schemeDelegate = new MyColorScheme(allScheme);
      initScheme(schemeDelegate);
      mySchemes.put(schemeDelegate.getName(), schemeDelegate);
    }

    mySelectedScheme = mySchemes.get(EditorColorsManager.getInstance().getGlobalScheme().getName());
    assert mySelectedScheme != null
        : EditorColorsManager.getInstance().getGlobalScheme().getName()
            + "; myschemes="
            + mySchemes;
  }
  public void removeScheme(String name) {
    if (mySelectedScheme.getName().equals(name)) {
      //noinspection HardCodedStringLiteral
      selectScheme("Default");
    }

    boolean deletedNewlyCreated = false;

    MyColorScheme toDelete = mySchemes.get(name);

    if (toDelete != null) {
      deletedNewlyCreated = toDelete.isNew();
    }

    mySchemes.remove(name);
    resetSchemesCombo(null);
    mySomeSchemesDeleted = mySomeSchemesDeleted || !deletedNewlyCreated;
  }
  private static void initScheme(@NotNull MyColorScheme scheme) {
    List<EditorSchemeAttributeDescriptor> descriptions =
        new ArrayList<EditorSchemeAttributeDescriptor>();
    initPluggedDescriptions(descriptions, scheme);
    initDiffDescriptors(descriptions, scheme);
    initFileStatusDescriptors(descriptions, scheme);
    initScopesDescriptors(descriptions, scheme);

    scheme.setDescriptors(
        descriptions.toArray(new EditorSchemeAttributeDescriptor[descriptions.size()]));
  }
    @Override
    public boolean isModified() {
      createPanel();
      for (MyColorScheme scheme : mySchemes.values()) {
        if (mySubPanel.containsFontOptions()) {
          if (scheme.isFontModified() || scheme.isConsoleFontModified()) {
            myRevertChangesCompleted = false;
            return true;
          }
        } else {
          for (EditorSchemeAttributeDescriptor descriptor : scheme.getDescriptors()) {
            if (mySubPanel.contains(descriptor) && descriptor.isModified()) {
              myRevertChangesCompleted = false;
              return true;
            }
          }
        }
      }

      return false;
    }
  @NotNull
  public String[] getSchemeNames() {
    List<MyColorScheme> schemes = new ArrayList<MyColorScheme>(mySchemes.values());
    Collections.sort(
        schemes,
        new Comparator<MyColorScheme>() {
          @Override
          public int compare(@NotNull MyColorScheme o1, @NotNull MyColorScheme o2) {
            if (isReadOnly(o1) && !isReadOnly(o2)) return -1;
            if (!isReadOnly(o1) && isReadOnly(o2)) return 1;

            return o1.getName().compareToIgnoreCase(o2.getName());
          }
        });

    List<String> names = new ArrayList<String>(schemes.size());
    for (MyColorScheme scheme : schemes) {
      names.add(scheme.getName());
    }

    return ArrayUtil.toStringArray(names);
  }
  @Override
  public void apply() throws ConfigurationException {
    if (myApplyCompleted) {
      return;
    }
    try {
      EditorColorsManager myColorsManager = EditorColorsManager.getInstance();

      myColorsManager.removeAllSchemes();
      for (MyColorScheme scheme : mySchemes.values()) {
        if (!scheme.isDefault()) {
          scheme.apply();
          myColorsManager.addColorsScheme(scheme.getOriginalScheme());
        }
      }

      EditorColorsScheme originalScheme = mySelectedScheme.getOriginalScheme();
      myColorsManager.setGlobalScheme(originalScheme);
      if (originalScheme != null
          && DarculaLaf.NAME.equals(originalScheme.getName())
          && !UIUtil.isUnderDarcula()) {
        int ok =
            Messages.showYesNoDialog(
                "Darcula color scheme has been set for editors. Would you like to set Darcula as default Look and Feel?",
                "Darcula Look and Feel",
                Messages.getQuestionIcon());
        if (ok == Messages.YES) {
          LafManager.getInstance().setCurrentLookAndFeel(new DarculaLookAndFeelInfo());
          DarculaInstaller.install();
        }
      }
      applyChangesToEditors();

      reset();
    } finally {
      myApplyCompleted = true;
    }
  }
  public void saveSchemeAs(String name) {
    MyColorScheme scheme = mySelectedScheme;
    if (scheme == null) return;

    EditorColorsScheme clone = (EditorColorsScheme) scheme.getOriginalScheme().clone();

    scheme.apply(clone);

    clone.setName(name);
    MyColorScheme newScheme = new MyColorScheme(clone);
    initScheme(newScheme);

    newScheme.setIsNew();

    mySchemes.put(name, newScheme);
    selectScheme(newScheme.getName());
    resetSchemesCombo(null);
  }
 @NotNull
 private static TextAttributes getInitialAttributes(
     @NotNull MyColorScheme scheme, @NotNull TextAttributesKey key) {
   TextAttributes attributes = scheme.getAttributes(key);
   return attributes != null ? attributes : new TextAttributes();
 }
 public EditorSchemeAttributeDescriptor[] getCurrentDescriptions() {
   return mySelectedScheme.getDescriptors();
 }
 public EditorColorsScheme getOriginalSelectedScheme() {
   return mySelectedScheme == null ? null : mySelectedScheme.getOriginalScheme();
 }
 private boolean isSomeSchemeModified() {
   for (MyColorScheme scheme : mySchemes.values()) {
     if (scheme.isModified()) return true;
   }
   return false;
 }