Extending component classes
ZIETrans provides a number of host component classes. You can extend
any of the host component classes that are found in the
ComponentWidget.xml
file
by replacing the statement public class MyCustomComponent extends
Component
in the created .java file for the new component with
the class name of an existing component. For example:
public class MyCustomComponent
extends com.ibm.hats.transform.components.CommandLineComponent
Note: Bidirectional components are stored in the com.ibm.hats.transform.components.BIDI
package. The names of bidirectional classes for components are the
same as regular components, but they are followed by
BIDI; for example, com.ibm.hats.transform.components.BIDI.CommandLineComponentBIDI.
Each ZIETrans component performs recognition of elements of the host
screen in the
recognize()
method. To extend a host component
and accomplish the specific recognition task you need, you can use
either of these approaches:
- Extend one of the component classes that is provided by ZIETrans and
override the
recognize()
method of the component. Somewhere in yourrecognize()
method you should add a call likesuper.recognize(region, settings);
to invoke therecognize()
method of the class you extended. You can modify the process by changing the settings before calling the superclass, or by manipulating the output returned by the superclass. - Extend one of the component classes that is provided by ZIETrans and
override the
recognize()
method of the component. Instead of using therecognize()
method of the superclass, invoke therecognize()
method of one of the other component classes. This approach will be useful if you want to recognize a complex host component that combines aspects of more than one of the ZIETrans components.
The Create Component wizard generates a recognize() method
that returns null, which indicates that the host screen region is
not recognized by the new component. To change the custom component
to act as the ZIETrans component it is extended from, whose elements contain
all of the correct ComponentElements, remove the "return null" from
the .java file and change the code in the component code. For example:
public ComponentElement[] recognize(LinearScreenRegion region, Properties settings) {
ComponentElement [] elements = super.recognize(region, settings);
return elements;
}
To edit the ComponentWidget.xml
file,
click the Navigator tab of the ZIETrans Toolkit.
The ComponentWidget.xml
file is shown at the bottom of
the Navigator view of your project.
See Registering your component or widget for more information about the ComponentWidget.xml
file.