/* Copyright 1996-2000 Simon Whiteside */ package simkin.examples.applet; 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 an XML 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(); public ScriptedDialog(InputStream in) throws FileNotFoundException, SAXException, IOException{ super(in); 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=dialog.getAttribute("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(dialog.getAttribute("width")); int height=Integer.parseInt(dialog.getAttribute("height")); m_Dialog.setSize(width,height); Dimension d = Toolkit.getDefaultToolkit().getScreenSize(); m_Dialog.setLocation((d.width-width)/2,(d.height-height)/2); m_Dialog.show(); // call the init in the XML file try{ method("init",new RValueArray(),new RValue()); }catch(Exception e){ trace(e.toString()); } } } /** * 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