In this section, you will be learning how to create a MIDlet Template to be integrated to the MTJ MIDlet Templates Wizard.
/** * Gets the template dictionary of tags * and it's corresponding values according * to the page's custom fields. * * @return template's dictionary. */ public abstract Map<String , String> getDictionary(); /** * Creates the Wizard Template custom page under the given * parent composite. * * @param parent the parent composite. */ public abstract void createControl(Composite parent); /** * Returns whether this page is complete or not. * * This information is typically used by the wizard to decide * when it is okay to finish. * * * @return true if this page is complete, and * false otherwise. */ public boolean isPageComplete();
import javax.microedition.lcdui.Canvas; import javax.microedition.lcdui.Font; import javax.microedition.lcdui.Graphics; public class ExampleCanvas extends Canvas { /* (non-Javadoc) * @see javax.microedition.lcdui.Canvas#paint(javax.microedition.lcdui.Graphics) */ protected void paint(Graphics g) { g.setColor($bg$); g.fillRect(0x00, 0x00, getWidth(), getHeight()); String message = "$message$"; Font font = Font.getFont($font-face$, $font-style$, $font-size$); g.setFont(font); g.setColor($fg$); g.drawString(message, getWidth()/2, getHeight()/2, Graphics.HCENTER | Graphics.TOP); } }NOTE: The template tags format is free for the developer to define since the tags will be replaced by the dictionary provided by the ITemplateProvider instance implemented by the template's developer as shown bellow:
public Map<String , String> getDictionary() { Map<String , String> dict = new HashMap<String , String>(); dict.put("$message$", this.msgText.getText()); dict.put("$bg$", this.bgColorText.getText()); dict.put("$fg$", this.fgColorText.getText()); dict.put("$font-face$", getFontFace()); dict.put("$font-style$", getFontStyle()); dict.put("$font-size$", getFontSize()); return dict; }Exception: The MIDlet class of the template MUST be named $class_name$.template
// File $class_name$.template public class $class_name$ extends MIDlet { public $class_name$() { } }