java.mct.MlResources

This object contains a set of resources and may be used to set resource values on components derived from MlCanvas or MlPanel. Resources consist of name/value pairs. An MlResources object contains a group of name/value pairs.

The best way to explain the use of an MlResources object is with an example. If you consult the documentation on the Grid component, you will see it supports the resources "rows" and "columns" to set the number of rows and columns. An MlResources object may be used to set these resources.

For example, to create a Grid containing 10 content rows and 20 content columns:

    Grid grid = new Grid();
    MlResources res = new MLResources();

    res.add("rows", 10);
    res.add("columns", 20);
    grid.setValues(res);

We could have added the "rows" resource as an int, Integer or String. The resources mechanism will convert what is passed as a value to an Integer before applying it to the component in a setValues() call. For example, all the following are valid ways to set the rows resource to a value of 10:

    res.add("rows", 10);
        -- or --
    res.add("rows", "10");
        -- or --
    Integer i = new Integer(10);
    res.add("rows", i);

You may use a single MlResources object to apply resources to a number of different components. For example, if you have three Grids and you wanted to set each of their selection colors to similar values:

    MlResources res = new MLResources();

    res.add("selectForeground", "#00ff00");
    res.add("selectBackground", "#ff0000");
    grid1.setValues(res);
    grid2.setValues(res);
    grid3.setValues(res);

You should use the clear() method to clear the name/value pairs contained in an MlResources object between calls to setValues() if you want to clear the resources contained in it to apply a new set of resources. For example, to set row 10 in a Grid to have a background of blue and row 20 in the same Grid to have a background of red:

    MlResources res = new MLResources();

    res.add("row", 10);
    res.add("cellBackground", "#0000ff");
    grid.setValues(res);

    res.clear();
    res.add("row", 20);
    res.add("cellBackground", "#ff0000");
    grid.setValues(res);

Public Methods

public void add(String name, int value)
public void add(String name, boolean value)
public void add(String name, Object value)
public void add(MlResource res)

Adds a name and value pair to the list of resources.

public void clear()
Clears the list of resources.

public Object clone()
Clones this object.

public MlResource getResource(int position)
Returns a reference to the resource at the given position in the internal list of resources.