Page 167 - The Ultimate Palm Robot
P. 167
Color profile: Generic CMYK printer profile
Composite Default screen
Bots / The Ultimate Palm Robot/ Mukhar & Johnson / 222880-6 / Chapter 6
150 The Ultimate Palm Robot
to the PRP installation, they will be recognized the next time you run the PRP,
and they can be used to convert a PRP program to source code.
The Java Class
To add a new converter to the PRP, we write a simple Java class that is recog-
nized by the PRP. Using the Java class, the PRP knows what new language se-
lection to add to the Converter menu and which style sheet to use when
translating the program to source code.
Only a few requirements for the class are necessary. The converter
class must
❏ Extend the com.prp.AbstractTranslator class
❏ Provide a getName( ) method that returns the name of the
language for which the translator is used
❏ Provide a getStyleSheet( ) method that returns the name of the
style sheet to use for the translation
❏ Provide a translate(Program p) method
❏ Provide a getIconName( ) method that returns the name of the
icon for the toolbar (you will also need to create an icon)
Here is a sample class for the mythical language “Cream”:
public class CreamTranslator extends AbstractTranslator {
public String getName() { return "Cream"; }
public String getStyleSheet() { return "cream.xslt"; }
public void translate(Program p) {
String msg = "Additional message";
doTransform(p, ".crm", msg);
}
public String getIconName() {
return "Cream.gif";
}
}
The getName( ) method is used by the PRP to create a menu entry for the
translator. The getStyleSheet( ) method is used during the translation to iden-
tify the style sheet to use for the translation. The getIconName( ) method is re-
quired, but if you do not have an icon, the method can just return an empty
string. If you do create an icon, it should be 16x16 pixels so that it is the same
size as the existing icons. The PRPwill provide a default icon if you do not pro-
vide one.
P:\010Comp\Bots\880-6\ch06.vp
Monday, May 12, 2003 1:06:27 PM