diff options
author | jestin | 2000-08-11 09:15:47 +0000 |
---|---|---|
committer | jestin | 2000-08-11 09:15:47 +0000 |
commit | a5ca9fd3f54783b7f9371d69574660f29fe0d10f (patch) | |
tree | 850cbfec003efde7a1a39085bb91d451265e9603 /src/TestIvySwing.java | |
parent | edeec74732762754557b61219ef52d4e8b105759 (diff) | |
download | ivy-java-a5ca9fd3f54783b7f9371d69574660f29fe0d10f.zip ivy-java-a5ca9fd3f54783b7f9371d69574660f29fe0d10f.tar.gz ivy-java-a5ca9fd3f54783b7f9371d69574660f29fe0d10f.tar.bz2 ivy-java-a5ca9fd3f54783b7f9371d69574660f29fe0d10f.tar.xz |
Probe is the java implementation of ivyprobe(1). It supports
the same syntax.
Diffstat (limited to 'src/TestIvySwing.java')
-rw-r--r-- | src/TestIvySwing.java | 120 |
1 files changed, 74 insertions, 46 deletions
diff --git a/src/TestIvySwing.java b/src/TestIvySwing.java index a6d3777..82afe43 100644 --- a/src/TestIvySwing.java +++ b/src/TestIvySwing.java @@ -4,30 +4,59 @@ import java.awt.BorderLayout; import java.awt.event.*; import javax.swing.* ; +/** + * 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 + * 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> + */ class TestIvySwing extends JPanel implements IvyApplicationListener { + + private static String version ="1.0.2"; private static int index; private static int nbTIS=0; - String localname; - - Ivy bus ; - String regexp = "^AIRCRAFT:";; - JLabel laRegex; - JTextArea ta ; - JTextField tfRegex, tfSend ; - JButton buApply, buSend, buClear ; - JComboBox ports; - int regexp_id; - REGCB reg; - - public TestIvySwing() throws IvyException { + private String localname; + private Ivy bus ; + private String regexp = "(.*)"; + private JLabel laRegex; + private JTextArea ta ; + private JTextField tfRegex, tfSend ; + private JButton buApply, buSend, buClear ; + private JComboBox ports; + private int regexp_id; + private REGCB reg; + private java.text.SimpleDateFormat format = new + java.text.SimpleDateFormat("hh:mm:ss"); + private static String[] startDomainList = { + "127.255.255.255:2010", + "10.192.36.255:2223", + "10.192.36.255:2333", + "10.192.36.255:2020", + "10.192.36.255:3110", + }; + private static java.util.Vector domainList; + + static { + // initialize the domainlist + domainList = new java.util.Vector(); + for (int i = 0; i<startDomainList.length;i++) + domainList.add(startDomainList[i]); + } + + public static void main(String[] args) throws IvyException {newTestIvy();} + + private TestIvySwing() throws IvyException { super(new BorderLayout()); nbTIS++; - // un textarea au centre ta = new JTextArea(25,40); ta.setEditable(false); add(new JScrollPane(ta),BorderLayout.CENTER); - // une zone regex au nord JPanel p = new JPanel(new BorderLayout()); p.add(new JLabel("Regex:"),BorderLayout.WEST); tfRegex = new JTextField(); @@ -35,14 +64,12 @@ class TestIvySwing extends JPanel implements IvyApplicationListener { p.add(tfRegex,BorderLayout.CENTER); p.add(laRegex=new JLabel(regexp),BorderLayout.EAST); add(p,BorderLayout.NORTH); - // une zone messages au sud du nord, mais au nord du centre JPanel p2 = new JPanel(new BorderLayout()); p2.add(new JLabel("Msg:"),BorderLayout.WEST); tfSend = new JTextField(""); tfSend.addActionListener(new SENDCB()); p2.add(tfSend,BorderLayout.CENTER); p.add(p2,BorderLayout.SOUTH); - // au sud, je rajoute un bouton pour spawner un autre testeur JButton tmpb ; (p = new JPanel()).add(tmpb=new JButton("spawn")); tmpb.addActionListener(new ActionListener() { @@ -57,31 +84,25 @@ class TestIvySwing extends JPanel implements IvyApplicationListener { ta.setText(""); } }); - ports=new JComboBox(); - ports.addItem("127.255.255.255:2010"); - ports.addItem("143.196.53.255:2010"); - ports.addItem("143.196.53.255:2020"); - ports.addItem("143.196.53.255:3110"); + ports.setEditable(true); + for (java.util.Enumeration e=domainList.elements();e.hasMoreElements();) { + ports.addItem((String) e.nextElement()); + } ports.addActionListener(new ComboCB()); p.add(ports); add(p,BorderLayout.SOUTH); - // gestion du fovus clavier tfRegex.setNextFocusableComponent(tfSend); tfSend.setNextFocusableComponent(tfRegex); tfSend.setRequestFocusEnabled(true); - localname = "TestIvySwing ("+index+")"; + localname = "TestIvySwing "+version+" ("+index+")"; index++; - bus = new Ivy(localname,localname+" prêt",this); + bus = new Ivy(localname,localname+" ready",this); regexp_id = bus.bindMsg(regexp,reg); bus.start(null); append( "Ivy Domain: "+ bus.getDomain(null) ); } - public String getLocalname(){ return localname;} - - public void stop() { bus.stop(); } - public void connect(IvyClient client) { append(client.getApplicationName() + " connected " ); } @@ -98,23 +119,31 @@ class TestIvySwing extends JPanel implements IvyApplicationListener { append(client.getApplicationName() + " direct Message "+ id + arg ); } - /* inner */ class ComboCB implements ActionListener { + private class ComboCB implements ActionListener { public void actionPerformed(ActionEvent e) { String newDomain=(String)ports.getSelectedItem(); + try { + append( "deconnexion from domain "+ bus.getDomain(null)); + } catch ( IvyException ie ) { + System.err.println("deconnexion failed"); + } bus.stop(); try { bus.start(newDomain); + append( "Ivy Domain: "+ newDomain ); } catch (IvyException ie ) { System.err.println("auuuugh "+newDomain); } } } // ComboCB - /* inner */ class REGCB implements ActionListener, IvyMessageListener { + private class REGCB implements ActionListener, IvyMessageListener { public void actionPerformed(ActionEvent e) { - // enlever l'ancienne regex - bus.unBindMsg(regexp_id); - // ajoute la nouvelle regex + try { + bus.unBindMsg(regexp_id); + } catch (IvyException ie) { + System.out.println("big badaboum"); // this cannot happen + } regexp=tfRegex.getText(); regexp.trim(); regexp_id = bus.bindMsg(regexp,this); @@ -131,7 +160,7 @@ class TestIvySwing extends JPanel implements IvyApplicationListener { } } - /* inner */ class SENDCB implements ActionListener { + private class SENDCB implements ActionListener { public void actionPerformed(ActionEvent e) { int count; String tosend = tfSend.getText(); @@ -143,31 +172,30 @@ class TestIvySwing extends JPanel implements IvyApplicationListener { } } - private void append(String s) { ta.append(s + "\n"); } - + private void append(String s) { + ta.insert("[" + format.format(new java.util.Date()) + "] "+ s + "\n",0); + } - public static void newTestIvy() throws IvyException { + private static void newTestIvy() throws IvyException { TestIvySwing tb = new TestIvySwing(); - JFrame f = new JFrame(tb.getLocalname()); + JFrame f = new JFrame(tb.localname); f.addWindowListener( tb.new WCCB(f,tb)) ; f.getContentPane().add(tb, BorderLayout.CENTER); f.pack(); f.setVisible(true); } - /* inner */ class WCCB extends WindowAdapter { + private class WCCB extends WindowAdapter { private JFrame f; public WCCB(JFrame f, TestIvySwing b) { this.f=f; } public void windowClosing(WindowEvent e) { bus.stop(); f.dispose(); + // I leave when the last TestIvySwing exits if (--nbTIS == 0) System.exit(0); - // je quitte l'appli au départ du dernier TIS } - public void windowActivated(WindowEvent e) { tfSend.grabFocus(); } - } // WCCB - - public static void main(String[] args) throws IvyException { newTestIvy(); } -} + public void windowActivated(WindowEvent e) {tfSend.grabFocus();} + } +} // class TestIvySwing // EOF |