Icon description
The icon description language helps describing and instantiating icons for various MPS elements: concepts, actions etc.
The langage has two aims:
1. Provide a tool for quick icon prototyping (e.g. making new icons for concepts)
2. Make icons an extensible language construct
First impression
Wherever an icon is expected in the MPS language definition languages, you can enter a textual description of the desired icon instead of pointing to an existing .png file.
The jetbrains.mps.lang.resources contains two constructs:
icon{} represents the image as an instance of javax.swing.Icon class.
iconResource{} returns an instance of jetbrains.mps.smodel.runtime.IconResource class.
Creating icon prototypes
When describing an icon, you can get assistance from the Create Icon intention, which offers an automatic way to create a textual description of an icon and thus to prototype it quickly.
Invoking the intention will result in creating a straightforward icon definition.
This definition describes a circular icon with letter "X" inside of it. Upon regeneration the generated icon will take effect and shows up in the UI.
The language explained
An icon description consists of layers, each of which can be any of:
a primitive graphical shape
a custom image loaded from a file
a character
These layers are then combined into a single image to represent the icon. These icon descriptions can be used:
to specify icons in different places of the language definition languages - in concepts, actions, etc, where icons are expected
in methods in the MPS UI that are supposed to return an Icon
Extending the language
The language is open for extension. To add new icon types, you need to create a new concept and make it implement the Icon interface. The Icon interface represents the desired icon and will get transformed to a .png file during the make process.
After generating a model, all Icons are collected from the output model and their generate() methods are called. These create .png files corresponding to the images described by the corresponding Icons . When an icon resource is requested (e.g. using the icon{} syntax), a resource referenced by Icon.getResourceId() method is loaded using the classloader of the corresponding module and converted into a Java Icon object.
icon{} vs iconResource{}
There are two constructs in the resources language to load resources. icon{} loads an image as an instance of javax.swing.Icon class, while iconResource{} returns an instance of jetbrains.mps.smodel.runtime.IconResource class. The second one is used in core MPS aspects, which should not depend on the javax.swing package. All UI-related code uses icon{}.