java.mct.MlIconMaker

An IconMaker allows you to create images from String data. This facilitates simple icon creation.

The best way to describe use of the IconMaker is with an example. The following example produces two icon images. The first icon (icon1) is a 3x2 image with the first column of pixels transparent. The top row of pixels is green and the bottom row is blue.

The second icon (icon1) is also a 3x2 image (the IconMaker is re-used), again with the first column of pixels transparent. The top row of pixels is blue and the bottom row is green.

    MlIconMaker im;
    Image icon1, icon2;

    im = new MlIconMaker();
    im.setDimensions(3, 2);
    im.setColor('G', 0xffff0000); // green
    im.setColor('B', 0xff0000ff); // blue

    im.setPixels(" GG");
    im.setPixels(" BB");
    icon1 = im.createImage(this);

    im.clear();
    im.setPixels(" BB");
    im.setPixels(" GG");
    icon2 = im.createImage(this);

Public Methods

public void clear()
Clears the image. When creating more than one image, you should call this function after each image creation to start a new image.

public Image createImage(Component c)
Returns an image for use by the passed Component c from the internal string representation of the icon.

public void setColor(char index, int rgb)
Sets a color in the icons colormap. The color is defined by a character index and a rgb value. The RGB value includes alpha information. For example, the color #ff000000 is fully opaque (defined by the first ff) black (defined by the 000000). The color #ff00ff00 is fully opaque green, etc.

public void setDimensions(int width, int height)
Sets the dimensions of the image to the given width and height.

public void setPixels(String string)
The first call to this method will set the top row of pixels in the image. Subsequent calls will set following rows of pixels. A call to clear() will reset the internal counter of the current row, so calling this function after calling clear() will once again start setting pixels at the top of the image. The data in string should contain characters which index into the colormap to define colored pixels and spaces to indentify fully transparent pixels.

public void setPixels(int row, String string)
Sets the row of pixels at the given row position to the data contained in string. The data in string should contain characters which index into the colormap to define colored pixels and spaces to indentify fully transparent pixels.