aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/Counter.java3
-rw-r--r--examples/Makefile7
-rw-r--r--examples/TestIvySwing.java6
-rw-r--r--examples/Translate.java63
4 files changed, 72 insertions, 7 deletions
diff --git a/examples/Counter.java b/examples/Counter.java
index bc23938..1275101 100644
--- a/examples/Counter.java
+++ b/examples/Counter.java
@@ -4,11 +4,12 @@
* @author Yannick Jestin
* @author <a href="http://www.tls.cena.fr/products/ivy/">http://www.tls.cena.fr/products/ivy/</a>
*
+ * (c) CENA 1998-2002
+ *
*/
import fr.dgac.ivy.* ;
import gnu.getopt.Getopt ;
-
/**
* A program to count to the Ivy software bus messages.
* The class itself can be used to collect data and send them on the terminal
diff --git a/examples/Makefile b/examples/Makefile
index 2deae23..94aed89 100644
--- a/examples/Makefile
+++ b/examples/Makefile
@@ -1,8 +1,8 @@
# Be sure to set this before compiling ...
-JIKESPATH = /usr/lib/j2re1.3/lib/rt.jar:../lib/ivy-java.jar
+JIKESPATH = /usr/local/j2sdk1.4.1/jre/lib/rt.jar:/usr/share/java/repository:../lib/ivy-java.jar:nanoxml-2.2.1.jar:.
JAVACOPTS = -deprecation
.SUFFIXES: .java .class
- SRCS = TestIvy.java TestIvySwing.java Counter.java ivyTranslater.java
+ SRCS = TestIvy.java TestIvySwing.java Counter.java ivyTranslater.java Translate.java TranslateXML.java
OBJS = $(SRCS:.java=.class)
JAVAC = jikes -classpath $(JIKESPATH) -d .
#JAVAC = javac
@@ -14,3 +14,6 @@ all: $(OBJS)
clean:
/bin/rm -f -- $(OBJS) *~ *.bak *.class
+
+path:
+ @echo "setenv CLASSPATH $(JIKESPATH)"
diff --git a/examples/TestIvySwing.java b/examples/TestIvySwing.java
index ddc199d..582e8a1 100644
--- a/examples/TestIvySwing.java
+++ b/examples/TestIvySwing.java
@@ -11,7 +11,6 @@ import fr.dgac.ivy.*;
* use TestIvy
*
* @see fr.dgac.ivy.TestIvy
- * @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>
*/
@@ -20,7 +19,7 @@ class TestIvySwing extends JPanel implements IvyApplicationListener {
/**
* help message for the standalone program
*/
- public static final String helpmsg = "usage: java fr.dgac.ivy.TestIvySwing [options]\n\t-b BUS\tspecifies the Ivy bus domain\n\t-q\tquiet, no tty output\n\t-d\tdebug\n\t-h\thelp\n";
+ public static final String helpmsg = "usage: java TestIvySwing [options]\n\t-b BUS\tspecifies the Ivy bus domain\n\t-q\tquiet, no tty output\n\t-d\tdebug\n\t-h\thelp\n";
public static final int WIDTH=30;
public static final int HEIGHT=30;
@@ -235,5 +234,4 @@ class TestIvySwing extends JPanel implements IvyApplicationListener {
}
}
-} // class TestIvySwing
-// EOF
+}
diff --git a/examples/Translate.java b/examples/Translate.java
new file mode 100644
index 0000000..dee8210
--- /dev/null
+++ b/examples/Translate.java
@@ -0,0 +1,63 @@
+import fr.dgac.ivy.* ;
+import java.io.* ;
+import gnu.regexp.* ;
+
+class Translate {
+
+ private Ivy bus;
+
+ Translate(String filename) {
+ bus = new Ivy("Translater","Hello le monde",null);
+ parseFile(filename);
+ bus.bindMsg("^Bye$",new IvyMessageListener() {
+ // callback for "Bye" message
+ public void receive(IvyClient client, String[] args) {System.exit(0);}
+ });
+ try {
+ // starts the bus on the default domain or IVY_DOMAIN property
+ bus.start(null);
+ } catch (IvyException ie) {
+ System.err.println("can't run the Ivy bus" + ie.getMessage());
+ }
+ }
+
+ private void parseFile(String filename) {
+ try {
+ BufferedReader in = new BufferedReader(new FileReader(new File(filename)));
+ String s;
+ RE regexp;
+ regexp = new RE("\"([^\"]*)\" \"([^\"]*)\"");
+ while ( (s=in.readLine()) != null ) {
+ REMatch result = regexp.getMatch(s);
+ bus.bindMsg(result.toString(1),new TALK(result.toString(2)));
+ }
+ in.close();
+ } catch (REException ree) {
+ System.out.println("regexp error");
+ System.exit(-1);
+ } catch (FileNotFoundException fnfe) {
+ System.out.println("file "+filename+" not found. Good bye !");
+ System.exit(-1);
+ } catch (IOException ioe) {
+ System.out.println("error reading "+filename+". Good bye !");
+ System.exit(-1);
+ }
+ }
+
+ private class TALK implements IvyMessageListener {
+ private String go;
+ TALK(String s) {go=s;}
+ public void receive(IvyClient client, String[] args) {
+ bus.sendMsg(go);
+ }
+ }
+
+ // callback associated to the "Hello" messages"
+ public void receive(IvyClient client, String[] args) {
+ bus.sendMsg("Bonjour"+((args.length>0)?args[0]:""));
+ }
+
+ public static void main(String args[]) {
+ new Translate("translation.txt");
+ }
+}