package jetbrains.mps.ide.icons;
/*Generated by MPS */
import jetbrains.mps.util.annotation.ToRemove;
import java.util.Map;
import javax.swing.Icon;
import jetbrains.mps.internal.collections.runtime.MapSequence;
import java.util.HashMap;
import org.jetbrains.mps.openapi.language.SAbstractConcept;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.mps.openapi.model.SNode;
import jetbrains.mps.lang.smodel.generator.smodelAdapter.SNodeOperations;
import jetbrains.mps.project.AbstractModule;
import jetbrains.mps.util.MacrosFactory;
import jetbrains.mps.util.MacroHelper;
import org.jetbrains.annotations.NonNls;
import jetbrains.mps.vfs.IFile;
import jetbrains.mps.vfs.FileSystem;
import com.intellij.openapi.util.IconLoader;
import java.net.MalformedURLException;
/**
*
* @deprecated use BaseIconManager instead
*/
@Deprecated
@ToRemove(version = 3.5)
public class CachingIconManager extends BaseIconManager {
private Map<String, Icon> myPathToIcon = MapSequence.fromMap(new HashMap<String, Icon>());
public Icon getConceptIcon(SAbstractConcept concept) {
return super.getIconFor(concept);
}
public Icon getNodeIcon(@NotNull SNode node) {
return super.getIconFor(node);
}
private Icon getIcon(@NotNull SNode conceptDeclaration) {
return super.getIconFor(SNodeOperations.asSConcept(conceptDeclaration));
}
public Icon getIcon(AbstractModule module, String path) {
String iconPath = expandPath(module, path);
if (iconPath == null) {
return null;
}
return getIcon(iconPath);
}
private String expandPath(AbstractModule module, String path) {
if (path == null || !(MacrosFactory.containsMacro(path))) {
// Don't bother looking up MacroHelper if there is nothing to expand anyway
return path;
}
if (module == null) {
return null;
}
MacroHelper macroHelper = MacrosFactory.forModule(module);
if (macroHelper == null) {
return null;
}
return macroHelper.expandPath(path);
}
private Icon getIcon(@NonNls String iconPath) {
if (!(MapSequence.fromMap(myPathToIcon).containsKey(iconPath))) {
IFile file = FileSystem.getInstance().getFileByPath(iconPath);
MapSequence.fromMap(myPathToIcon).put(iconPath, getIcon(file));
}
return MapSequence.fromMap(myPathToIcon).get(iconPath);
}
private Icon getIcon(IFile file) {
try {
return IconLoader.findIcon(file.getUrl(), false);
} catch (MalformedURLException e) {
return null;
}
}
}