Customizing host color mappings

The mapping of host colors to colors on the view are controlled by the IColorMapper object returned by the getColorMapper() method of the template class. The default implementation of this method returns an object of type DefaultColorMapper. The following color mapper classes are provided by ZIETrans:
  • com.ibm.hats.rcp.ui.templates.DefaultColorMapper
  • com.ibm.hats.rcp.ui.templates.WhiteBackgroundColorMapper

DefaultColorMapper should be used by templates that have a non-white background color since it maps the color of white host fields to white. WhiteBackgroundColorMapper should be used by templates that have a white or light background color since it maps the color of white host fields to black and uses darker colors (compared to the default color mapper).

The mapColor() method of the IColorMapper object is responsible for mapping a host color to an SWT RGB value. This method is typically called from the ZIETrans field widget when the Enable foreground colors setting is enabled. Table 1 lists the possible host color values that can be supplied to this method.
Table 1. Colors supplied to the mapColor method
Host Color Description
0 Blank
1 Blue
2 Green
3 Cyan
4 Red
5 Magenta
6 Brown (3270), Yellow (5250)
7 White (normal intensity)
8 Gray
9 Light blue
10 Light green
11 Light cyan
12 Light red
13 Light magenta
14 Yellow
15 White (high intensity)
There are two approaches for altering how colors are mapped by your template:
  1. Create a class that implements the IColorMapper interface, implement the mapColor() method, and update your template to return a new instance of this class
  2. Create a class that extends from one of the provided color mapper classes, override the mapColor() method, and update your template to return a new instance of this class.
If you choose to extend one of the classes provided by ZIETrans, you will need to override the mapColor() method. The following code sample shows how to change the color for blue (host color 1) and magenta (host color 5) host fields:
public class MyCustomColorMapper extends DefaultColorMapper {

	public RGB mapColor(int hostColor) {
		RGB rgb = null;
		
		if (hostColor == 1) {
			rgb = new RGB(100, 100, 100);
		} else if (hostColor == 5) { 
			rgb = new RGB(255, 0, 0); 	
		} else {
			rgb = super.mapColor(hostColor);
		}
		
		return rgb;
	}

}
The following code sample shows how to implement the getColorMapper() method of your template class to return your custom color mapper.
Note:
  1. This method might already exist in your template. If so, replace the current method with the following:
    public IColorMapper getColorMapper() {
            return new MyCustomColorMapper();
        }
  2. Color mappings are controlled at the template level. If you need to alter how colors are mapped at the transformation level, you need to create a new template, which can extend your existing template, and configure your screen customizations to use this template.