import java.awt.* ;
import java.awt.event.* ;
import fr.dgac.ivy.*;
/**
* toy tool to probe the Ivy software bus.
* it relies on the AWT, and is less useable than TestIvySwing, which should
* be preferred.
*
* @see fr.dgac.ivy.TestIvySwing
* @author François-Régis Colin
* @author Yannick Jestin
* @author http://www.tls.cena.fr/products/ivy/
*
* CHANGELOG
* 1.0.10:
* - System.exit on bus die
*/
class TestIvy extends Panel implements IvyApplicationListener {
private Ivy bus ;
private String regexp="";
private TextField tfRegex, tfSend ;
private TextArea ta ;
private Button buApply, buSend, buClear ;
private java.text.SimpleDateFormat format = new
java.text.SimpleDateFormat("hh:mm:ss");
private int regexp_id;
public TestIvy() throws IvyException {
super(new BorderLayout());
ta = new TextArea();
ta.setEditable(false);
add(ta,BorderLayout.CENTER);
Panel p = new Panel(new BorderLayout());
p.add(new Label("Regex:"),BorderLayout.WEST);
tfRegex = new TextField(regexp);
tfRegex.addActionListener(new REGCB());
p.add(tfRegex,BorderLayout.CENTER);
add(p,BorderLayout.NORTH);
p = new Panel(new BorderLayout());
p.add(new Label("Msg:"),BorderLayout.WEST);
tfSend = new TextField("");
tfSend.addActionListener(new SENDCB());
p.add(tfSend,BorderLayout.CENTER);
add(p,BorderLayout.SOUTH);
bus = new Ivy("JAVATESTBUS","Testbus is ready",this);
bus.start(null);
append( "Ivy Domain: "+ bus.getDomain(null) );
}
public static Frame f;
public static void main(String[] args) throws IvyException {
TestIvy tb = new TestIvy();
f = new Frame("TestIvy");
f.addWindowListener( tb.new WCCB(f,tb)) ;
f.add(tb, BorderLayout.CENTER);
f.pack();
f.setVisible(true);
}
public void connect(IvyClient client) {
append(client.getApplicationName() + " connected " );
}
public void disconnect(IvyClient client) {
append(client.getApplicationName() + " disconnected " );
}
public void die(IvyClient client, int id) {
f.dispose();
System.exit(0);
}
public void directMessage(IvyClient client, int id, String arg) {
append(client.getApplicationName() + " direct Message "+ id + arg );
}
class REGCB implements ActionListener, IvyMessageListener {
public void actionPerformed(ActionEvent e) {
try {
bus.unBindMsg(regexp_id);
} catch (IvyException ie) {
System.out.println("Big badaboum"); // this should not happen
}
regexp=tfRegex.getText();
regexp.trim();
regexp_id = bus.bindMsg(regexp,this);
tfRegex.setText("");
}
public void receive(IvyClient client, String[] args) {
String out="client " + client.getApplicationName() + " envoie: [ ";
for (int i=0;i