aboutsummaryrefslogtreecommitdiff
path: root/examples/TestIvy.java
diff options
context:
space:
mode:
authorjestin2002-12-30 13:06:40 +0000
committerjestin2002-12-30 13:06:40 +0000
commite126ac84a2d2415328989d0e084faeda42e303c8 (patch)
tree7724dfdd52714fcf2edec63c2c2e21d3600f51b1 /examples/TestIvy.java
parent4aa86fb6b7edab0406d4003eb2c5be378a87f982 (diff)
downloadivy-java-e126ac84a2d2415328989d0e084faeda42e303c8.zip
ivy-java-e126ac84a2d2415328989d0e084faeda42e303c8.tar.gz
ivy-java-e126ac84a2d2415328989d0e084faeda42e303c8.tar.bz2
ivy-java-e126ac84a2d2415328989d0e084faeda42e303c8.tar.xz
Cleanup.
Diffstat (limited to 'examples/TestIvy.java')
-rw-r--r--examples/TestIvy.java142
1 files changed, 56 insertions, 86 deletions
diff --git a/examples/TestIvy.java b/examples/TestIvy.java
index 7bbc99c..3ab0cc0 100644
--- a/examples/TestIvy.java
+++ b/examples/TestIvy.java
@@ -1,126 +1,96 @@
-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.
+ * TestIvy, an AWT Ivy Java program example.
+ *
+ * toy tool to probe the Ivy software bus it relies on the AWT, and is less useable than
+ * TestIvySwing, which should be preferred if swing is on your JDK.
*
- * @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>
+ * @see fr.dgac.ivy.TestIvySwing
+ *
+ * (c) CENA
*
- * CHANGELOG
- * 1.0.10:
- * - System.exit on bus die
*/
+import java.awt.* ;
+import java.awt.event.* ;
+import fr.dgac.ivy.*;
-class TestIvy extends Panel implements IvyApplicationListener {
+class TestIvy extends Frame implements IvyApplicationListener,IvyMessageListener {
+ public static String DEFAULTREGEXP = "(.*)";
private Ivy bus ;
private String regexp="";
+ private Label tfBound;
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 java.text.SimpleDateFormat format = new java.text.SimpleDateFormat("hh:mm:ss");
private int regexp_id;
public TestIvy() throws IvyException {
- super(new BorderLayout());
+ addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } });
+ setLayout(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);
+ add(p,BorderLayout.NORTH);
+ p.add(tfBound=new Label("Boung to: "+DEFAULTREGEXP),BorderLayout.WEST);
tfRegex = new TextField(regexp);
- tfRegex.addActionListener(new REGCB());
+ tfRegex.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ try { bus.unBindMsg(regexp_id); } catch (IvyException ie) {
+ System.out.println("Big badaboum"); // this should not happen
+ System.exit(0);
+ }
+ regexp=tfRegex.getText();
+ tfBound.setText("Bound to: " +regexp);
+ regexp.trim();
+ regexp_id = bus.bindMsg(regexp,TestIvy.this);
+ tfRegex.setText("");
+ pack();
+ }
+ });
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());
+ tfSend.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ int count;
+ String tosend = tfSend.getText();
+ tfSend.setText("");
+ count = bus.sendMsg(tosend);
+ append("Sending '" + tosend + "' count " + count );
+ }
+ });
p.add(tfSend,BorderLayout.CENTER);
add(p,BorderLayout.SOUTH);
bus = new Ivy("JAVATESTBUS","Testbus is ready",this);
- bus.start(null);
+ regexp_id = bus.bindMsg(DEFAULTREGEXP,this);
+ bus.start(Ivy.getDomain(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 " );
+ tb.pack();
+ tb.setVisible(true);
}
- public void disconnect(IvyClient client) {
- append(client.getApplicationName() + " disconnected " );
- }
- public void die(IvyClient client, int id) {
- f.dispose();
- System.exit(0);
- }
+ 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) { System.exit(0); }
public void directMessage(IvyClient client, int id, String arg) {
- append(client.getApplicationName() + " direct Message "+ id + 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<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+=args[i]+ ((i<args.length-1)?" , ":"");
+ out+= " ]";
+ append(out);
}
- class SENDCB implements ActionListener {
- public void actionPerformed(ActionEvent e) {
- int count;
- String tosend = tfSend.getText();
- tfSend.setText("");
- count = bus.sendMsg(tosend);
- append("Sending '" + tosend + "' count " + count );
- }
- }
-
- private void append(String s) {
- ta.append("[" + format.format(new java.util.Date()) + "] "+ s + "\n");
- }
-
- class WCCB extends WindowAdapter {
- private Frame f;
- public WCCB(Frame f, TestIvy b) { this.f=f; }
- public void windowClosing(WindowEvent e) {
- f.setVisible(false);
- bus.stop();
- bus = null;
- f.dispose();
- System.exit(0);
- }
- }
+ private void append(String s) { ta.append("[" + format.format(new java.util.Date()) + "] "+ s + "\n"); }
-} // class TestIvy
-// EOF
+}