aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjestin2002-03-06 13:23:00 +0000
committerjestin2002-03-06 13:23:00 +0000
commit5262e8e962f79cd7b238d36846ea352bb1ad341f (patch)
treef78e2b11a8058c922721c1b14cfcc076718c4420
parent07436a14bec3206aba4ee0874c0384b86ecda33d (diff)
downloadivy-java-5262e8e962f79cd7b238d36846ea352bb1ad341f.zip
ivy-java-5262e8e962f79cd7b238d36846ea352bb1ad341f.tar.gz
ivy-java-5262e8e962f79cd7b238d36846ea352bb1ad341f.tar.bz2
ivy-java-5262e8e962f79cd7b238d36846ea352bb1ad341f.tar.xz
Moved the Counter to examples.
-rw-r--r--src/Counter.java98
-rw-r--r--src/TestIvySwing.java6
2 files changed, 4 insertions, 100 deletions
diff --git a/src/Counter.java b/src/Counter.java
deleted file mode 100644
index 7e355db..0000000
--- a/src/Counter.java
+++ /dev/null
@@ -1,98 +0,0 @@
-/**
- * a software bus package geiger counter
- *
- * @author Yannick Jestin
- * @author <a href="http://www.tls.cena.fr/products/ivy/">http://www.tls.cena.fr/products/ivy/</a>
- *
- */
-package fr.dgac.ivy ;
-
-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
- * or on the bus.
- */
-public class Counter implements IvyMessageListener, Runnable {
-
- private Ivy bus ;
- private int[] secCount = new int[60];
- private int totalminute=0;
- private int totaldix=0;
- private int counter=0;
- private int moindix=secCount.length-10;
- private int moinune=1;
- private Thread thread;
- boolean isRunning=false;
- boolean quiet=false;
-
- public static final String helpmsg = "usage: java Counter -[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 Counter(String domain,boolean quiet) {
- this.quiet=quiet;
- for (int j=0;j<secCount.length;j++) {secCount[j]=0;}
- bus = new Ivy("Counter","Counter ready",null);
- bus.bindMsg(".*",this);
- bus.bindMsg("^EXHAUSTED$",new IvyMessageListener(){
- public void receive(IvyClient client,String[] args) {
- isRunning=false;
- }
- });
- thread = new Thread(this);
- isRunning=true;
- thread.start();
- try {
- bus.start(domain);
- } catch (IvyException ie) {
- ie.printStackTrace();
- }
- }
-
- // implements the Runnable interface
- public void run() {
- while (isRunning) {
- try {
- thread.sleep(1000);
- } catch (InterruptedException ie) {
- }
- totalminute+=secCount[counter]-secCount[moinune];
- totaldix+=secCount[counter]-secCount[moindix];
- String s = "MessageCount "+ secCount[counter]+" "+totaldix+" "+totalminute;
- if (!quiet) { System.out.println(s); }
- bus.sendMsg(s);
- moinune=(moinune+1)%secCount.length;
- moindix=(moindix+1)%secCount.length;
- counter=(counter+1)%secCount.length;
- secCount[counter]=0;
- }
- }
-
- public void receive(IvyClient client,String[] args) { secCount[counter]++; }
-
- public static void main(String[] args) {
- String domain="127.255.255.255:2010";
- Getopt opt = new Getopt("Counter",args,"b:dhq");
- int c;
- boolean quiet=false;
- while ((c=opt.getopt()) != -1 ) switch(c) {
- case 'q':
- quiet=true;
- break;
- case 'b':
- domain=opt.getOptarg();
- break;
- case 'd':
- System.setProperty("IVY_DEBUG","yesla!");
- break;
- case 'h':
- default:
- System.out.println(helpmsg);
- System.exit(0);
- }
- new Counter(domain,quiet);
- } // main
-
-} // class Counter
diff --git a/src/TestIvySwing.java b/src/TestIvySwing.java
index e5138f6..f3f2ae6 100644
--- a/src/TestIvySwing.java
+++ b/src/TestIvySwing.java
@@ -8,7 +8,7 @@ import gnu.getopt.Getopt ;
/**
* toy tool to probe the Ivy software bus.
* it relies on the Swing toolkit, which is not standard on jdk1.1 platform.
- * if yyou don't have jdk1.2 or swing, consider downloading it. You can also
+ * if you don't have jdk1.2 or swing, consider downloading it. You can also
* use TestIvy
*
* @see fr.dgac.ivy.TestIvy
@@ -22,6 +22,8 @@ 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 int WIDTH=30;
+ public static final int HEIGHT=30;
private static int index;
private static int nbTIS=0;
@@ -78,7 +80,7 @@ class TestIvySwing extends JPanel implements IvyApplicationListener {
super(new BorderLayout());
this.domain=domain;
nbTIS++;
- ta = new JTextArea(25,30);
+ ta = new JTextArea(WIDTH,HEIGHT);
ta.setEditable(false);
add(new JScrollPane(ta),BorderLayout.CENTER);
JPanel p = new JPanel(new BorderLayout());