aboutsummaryrefslogtreecommitdiff
path: root/src/TestIvy.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/TestIvy.java')
-rwxr-xr-xsrc/TestIvy.java115
1 files changed, 60 insertions, 55 deletions
diff --git a/src/TestIvy.java b/src/TestIvy.java
index 46f484d..27a6d08 100755
--- a/src/TestIvy.java
+++ b/src/TestIvy.java
@@ -3,46 +3,62 @@ package fr.dgac.ivy ;
import java.awt.* ;
import java.awt.event.* ;
-class TestIvy extends Panel implements IvyApplicationListener{
+/**
+ * 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 <a href="http://www.tls.cena.fr/products/ivy/">http://www.tls.cena.fr/products/ivy/</a>
+ */
+
+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;
- Ivy bus ;
- String regexp ;
- TextField tfRegex, tfSend ;
- TextArea ta ;
- Button buApply, buSend, buClear ;
- int regexp_id;
public TestIvy() throws IvyException {
super(new BorderLayout());
- regexp = "";
- // un textarea au centre
ta = new TextArea();
ta.setEditable(false);
add(ta,BorderLayout.CENTER);
- // une zone regex au nord
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);
- // une zone messages au sud
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("JAVA TESTBUS","Testbus ridi",this);
- bus.start(null);
- append( "Ivy Domain: "+ bus.getDomain(null) );
+ bus = new Ivy("JAVA TESTBUS","Testbus is ready",this);
+ bus.start(null);
+ append( "Ivy Domain: "+ bus.getDomain(null) );
+ }
+
+ public static void main(String[] args) throws IvyException {
+ TestIvy tb = new TestIvy();
+ Frame f = new Frame("TestIvy");
+ f.addWindowListener( tb.new WCCB(f,tb)) ;
+ f.add(tb, BorderLayout.CENTER);
+ f.pack();
+ f.setVisible(true);
}
- public void stop() {
- bus.stop();
- }
public void connect(IvyClient client) {
- append(client.getApplicationName() + " connected " );
+ append(client.getApplicationName() + " connected " );
}
+
public void disconnect(IvyClient client) {
append(client.getApplicationName() + " disconnected " );
}
@@ -52,64 +68,53 @@ class TestIvy extends Panel implements IvyApplicationListener{
public void directMessage(IvyClient client, int id, String arg) {
append(client.getApplicationName() + " direct Message "+ id + arg );
}
- /* inner */ class REGCB implements ActionListener, IvyMessageListener {
+
+ class REGCB implements ActionListener, IvyMessageListener {
public void actionPerformed(ActionEvent e) {
- // enlever l'ancienne regex
- bus.unBindMsg(regexp_id);
- // ajoute la nouvelle regex
- regexp=tfRegex.getText();
- regexp.trim();
+ 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("");
+ tfRegex.setText("");
+ }
+ public void receive(IvyClient client, String[] args) {
+ String out="client " + client.getApplicationName() + " envoie: [ ";
+ for (int i=0;i<args.length;i++)
+ out=out+args[i]+ ((i<args.length-1)?" , ":"");
+ out = out + " ]";
+ append(out);
}
- public void receive(IvyClient client, String[] args) {
- String out="client " + client.getApplicationName() + " envoie: [ ";
- for (int i=0;i<args.length;i++)
- out=out+args[i]+ ((i<args.length-1)?" , ":"");
- out = out + " ]";
- append(out);
- }
}
- /* inner */ class SENDCB implements ActionListener {
+ class SENDCB implements ActionListener {
public void actionPerformed(ActionEvent e) {
- int count;
+ int count;
String tosend = tfSend.getText();
tfSend.setText("");
count = bus.sendMsg(tosend);
- append("Sending '" + tosend + "' count " + count );
-
+ append("Sending '" + tosend + "' count " + count );
}
}
private void append(String s) {
- // je mettrais bien la date, aussi.
- ta.append(s + "\n");
- }
-
- public static void main(String[] args) throws IvyException {
- TestIvy tb = new TestIvy();
- Frame f = new Frame("TestIvy");
- f.addWindowListener( tb.new WCCB(f,tb)) ;
- f.add(tb, BorderLayout.CENTER);
- f.pack();
- f.setVisible(true);
+ ta.append("[" + format.format(new java.util.Date()) + "] "+ s + "\n");
}
- /* inner */ class WCCB extends WindowAdapter {
+ class WCCB extends WindowAdapter {
private Frame f;
- public WCCB(Frame f, TestIvy b) {
- this.f=f;
- }
+ public WCCB(Frame f, TestIvy b) { this.f=f; }
public void windowClosing(WindowEvent e) {
f.setVisible(false);
bus.stop();
- bus = null;
+ bus = null;
f.dispose();
- System.exit(0);
+ System.exit(0);
}
}
-}
-
+} // class TestIvy
// EOF