/* Copyright 1996-2003 Simon Whiteside */ package simkin.examples.dialog; import simkin.*; import java.io.*; import org.xml.sax.SAXException; import org.w3c.dom.*; import java.util.*; import java.awt.*; import java.awt.event.*; /** * This class shows how you can use Simkin to show dialogs described in script */ public class ScriptedDialog extends XMLExecutable implements ActionListener{ /** * this class holds the name and associated method name for a component */ class ControlInfo { String m_Name=""; String m_Method=""; ControlInfo(String name,String method){ m_Name=name; m_Method=method; } } /** * the parent frame */ Frame m_Frame=new Frame(); /** * the actual dialog created */ Dialog m_Dialog; /** * a hashtable mapping controls to ControlInfo objects */ Hashtable m_ControlInfo=new Hashtable(); /** * the name of the XML file */ public String FileName; /** * Interpreter to use for method calls */ Interpreter m_Interpreter=new Interpreter(); public ScriptedDialog(String fileName) throws FileNotFoundException, SAXException, IOException{ super(new FileInputStream(fileName)); FileName=fileName; load(); } /** * this method loads the dialog definition from the XML file */ void load(){ // extract the "dialog" tag from the document Element dialog=XMLElementObject.findChild(getElement(),"dialog"); if (dialog!=null){ String title=getStringField(dialog,"title"); m_Dialog=new Dialog(m_Frame,title); Panel dialogPanel=new Panel(); dialogPanel.setLayout(new FlowLayout()); loadControls(dialogPanel,dialog); m_Dialog.add(dialogPanel); int width=Integer.parseInt(getStringField(dialog,"width")); int height=Integer.parseInt(getStringField(dialog,"height")); m_Dialog.setSize(width,height); m_Dialog.setModal(true); m_Dialog.show(); // call the init in the XML file try{ ExecutableContext context=new ExecutableContext(m_Interpreter); method("init",null,context); }catch(Exception e){ } } } /** * this method loads controls from the controls sub-element of the given element * @param panel the panel the controls will be added to * @param element the owner of the controls element */ void loadControls(Panel panel,Element element){ Element controls=XMLElementObject.findChild(element,"controls"); if (controls!=null){ NodeList control_list=controls.getChildNodes(); for (int i=0;i"); } }